diff --git a/controllers/plugin_dbui.py b/controllers/plugin_dbui.py index 7639dd302ad424feb0dec0d0c58f05793662fde7..9b0b7f97c42611723597f8c91e3b68e403a8f597 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 d73eb3cb25f0b16d3facdf42bd8632b278778af3..805d9a8780e0153dbe53e19131ec5be0db933dbe 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 bf523e244fa39e77058565d8624a08db53ceb1bc..38e20d638a5191fc5c0993a6d5781dbbde5b719c 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 0a34e97827270f3a107be209fc9d91a4aceb4135..9e11dde9266358d01b656ae3aa887d11ccfbdb74 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 38b0ab39375a50c7948ff32d777546bc06bcd34b..b1964566a9f30663911b4ee65adbc8d20f9e24c4 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 314e317441b338f6b03b4e286706e4a85ed726ab..49d22d41287e022c072e8e164d12c3ffa201b44a 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