diff --git a/models/ui_publications.py b/models/ui_publications.py index 4e48f29d20b0ca5b358420f629815c9838870244..a81fe07d481b70936aac49d0c407c68a828f456e 100644 --- a/models/ui_publications.py +++ b/models/ui_publications.py @@ -101,7 +101,10 @@ tpl = ['<b>{PublicationsTitle}</b><br>', ] gridModifier = dbui.GridModifier('publications') -gridModifier.configure(plugins=['pMathJax']) +gridModifier.configure(plugins=['pMathJax', + {'ptype': 'pGridRowEditorConfirmDelete', + 'resetFields': ['PublicationsId_projects']} + ]) gridModifier.merge_columns('title', 'authors', 'id_collaborations', diff --git a/modules/plugin_dbui/modifier.py b/modules/plugin_dbui/modifier.py index d23feefd5258dbe4fcb5ecd3f4860d4f43a1c86f..a56f26e6d893df4fd303d33593a5746bb445c71b 100644 --- a/modules/plugin_dbui/modifier.py +++ b/modules/plugin_dbui/modifier.py @@ -3,11 +3,14 @@ @author: R. Le Gac """ - +from gluon import current from gluon.storage import Storage from gluon.tools import PluginManager +MSG_INVALID_TYPE = current.T("Invalid plugin type") + + class Modifier(object): """Base class to construct Modifier tools. @@ -68,7 +71,10 @@ class Modifier(object): - The keyword argument C{plugins} contains a list of plugins. The current list of C{plugins} are extend with the new ones - defined by the keyword argument C{plugins}. + defined by the keyword argument C{plugins}. + + If a plugin with the same ptype alsready exists in the list + it is replaced by the new definition. - A plugin is defined by a string containing is C{pType}. @@ -89,7 +95,33 @@ class Modifier(object): plugins = [plugins] if 'plugins' in self.data.extjs: - self.data.extjs['plugins'].extend(plugins) + + # list of existing ptypes + ptypes = [] + for el in self.data.extjs['plugins']: + if isinstance(el, (str, unicode)): + ptypes.append(el) + elif isinstance(el, dict): + ptypes.append(el['ptype']) + else: + raise TypeError(MSG_INVALID_TYPE) + + # append new plugins replacing existing one + for plugin in plugins: + + ptype = "" + if isinstance(plugin, (str, unicode)): + ptype = plugin + elif isinstance(plugin, dict): + ptype= plugin['ptype'] + else: + raise TypeError(MSG_INVALID_TYPE) + + if ptype in ptypes: + i = ptypes.index(ptype) + self.data.extjs['plugins'][i] = plugin + else: + self.data.extjs['plugins'].append(plugin) else: self.data.extjs['plugins'] = list(plugins) diff --git a/static/plugin_dbui/CHANGELOG b/static/plugin_dbui/CHANGELOG index 3a4ed9995de40d79c75ee663a810ef1bc07941af..2bf6f192e0cc6d18016f8f117626ab6bc9f178fc 100644 --- a/static/plugin_dbui/CHANGELOG +++ b/static/plugin_dbui/CHANGELOG @@ -2,9 +2,13 @@ HEAD + - Add the configuration paremeter resetFields in the RowEditorBase + It allows to reset any fields when duplcating a record. + - The defintion of a plugin can be superseed at any time when using Modifier. + 0.6.1.3 (Jun 2014) - Add protection in CLEAN_COMMA and CLEAN_SPACES. - - Add the configuration panelLayout, panelLoader and selectorLayout to + - Add the configuration panelLayout, panelLoader and selectorLayout to the BaseWithSelector class. 0.6.1.1 (Mar 2014) diff --git a/static/plugin_dbui/src/form/Panel.js b/static/plugin_dbui/src/form/Panel.js index 1f0430ad26e83abaf745b46fb72eddb954ac8942..3252999c071974f2d1ce0779c9321cca18c78e8b 100644 --- a/static/plugin_dbui/src/form/Panel.js +++ b/static/plugin_dbui/src/form/Panel.js @@ -322,9 +322,6 @@ Ext.define('App.form.Panel', { case 'duplicate': this.buttonAction.setText(this.textDuplicate); - table = App.getTableName(this.store); - tableId = App.encodeField(table, 'id'); - delete record.data[tableId]; form.loadRecord(record); break; diff --git a/static/plugin_dbui/src/grid/plugin/RowEditorBase.js b/static/plugin_dbui/src/grid/plugin/RowEditorBase.js index b6de8b578385529c08aad52dc4c02bc864c3bc26..ea6d9e05337aafa787b26f5c668d2abbd564bfb0 100644 --- a/static/plugin_dbui/src/grid/plugin/RowEditorBase.js +++ b/static/plugin_dbui/src/grid/plugin/RowEditorBase.js @@ -17,6 +17,15 @@ Ext.define('App.grid.plugin.RowEditorBase', { ], uses: 'App.form.Panel', + /** + * @cfg {Array} [resetFields="TableId"] + * A list of fields which are reset to their defaults + * during the duplicate operation. the field are identified by + * their name defined in the Ext.data.Field. + * A typical example is the reset of a status from OK to undefined. + */ + resetFields: [], + // Pre-defined configuration pluginId: 'rowEditor', @@ -65,6 +74,9 @@ Ext.define('App.grid.plugin.RowEditorBase', { // get the formPanel configuration and instantiate the object table = App.getTableName(grid.getStore()); Dbui.getForm(table, this.addFormPanel, this); + + // On duplicate the field id is reset + this.resetFields.push(App.encodeField(table, 'id')); }, /** @@ -177,11 +189,23 @@ Ext.define('App.grid.plugin.RowEditorBase', { "use strict"; - var record = this.getSelected(); + var i, + record = this.getSelected(), + value; + if (!record) {return; } this.setCurrentIndex(); + // reset some fields at least the field id. + // + // NOTE: the method record.set is not used since it change + // the record as dirty which trigger update on the server + for (i = 0; i < this.resetFields.length; i += 1) { + value = record.fields.get(this.resetFields[i]).defaultValue; + record.data[this.resetFields[i]] = value; + } + this.formPanel.setAction('duplicate', record); this.window.setTitle(this.duplicateTitle); this.window.show();