forked from kartik-v/yii2-tree-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
100 lines (89 loc) · 2.6 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015
* @package yii2-tree
* @version 1.0.3
*/
namespace kartik\tree;
use Yii;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
/**
* The tree management module for Yii Framework 2.0.
*
* @author Kartik Visweswaran <[email protected]>
* @since 1.0
*/
class Module extends \kartik\base\Module
{
const MODULE = 'treemanager';
const NODE_MANAGE = 'manage';
const NODE_REMOVE = 'remove';
const NODE_MOVE = 'move';
const NODE_SAVE = 'save';
const VIEW_PART_1 = 1;
const VIEW_PART_2 = 2;
const VIEW_PART_3 = 3;
const VIEW_PART_4 = 4;
const VIEW_PART_5 = 5;
/**
* @var array the configuration of nested set attributes structure
*/
public $treeStructure = [];
/**
* @var array the configuration of additional data attributes
* for the tree
*/
public $dataStructure = [];
/**
* @var array the default configuration settings for the tree view widget
*/
public $treeViewSettings = [
'nodeView' => '@kvtree/views/_form',
'nodeAddlViews' => [
self::VIEW_PART_1 => '',
self::VIEW_PART_2 => '',
self::VIEW_PART_3 => '',
self::VIEW_PART_4 => '',
self::VIEW_PART_5 => '',
]
];
/**
* @var array the list of asset bundles that would be unset when rendering
* the node detail form via ajax
*/
public $unsetAjaxBundles = [
'yii\web\YiiAsset',
'yii\web\JqueryAsset',
'yii\widgets\ActiveFormAsset',
'yii\validators\ValidationAsset'
];
/**
* @inherit doc
*/
public function init()
{
$this->_msgCat = 'kvtree';
parent::init();
$this->treeStructure += [
'treeAttribute' => 'root',
'leftAttribute' => 'lft',
'rightAttribute' => 'rgt',
'depthAttribute' => 'lvl',
];
$this->dataStructure += [
'keyAttribute' => 'id',
'nameAttribute' => 'name',
'iconAttribute' => 'icon',
'iconTypeAttribute' => 'icon_type'
];
$nodeActions = ArrayHelper::getValue($this->treeViewSettings, 'nodeActions', []);
$nodeActions += [
self::NODE_MANAGE => Url::to(['/treemanager/node/manage']),
self::NODE_SAVE => Url::to(['/treemanager/node/save']),
self::NODE_REMOVE => Url::to(['/treemanager/node/remove']),
self::NODE_MOVE => Url::to(['/treemanager/node/move']),
];
$this->treeViewSettings['nodeActions'] = $nodeActions;
}
}