diff --git a/models/db_widgets.py b/models/db_widgets.py index 210d62fe6807217295ef2b67957a72bcde199878..0b7ca83747f0d4cfbfe1d47aae6d49ddded2b168 100755 --- a/models/db_widgets.py +++ b/models/db_widgets.py @@ -73,7 +73,7 @@ formModifier.merge_fields('conference_title', 'conference_town', 'id_countries', 'conference_speaker', - spacer=26*3, + dbui.Spacer(height=26*3), title=T('Conference'), flex=1) @@ -82,13 +82,13 @@ formModifier.merge_fields('authors_cppm', 'id_teams', 'id_projects', 'id_categories_aeres', - spacer= 26*5, + dbui.Spacer(height=26*5), title='CPPM', flex=1) formModifier.merge_fields('report_numbers', 'id_reports', - spacer=220, + dbui.Spacer(height=220), title=T('Report'), flex=1) diff --git a/modules/plugin_dbui/__init__.py b/modules/plugin_dbui/__init__.py index 5ff870ca45cc971a9f937805876d039561468c1b..4c6c50680f31e0ee3a374be0b2e3cc9b171cecea 100755 --- a/modules/plugin_dbui/__init__.py +++ b/modules/plugin_dbui/__init__.py @@ -15,4 +15,5 @@ from helper import (get_js_files, get_reference_paths, get_script_path) from mapper import map_default, map_tabpanel +from modifier import Spacer, Widget from viewportmodifier import VIEWPORT_DP, ViewportModifier \ No newline at end of file diff --git a/modules/plugin_dbui/cfgsvc.py b/modules/plugin_dbui/cfgsvc.py index d43727b5b6ab47f335df492dd7595370e700e306..5a6b47dce6902534efcab4a084c423c9fab80910 100755 --- a/modules/plugin_dbui/cfgsvc.py +++ b/modules/plugin_dbui/cfgsvc.py @@ -10,6 +10,7 @@ from basesvc import BaseSvc from foreignfield import ForeignField from helper import encode_field from mapper import map_default +from modifier import Widget from setfield import SetField FIELD_IN_DBFIELD = "Field %s already in the dbFields list." @@ -64,6 +65,10 @@ class CfgSvc(BaseSvc): See the documentation of the Ext.form.Compositefield class for details. """ + # handle spacer and simple text widget + if isinstance(fieldname, Widget): + li.append(fieldname.extjs) + return # handle composite field and fieldsets field_modifiers = self.environment['plugins'].dbui.field_modifiers @@ -291,18 +296,9 @@ class CfgSvc(BaseSvc): self._append_form_field(tablename, fieldname, cfg['items']) if fieldname == 'id': id_is_not_used = False - - # protection when applying Ext JS configuration parameters - # NOTE: if the user submit a list of items they are append at the - # end of the current list. - # It is a way to add spacer and to fine tune the layout - extjs = dict(fieldset.extjs) - if 'items' in extjs: - cfg['items'].extend(extjs['items']) - del extjs['items'] # Apply the remaining Ext JS configuration options - cfg.update(extjs) + cfg.update(fieldset.extjs) fielditems.append(cfg) # append the field Id diff --git a/modules/plugin_dbui/formmodifier.py b/modules/plugin_dbui/formmodifier.py index b1a293d2f6989177b44ee15477958efb6d6c1dfe..1c8366dc1e28563f4cf89e89b9a5e61883d8dab8 100644 --- a/modules/plugin_dbui/formmodifier.py +++ b/modules/plugin_dbui/formmodifier.py @@ -59,15 +59,6 @@ class FormModifier(Modifier): extjs = {'defaults': {'anchor': '100%'}} extjs.update(kwargs) - if 'spacer' in extjs: - di = {'xtype': 'spacer', 'height': extjs['spacer']} - if 'items' in extjs: - items.append(di) - else: - extjs['items'] = [di] - - del extjs['spacer'] - di = Storage(fields=fields, extjs= extjs) self.data.field_sets.append(di) diff --git a/modules/plugin_dbui/modifier.py b/modules/plugin_dbui/modifier.py index d2b4c20d4ec8e14bb268f65a2c803ce4e5138312..e4bf7c8aefa2bc083d8d40945f8f6d1cf54be685 100644 --- a/modules/plugin_dbui/modifier.py +++ b/modules/plugin_dbui/modifier.py @@ -84,3 +84,20 @@ class Modifier(object): """ self.data.extjs.update(extjs) + +class Widget(object): + """Base class defining a the configuration of an ExtJS widget. + + """ + def __init__(self, xtype, **kwargs): + self.extjs = dict(xtype=xtype, **kwargs) + + +class Spacer(Widget): + """Define a spacer which can be add when combining fields in fieldset + or in field container. + + """ + def __init__(self, **kwargs): + Widget.__init__(self, 'spacer', **kwargs) +