diff --git a/modules/plugin_dbui/converter.py b/modules/plugin_dbui/converter.py index ff8b5f13898b56f7e89e613c9160547e8c588d43..b0a7084f72d1d37206f74881677cd359be317319 100644 --- a/modules/plugin_dbui/converter.py +++ b/modules/plugin_dbui/converter.py @@ -129,13 +129,13 @@ def _to_field(field, **kwargs): return cfg -def to_field(field, **kwargs): +def to_field(field, composite=True, **kwargs): """Convert a gluon.dal.Field into an Ext.form.Field and its inherited class as well as into a composite field, i.e Ext.form.CompositeField. Composite fields are set using the FieldsModifer. - Return None if the field is consumed by a CompositeField. + composite field can be ignore when the keyword argument composite is False. ExtJS configuration parameters are applied in the following order: constructor, modifiers, keyword arguments. @@ -153,20 +153,20 @@ def to_field(field, **kwargs): # main field of the composite field # it will consume the embedded field too - if composite_fields and field.name in composite_fields.main: - - cfg = CompositeField() + if composite and composite_fields: - for fieldname in composite_fields[field.name].fields: - cfg.append_items(_to_field(table[fieldname])) - - # use configuration options from the modifier - cfg.update(composite_fields[field.name].extjs) - - # an embedded field already used in a composite field - elif composite_fields and field.name in composite_fields.others: cfg = None + + if field.name in composite_fields.main: + + cfg = CompositeField() + for fieldname in composite_fields[field.name].fields: + cfg.append_items(_to_field(table[fieldname])) + + # use configuration options from the modifier + cfg.update(composite_fields[field.name].extjs) + # a basic field else: cfg = _to_field(field) @@ -400,7 +400,12 @@ def to_gridFilter(table, **kwargs): di = GridFilter(title=T('Filter %s' % tablename)) - for (fieldname, operator, comment) in grid_filters.filters: + print grid_filters.filters + print grid_filters.extjs_filters + + for i in range(len(grid_filters.filters)): + + fieldname, operator, comment = grid_filters.filters[i] # filter rule dealing with any foreign field m = re.match(r"(\w+)\.(\w+)", fieldname) @@ -416,7 +421,8 @@ def to_gridFilter(table, **kwargs): name = '[%s.%s]' % (tablename, fieldname) # get the standard configuration for the field - cfg = to_field(field) + # ignore composite field defined for form + cfg = to_field(field, composite=False) # remove default value # make no sense in this context @@ -429,7 +435,7 @@ def to_gridFilter(table, **kwargs): # empty text for combobox if cfg['xtype'] == 'xcombobox': - cfg['emptyText']= 'select...' + cfg['emptyText']= T('select...') # prepare the name for the where close [table.field] cfg['name'] = name @@ -443,6 +449,9 @@ def to_gridFilter(table, **kwargs): # 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 diff --git a/modules/plugin_dbui/gridmodifier.py b/modules/plugin_dbui/gridmodifier.py index f56330d1f393cc8f828f7cf6d2d0bdf0baabb658..da5ce02189536a14a5babfb5c1c0956c1e2a3ac4 100644 --- a/modules/plugin_dbui/gridmodifier.py +++ b/modules/plugin_dbui/gridmodifier.py @@ -48,7 +48,9 @@ class GridModifier(Modifier): self.data.configure_columns = {} self.data.delete_columns = [] - self.data.grid_filters = [] + self.data.grid_filters = Storage(filters=[], + extjs_filters=[], + extjs={}) self.data.hidden_columns = [] self.data.row_numbering = False self.data.template_columns = [] @@ -148,8 +150,9 @@ class GridModifier(Modifier): self.hide_columns(*fields) - def set_filters(self, *filters, **kwargs): - """Define the filters associated to the grid. + def append_filter(self, filter, **kwargs): + """Append a filter associated to the grid. + The widget associated to each filter is a field, comboBox, dataField,.. They are grouped in a Ext.form.Fieldset appearing in a panel on the right side of the grid. @@ -160,12 +163,50 @@ class GridModifier(Modifier): the method dbsvc._encode_query - a string with a comment for the tool tip + A more elaborate filter rule allows to filter on any foreign field. + the syntax is (table2.field1, operator, comments). + + The keyword argument contains the additional configuration options + for the underlying Ext.form.Field. For more information see the ExtJS + documentation. + + A set of filters can be defined in one go using the method set_filters. + This method allows to tune each field while the other allows to tune + the FieldSet. + + """ + self.data.grid_filters.filters.append(filter) + self.data.grid_filters.extjs_filters.append(kwargs) + + + def set_filters(self, *filters, **kwargs): + """Define the filters associated to the grid. + + It is an Ext.form.Fieldset appearing in a panel on the right side + of the grid. It contains widget associated to each filter: field, + comboBox, dataField,.. + + A filter is define by a tuple containing three columns: + - a string with the database field name + - a string with the operator. Valid operator are defined in + the method dbsvc._encode_query + - a string with a comment for the tool tip + + A more elaborate filter rule allows to filter on any foreign field. + the syntax is (table2.field1, operator, comments). + The keyword argument contains the configuration options for the underlying Ext.form.FieldSet. For more information see the ExtJS documentation. + Filter can be defined and tuned individually + using the method append_filter. + """ - self.data.grid_filters = Storage(filters=filters, extjs=kwargs) + for el in filters: + self.append_filter(el) + + self.data.grid_filters.extjs=kwargs def set_rownumbering(self): diff --git a/static/plugin_dbui/CHANGELOG b/static/plugin_dbui/CHANGELOG index c20b8250b223e783170efd03f1a1c41655b6df25..09535bf74190f6b7423ec8735804d791c885f341 100644 --- a/static/plugin_dbui/CHANGELOG +++ b/static/plugin_dbui/CHANGELOG @@ -1,7 +1,8 @@ --------------------------------- CHANGE LOG ---------------------------------- HEAD - + - improve grid filter namely by adding the method append_filter. + 0.4.8.2 (Jul 2012) - Consolidation version - Add a StoreModifier to handle the orderby directive diff --git a/static/plugin_dbui/src/appgridfilter.js b/static/plugin_dbui/src/appgridfilter.js index 3800751252cd94e39d6c8254f276750f381bd8cf..ee78fc9759b933dfc85cd5bc3bb6abcd6049ba6e 100644 --- a/static/plugin_dbui/src/appgridfilter.js +++ b/static/plugin_dbui/src/appgridfilter.js @@ -67,10 +67,14 @@ App.grid.GridFilter = Ext.extend(Ext.form.FieldSet, { // catch a change of value for comboBox if (field.xtype === 'xcombobox') { field.on('select', this.onChange, this); + + // catch a change of date + } else if (field.xtype === 'datefield') { + field.on('select', this.onChange, this); + // catch the key pressed enter for other fields + // wait that user finish to type to run the handler } else { - // catch the key pressed enter for other fields - // wait that user finish to type to run the handler field.on('keyup', this.onChange, this, {buffer: 500}); } }