1 | <?php |
||
23 | class ToggleColumn extends DataColumn |
||
24 | { |
||
25 | /** |
||
26 | * @var int the value to check against `On` state. |
||
27 | */ |
||
28 | public $onValue = 1; |
||
29 | /** |
||
30 | * @var string the label for the toggle button. Defaults to "Check". |
||
31 | * Note that the label will not be HTML-encoded when rendering. |
||
32 | */ |
||
33 | public $onLabel; |
||
34 | /** |
||
35 | * @var string the label for the toggle button. Defaults to "Uncheck". |
||
36 | * Note that the label will not be HTML-encoded when rendering. |
||
37 | */ |
||
38 | public $offLabel; |
||
39 | /** |
||
40 | * @var string the label for the NULL value toggle button. Defaults to "Not Set". |
||
41 | * Note that the label will not be HTML-encoded when rendering. |
||
42 | */ |
||
43 | public $emptyLabel; |
||
44 | /** |
||
45 | * @var string the glyph icon toggle button "checked" state. |
||
46 | * You may set this property to be false to render a text link instead. |
||
47 | */ |
||
48 | public $onIcon = 'glyphicon glyphicon-ok-circle'; |
||
49 | /** |
||
50 | * @var string the glyph icon toggle button "unchecked" state. |
||
51 | * You may set this property to be false to render a text link instead. |
||
52 | */ |
||
53 | public $offIcon = 'glyphicon glyphicon-remove-circle'; |
||
54 | /** |
||
55 | * @var string the glyph icon toggle button "empty" state (example for null value) |
||
56 | */ |
||
57 | public $emptyIcon = 'glyphicon glyphicon-question-sign'; |
||
58 | /** |
||
59 | * @var boolean display button with text or only icon with label tooltip |
||
60 | */ |
||
61 | public $asText = false; |
||
62 | /** |
||
63 | * @var string Name of the action to call and toggle values. Defaults to `toggle`. |
||
64 | * @see [[ToggleAction]] for an easy way to use with your controller |
||
65 | */ |
||
66 | public $url = ['toggle']; |
||
67 | /** |
||
68 | * @var string a javascript function that will be invoked after the toggle ajax call. |
||
69 | * |
||
70 | * The function signature is `function(success, data)`. |
||
71 | * |
||
72 | * - success: status of the ajax call, true if the ajax call was successful, false if the ajax call failed. |
||
73 | * - data: the data returned by the server in case of a successful call or XHR object in case of error. |
||
74 | * |
||
75 | * Note that if success is true it does not mean that the delete was successful, it only means that the ajax call |
||
76 | * was successful. |
||
77 | * |
||
78 | * Example: |
||
79 | * |
||
80 | * ``` |
||
81 | * [ |
||
82 | * 'class'=> ToggleColumn::className(), |
||
83 | * 'afterToggle'=>'function(success, data){ if (success) alert("Toggled successfully"); }', |
||
84 | * ], |
||
85 | * ``` |
||
86 | */ |
||
87 | public $afterToggle; |
||
88 | /** |
||
89 | * @var string suffix substituted to a name class of the tag <a> |
||
90 | */ |
||
91 | public $classSuffix; |
||
92 | |||
93 | /** |
||
94 | * @inheritdoc |
||
95 | * @throws \yii\base\InvalidConfigException |
||
96 | */ |
||
97 | public function init() |
||
112 | |||
113 | /** |
||
114 | * @inheritdoc |
||
115 | */ |
||
116 | public function renderDataCell($model, $key, $index) |
||
127 | |||
128 | /** |
||
129 | * @inheritdoc |
||
130 | */ |
||
131 | protected function renderDataCellContent($model, $key, $index) |
||
164 | |||
165 | /** |
||
166 | * @param $value |
||
167 | * |
||
168 | * @return string |
||
169 | */ |
||
170 | protected function getToggleText($value) |
||
174 | |||
175 | /** |
||
176 | * Registers the required scripts for the toggle column to work properly |
||
177 | */ |
||
178 | protected function registerClientScript() |
||
199 | } |
||
200 |