-
Notifications
You must be signed in to change notification settings - Fork 0
/
AjaxDropdown.php
56 lines (48 loc) · 1.18 KB
/
AjaxDropdown.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
<?php
/**
* @author chervand <chervand@gmail.com>
*/
namespace chervand\bootstrap;
use yii\bootstrap\Dropdown;
use yii\helpers\Json;
/**
* Class AjaxDropdown
* @package chervand\bootstrap
*/
class AjaxDropdown extends Dropdown
{
public $ajaxOptions = [];
public $confirm;
public $itemSelector;
/**
* @inheritdoc
* @return string
*/
public function run()
{
$id = $this->options['id'];
$options = $this->getClientOptions();
$options = empty($options) ? '' : Json::htmlEncode($options);
$view = &$this->getView();
Yii2BootstrapAsset::register($view);
$view->registerJs("jQuery('#$id').ajaxDropdown($options);");
return parent::run();
}
/**
* @return array client script options
*/
protected function getClientOptions()
{
$options = [];
if ($this->ajaxOptions) {
$options['ajaxOptions'] = $this->ajaxOptions;
}
if ($this->itemSelector) {
$options['itemSelector'] = $this->itemSelector;
}
if ($this->confirm) {
$options['confirm'] = $this->confirm;
}
return $options;
}
}