2017 © Pedro Peláez
 

yii2-extension yii2-tree-manager

Yii2 widget for manage tree using fancytree

image

kr0lik/yii2-tree-manager

Yii2 widget for manage tree using fancytree

  • Wednesday, April 25, 2018
  • by kr0lik
  • Repository
  • 1 Watchers
  • 1 Stars
  • 16 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

yii2-tree-manager

Yii2 tree manager using fancytree library., (*1)

This extension can add/delete/move branches of tree and quick edit branch fields., (*2)

Tree manager example, (*3)

Tree select example, (*4)

Installation

The preferred way to install this extension is through composer., (*5)

Either run, (*6)

composer require --prefer-dist kr0lik/yii2-tree-manager

to the require section of your composer.json file., (*7)

Description

Extension will install fancytree library, yii2-jquery, yii2-jqueryui and yii2-bootstrap., (*8)

You can with any tree extensions, just implement kr0lik\tree\contracts\TreeModelInterface, (*9)

Required fileds in model: id., (*10)

Usage

First implement kr0lik\tree\contracts\TreeModelInterface in Model., (*11)

Tree Manager

Add kr0lik\tree\TreeManagerAction into controller., (*12)

Required options: * treeModelClass - tree model class., (*13)

Optional: * bsVersion: int - Bootstrap version. Default 3. * formViewPath - Path to form view. * formNameField - Field with name of node. Default: name. * formFields - Array of additional edit fields (ex: body or description). It can be string or callable. * formLinks - Array of links (ex: link to view page or edit page). It can be string or callable., (*14)

Example:, (*15)

 [
                'class' => TreeManagerAction::class,
                'treeModelClass' => YourActiveRecord::class,
                'formNameField' => 'title',
                'formFields' => [
                    'description',
                    function (ActiveForm $form, YourActiveRecord $model) {
                        return $form->field($model, 'body')->textarea();
                    },
                ],
                'formLinks' => [
                    function (YourActiveRecord $model) {
                        return Html::a('View', ['/url/to/view', 'id' => $model->id], ['class' => 'btn btn-sm btn-info']);
                    },
                ]
            ]
        ];
    }
}
```

Add `kr0lik\tree\TreeManagerWidget` into view.

Required options:
* pathAction - Url to tree model backend action.

Optional:
* bsVersion: int - Bootstrap version. Default 3.
* treeOptions: array - Container tag options.
* multipleRoots: bool - Allow multiple roots. Default: false.
* activeId: int - ID active node by default.
* dndEnable: bool - for dissable drag and drop set null or false. Default: true.
* viewPath - path to view of manager.
* firstRootActivateDefault - Activate first root on load if no activeId. Default: true.
* buttons - Array of additional buttons(as Html).

```php


= TreeManagerWidget::widget([
    'pathAction' => 'url/to/YourController/tree/action',
]) ?>

Events:, (*16)

$(document).on('treeFormAfterLoade', function (event, form, node) {

});
$(document).on('treeFormAfterSubmit', function (event, form, node) {

});
$(document).on('treeElementAfterMove', function (event, targetNode, hitNode) {

});
$(document).on('treeElementAfterRemove', function (event, node) {

});
$(document).on('treeFormAfterReset', function (event, node) {

});

Tree Input

Add kr0lik\tree\TreeAction into controller., (*17)

Required options: * treeModelClass - tree model class., (*18)

Example:, (*19)

 [
                'class' => TreeAction::class,
                'treeModelClass' => YourActiveRecord::class,
            ]
        ];
    }
}
```

Add `kr0lik\tree\TreeInput` into view.

Required options:
* pathAction - Url to tree model backend action.

Optional:
* bsVersion: int - Bootstrap version. Default 3.
* treeOptions: array - Container tag options.
* leavesOnly: bool - Select only endpoint nodes. Default: true.
* multiple: bool - Select multiple nodes. Default: false.
* options: array - input options.
* viewPath: string - path to view of input.
* collapse: bool - collapse tree. Default: true.

Example:
```php


= $form->field($model, 'field')->widget(TreeInput::class, [
    'pathAction' => 'url/to/YourController/tree/action',
]) ?>

Events:, (*20)

$(document).on('treeInputChange', function (event, selections) {

});

Tree Relations Input

Add kr0lik\tree\TreeRelationAction into controller., (*21)

Required options: * treeModelClass - tree model class. * relationModelClass - tree relaion model class., (*22)

Example:, (*23)

 [
                'class' => TreeRelationAction::class,
                'treeModelClass' => YourTreeActiveRecord::class,
                'relationModelClass' => YourRelationActiveRecord::class,
            ]
        ];
    }
}
```

Add `kr0lik\tree\TreeRelationInput` into view.

Required options:
* pathAction - Url to tree model backend action.

Optional:
* bsVersion: int - Bootstrap version. Default 3.
* treeOptions: array - Container tag options.
* leavesOnly: bool - Select only endpoint nodes. Default: true.
* multiple: bool - Select multiple nodes. Default: false.
* options: array - input options.
* viewPath: string - path to view of input.
* collapse: bool - collapse tree. Default: true.

Example:
```php


= $form->field($model, 'field')->widget(TreeRelationInput::class, [
    'pathAction' => 'url/to/YourController/tree/action',
]) ?>

Events:, (*24)

$(document).on('treeInputChange', function (event, selections) {

});

Internationalization

All text and messages introduced in this extension are translatable under category 'kr0lik.tree'. You may use translations provided within this extension, using following application configuration:, (*25)

return [
    'components' => [
        'i18n' => [
            'translations' => [
                'kr0lik.tree' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@kr0lik/tree/messages',
                ],
                // ...
            ],
        ],
        // ...
    ],
    // ...
];

Global bootstrap version

You can specify bootstrap version for tree-manager globaly by adding bsVersion option in yii params (e.g. config/params.php):, (*26)

'params' => [
    'bsVersion' => 4,
    // other settings
],
// ...

The Versions

25/04 2018

dev-master

9999999-dev

Yii2 widget for manage tree using fancytree

  Sources   Download

MIT

The Requires

 

by krolik

postgresql postgres yii2 jquery bootstrap ajax tree fancytree jqueryui ltree nestedsets treemanager

25/04 2018

1.0.0

1.0.0.0

Yii2 widget for manage tree using fancytree

  Sources   Download

MIT

The Requires

 

by krolik

postgresql postgres yii2 jquery bootstrap ajax tree fancytree jqueryui ltree nestedsets treemanager

27/11 2017

1.1

1.1.0.0

Yii2 widget for manage tree using fancytree

  Sources   Download

MIT

The Requires

 

by krolik

postgresql postgres yii2 jquery bootstrap ajax tree fancytree jqueryui ltree nestedsets treemanager