1 | <?php |
||
18 | class TreeWidget extends Widget |
||
19 | { |
||
20 | |||
21 | const TREE_TYPE_ADJACENCY = 'adjacency'; |
||
22 | const TREE_TYPE_NESTED_SET = 'nested-set'; |
||
23 | |||
24 | public $treeType = self::TREE_TYPE_ADJACENCY; |
||
25 | /** |
||
26 | * @var array Enabled jsTree plugins |
||
27 | * @see http://www.jstree.com/plugins/ |
||
28 | */ |
||
29 | public $plugins = [ |
||
30 | 'wholerow', |
||
31 | 'contextmenu', |
||
32 | 'dnd', |
||
33 | 'types', |
||
34 | 'state', |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * @var array Configuration for types plugin |
||
39 | * @see http://www.jstree.com/api/#/?f=$.jstree.defaults.types |
||
40 | */ |
||
41 | public $types = [ |
||
42 | 'show' => [ |
||
43 | 'icon' => 'fa fa-file-o', |
||
44 | ], |
||
45 | 'list' => [ |
||
46 | 'icon' => 'fa fa-list', |
||
47 | ], |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * Context menu actions configuration. |
||
52 | * @var array |
||
53 | */ |
||
54 | public $contextMenuItems = []; |
||
55 | |||
56 | /** |
||
57 | * Various options for jsTree plugin. Will be merged with default options. |
||
58 | * @var array |
||
59 | */ |
||
60 | public $options = []; |
||
61 | |||
62 | /** |
||
63 | * Route to action which returns json data for tree |
||
64 | * @var array |
||
65 | */ |
||
66 | public $treeDataRoute = null; |
||
67 | |||
68 | /** |
||
69 | * Translation category for Yii::t() which will be applied to labels. |
||
70 | * If translation is not needed - use false. |
||
71 | */ |
||
72 | public $menuLabelsTranslationCategory = 'app'; |
||
73 | |||
74 | /** |
||
75 | * JsExpression for action(callback function) on double click. You can use JsExpression or make custom expression. |
||
76 | * Warning! Callback function differs from native jsTree function - it consumes only one attribute - node(similar to contextmenu action). |
||
|
|||
77 | * Use false if no action needed. |
||
78 | * @var bool|JsExpression |
||
79 | */ |
||
80 | public $doubleClickAction = false; |
||
81 | |||
82 | /** @var bool|array route to change parent action (applicable to Adjacency List only) */ |
||
83 | public $changeParentAction = false; |
||
84 | |||
85 | /** @var bool|array route to reorder action */ |
||
86 | public $reorderAction = false; |
||
87 | |||
88 | /** @var bool plugin config option for allow multiple nodes selections or not */ |
||
89 | public $multiSelect = false; |
||
90 | |||
91 | /** |
||
92 | * @inheritdoc |
||
93 | */ |
||
94 | public function init() |
||
99 | |||
100 | public static function registerTranslations() |
||
107 | |||
108 | /** |
||
109 | * @inheritdoc |
||
110 | */ |
||
111 | public function run() |
||
168 | |||
169 | /** |
||
170 | * @return array |
||
171 | */ |
||
172 | private function contextMenuOptions() |
||
191 | |||
192 | /** |
||
193 | * Prepares js according to given tree type |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | private function prepareJs() |
||
206 | |||
207 | /** |
||
208 | * @return string |
||
209 | */ |
||
210 | private function adjacencyJs() |
||
263 | |||
264 | /** |
||
265 | * @return string |
||
266 | */ |
||
267 | private function nestedSetJs() |
||
303 | } |
||
304 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.