/** * Load fiter model by PK. * @param type $id * @return GridViewFilter */ protected function _loadModel($id) { return GridViewFilter::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'id' => $id)); }
/** * Insert dropdown menu html code. */ public function insertDropdownHtml() { $filters = GridViewFilter::model()->findAllByAttributes(array('grid_id' => $this->getId(), 'user_id' => Yii::app()->user->id)); $filtersHtml = ''; if ($filters) { $filtersHtml .= CHtml::openTag('hr'); foreach ($filters as $filter) { $filtersHtml .= strtr(' <li id="SGridViewFilter_' . $filter->id . '"> <div style="clear:both;"> <div style="float:left;"> <a href="#" onClick="return loadSGridViewFilterById(\'{gridId}\',{filterId})">{name}</a> </div> <div style="float:right;"> {delete} </div> </div> </li>', array('{name}' => CHtml::encode($filter->name), '{gridId}' => $this->getId(), '{filterId}' => $filter->id, '{delete}' => CHtml::ajaxLink(CHtml::image($this->baseScriptUrl . '/cross.png', Yii::t('SGridView.core', 'Удалить')), Yii::app()->createUrl('core/admin/gridView/deleteFilter', array('id' => $filter->id)), array('success' => "js:function(){\$('#SGridViewFilter_{$filter->id}').remove();}"), array('confirm' => Yii::t('SGridView.core', 'Вы действительно хотите удалить этот фильтр?'), 'id' => 'fdLink' . $filter->id)))); } } echo strtr(' <div class="gridViewOptions"> </div> <div class="gridViewOptionsMenu"> <ul> <li> <a href="#" onClick="clearSGridViewFilter(\'' . $this->getId() . '\');">' . Yii::t('SGridView.core', 'Очистить фильтр') . '</a> </li> <li>{saveLink}</li> ' . $filtersHtml . ' </ul> </div>', array('{saveLink}' => $this->_checkAttributes() ? '<a href="#" onClick="$(\'#' . $this->getId() . 'saveFilterDialog\').dialog(\'open\');">' . Yii::t('SGridView.core', 'Сохранить фильтр') . '</a>' : '<a class="nonActive">' . Yii::t('SGridView.core', 'Сохранить фильтр') . '</a>')); echo CHtml::openTag('div', array('id' => $this->getId() . 'saveFilterDialog', 'data-token' => Yii::app()->request->csrfToken)); echo ' <div class="form"> <div class="row"> <input type="text" id="' . $this->getId() . 'FilterBox" maxlength="255"> <div class="hint">' . Yii::t('SGridView.core', 'Укажите имя фильтра') . '</div> </div> </div> '; echo CHtml::closeTag('div'); Yii::app()->getClientScript()->registerScript('grid-modal-' . $this->getId(), 'initializeSaveFilterModal("' . $this->getId() . '");', CClientScript::POS_READY); }