Esempio n. 1
0
 function __construct($opts)
 {
     if (!($model = MMap::getValue($opts, 'model'))) {
         throw new Exception('no model for list display');
     }
     $this->model = $model;
     $this->opts = $opts;
     $columns = array();
     if (isset($opts['columns'])) {
         foreach ($opts['columns'] as $k => $v) {
             if ('buttons' === $k) {
                 !$v && ($v = array());
                 $v = array_merge($v, array('grid' => $this));
                 $this->buttons = new MButton($v);
                 continue;
             } else {
                 if (is_array($v)) {
                     $columns[$v[0]] = array_slice($v, 1);
                 } else {
                     $columns[$v] = array();
                 }
             }
         }
     }
     $this->columns = $columns;
     $options = array('url' => app()->controller->getRequest()->uri, 'ajaxType' => 'GET', 'ajaxUpdate' => array($this->id), 'pageVar' => $this->pagerVar(), 'ajaxVar' => $this->ajaxVar, 'pagerClass' => 'pagination', 'loadingClass' => 'grid-view-loading', 'filterClass' => 'filters', 'tableClass' => 'items table table-hover', 'selectableRows' => 1, 'enableHistory' => false, 'updateSelector' => '{page}, {sort}', 'filterSelector' => '{filter}');
     $options = MJavaScript::encode($options);
     app()->controller->appendScript(__CLASS__ . '#' . $this->getId(), "jQuery('#{$this->id}').yiiGridView({$options});");
 }
Esempio n. 2
0
 /**
  * @param $model
  * @param $attribute
  * @param $htmlOptions
  * @return array
  */
 protected static function activeControlBefore($model, $attribute, $htmlOptions)
 {
     $modelClass = get_class($model);
     $controlOptions = MMap::getValue($htmlOptions, 'controlOptions');
     $labelOptions = MMap::getValue($htmlOptions, 'labelOptions');
     $classL = MMap::getValue($labelOptions, 'class');
     $id = MMap::getValue($htmlOptions, 'id');
     !$id && ($id = self::id($model, $attribute));
     $class = MMap::getValue($controlOptions, 'class');
     $class .= ' ' . 'data-' . $class;
     $uniqid = uniqid();
     $labelAttr = $model->label($attribute);
     $labelAttr = t($labelAttr);
     $value = $model->{$attribute};
     return array($modelClass, $classL, $id, $class, $uniqid, $labelAttr, $value);
 }