/**
  * @inheritdoc
  */
 public function run()
 {
     //register assets
     $this->registerPlugin('button');
     AjaxToggleButtonAsset::register($this->getView());
     //prepare ajax params
     $params = [];
     foreach ($this->model->primaryKey() as $pkCol) {
         $params[$pkCol] = $this->model->{$pkCol};
     }
     Html::addCssClass($this->options, 'widget-ajax-button');
     if ($this->model->{$this->booleanAttribute}) {
         Html::removeCssClass($this->options, $this->buttonClassOff);
         Html::addCssClass($this->options, $this->buttonClassOn);
     } else {
         Html::removeCssClass($this->options, $this->buttonClassOn);
         Html::addCssClass($this->options, $this->buttonClassOff);
     }
     $this->options['data']['current-value'] = $this->model->{$this->booleanAttribute};
     $this->options['data']['pjax'] = 0;
     $this->options['data']['boolean-format'] = $this->booleanFormat;
     $this->options['data']['ajax-params'] = $params;
     $this->options['data']['ajax-method'] = $this->ajaxMethod;
     $this->options['data']['event-success'] = $this->jsEventSuccess;
     $this->options['data']['event-error'] = $this->jsEventError;
     $this->options['data']['class-on'] = $this->buttonClassOn;
     $this->options['data']['class-off'] = $this->buttonClassOff;
     return Html::a($this->createLabel(), $this->ajaxUrl, $this->options);
 }
Example #2
0
 /**
  * @return self
  */
 public function noBlock()
 {
     Html::removeCssClass($this->options, self::BTN_BLOCK);
     return $this;
 }