2017 © Pedro Peláez
 

yii2-widget yii2-jstree

jsTree Manager Plugin for Yii2

image

coderovich/yii2-jstree

jsTree Manager Plugin for Yii2

  • Thursday, February 15, 2018
  • by coderovich
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

jsTree Manager for Yii2

Виджет для управления деревом для моделей Nested Tree., (*1)

Набор Yii2 Behavior для хранения деревьев в БД и их совместного использования

https://habrahabr.ru/post/266155/, (*2)

Nested Behaviors

https://github.com/paulzi/yii2-materialized-path, (*3)

https://github.com/paulzi/yii2-adjacency-list, (*4)

https://github.com/paulzi/yii2-nested-sets, (*5)

https://github.com/paulzi/yii2-nested-intervals, (*6)

How to use this extension

Добавить в модель, (*7)

const NODE_NAME = "nodeName";
# Your custom item renderer, named like get+self::NODE_NAME
public function getNodeName() {
    return "<strong>" . $this->name . "</strong>";
}

Добавить в контроллер, (*8)

public function actions() {
    $modelClass = 'app\models\TreeModel';
    return [
        'moveNode'   => [
            'class'      => 'coderovich\jsTree\actions\MoveNodeAction',
            'modelClass' => $modelClass,
        ],
        'deleteNode' => [
            'class'      => 'coderovich\jsTree\actions\DeleteNodeAction',
            'modelClass' => $modelClass,
        ],
        'updateNode' => [
            'class'      => 'coderovich\jsTree\actions\UpdateNodeAction',
            'modelClass' => $modelClass,
        ],
        'createNode' => [
            'class'      => 'coderovich\jsTree\actions\CreateNodeAction',
            'modelClass' => $modelClass,
        ],
        'fetchTree'  => [
            'class'      => 'coderovich\jsTree\actions\FetchTreeAction',
            'modelClass' => $modelClass,
            # Максимально возможное число уровней в дереве. Опционально.
            # Callable  
            "maxDepth"   => function ( $node ) {
                /** @var \app\models\TreeModel $node */
                return $node->depth < 2;
            }
        ],
    ];
}

Добавить в представление, (*9)

use coderovich\jsTree\JsTree;

echo JsTree::widget([
    'modelClass' => '\app\models\TreeModel',
    'core'    => [
    "themes" => [ "stripes" => true ],
    ],
    'contextmenu' => [
    "items_top"=>new \yii\web\JsExpression( '{"assoc": {
    "separator_before": false,
    "separator_after": false,
    "label": "My Label",
    "title": "My Label",
    "_disabled":function(){
    return node.text.match(/disable_me_by_some_js_behavior_if_needed/i);
    },
    "action": function (obj) {
    window.location = "'.\yii\helpers\Url::to(['update']).'?id="+node.id
    }
    }}' )
    ],

    'plugins' => [ "changed", "state", 'types', 'dnd', 'contextmenu', 'sort' ,'wholerow'],
    //...
    ]); 

Изменить вызов ActiveForm в _form.php, (*10)

<div class="region-form">
    <?php $form = yii\widgets\ActiveForm::begin( [
        "enableAjaxValidation"   => false,
        "enableClientValidation" => true,
        "options"                => [ "id"=>"JsTreeDialogForm",'role' => "form" ]
    ] );
    ?>
    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
    <?php ActiveForm::end(); ?>
</div>

Проблемы

Если не отображается Context меню, то проверить z-index в своей верстке..., (*11)

The Versions

15/02 2018

dev-master

9999999-dev https://github.com/coderovich/yii2-jstree

jsTree Manager Plugin for Yii2

  Sources   Download

MIT

The Requires

 

yii2 widget editor nested sets nestable materialized path

11/02 2018

1.0.5

1.0.5.0 https://github.com/coderovich/yii2-jstree

jsTree Manager Plugin for Yii2

  Sources   Download

MIT

The Requires

 

yii2 widget editor nested sets nestable materialized path

11/02 2018

1.0.4

1.0.4.0 https://github.com/coderovich/yii2-jstree

jsTree Manager Plug for Yii2

  Sources   Download

MIT

The Requires

 

yii2 widget editor nested sets nestable materialized path

11/02 2018

1.0.3

1.0.3.0 https://github.com/coderovich/yii2-jstree

jsTree Manager Plug for Yii2

  Sources   Download

MIT

The Requires

 

yii2 widget editor nested sets nestable materialized path

11/02 2018

1.0.2

1.0.2.0 https://github.com/coderovich/yii2-jstree

jsTree Manager Plugin for Yii2

  Sources   Download

MIT

The Requires

 

yii2 widget editor nested sets nestable materialized path

11/02 2018

1.0.1

1.0.1.0 https://github.com/coderovich/yii2-jstree

jsTree Manager Plugin for Yii 2

  Sources   Download

MIT

The Requires

 

yii2 widget editor nested sets nestable

11/02 2018

1.0

1.0.0.0 https://github.com/coderovich/yii2-jstree

jsTree Manager Plugin for Yii 2

  Sources   Download

MIT

The Requires

 

yii2 widget editor nested sets nestable