From 99af6f109ee18301dbc540c0892a9a2c7649e383 Mon Sep 17 00:00:00 2001
From: legac <renaud.legac@free.fr>
Date: Sat, 6 Oct 2012 15:57:38 +0200
Subject: [PATCH] Add the possibility to defined array store in the model.

---
 controllers/plugin_dbui.py           |  6 ++---
 models/plugin_dbui.py                |  4 ++-
 models/widgets_stores.py             | 11 ++++++++
 modules/plugin_dbui/__init__.py      |  2 +-
 modules/plugin_dbui/storemodifier.py | 38 ++++++++++++++++++++++++++++
 static/plugin_dbui/CHANGELOG         |  1 +
 6 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/controllers/plugin_dbui.py b/controllers/plugin_dbui.py
index 7639dd30..9b0b7f97 100644
--- a/controllers/plugin_dbui.py
+++ b/controllers/plugin_dbui.py
@@ -92,9 +92,7 @@ def dbui_conf():
     """
     from gluon.contrib import simplejson as json
     dbui = local_import('plugin_dbui')
-    
     di = {}
-    dbui = local_import('plugin_dbui')
     
     # build the dictionary required by Ext.direct
     # containing the definition of the remote procedure
@@ -111,8 +109,8 @@ def dbui_conf():
             
         di[action].append({'name': method, 'len': nargs})
   
-    # the stores configuration for each table
-    storeCfgs = {}
+    # the stores configuration (static, for each table,...)
+    storeCfgs = plugins.dbui.static_stores
     for table in db:
         storeCfgs[table._tablename] = dbui.to_jsonstore(table)
     
diff --git a/models/plugin_dbui.py b/models/plugin_dbui.py
index d73eb3cb..805d9a87 100644
--- a/models/plugin_dbui.py
+++ b/models/plugin_dbui.py
@@ -55,7 +55,9 @@ plugins = PluginManager('dbui',
                         modifier_forms={},
                         modifier_grids={},
                         modifier_stores={},
-                        modifier_viewports=Storage(extjs={}))
+                        modifier_viewports=Storage(extjs={}),
+                        
+                        static_stores={})
                         
 
 # Start common services
diff --git a/models/widgets_stores.py b/models/widgets_stores.py
index bf523e24..38e20d63 100755
--- a/models/widgets_stores.py
+++ b/models/widgets_stores.py
@@ -3,6 +3,17 @@
 
 """
 #
+# Create a static store with the axes definition
+#
+dbui.AddStore('axes',
+              fields=['axis', 'granularity'],
+              data=[['projects', 'agency'],
+                    ['projects', 'project'],
+                    ['teams', 'domain'],
+                    ['teams', 'team'],
+                    ['time', 'year']],
+              xtype='arraystore')
+#
 # order store contents for technical tables
 #
 storeModifier = dbui.StoreModifier('teams')
diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py
index 0a34e978..9e11dde9 100755
--- a/modules/plugin_dbui/__init__.py
+++ b/modules/plugin_dbui/__init__.py
@@ -42,7 +42,7 @@ from extjs import (CheckBox,
 from fieldsmodifier import FieldsModifier
 from formmodifier import configure_forms, FormModifier
 from gridmodifier import configure_grids, GridModifier
-from storemodifier import StoreModifier
+from storemodifier import AddStore, StoreModifier
 from helper import (as_list,
                     decode_field,
                     encode_field,
diff --git a/modules/plugin_dbui/storemodifier.py b/modules/plugin_dbui/storemodifier.py
index 38b0ab39..b1964566 100644
--- a/modules/plugin_dbui/storemodifier.py
+++ b/modules/plugin_dbui/storemodifier.py
@@ -2,13 +2,51 @@
 
 """
 
+from converter import STOREID
 from gluon.storage import Storage
+from gluon.tools import PluginManager
 from modifier import Modifier
 
 
 MODIFIER_STORES = 'modifier_stores'
 
 
+class AddStore(object):
+    """Helper tool to add the configuration of a store.
+    The configuration of all store are kept in a dedicated dictionary
+    which is given to the client via the action dbui_conf.
+    
+    This tool is suited to defined static store (Ext.data.ArrayStore) used
+    for example in selectors. It should not be used to define store 
+    associated to the database tables. The latter are configured using the 
+    converter to_jsonstore. 
+    
+    However, this approach is generic and any store can be added to the 
+    configuration dictionary.
+    
+    """ 
+    
+    def __init__(self, name, **kwargs):
+        """ Create the configuration of a Store.
+        
+        the ExtJS configuration parameters of the store are defined
+        by the keyword arguments kwargs.
+        
+        For an Ext.data.ArrayStore the properties fields and data
+        have to be defined. For more details see the ExtJS documentation.
+        
+        The key associated to this store in the configuration dictionary
+        is the storeId. It derived from the name in the 
+        following way: nameStore.
+        
+        """
+        static_stores = PluginManager('dbui').dbui.static_stores
+    
+        storeId = STOREID % name
+        kwargs['storeId'] = storeId
+        static_stores[storeId] = kwargs
+
+    
 class StoreModifier(Modifier):
     """Helper tool to customize the store associated to a table.
     
diff --git a/static/plugin_dbui/CHANGELOG b/static/plugin_dbui/CHANGELOG
index 314e3174..49d22d41 100644
--- a/static/plugin_dbui/CHANGELOG
+++ b/static/plugin_dbui/CHANGELOG
@@ -4,6 +4,7 @@ HEAD
   - New syntax for grid filter via the method GridModifier.append_filter.
   - Improve the files organization defining the model.
   - Enable tab scrolling in viewport.
+  - Add the possibility to define static store (Ext.data.ArrayStore) in the model.
   
 0.4.8.2 (Jul 2012)
   - Consolidation version
-- 
GitLab