Parcourir la source

#204 preserve grid state (such as filter and paginate) after actions

Alex Trofimov il y a 11 ans
Parent
commit
49de0220ed

+ 26 - 10
inc/js/classes/BxDolGrid.js

@@ -281,15 +281,23 @@ BxDolGrid.prototype.reload = function (iStart, iPerPage) {
 BxDolGrid.prototype._getActionDataForReload = function (iStart, iPerPage) {
     var oData = {};
 
-    if (typeof(iStart) != 'undefined')
+    if (typeof(iStart) != 'undefined') {
         oData[this._oOptions.paginate_get_start] = iStart;
-    else
+        this._oOptions.start = iStart;
+    } 
+    else {
         oData[this._oOptions.paginate_get_start] = this._oOptions.start;
+    }
 
-    if (typeof(iPerPage) != 'undefined')
-        oData[this._oOptions.paginate_get_per_page] = iPerPage;
-    else
-        oData[this._oOptions.paginate_get_per_page] = this._oOptions.per_page;
+    if (this._oOptions.paginate_get_per_page.length) {
+        if (typeof(iPerPage) != 'undefined') {
+            oData[this._oOptions.paginate_get_per_page] = iPerPage;
+            this._oOptions.per_page = iPerPage;
+        }
+        else {
+            oData[this._oOptions.paginate_get_per_page] = this._oOptions.per_page;
+        }
+    }
 
     return oData;
 }
@@ -320,7 +328,9 @@ BxDolGrid.prototype._bindActionsSingle = function (eElement) {
         var sAction = $(this).attr('bx_grid_action_single');
         var sActionConfirm = $(this).attr('bx_grid_action_confirm');
         var sActionData = $(this).attr('bx_grid_action_data');
-        $this.actionWithId (sActionData, sAction, {}, '', false, sActionConfirm);
+        var iActionResetPaginate = parseInt($(this).attr('bx_grid_action_reset_paginate'));
+        var oData = iActionResetPaginate ? {} : $this._getActionDataForReload();
+        $this.actionWithId (sActionData, sAction, oData, '', false, sActionConfirm);
     });
 
 }
@@ -334,7 +344,9 @@ BxDolGrid.prototype._bindActions = function (isSkipSearchInput) {
         var sAction = $(this).attr('bx_grid_action_bulk');
         var sActionConfirm = $(this).attr('bx_grid_action_confirm');
         var sActionData = $(this).attr('bx_grid_action_data');
-        $this.actionWithSelected (sActionData, sAction, {}, '', false, sActionConfirm);
+        var iActionResetPaginate = parseInt($(this).attr('bx_grid_action_reset_paginate'));
+        var oData = iActionResetPaginate ? {} : $this._getActionDataForReload();
+        $this.actionWithSelected (sActionData, sAction, oData, '', false, sActionConfirm);
     });
 
     this._bindActionsSingle ();
@@ -345,7 +357,9 @@ BxDolGrid.prototype._bindActions = function (isSkipSearchInput) {
         var sAction = $(this).attr('bx_grid_action_single');
         var sActionConfirm = $(this).attr('bx_grid_action_confirm');
         var sActionData = $(this).attr('bx_grid_action_data');
-        $this.actionWithId (sActionData, sAction, {checked:this.checked ? 1 : 0}, '', false, sActionConfirm);
+        var iActionResetPaginate = parseInt($(this).attr('bx_grid_action_reset_paginate'));
+        var oData = iActionResetPaginate ? {} : $this._getActionDataForReload();
+        $this.actionWithId (sActionData, sAction, $.extend({}, oData, {checked:this.checked ? 1 : 0}), '', false, sActionConfirm);
     });
 
     if (typeof(isSkipSearchInput) == 'undefined' || false == isSkipSearchInput) {
@@ -355,7 +369,9 @@ BxDolGrid.prototype._bindActions = function (isSkipSearchInput) {
                 return;
             var sAction = $(this).attr('bx_grid_action_independent');
             var sActionConfirm = $(this).attr('bx_grid_action_confirm');
-            $this.action (sAction, {}, '', false, sActionConfirm);
+            var iActionResetPaginate = parseInt($(this).attr('bx_grid_action_reset_paginate'));
+            var oData = iActionResetPaginate ? {} : $this._getActionDataForReload();
+            $this.action (sAction, oData, '', false, sActionConfirm);
         });    
 
         jQuery('#bx-grid-search-' + this._sObject).bind({

+ 5 - 4
samples/BxGridMy.php

@@ -111,8 +111,9 @@ class BxGridMy extends BxTemplGrid
         $aForm = array(
             'form_attrs' => array(
                 'id' => 'sample-add-form',
-                'action' => 'grid.php?o=' . $this->_sObject . '&a=' . $sAction, // grid.php is usiversal actions handler file, we need to pass object and action names to it at least
+                'action' => 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r')), // grid.php is usiversal actions handler file, we need to pass object and action names to it at least, or just all the params to preserve such states like filter and paginate
                 'method' => 'post',
+                'class' => 'bx-def-margin-bottom',
             ),
             'params' => array (
                 'db' => array(
@@ -176,7 +177,7 @@ class BxGridMy extends BxTemplGrid
                         'name' => 'close',
                         'value' => _t('Close'),
                         'attrs' => array(
-                            'onclick' => "$('.dolPopup:visible').dolPopupHide()",
+                            'onclick' => "$('.bx-popup-active').dolPopupHide()",
                             'class' => 'bx-def-margin-sec-left',
                         ),
                     ),
@@ -192,7 +193,7 @@ class BxGridMy extends BxTemplGrid
 
             $iNewId = $oForm->insert (array(), true); // insert record to database
             if ($iNewId)
-                $aRes = array('grid' => $this->getCode(true), 'blink' => $iNewId); // if record is successfully added, reload grid and highlight added row
+                $aRes = array('grid' => $this->getCode(false), 'blink' => $iNewId); // if record is successfully added, reload grid and highlight added row
             else
                 $aRes = array('msg' => "Error occured"); // if record adding failed, display error message
 
@@ -211,7 +212,7 @@ class BxGridMy extends BxTemplGrid
                                 bx_loading($("#' . $aForm['form_attrs']['id'] . '"), true);
                             },
                             success: function (data) {
-                                $(".dolPopup:visible").dolPopupHide();
+                                $(".bx-popup-active").dolPopupHide();
                                 glGrids.' . $this->_sObject . '.processJson(data, "' . $sAction . '");
                             }
                         });

+ 1 - 1
studio/template/scripts/BxBaseStudioPolyglotKeys.php

@@ -28,7 +28,7 @@ class BxBaseStudioPolyglotKeys extends BxDolStudioPolyglotKeys
         $aForm = array(
             'form_attrs' => array(
                 'id' => 'adm-lang-new-key-form',
-                'action' => BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction,
+                'action' => BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r')),
                 'method' => 'post'
             ),
             'params' => array(

+ 1 - 0
template/scripts/BxBaseGrid.php

@@ -502,6 +502,7 @@ class BxBaseGrid extends BxDolGrid
                     $a['attr']['bx_grid_action_data'] = $sActionData;
                 if (isset($a['confirm']))
                     $a['attr']['bx_grid_action_confirm'] = $a['confirm'] ? 1 : 0;
+                $a['attr']['bx_grid_action_reset_paginate'] = false === strpos($sKey, 'delete') ? 0 : 1; // reset paginate after deleting row 
             }
 
             if ($isPermanentState && !isset($a['attr']['bx_grid_permanent_state']))