146 if ($this->name === null) {
147 throw new CException(Yii::t(
149 '"{attribute}" attribute cannot be empty.',
150 array(
'{attribute}' =>
"name")
163 if ($this->checkedButtonLabel === null) {
164 $this->checkedButtonLabel = Yii::t(
'zii',
'Uncheck');
166 if ($this->uncheckedButtonLabel === null) {
167 $this->uncheckedButtonLabel = Yii::t(
'zii',
'Check');
169 if ($this->emptyButtonLabel === null) {
170 $this->emptyButtonLabel = Yii::t(
'zii',
'Not set');
173 $this->button = array(
174 'url' =>
'Yii::app()->controller->createUrl("' . $this->toggleAction .
'",array("pk"=>$data->primaryKey,"attribute"=>"' . $this->name .
'"))',
175 'htmlOptions' => array(
'class' => $this->name .
'_toggle' . $this->uniqueClassSuffix),
178 if (Yii::app()->request->enableCsrfValidation) {
179 $csrfTokenName = Yii::app()->request->csrfTokenName;
180 $csrfToken = Yii::app()->request->csrfToken;
181 $csrf =
"\n\t\tdata:{ '$csrfTokenName':'$csrfToken' },";
186 if ($this->afterToggle === null) {
187 $this->afterToggle =
'function(){}';
190 $this->button[
'click'] =
"js:
193 var afterToggle={$this->afterToggle};
194 $.fn.yiiGridView.update('{$this->grid->id}', {
196 url:$(this).attr('href'),{$csrf}
197 success:function(data) {
198 $.fn.yiiGridView.update('{$this->grid->id}');
199 afterToggle(true, data);
202 afterToggle(false,XHR);
216 $function = CJavaScript::encode($this->button[
'click']);
217 unset($this->button[
'click']);
218 $class = preg_replace(
'/\s+/',
'.', $this->button[
'htmlOptions'][
'class']);
219 $js[] =
"$(document).on('click','#{$this->grid->id} a.{$class}',$function);";
221 if ($js !== array()) {
222 Yii::app()->getClientScript()->registerScript(__CLASS__ .
'#' . $this->
id, implode(
"\n", $js));
235 $checked = ($this->
value === null)
237 : $this->evaluateExpression($this->
value, array(
'data' =>
$data,
'row' => $row));
241 $button[
'url'] = isset(
$button[
'url']) ? $this->evaluateExpression(
243 array(
'data' =>
$data,
'row' => $row)
246 if (!$this->displayText) {
248 if (!isset(
$button[
'htmlOptions'][
'data-toggle'])) {
249 $button[
'htmlOptions'][
'data-toggle'] =
'tooltip';
251 echo CHtml::link(
'<span class="glyphicon glyphicon-' .
$button[
'icon'] .
'"></span>',
$button[
'url'],
$button[
'htmlOptions']);
254 $button[
'class'] =
'booster.widgets.TbButton';
255 $widget = Yii::createComponent(
$button);