Exemplo n.º 1
0
    /**
     *
     */
    public function registerClientScript()
    {
        parent::registerClientScript();
        if ($this->multiActions || $this->gridActions || $this->gridButtons) {
            Yii::app()->clientScript->registerScriptFile(Yii::app()->dressing->getAssetsUrl() . '/js/jquery.form.js');
            // put the url from the button into the form action
            // handle submit form to capture the response into a modal
            Yii::app()->controller->beginWidget('dressing.widgets.YdJavaScriptWidget', array('position' => CClientScript::POS_END));
            ?>
            <script type="text/javascript">
                var modalRemote = $('#modal-remote');

                // handle multiActions
                $('#<?php 
            echo $this->id;
            ?>
-form').on('change', '.multi-actions', function () {
                    var checked = false;
                    var action = $('#<?php 
            echo $this->id;
            ?>
-form').attr('action');
                    var url = $(this).val();
                    $(this).val('');
                    if (url) {
                        $('.select-on-check').each(function () {
                            if ($(this).is(':checked'))
                                checked = true;
                        });
                        if (checked) {
                            setupGridViewAjaxForm();
                            $('#<?php 
            echo $this->id;
            ?>
-form').attr('action', url).submit();
                        }
                        else {
                            alert('<?php 
            echo Yii::t('dressing', 'No rows selected.');
            ?>
');
                        }
                    }
                });

                // handle gridActions
                $('#<?php 
            echo $this->id;
            ?>
-form').on('change', '.grid-actions', function () {
                    var action = $('#<?php 
            echo $this->id;
            ?>
-form').attr('action');
                    var url = $(this).val();
                    $(this).val('');
                    if (url) {
                        setupGridViewAjaxForm();
                        $('#<?php 
            echo $this->id;
            ?>
-form').attr('action', url).submit();
                    }
                });

                // handle gridButtons
                $('#<?php 
            echo $this->id;
            ?>
-form').on('click', '.gridButton', function () {
                    var action = $('#<?php 
            echo $this->id;
            ?>
-form').attr('action');
                    var url = $(this).val();
                    $(this).val('');
                    if (url) {
                        $('#<?php 
            echo $this->id;
            ?>
-form').attr('action', url).submit();
                    }
                });

                // handle form submission
                function setupGridViewAjaxForm() {
                    $('#<?php 
            echo $this->id;
            ?>
-form').ajaxForm({
                        beforeSubmit: function (response) {
                            if (!modalRemote.length) modalRemote = $('<div class="modal hide fade" id="modal-remote"></div>');
                            modalRemote.modalResponsiveFix();
                            modalRemote.touchScroll();
                            modalRemote.html('<div class="modal-header"><h3><?php 
            echo Yii::t('dressing', 'Loading...');
            ?>
</h3></div><div class="modal-body"><div class="modal-remote-indicator"></div>').modal();
                        },
                        success: function (response) {
                            modalRemote.html(response);
                            $(window).resize();
                            $('#modal-remote input:text:visible:first').focus();
                        },
                        error: function (response) {
                            modalRemote.children('.modal-header').html('<button type="button" class="close" data-dismiss="modal"><i class="icon-remove"></i></button><h3><?php 
            echo Yii::t('dressing', 'Error!');
            ?>
</h3>');
                            modalRemote.children('.modal-body').html(response);
                        }
                    });
                }
            </script>
            <?php 
            Yii::app()->controller->endWidget();
        }
    }
Exemplo n.º 2
0
 /**
  * Registers necessary client scripts.
  */
 public function registerClientScript()
 {
     //Call parent
     parent::registerClientScript();
     if ($this->enableDragDropSorting === true) {
         $cs = Yii::app()->getClientScript();
         //Register jquery-ui
         $cs->registerCoreScript('jquery.ui');
         //Register sort script
         $cs->registerScript(__CLASS__ . '-' . $this->id, $this->getSortScript() . '
         $("body").ajaxSuccess(function(e, xhr, settings) {
            if (settings.url === $.fn.yiiGridView.getUrl(' . Cjavascript::encode($this->getId()) . ')) {
               ' . $this->getSortScript() . '
            }
         });
   ');
     }
 }
Exemplo n.º 3
0
 /**
  * injects ajaxUpdate event into widget
  *
  * @param TbGridView $widget
  */
 public static function attachAjaxUpdateEvent($widget)
 {
     $trigger = '$("#' . $widget->id . '").trigger("ajaxUpdate.editable");';
     //check if trigger already inserted by another column
     if (strpos($widget->afterAjaxUpdate, $trigger) !== false) {
         return;
     }
     //inserting trigger
     if (strlen($widget->afterAjaxUpdate)) {
         $orig = $widget->afterAjaxUpdate;
         if (strpos($orig, 'js:') === 0) {
             $orig = substr($orig, 3);
         }
         $orig = "\n({$orig}).apply(this, arguments);";
     } else {
         $orig = '';
     }
     $widget->afterAjaxUpdate = "js: function(id, data) {\n            {$trigger} {$orig}\n        }";
     $widget->registerClientScript();
 }
Exemplo n.º 4
0
 /**
  * Изначально регистрируются 2 плагина gridBase и grid
  * Если установить значение свойства jsPlugin, то подключится так же плагин /css/admin/gridview/grid.js
  * И на сам grid будет инициализироват плагин с названием из jsPlugin
  */
 public function registerClientScript()
 {
     parent::registerClientScript();
     $cs = Yii::app()->clientScript;
     $cs->registerCoreScript('jquery.ui');
     $cs->registerScriptFile("/js/plugins/gridview/gridBase.js");
     $cs->registerScriptFile("/js/plugins/gridview/grid.js");
     $options = CJavaScript::encode(array('mass_removal' => $this->mass_removal, 'filter_hint' => $this->filter_hint));
     $cs->registerScript($this->getId() . '.grid', "\r\n            \$('#{$this->getId()}').grid({$options});\r\n        ");
     $this->onRegisterScript(new CEvent());
 }