Ejemplo n.º 1
0
 /**
  * View, create, or update a tree node via ajax
  *
  * @return string json encoded response
  */
 public function actionManage()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     static::checkValidRequest();
     $parentKey = $action = null;
     $modelClass = 'Category';
     $isAdmin = $softDelete = $showFormButtons = $showIDAttribute = false;
     $currUrl = $nodeView = $formOptions = $formAction = '';
     $iconsList = $nodeAddlViews = [];
     extract(static::getPostData());
     if (!isset($id) || empty($id)) {
         $node = new $modelClass();
         $node->initDefaults();
     } else {
         $node = $modelClass::findOne($id);
     }
     $module = TreeView::module();
     $params = $module->treeStructure + $module->dataStructure + ['node' => $node, 'parentKey' => $parentKey, 'action' => $formAction, 'formOptions' => empty($formOptions) ? [] : Json::decode($formOptions), 'modelClass' => $modelClass, 'currUrl' => $currUrl, 'isAdmin' => $isAdmin, 'iconsList' => $iconsList, 'softDelete' => $softDelete, 'showFormButtons' => $showFormButtons, 'showIDAttribute' => $showIDAttribute, 'nodeView' => $nodeView, 'nodeAddlViews' => $nodeAddlViews];
     if (!empty($module->unsetAjaxBundles)) {
         Event::on(View::className(), View::EVENT_AFTER_RENDER, function ($e) use($module) {
             foreach ($module->unsetAjaxBundles as $bundle) {
                 unset($e->sender->assetBundles[$bundle]);
             }
         });
     }
     $callback = function () use($nodeView, $params) {
         return $this->renderAjax($nodeView, ['params' => $params]);
     };
     return self::process($callback, Yii::t('kvtree', 'Error while viewing the node. Please try again later.'), null);
 }