示例#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});");
 }
示例#2
0
    function parseConfirmButton($id)
    {
        $button = $this->buttons[$id];
        if (!isset($this->buttons[$id]['click'])) {
            $confirmation = "if(!confirm(" . MJavaScript::encode(isset($button['confirm']) ? $button['confirm'] : '确定执行?') . ")) return false;";
            $csrf = '';
            $after = 'function(){}';
            $funcNam = str_replace('-', '_', 'gridFunc' . $this->grid->id . $id);
            $this->buttons[$id]['click'] = <<<EOD
                function {$funcNam}() {
                    {$confirmation}
                    var th = this,
                        afterFunc = {$after};
                    console.log('do confirm')
                    console.log(this)
                    jQuery('#{$this->grid->id}').yiiGridView('update', {
                        type: 'POST',
                        url: jQuery(this).data('href'),{$csrf}
                        success: function(data) {
                            jQuery('#{$this->grid->id}').yiiGridView('update');
                            afterFunc(th, true, data);
                        },
                        error: function(XHR) {
                            return afterFunc(th, false, XHR);
                        }
                    });
                    return false;
                }
EOD;
            $this->buttons[$id]['clickFunc'] = $funcNam;
            app()->controller->appendScript($funcNam, $this->buttons[$id]['click']);
        }
    }