Skip to content
Snippets Groups Projects
Commit f3f5a923 authored by Renaud Le Gac's avatar Renaud Le Gac
Browse files

The CfgSvc understands composite_fields.

parent 2a65858f
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,14 @@ dbui.configure_grids(db, plugins=['pGridRowEditorContextMenu',
m = dbui.FieldModifier('publications')
m.configure_field('year', maxValue=datetime.now().year)
m.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 = dbui.FormModifier('publications')
fm.merge_fields('title',
'authors',
......@@ -48,14 +56,12 @@ fm.merge_fields('title',
'doi',
'volume',
'first_page',
'last_page',
'e_print',
extjs={'title': T('General'), 'collapsible': True, 'flex': 1})
fm.merge_fields('conference_title',
'conference_url',
'conference_start',
'conference_end',
'conference_town',
'id_countries',
'conference_speaker',
......
......@@ -42,6 +42,30 @@ class CfgSvc(object):
setattr(self, '_%s' % key, pluginManager.dbui[key])
def _append_form_field(self, tablename, fieldname, li):
"""Append the field configuration dictionary to the list li.
The field is identify by its database tablename and fieldname.
This method handle single and composite fields.
A composite field is a set of field display in a row.
Only the label of the first field is shown.
See the documentation of the Ext.form.Compositefield class for details.
"""
if tablename in self._field_modifiers:
fieldmodifier = self._field_modifiers[tablename]
if fieldname in fieldmodifier.composite_fields.main:
li.append(self._get_form_composite_field(tablename, fieldname))
elif fieldname not in fieldmodifier.composite_fields.others:
li.append(self._get_form_field(tablename, fieldname))
else:
li.append(self._get_form_field(tablename, fieldname))
def _get_column(self, tablename, fieldname):
"""Build the column model required by the Ext.grid.GridPanel widget
for the database field tablename.fieldname.
......@@ -126,6 +150,22 @@ class CfgSvc(object):
"""
return self._set.get_set_data(tablename, fieldname)
def _get_form_composite_field(self, tablename, fieldname):
"""Build the configuration dictionary for a composite field.
"""
cfg = {'xtype': 'compositefield', 'items':[]}
fieldmodifier = self._field_modifiers[tablename]
compositefield = fieldmodifier.composite_fields[fieldname]
for field in compositefield.fields:
cfg['items'].append(self._get_form_field(tablename, field))
cfg.update(compositefield.extjs)
return cfg
def _get_form_field(self, tablename, fieldname):
......@@ -209,11 +249,14 @@ class CfgSvc(object):
def _get_form_model_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
# form with field sets
# 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.
......@@ -224,7 +267,7 @@ class CfgSvc(object):
cfg = {'xtype': 'fieldset', 'items': []}
for fieldname in fieldset.fields:
cfg['items'].append(self._get_form_field(tablename, fieldname))
self._append_form_field(tablename, fieldname, cfg['items'])
if fieldname == 'id':
id_is_not_used = False
......@@ -245,10 +288,10 @@ class CfgSvc(object):
if id_is_not_used:
li[-1]['items'].append(self._get_form_field(tablename, 'id'))
# the default form
# Form with fields
else:
for fieldname in self._db[tablename].fields:
li.append(self._get_form_field(tablename, fieldname))
self._append_form_field(tablename, fieldname, li)
return li
......
......@@ -24,8 +24,11 @@ class FieldModifier(Modifier):
"""
Modifier.__init__(self, FIELD_MODIFIERS, tablename)
self.data.composite_fields = []
self.data.extjs_fields = {}
self.data.composite_fields = Storage()
self.data.composite_fields.main = []
self.data.composite_fields.others = []
def append_plugins(self, *plugins):
......@@ -67,5 +70,16 @@ class FieldModifier(Modifier):
if 'extjs' in kwargs:
extjs.update(kwargs['extjs'])
main_field = fields[0]
other_fields = fields[1:]
# NOTE
# In order to simplify the processing keep a list of
# the main field, the first field appearing in the composite field,
# and a list of the other fields.
self.data.composite_fields.main.append(main_field)
self.data.composite_fields.others.extend(other_fields)
di = Storage(fields=fields, extjs=extjs)
self.data.composite_fields.append(di)
self.data.composite_fields[main_field] = di
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