Esempio n. 1
0
<?php

use common\widgets\Alert;
use frontend\helper\StatusHelper;
use kartik\sortable\Sortable;
use kartik\switchinput\SwitchInput;
use yii\helpers\Html;
use yii\widgets\Pjax;
/* @var $modelAll frontend\models\Category */
$this->title = 'Категории';
$this->params['breadcrumbs'][] = $this->title;
$list = [];
/** @var \frontend\models\Category $model */
foreach ($modelAll as $model) {
    $switch = SwitchInput::widget(['name' => 'status_' . $model->id, 'value' => StatusHelper::getValueForHtml($model->status), 'options' => ['class' => 'switchInputCategory'], 'pluginOptions' => ['onText' => 'Отображать', 'offText' => 'Скрыть', 'onColor' => 'success', 'offColor' => 'danger', 'size' => 'small'], 'pluginEvents' => ["switchChange.bootstrapSwitch" => 'function(event, state) {
                                                    $.ajax({
                                                            url: "' . Yii::$app->urlManager->createUrl(["category/hidden-category", 'id' => $model->id]) . '",
                                                            type: "post",
                                                            data: {"value": +state},
                                                            cache: false,
                                                            success: function(data) {}
                                                    });
                                                }']]);
    $remove = '';
    if (!isset($model->base_category_id)) {
        $remove = Html::a('', Yii::$app->urlManager->createUrl(['category/remove', 'id' => $model->id]), ['class' => 'btn btn-danger glyphicon glyphicon-remove management-help', 'data-pjax' => 'false', 'data' => ['confirm' => 'Вы уверены, что хотите удалить категорию?', 'method' => 'post']]);
    }
    $list[] = ['content' => '
                        <div class="col-md-8">' . $model->title . '</div>
                        <div class="col-md-2">' . $switch . '</div>
                        <div class="col-md-2">' . Html::a('', Yii::$app->urlManager->createUrl(['category/edit', 'id' => $model->id]), ['class' => 'btn btn-info glyphicon glyphicon-pencil management-help', 'data-pjax' => 'false']) . $remove . '</div>', 'options' => ['data-icat' => $model->id]];
 /**
  * @param integer $id
  * @return mixed
  */
 public function actionHiddenCategory($id)
 {
     $model = $this->findModel($id);
     $model->status = StatusHelper::getChangeStatus($model->status);
     if ($model->save()) {
         return true;
     } else {
         return false;
     }
 }