Skip to content
Snippets Groups Projects
Commit f7ac1f46 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files
parents 95b2b894 3e81152a
No related branches found
No related tags found
No related merge requests found
...@@ -101,7 +101,10 @@ tpl = ['<b>{PublicationsTitle}</b><br>', ...@@ -101,7 +101,10 @@ tpl = ['<b>{PublicationsTitle}</b><br>',
] ]
gridModifier = dbui.GridModifier('publications') gridModifier = dbui.GridModifier('publications')
gridModifier.configure(plugins=['pMathJax']) gridModifier.configure(plugins=['pMathJax',
{'ptype': 'pGridRowEditorConfirmDelete',
'resetFields': ['PublicationsId_projects']}
])
gridModifier.merge_columns('title', gridModifier.merge_columns('title',
'authors', 'authors',
'id_collaborations', 'id_collaborations',
......
...@@ -3,11 +3,14 @@ ...@@ -3,11 +3,14 @@
@author: R. Le Gac @author: R. Le Gac
""" """
from gluon import current
from gluon.storage import Storage from gluon.storage import Storage
from gluon.tools import PluginManager from gluon.tools import PluginManager
MSG_INVALID_TYPE = current.T("Invalid plugin type")
class Modifier(object): class Modifier(object):
"""Base class to construct Modifier tools. """Base class to construct Modifier tools.
...@@ -68,7 +71,10 @@ class Modifier(object): ...@@ -68,7 +71,10 @@ class Modifier(object):
- The keyword argument C{plugins} contains a list of plugins. - The keyword argument C{plugins} contains a list of plugins.
The current list of C{plugins} are extend with the new ones 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}. - A plugin is defined by a string containing is C{pType}.
...@@ -89,7 +95,33 @@ class Modifier(object): ...@@ -89,7 +95,33 @@ class Modifier(object):
plugins = [plugins] plugins = [plugins]
if 'plugins' in self.data.extjs: 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: else:
self.data.extjs['plugins'] = list(plugins) self.data.extjs['plugins'] = list(plugins)
......
...@@ -2,9 +2,13 @@ ...@@ -2,9 +2,13 @@
HEAD 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) 0.6.1.3 (Jun 2014)
- Add protection in CLEAN_COMMA and CLEAN_SPACES. - 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. the BaseWithSelector class.
0.6.1.1 (Mar 2014) 0.6.1.1 (Mar 2014)
......
...@@ -322,9 +322,6 @@ Ext.define('App.form.Panel', { ...@@ -322,9 +322,6 @@ Ext.define('App.form.Panel', {
case 'duplicate': case 'duplicate':
this.buttonAction.setText(this.textDuplicate); this.buttonAction.setText(this.textDuplicate);
table = App.getTableName(this.store);
tableId = App.encodeField(table, 'id');
delete record.data[tableId];
form.loadRecord(record); form.loadRecord(record);
break; break;
......
...@@ -17,6 +17,15 @@ Ext.define('App.grid.plugin.RowEditorBase', { ...@@ -17,6 +17,15 @@ Ext.define('App.grid.plugin.RowEditorBase', {
], ],
uses: 'App.form.Panel', 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 // Pre-defined configuration
pluginId: 'rowEditor', pluginId: 'rowEditor',
...@@ -65,6 +74,9 @@ Ext.define('App.grid.plugin.RowEditorBase', { ...@@ -65,6 +74,9 @@ Ext.define('App.grid.plugin.RowEditorBase', {
// get the formPanel configuration and instantiate the object // get the formPanel configuration and instantiate the object
table = App.getTableName(grid.getStore()); table = App.getTableName(grid.getStore());
Dbui.getForm(table, this.addFormPanel, this); 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', { ...@@ -177,11 +189,23 @@ Ext.define('App.grid.plugin.RowEditorBase', {
"use strict"; "use strict";
var record = this.getSelected(); var i,
record = this.getSelected(),
value;
if (!record) {return; } if (!record) {return; }
this.setCurrentIndex(); 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.formPanel.setAction('duplicate', record);
this.window.setTitle(this.duplicateTitle); this.window.setTitle(this.duplicateTitle);
this.window.show(); this.window.show();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment