예제 #1
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     $module = TreeView::module();
     $keyAttribute = $nameAttribute = $leftAttribute = $rightAttribute = $depthAttribute = null;
     $treeAttribute = $iconAttribute = $iconTypeAttribute = null;
     extract($module->treeStructure + $module->dataStructure);
     $labels = [$keyAttribute => Yii::t('kvtree', 'ID'), $nameAttribute => Yii::t('kvtree', 'Name'), $leftAttribute => Yii::t('kvtree', 'Left'), $rightAttribute => Yii::t('kvtree', 'Right'), $depthAttribute => Yii::t('kvtree', 'Depth'), $iconAttribute => Yii::t('kvtree', 'Icon'), $iconTypeAttribute => Yii::t('kvtree', 'Icon Type'), 'active' => Yii::t('kvtree', 'Active'), 'selected' => Yii::t('kvtree', 'Selected'), 'disabled' => Yii::t('kvtree', 'Disabled'), 'readonly' => Yii::t('kvtree', 'Read Only'), 'visible' => Yii::t('kvtree', 'Visible'), 'collapsed' => Yii::t('kvtree', 'Collapsed'), 'movable_u' => Yii::t('kvtree', 'Movable Up'), 'movable_d' => Yii::t('kvtree', 'Movable Down'), 'movable_l' => Yii::t('kvtree', 'Movable Left'), 'movable_r' => Yii::t('kvtree', 'Movable Right'), 'removable' => Yii::t('kvtree', 'Removable'), 'code' => Yii::t('kvtree', 'Code'), 'removable_all' => Yii::t('kvtree', 'Removable (with children)')];
     if (!$treeAttribute) {
         $labels[$treeAttribute] = Yii::t('kvtree', 'Root');
     }
     return $labels;
 }
예제 #2
0
 /**
  * Generate and return the breadcrumbs for the node
  *
  * @param int $depth the breadcrumbs parent depth
  * @param string $glue the pattern to separate the breadcrumbs
  * @param string $currNodeCss the CSS class to be set for current node
  * @param string $untitled the name to be displayed for a new node
  *
  * @return string the parsed breadcrumbs
  */
 public function getBreadcrumbs($depth = 1, $glue = ' » ', $currNodeCss = 'kv-crumb-active', $untitled = 'Untitled')
 {
     /**
      * @var Tree $this
      */
     if ($this->isNewRecord || empty($this)) {
         return $currNodeCss ? Html::tag('span', $untitled, ['class' => $currNodeCss]) : $untitled;
     }
     $depth = empty($depth) ? null : intval($depth);
     $module = TreeView::module();
     $nameAttribute = ArrayHelper::getValue($module->dataStructure, 'nameAttribute', 'name');
     $crumbNodes = $depth === null ? $this->parents()->all() : $this->parents($depth - 1)->all();
     $crumbNodes[] = $this;
     $i = 1;
     $len = count($crumbNodes);
     $crumbs = [];
     foreach ($crumbNodes as $node) {
         $name = $node->{$nameAttribute};
         if ($i === $len && $currNodeCss) {
             $name = Html::tag('span', $name, ['class' => $currNodeCss]);
         }
         $crumbs[] = $name;
         $i++;
     }
     return implode($glue, $crumbs);
 }
예제 #3
0
 * SECTION 1: Initialize node view params & setup helper methods.
 */
extract($params);
$isAdmin = $isAdmin == true || $isAdmin === "true";
// admin mode flag
$inputOpts = [];
// readonly/disabled input options for node
$flagOptions = ['class' => 'kv-parent-flag'];
// node options for parent/child
// parse parent key
if (empty($parentKey)) {
    $parent = $node->parents(1)->one();
    $parentKey = empty($parent) ? '' : Html::getAttributeValue($parent, $keyAttribute);
}
// get module and setup form
$module = TreeView::module();
// the treemanager module
$formOptions['id'] = 'kv-' . uniqid();
$form = ActiveForm::begin(['action' => $action, 'options' => $formOptions]);
//default code
if ($node->isNewRecord and $parentKey != 'root') {
    $parentObj = $modelClass::findOne($parentKey);
    $node->code = $parentObj->code;
}
// the primary key input field
if ($showIDAttribute) {
    $options = ['readonly' => true];
    if ($node->isNewRecord) {
        $options['value'] = Yii::t('kvtree', '(new)');
    }
    $keyField = $form->field($node, $keyAttribute)->textInput($options);
예제 #4
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 = '\\jaclise\\tree\\models\\Tree';
     $isAdmin = $softDelete = $showFormButtons = $showIDAttribute = false;
     $currUrl = $nodeView = $formOptions = $formAction = $breadCrumbs = $nodeSelected = '';
     $iconsList = $nodeAddlViews = [];
     extract(static::getPostData());
     /**
      * @var Tree $modelClass
      * @var Tree $node
      */
     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) ? [] : $formOptions, 'modelClass' => $modelClass, 'currUrl' => $currUrl, 'isAdmin' => $isAdmin, 'iconsList' => $iconsList, 'softDelete' => $softDelete, 'showFormButtons' => $showFormButtons, 'showIDAttribute' => $showIDAttribute, 'nodeView' => $nodeView, 'nodeAddlViews' => $nodeAddlViews, 'nodeSelected' => $nodeSelected, 'breadcrumbs' => empty($breadcrumbs) ? [] : $breadcrumbs];
     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);
 }