diff --git a/models/db_widgets.py b/models/db_widgets.py index f03d6170e61a8c3b9a1b780a0731c6ea51e6c4b2..9d2519e1cdee73efa7afd065972bfa9c9f287aa1 100644 --- a/models/db_widgets.py +++ b/models/db_widgets.py @@ -34,21 +34,24 @@ dbui.configure_grids(db, plugins=['pGridRowEditorContextMenu', # -# Modify the publication form +# Create composite fields for the publication form # -m = dbui.FieldModifier('publications') -m.configure_field('year', maxValue=datetime.now().year) +fm = dbui.FieldModifier('publications') +fm.configure_field('year', maxValue=datetime.now().year) -m.merge_fields('first_page', - 'last_page', - extjs={'fieldLabel': T('Pages'), 'defaults': {'flex': 1}}) +fm.merge_fields('first_page', + 'last_page', + extjs={'fieldLabel': T('Pages'), 'defaults': {'flex': 1}}) -m.merge_fields('conference_start', - 'conference_end', - extjs={'fieldLabel': T('Dates'), 'defaults': {'flex': 1}}) +fm.merge_fields('conference_start', + 'conference_end', + extjs={'fieldLabel': T('Dates'), 'defaults': {'flex': 1}}) -fm = dbui.FormModifier('publications') -fm.merge_fields('title', +# +# Create fieldSet for the publication form +# +pm = dbui.FormModifier('publications') +pm.merge_fields('title', 'authors', 'id_collaborations', 'id_publishers', @@ -57,37 +60,43 @@ fm.merge_fields('title', 'volume', 'first_page', 'e_print', - extjs={'title': T('General'), 'collapsible': True, 'flex': 1}) + extjs={'title': T('General'), 'flex': 1}) -fm.merge_fields('conference_title', +pm.merge_fields('conference_title', 'conference_url', 'conference_start', 'conference_town', 'id_countries', 'conference_speaker', - spacer=78, - extjs={'title': T('Conference'), 'collapsible': True, 'flex': 1}) + extjs={'title': T('Conference'), 'flex': 1}) -fm.merge_fields('authors_cppm', +pm.merge_fields('authors_cppm', 'id_teams', 'id_projects', 'id_categories_aeres', - extjs={'title': 'CPPM', 'collapsible': True, 'flex': 1}) + extjs={'title': 'CPPM', 'flex': 1}) -fm.merge_fields('report_numbers', +pm.merge_fields('report_numbers', 'id_reports', spacer=90, - extjs={'title': T('Report'), 'collapsible': True, 'flex': 1}) + extjs={'title': T('Report'), 'flex': 1}) +# +# Organize fieldSet within a TabPanel embedded in the publication form +# +pm.set_mapper(dbui.map_tabpanel) -fm.configure(buttonAlign='right', +# +# Polish the look and feel of the publication form +# NOTE: the width define the width of the window +# when running the form from the grid. +# +pm.configure(buttonAlign='right', labelWidth=100, labelAlign='right', - layout={'type': 'table', 'columns': 2}, - layoutConfig={'tableAttrs': {'style': {'width': '100%', - 'cellspacing': 10}}}) + width=400) # # Modify the publications grid diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py index b74090b508a379b71fdb8915209864eb3e254b39..3a76bca5a428c8a8eaaf9c185ef27bc0f68f2995 100644 --- a/modules/plugin_dbui/__init__.py +++ b/modules/plugin_dbui/__init__.py @@ -7,4 +7,5 @@ from dbsvc import DbSvc from fieldmodifier import FieldModifier from formmodifier import configure_forms, FormModifier from gridmodifier import configure_grids, GridModifier +from mapper import map_default, map_tabpanel from viewportmodifier import VIEWPORT_DP, ViewportModifier diff --git a/modules/plugin_dbui/cfgsvc.py b/modules/plugin_dbui/cfgsvc.py index 4d89e1660d56ea57a9ddd12ae4e99079aa3d0b4f..abe227206507a6ce03e12b14da8875c3db58e217 100644 --- a/modules/plugin_dbui/cfgsvc.py +++ b/modules/plugin_dbui/cfgsvc.py @@ -7,6 +7,7 @@ __version__ = "$Revision$" from foreignfield import ForeignField from helper import encode_field +from mapper import map_default from setfield import SetField FIELD_IN_DBFIELD = "Field %s already in the dbFields list." @@ -247,22 +248,22 @@ class CfgSvc(object): return cfg - def _get_form_model_items(self, tablename): + def _get_form_items(self, tablename): """Build the list of items appearing in a Form model. - The method return a list of configuration dictionary for fields - or a list of configuration dictionary for fieldsets. - """ - li, id_is_not_used, formmodifiers = [], True, self._form_modifiers + fielditems = [] + id_is_not_used = True + modifiers = self._form_modifiers + modifier = (modifiers[tablename] if tablename in modifiers else None) # Form with field sets # NOTE: the field id is add in order to run this form # in all context, create, update, destroy. # It is add to the latest fieldset. - if tablename in formmodifiers and formmodifiers[tablename].field_sets: - for fieldset in formmodifiers[tablename].field_sets: + if modifier and modifier.field_sets: + for fieldset in modifier.field_sets: cfg = {'xtype': 'fieldset', 'items': []} @@ -282,18 +283,24 @@ class CfgSvc(object): # Apply the remaining Ext JS configuration options cfg.update(extjs) - li.append(cfg) + fielditems.append(cfg) # append the field Id if id_is_not_used: - li[-1]['items'].append(self._get_form_field(tablename, 'id')) + fielditems[-1]['items'].append(self._get_form_field(tablename, 'id')) # Form with fields else: for fieldname in self._db[tablename].fields: - self._append_form_field(tablename, fieldname, li) - - return li + self._append_form_field(tablename, fieldname, fielditems) + + # map the list of fields/fieldSets on Ext.form.formPanel + if modifier and modifier.mapper: + formitems = modifier.mapper(fielditems) + else: + formitems = map_default(fielditems) + + return formitems def _get_grid_filter(self, tablename): @@ -421,16 +428,15 @@ class CfgSvc(object): Return a dictionary. """ - model = {"title": str(self._translate(tablename.title())), - "table": tablename, - "items": self._get_form_model_items(tablename)} - - di = {"xtype": "xentry", "model": model} + cfg = {'xtype': 'xentry', + 'tableName': tablename, + 'tableTitle': str(self._translate(tablename.title())), + 'items': self._get_form_items(tablename)} if tablename in self._form_modifiers: - di.update(self._form_modifiers[tablename].extjs) + cfg.update(self._form_modifiers[tablename].extjs) - return di + return cfg def get_grid(self, tablename): @@ -440,9 +446,8 @@ class CfgSvc(object): Return a dictionary """ - formModel = {'xtype': 'xform', - 'items': self._get_form_model_items(tablename)} + 'items': self._get_form_items(tablename)} if tablename in self._form_modifiers: formModel.update(self._form_modifiers[tablename].extjs) diff --git a/modules/plugin_dbui/formmodifier.py b/modules/plugin_dbui/formmodifier.py index d5def34d71b7c347b9f6729eec1733bc25102604..2ba13dfca796c9550bfa4f677284766ebfa378a5 100644 --- a/modules/plugin_dbui/formmodifier.py +++ b/modules/plugin_dbui/formmodifier.py @@ -38,8 +38,9 @@ class FormModifier(Modifier): """ Modifier.__init__(self, FORM_MODIFIERS, tablename) - self.data.field_sets=[] - self.data.hidden_fields=[] + self.data.field_sets = [] + self.data.hidden_fields = [] + self.data.mapper = None def merge_fields(self, *fields, **kwargs): @@ -79,3 +80,23 @@ class FormModifier(Modifier): for el in fields: if el not in self.data.hidden_fields: self.data.hidden_fields.append(el) + + def set_mapper(self, func): + """Link the mapper tool to the function func. + + A mapper tool is related to the organization of the field/fieldest + in the form. By default the form layout is a column where fields are + pushed from the top to the bottom. By using the layout configuration + option it is possible to organize the field/fieldset in horizontal + box, vertical box, columns or in table. + + This approach does not allow to map field/fieldset in panels + contains in the form, like an Ext.TabPanel. The mapper tool allows to + handle this case. It is a function with one arguments, the list of + field/fieldset. The function return a dictionary with the structure of + panels embedded in the form an the fields they contained. + + Example of mapper can be found in the mapper module. + + """ + self.data.mapper = func \ No newline at end of file diff --git a/static/plugin_dbui/src/appform2.js b/static/plugin_dbui/src/appform2.js index 59ae0e5bdf983914ceaa2b0f4987e58d0dbc7c5d..17899426faea15bb7758fde21217d426e2ea1111 100644 --- a/static/plugin_dbui/src/appform2.js +++ b/static/plugin_dbui/src/appform2.js @@ -40,17 +40,14 @@ App.form.setToolTip = function (c) { App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, { /** - * @cfg {Object} model Object to configure the widget - * for a table of the database. It is provided by the server - * and contains the following keys: - * - * item: [...], - * table: 'x', - * title: 'y', - * xtype: 'xentry' - * } + * @cfg {String} tableName name of the table in the database */ - model: null, + tableName: null, + + /** + * @cfg {String} tableTitle title of the table + */ + tableTitle: null, /** * private method require by the ExtJs component model @@ -59,13 +56,11 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, { var fields, field, i; - if (!this.model) { - throw new Error("the property model is missing !!!"); + if (!this.tableName) { + throw new Error("the property tablename is missing !!!"); } - // define the item and the url - // NOTE: it is mandatory to defined the url here. - this.items = this.model.items; + // NOTE: mandatory to defined the url here. this.url = App.dburl; App.form.EntryFormPanel.superclass.initComponent.call(this); @@ -101,7 +96,7 @@ App.form.EntryFormPanel = Ext.extend(App.form.FormPanel, { method: 'POST', params: { 'debug': App.debug, - 'table': this.model.table, + 'table': this.tableName, 'xaction': 'create' }, reset: true,