From d6d6fb2546fdf3c6bd8267bcca86ae1d4fd6da61 Mon Sep 17 00:00:00 2001 From: legac <renaud.legac@free.fr> Date: Sat, 6 Oct 2012 16:35:31 +0200 Subject: [PATCH] Modify the key for the store configuration (storeId). New tool App.getStore to instanciate the any kind of store. Remove the old tool App.getDirectStore. --- controllers/plugin_dbui.py | 3 +- static/plugin_dbui/src/appbase.js | 50 +++++++++++++++++++++------ static/plugin_dbui/src/appcombobox.js | 2 +- static/plugin_dbui/src/appform.js | 2 +- static/plugin_dbui/src/appgrid.js | 2 +- 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/controllers/plugin_dbui.py b/controllers/plugin_dbui.py index 9b0b7f97..e6f8281d 100644 --- a/controllers/plugin_dbui.py +++ b/controllers/plugin_dbui.py @@ -112,7 +112,8 @@ def dbui_conf(): # the stores configuration (static, for each table,...) storeCfgs = plugins.dbui.static_stores for table in db: - storeCfgs[table._tablename] = dbui.to_jsonstore(table) + cfg = dbui.to_jsonstore(table) + storeCfgs[cfg['storeId']] = cfg # the viewport configuration viewportCfg = dbui.to_viewport() diff --git a/static/plugin_dbui/src/appbase.js b/static/plugin_dbui/src/appbase.js index a9a9dedb..441137b5 100644 --- a/static/plugin_dbui/src/appbase.js +++ b/static/plugin_dbui/src/appbase.js @@ -36,19 +36,20 @@ App.encodeField = function (table, field) { }; /** - * Helper function returning the App.data.DirectStore identifies by its id. + * Helper function returning an App.data.Store identifies by its id. * If the store does not exit it is created and register in the store manager. * - * NOTE: The storeId is defined by the server for each widget. - * The syntax of the storeId is "tableStore". + * NOTE: The storeId is defined by the server. + * The syntax of the storeId is "nameStore". * If the store does not exist, its configuration is extract from * the application constant App.storeCfgs.Then it is created and registered. - * In the current frame work a unique store is associated to a database table. - * This property guaranty that widget share the same store. + * + * In the current frame work, this function allows to associated a unique store + * to a database table and that widget share the same store. * * @param {String} storeId */ -App.getDirectStore = function (storeId) { +App.getStore = function (storeId) { var cfg, store, @@ -61,12 +62,39 @@ App.getDirectStore = function (storeId) { } if (!store && Ext.isString(storeId)) { - - table = storeId.slice(0, storeId.search('Store')); - cfg = App.storeCfgs[table]; - store = new App.data.DirectStore(cfg); + + cfg = App.storeCfgs[storeId]; + + switch (cfg.xtype) { + case 'arraystore': + store = new Ext.data.ArrayStore(cfg); + break; + + case 'directstore': + store = new Ext.data.DirectStore(cfg); + break; + + case 'jsonstore': + store = new Ext.data.JsonStore(cfg); + break; + + case 'store': + store = new Ext.data.Store(cfg); + break; + + case 'xdirectstore': + store = new App.data.DirectStore(cfg); + break; + + case 'xmlstore': + store = new Ext.data.XmlStore(cfg); + break; + + default: + throw new Error('Fail to instanciate the object: "' + cfg.xtype + '"'); + break; + } } - return store; }; diff --git a/static/plugin_dbui/src/appcombobox.js b/static/plugin_dbui/src/appcombobox.js index 86cd26f6..f5fb3bd1 100644 --- a/static/plugin_dbui/src/appcombobox.js +++ b/static/plugin_dbui/src/appcombobox.js @@ -32,7 +32,7 @@ App.form.ComboBox = Ext.extend(Ext.form.ComboBox, { } // link the combobox to the data store - this.store = App.getDirectStore(this.store); + this.store = App.getStore(this.store); // construct the underlying class. DON'T MOVE App.form.ComboBox.superclass.initComponent.call(this); diff --git a/static/plugin_dbui/src/appform.js b/static/plugin_dbui/src/appform.js index 2c75439c..b34dd624 100644 --- a/static/plugin_dbui/src/appform.js +++ b/static/plugin_dbui/src/appform.js @@ -77,7 +77,7 @@ App.form.FormPanel = Ext.extend(Ext.form.FormPanel, { this.buttonReset.on('click', resetForm, this.getForm()); // link the form to the data store - this.store = App.getDirectStore(this.store); + this.store = App.getStore(this.store); this.store.on('exception', this.onStoreException, this); this.store.on('write', resetForm, this.getForm()); diff --git a/static/plugin_dbui/src/appgrid.js b/static/plugin_dbui/src/appgrid.js index e1885fac..4d1ac9b3 100644 --- a/static/plugin_dbui/src/appgrid.js +++ b/static/plugin_dbui/src/appgrid.js @@ -44,7 +44,7 @@ App.grid.Grid = Ext.extend(Ext.grid.GridPanel, { initComponent: function () { // link the grid to the data store - this.store = App.getDirectStore(this.store); + this.store = App.getStore(this.store); // empty toolBar requires by the plugins this.bbar = new Ext.Toolbar(); -- GitLab