-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJQTree.php
69 lines (56 loc) · 1.74 KB
/
JQTree.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
<?php
namespace forecho\jqtree;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\bootstrap\Widget;
class JQTree extends Widget
{
public static $theme = 'forecho\jqtree\JQTreeAssets';
public $url;
public $data = [];
public $htmlOptions;
public $dragAndDrop;
public $selectable;
public $saveState;
public $dataUrl;
public $autoOpen;
public $autoEscape;
public $onCanSelectNode;
public $onCreateLi;
public $onIsMoveHandle;
public $onCanMove;
public $onCanMoveTo;
public function run()
{
$view = $this->getView();
/** @var \yii\web\AssetBundle $asset */
$asset = static::$theme;
$asset::register($view);
if (isset($this->htmlOptions['id']))
$id = $this->htmlOptions['id'];
else
$id = $this->htmlOptions['id'] = $this->getId();
if ($this->url !== null)
$this->url = Html::normalizeUrl($this->url);
$options = $this->getClientOptions();
$options = $options === [] ? '{}' : JSON::encode($options);
$js = "$('#$id').tree({$options});";
$view->registerJs($js);
echo Html::tag('ul', '', $this->htmlOptions)."\n";
}
/**
* @return array the javascript options
*/
protected function getClientOptions()
{
$options = $this->options;
$availableOptions = ['data', 'id', 'dragAndDrop', 'saveState', 'dataUrl', 'autoOpen', 'selectable', 'autoEscape',
'onCanSelectNode', 'onCreateLi', 'onIsMoveHandle', 'onCanMove', 'onCanMoveTo'];
foreach ($availableOptions as $name) {
if ($this->$name !== null)
$options[$name] = $this->$name;
}
return $options;
}
}