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

Add a new tool to define grid filter.

parent 59f9fe84
No related branches found
No related tags found
No related merge requests found
...@@ -241,6 +241,50 @@ class CfgSvc(object): ...@@ -241,6 +241,50 @@ class CfgSvc(object):
return li return li
def _getGridFilter(self, tablename):
""" Generate configuration object for the grid filter
"""
di = {}
if tablename in self._grid_filters:
di = {'xtype':'fieldset',
'defaults': {'anchor': '100%'},
'items': [],
'title': self._translate('Filter %s' % tablename)}
filters = self._grid_filters[tablename].filters
for (fieldname, operator, comment) in filters:
# get the standard form field
cfg = self._getFormField(tablename, fieldname)
# remove default value for fields which are not combobox
if cfg['xtype'] != 'xcombobox':
cfg['value'] = ''
cfg['allowBlank'] = True
# replace all textarea by textfield
if cfg['xtype'] == 'textarea':
cfg['xtype'] = 'textfield'
# prepare the name for the where close
cfg['name'] = '[%s.%s]' % (tablename, fieldname)
# store information to customize the filter
cfg['filterComment'] = comment
cfg['filterOperator'] = operator
cfg['filterType'] = self._db[tablename][fieldname].type
di['items'].append(cfg)
extjs = self._grid_filters[tablename].extjs
di.update(extjs)
return di
def _getJsonStore(self, table): def _getJsonStore(self, table):
""" Generate configuration object for JSON stores """ Generate configuration object for JSON stores
...@@ -335,6 +379,7 @@ class CfgSvc(object): ...@@ -335,6 +379,7 @@ class CfgSvc(object):
model = {} model = {}
model["colModel"] = self._getColumnsModel(tablename) model["colModel"] = self._getColumnsModel(tablename)
model["formModel"] = formModel model["formModel"] = formModel
model["filterModel"] = self._getGridFilter(tablename)
model["store"] = self._getJsonStore(tablename) model["store"] = self._getJsonStore(tablename)
model["table"] = tablename model["table"] = tablename
model["title"] = str(self._translate(tablename.title())) model["title"] = str(self._translate(tablename.title()))
......
...@@ -83,9 +83,9 @@ def customize_form_with_field_set(tablename, title, fields, spacer=0, **extjs): ...@@ -83,9 +83,9 @@ def customize_form_with_field_set(tablename, title, fields, spacer=0, **extjs):
Useful to tune the final height of the field set. Useful to tune the final height of the field set.
extjs extjs
Additional Ext JS configuration parameters additional keyword arguments corresponding
apply to the fieldset (See the documentation to Ext.form.FieldSet configuration parameters
of Ext.form.FieldSet) (See the Ext JS APIdocumentation)
""" """
p = _init_tool('field_sets') p = _init_tool('field_sets')
...@@ -157,9 +157,9 @@ def customize_grid_with_template_column(tablename, ...@@ -157,9 +157,9 @@ def customize_grid_with_template_column(tablename,
via their fieldname. via their fieldname.
extjs extjs
Additional Ext JS configuration parameters additional keyword arguments corresponding
to be apply on the column to Ext.grid.Column configuration parameters
(See the documentation of Ext.gid.Column) (See the documentation of Ext.grid.Column)
""" """
p = _init_tool('template_columns') p = _init_tool('template_columns')
...@@ -191,12 +191,30 @@ def define_combined_field(): ...@@ -191,12 +191,30 @@ def define_combined_field():
p = _init_tool('combined_fields') p = _init_tool('combined_fields')
def define_grid_filter(): def define_grid_filter(tablename, filters, **extjs):
""" Helper tool to define filter associate to grid. """ Helper tool to define filter associate to grid.
tablename
name of the database table
filters
a list of tuple.
Each tuple contains three columns:
-- a string with the database field
-- a string with the operator
the list of valid operator is defined in
the method dbsvc._encode_query
-- a string with a comment for the tool tip
extjs
additional keyword arguments corresponding
to the configuration parameter of Ext.form.FieldSet
(see the Ext JS API documentation)
""" """
p = _init_tool('grid_filters') p = _init_tool('grid_filters')
di = Storage(filters=filters, extjs=extjs)
p.dbui.grid_filters[tablename] = di
def define_wizard(): def define_wizard():
""" Helper tool to define wizard in form. """ Helper tool to define wizard in form.
......
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