<?php echo str_repeat(' ', $category['level']), $category['name']; ?> </option> <?php } ?> <?php } ?> </select> <?php $assetsDir = Yii::app()->basePath; $labels = BanersElements::model()->attributeLabels(); $this->widget('bootstrap.widgets.TbExtendedGridView', array('id' => 'baners-grid', 'template' => "{items}\n{pager}", 'enableHistory' => true, 'htmlOptions' => array('class' => 'content_table'), 'dataProvider' => $provider, 'filter' => $model, 'bulkActions' => array('actionButtons' => $this->bulkRemoveButton(), 'checkBoxColumnConfig' => array('name' => 'id')), 'columns' => array('id', array('header' => 'Картинка', 'name' => "image", 'type' => 'raw', 'value' => function ($dataProvider) { return '<img src="' . $dataProvider->getImageLink('admin', true) . '" style="width:80px" />'; }, 'filter' => ''), 'name', array('name' => "parent_id", 'value' => '$data->parent->name'), array('header' => 'Статус', 'name' => "status", 'type' => 'raw', 'value' => function ($data) { return ' <a href="#" class="on-off-product" data-id="' . $data->id . '" data-status="' . $data->status . '"> <div style="margin-left:20px; width: 13px; height: 13px; border-radius: 3px; background:' . ($data->status == 1 ? 'green' : 'red') . '"></div> </a> '; }, 'filter' => ''), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update} {delete}', 'buttons' => array('update' => array('label' => yii::t('Bootstrap', 'PHRASE.UPDATE'), 'url' => 'CHtml::normalizeUrl(array("update", "id" => $data->id))', 'options' => array()), 'delete' => array('label' => yii::t('Bootstrap', 'PHRASE.DELETE'), 'options' => array())), 'htmlOptions' => array('style' => 'white-space: nowrap'))))); ?> <div id="ajax_loader" style="display: none;"><img width="40px;" style="position:absolute; margin-top:10px; margin-left:-40px;" src="/images/admin/ajaxloader.gif"></div> <div class="buttons"> <a class="btn btn-primary" style="margin-top:14px; float:left; margin-left:15px" href="/admin/<?php echo Yii::app()->controller->module->id;
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = BanersElements::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionAjax() { if (isset($_POST)) { switch ((int) $_POST['type']) { case 1: //Смена статуса $model = $this->loadModel((int) $_POST['id']); $model->status = $model->status == 1 ? 0 : 1; $model->save(); //Меняем статус для вопросов foreach (BanersElements::model()->findAll('parent_id = ' . $model->id) as $data) { $data->status = $model->status; $data->save(); } break; } echo CJavaScript::jsonEncode('ok'); } Yii::app()->end(); }