public function build($view = '') { $this->initJsWidget(); $view == '' and $view = 'rapyd::datatree'; $this->open = Form::open($this->attributes); $this->close = Form::hidden('save', 1) . Form::close(); // we save on POST and only if the widget's own input variable is filled // because sometimes we have more than a tree widget on the same page // but just one save if (\Request::method() == 'POST' && \Input::get($this->name)) { $this->lockAndSave(); } $this->data = $this->source->find($this->source->getKey())->getDescendants()->toHierarchy(); Persistence::save(); $this->rows = $this->makeRowsRecursive($this->data); return \View::make($view, array('dg' => $this, 'buttons' => $this->button_container, 'label' => $this->label)); }
/** * Show the Dashboard. * * @return Response */ public function getIndex() { $id = \Input::get('id') ?: null; $name = \Input::get('column_name') ? explode(',', \Input::get('column_name')) : null; $tableName = \Input::get('table_name') ?: null; $moduleName = \Input::get('name') ?: null; $output = array(); // Instantiate model $modelName = studly_case(str_singular($tableName)); $model = '\\Orangehill\\Photon\\' . $modelName; if (!class_exists($model)) { $model = '\\' . $modelName; } $this->modelInstance = new $model(); if (is_null($id)) { // Get roots $entries = $this->modelInstance->roots()->get(); } else { // Get parent by id $parent = $this->modelInstance->find($id); // Get children $entries = $parent->children()->get(); } foreach ($entries as $entry) { $node = array(); // Check if entry name is from one to many relation // $entry->$name = $this->checkOneToManyRelation($name, $entry); if ($name === null) { $entryName = (string) $entry; } else { $entryNameElements = array(); array_walk($name, function ($value) use(&$entry, &$entryNameElements) { $entryNameElements[] = $entry->{$value}; }); $entryName = join(' ', $entryNameElements); } $node['data'] = array('title' => $entryName, 'attr' => array('href' => '/admin/' . $moduleName . '/' . $entry->id)); $node['attr'] = array('data-module-name' => $moduleName, 'id' => $moduleName . '_' . $entry->id); if (count($entry->children()->get())) { $node['state'] = 'closed'; } $output[] = $node; } return \Response::json($output); }
/** * Deletes a single field via ajax call (used to delete an image without deleting entire entry) * * @return object */ public function deleteField() { // Get the values $id = \Input::get('id'); $column_name = \Input::get('column_name'); // Get the entry record $entry = $this->modelInstance->find($id); // Remove the file $module_storage_path = \public_path() . '/media/' . $this->data['module']->table_name; \File::delete($module_storage_path . '/' . $entry[$column_name]); // Set selected field to null $entry[$column_name] = null; // Save entry $entry->save(); // Render the view return \Response::json(array('Success')); }
/** * Get Root node * * @return root model */ public function getRootNode() { return parent::find(1); }