Commit 80c975b7 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update converter.to_gridFilter to be able to instantiate any field widget.

parent 9d3dcb66
......@@ -29,6 +29,7 @@ from extjs import (Base,
Model,
PanelWithUrlSelector)
from gluon import current
from gluon.storage import Storage
from gluon.tools import PluginManager
from gridmodifier import ROW_NUMBERING
from helper import (encode_field,
......@@ -528,12 +529,21 @@ def to_gridFilter(table, **kwargs):
method :meth:`.GridModifier.append_filter`
and :meth:`.GridModifier.configure_filters`
A ``GridFilter`` is a collection of widget. Each of them is associated
to a database field. The configuration of the widget is similar to one use
in the form for the database field. The configuration of the widget can be
tuned via the keyword arguments.
The configuration of the widget can be fully specified, without any link
to the form. In that case, the keyword argument ``xtype`` has to be
defined.
Args:
table (gluon.dal.Table): database table
Keyword Args:
**kwargs (dict): any of the Ext JS configuration parameters of the
the :class:`.GridFilter`` class. They are applied in the following
the :class:`.GridFilter` class. They are applied in the following
order: constructor, modifiers, keyword arguments.
Returns:
......@@ -574,50 +584,66 @@ def to_gridFilter(table, **kwargs):
field = table[fieldname]
name = '[%s.%s]' % (tablename, fieldname)
# get the standard configuration for the field
# ignore composite field set up for form
# ignore linked ComboBox set up for form
cfg = to_field(field, composite=False, linkedcombo=False)
# remove field constraints making no sense for a filter
if 'allowBlank' in cfg:
cfg["allowBlank"] = True
if 'readOnly' in cfg:
cfg['readOnly'] = False
if 'value' in cfg:
del cfg['value']
# Remove the star in the label for required field
if field.notnull and 'afterLabelTextTpl' in cfg:
del cfg['afterLabelTextTpl']
# replace all textarea by textfield
if cfg['xtype'] == 'xtextarea':
cfg['xtype'] = 'xtextfield'
# combobox can be reset individually
# not valid for combobox associated to a set of data
if cfg['xtype'] == 'xcombobox' and not is_set_field(field):
cfg['emptyText'] = T('select...')
cfg['xtype'] = 'xcomboboxuserreset'
# prepare the name for the where close [table.field]
cfg['name'] = name
# store information to customise the filter
# ....................................................................
#
# standalone configuration of the widget from the keyword arguments
#
extjs_filter = grid_filters.extjs_filters[i]
if 'xtype' in extjs_filter:
cfg = Storage(extjs_filter)
# ....................................................................
#
# configuration of the widget from the database form
#
else:
# get the standard configuration for the field
# ignore composite field set up for form
# ignore linked ComboBox set up for form
cfg = to_field(field, composite=False, linkedcombo=False)
# remove field constraints making no sense for a filter
if 'allowBlank' in cfg:
cfg["allowBlank"] = True
if 'readOnly' in cfg:
cfg['readOnly'] = False
if 'value' in cfg:
del cfg['value']
# Remove the star in the label for required field
if field.notnull and 'afterLabelTextTpl' in cfg:
del cfg['afterLabelTextTpl']
# replace all textarea by textfield
if cfg['xtype'] == 'xtextarea':
cfg['xtype'] = 'xtextfield'
# combobox can be reset individually
# not valid for combobox associated to a set of data
if cfg['xtype'] == 'xcombobox' and not is_set_field(field):
cfg['emptyText'] = T('select...')
cfg['xtype'] = 'xcomboboxuserreset'
# field configuration option
cfg.update(grid_filters.extjs_filters[i])
# ....................................................................
#
# add dedicated information to customise the filter
#
cfg['filterComment'] = comment
cfg['filterOperator'] = operator
cfg['filterType'] = field.type
# prepare the name for the where close [table.field]
cfg['name'] = name
# copy the comment to be used as a tool tip
# when the plugin pFormToolTip is used
cfg['tipText'] = comment
# field configuration option
cfg.update(grid_filters.extjs_filters[i])
di.append_items(cfg)
# configuration options from the grid modifier
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment