-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathButtonSingle.php
83 lines (70 loc) · 1.61 KB
/
ButtonSingle.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
<?php
namespace integready\bulkactionscheckboxcolumn;
use yii\base\Widget;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\View;
class ButtonSingle extends Widget
{
/**
* @var string
*/
public $label;
/**
* @var string
*/
public $selectorName = 'updateStatusIds';
/**
* @var string
*/
public $gridId = 'gridview-index';
/**
* @var string
*/
public $buttonClass = 'btn';
/**
* @var array
*/
public $buttonOptions = [];
/**
* @var string
*/
public $customJs;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->registerAssets();
}
/**
* @return bool|string
*/
public function run()
{
return Html::button($this->label, ArrayHelper::merge([
'id' => 'single-' . $this->selectorName,
'class' => $this->buttonClass,
'data-selector' => $this->selectorName,
], $this->buttonOptions));
}
/**
* Registers the needed assets
*/
public function registerAssets()
{
$view = $this->getView();
ButtonSingleAsset::register($view);
$options = [
'selectorName' => $this->selectorName,
];
$view->registerJs("$(document).on('buttonSingle:click', " . $this->customJs . ");", View::POS_LOAD);
$view->registerJs(
'window.yiiOptionsSingle = ' . Json::htmlEncode($options),
View::POS_HEAD,
'yiiOptionsSingle_' . $this->gridId
);
}
}