From 533afd702d1b1a3f320bf3f03d38f8838070f1f3 Mon Sep 17 00:00:00 2001 From: Renaud Le Gac <renaud.legac@free.fr> Date: Sun, 13 Mar 2011 16:30:50 +0000 Subject: [PATCH] The grid does not contains form configuration options anymore. --- modules/plugin_dbui/cfgsvc.py | 3 +- static/plugin_dbui/src/appgridroweditor.js | 44 +++++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/modules/plugin_dbui/cfgsvc.py b/modules/plugin_dbui/cfgsvc.py index b92e68bd..d94899b2 100644 --- a/modules/plugin_dbui/cfgsvc.py +++ b/modules/plugin_dbui/cfgsvc.py @@ -560,10 +560,9 @@ class CfgSvc(BaseSvc): cfg = {'columns': self._get_columns_model(tablename), 'frame': False, - 'formCfg': self.get_form(tablename), 'store': self.get_jsonstore(tablename), 'viewConfig': {'forceFit': True}, - 'xtype': 'grid'} + 'xtype': 'xgrid'} filter = self._get_grid_filter(tablename) if filter: diff --git a/static/plugin_dbui/src/appgridroweditor.js b/static/plugin_dbui/src/appgridroweditor.js index a66598b7..9ab224cf 100644 --- a/static/plugin_dbui/src/appgridroweditor.js +++ b/static/plugin_dbui/src/appgridroweditor.js @@ -21,7 +21,9 @@ App.grid.RowEditor = Ext.extend(Ext.Window, { * Private attribute identifying the type of plugin */ ptype: 'pGridRowEditor', - + formPanel: null, + grid: null, + /** * pre-defined configuration options for the window */ @@ -39,28 +41,52 @@ App.grid.RowEditor = Ext.extend(Ext.Window, { */ init: function (grid) { + var table; + this.grid = grid; // The grid keeps track of the editor // since it can be shared between different plugins - grid.rowEditor = this; + this.grid.rowEditor = this; // The user can only select one row of the grid this.grid.selModel = new Ext.grid.RowSelectionModel({ singleSelect: true }); - // add the form to this window - this.formPanel = Ext.ComponentMgr.create(grid.formCfg); - this.formPanel.store = this.grid.store; - this.add(this.formPanel); - // Add a listener to hide the window when the transaction is successful - // and to catch store exception this.grid.store.on('write', this.onWrite, this); - this.grid.store.on('exception', this.formPanel.onStoreException, this.formPanel); + + // get the formPanel configuration and instanciate the object + table = App.getTableName(this.grid.store); + Dbui.getForm(table, this.addFormPanel, this); }, + /** + * Private call-back method to instanciate the formPanel + * the scope is the gridRowEditor + * @param {Object} provider + * @param {Object} response + */ + addFormPanel: function (provider, response) { + var formCfg = response.result; + + // By construction the formPanel and the grid share the same store. + // This approach relies on the Ext.StrMgr. + // However this approach creates confusion in listeners. + // It is why we force the use of the same object. + this.formPanel.store = this.grid.store; + + // instanciate the form + this.formPanel = Ext.ComponentMgr.create(formCfg); + this.add(this.formPanel); + + // add a listeners to catch store exception + // since listener on the formPanel never fire in this context ! + this.grid.store.on('exception', + this.formPanel.onStoreException, + this.formPanel); + }, /** * Private method to return the record * associate to the row selected in the grid -- GitLab