-
Notifications
You must be signed in to change notification settings - Fork 2
/
TreeView.php
78 lines (65 loc) · 1.86 KB
/
TreeView.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
<?php
namespace lesha724\bootstraptree;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\JsExpression;
use yii\web\View;
/**
* This is just an example.
*/
class TreeView extends \yii\base\Widget
{
public static $autoIdPrefix = 'wbtreeview_';
/**
* @var array additional HTML attributes that will be rendered in the div tag.
*/
public $htmlOptions=[];
/**
* @var array additional options that can be passed to the constructor of the treeview js object.
*/
public $options=[];
/**
* @var array additional options that can be passed to the constructor of the treeview js object.
*/
public $events=[];
protected $_id;
public function init(){
parent::init();
if(isset($this->htmlOptions['id']))
$this->_id=$this->htmlOptions['id'];
else
$this->_id=$this->htmlOptions['id']=$this->getId();
}
public function run()
{
parent::run(); // TODO: Change the autogenerated stub
$view = $this->getView();
TreeViewAsset::register($view);
$options = $this->_getEventsOptions();
$options=$options===[]?'{}' : Json::encode($options);
$view->registerJs('$("#' . $this->_id . '").treeview( ' .$options .')', View::POS_READY);
return $this->_runWidget();
}
/**
* @return array the javascript options
*/
protected function _getEventsOptions()
{
$options=$this->options;
foreach($this->events as $key=>$event)
{
$options[$key]=$_function = new JsExpression($event);
}
return $options;
}
/**
* Вывод виджета
* @return string html widget
*/
protected function _runWidget()
{
$html = Html::beginTag('div',$this->htmlOptions);
$html .= Html::endTag('div');
return $html;
}
}