From 762553a7e320d78d55393c32316641e4619a499c Mon Sep 17 00:00:00 2001
From: legac <renaud.legac@free.fr>
Date: Sun, 10 Nov 2013 15:51:57 +0100
Subject: [PATCH] ExtJS 4.2: gridfilter almost working.

---
 static/plugin_dbui/src/directstore.js | 38 ++++++++++++++-------------
 static/plugin_dbui/src/gridfilter.js  |  8 +++++-
 2 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/static/plugin_dbui/src/directstore.js b/static/plugin_dbui/src/directstore.js
index 145891a9..ebfc0468 100644
--- a/static/plugin_dbui/src/directstore.js
+++ b/static/plugin_dbui/src/directstore.js
@@ -40,15 +40,6 @@ Ext.define('App.data.DirectStore', {
 
         var proxy;
 
-        /*
-        // keep a copy of the initial where condition
-        if (cfg.baseParams.hasOwnProperty('where')) {
-            cfg.initialWhere = [];
-            for (i = 0; i < cfg.baseParams.where.length; i += 1) {
-                cfg.initialWhere.push(cfg.baseParams.where[i]);
-            }
-        }
-        */
         // the proxy
         if (!config.proxy) {
             proxy = {
@@ -58,6 +49,14 @@ Ext.define('App.data.DirectStore', {
             config.proxy = proxy;
         }
 
+        // copy of the initial where condition
+        if (this.extraParams && this.extraParams.where) {
+            this.initialWhere = [];
+            for (i = 0; i < this.extraParams.where.length; i += 1) {
+                this.initialWhere.push(this.extraParams.where[i]);
+            }
+        }
+
         // initialise the base class
         this.callParent(arguments);
 
@@ -76,16 +75,19 @@ Ext.define('App.data.DirectStore', {
     },
 
     /**
-     * Handler to update the total number of records after a write action
+     * Handler to update the total number of records after a write action.
+     *
      * @param {Ext.data.Store} store
-     * @param {String} action
-     * Understood action are *create* and *destroy*.
+     * @param {Ext.data.Operation} operation
+     * Understood action are *create* and *destroy*
+     * @param {Object} eOpts
+     *
      */
-    onWrite: function (store, action) {
+    onWrite: function (store, operation, eOpts) {
 
         "use strict";
 
-        switch (action) {
+        switch (operation.action) {
         case 'create':
             store.totalLength += 1;
             break;
@@ -106,16 +108,16 @@ Ext.define('App.data.DirectStore', {
 
         var i;
 
-        if (this.baseParams.hasOwnProperty('where')) {
+        if (this.extraParams.where) {
 
             if (this.initialWhere) {
-                this.baseParams.where = [];
+                this.extraParams.where = [];
                 for (i = 0; i < this.initialWhere.length; i += 1) {
-                    this.baseParams.where.push(this.initialWhere[i]);
+                    this.extraParams.where.push(this.initialWhere[i]);
                 }
 
             } else {
-                delete this.baseParams.where;
+                delete this.extraParams.where;
             }
         }
     }
diff --git a/static/plugin_dbui/src/gridfilter.js b/static/plugin_dbui/src/gridfilter.js
index 5707dd3b..dc759c60 100644
--- a/static/plugin_dbui/src/gridfilter.js
+++ b/static/plugin_dbui/src/gridfilter.js
@@ -223,7 +223,13 @@ Ext.define('App.grid.GridFilter', {
         }
 
         // push new condition in the where clause of the store
-        this.store.baseParams.where = conditions;
+        if (conditions.length) {
+            this.store.extraParams.where = conditions;
+
+        // go back to the initial where setting when conditions are empty
+        } else {
+            this.store.restoreWhere();
+        }
     },
 
     // private method to load the store applying filter conditions
-- 
GitLab