From 63d9cfbd41b4ed02b2a8f3843beb067b2078c38f Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 16 May 2016 08:58:40 -0600 Subject: [PATCH] Move filterheader using taglist to its own widget, nextmatch-taglistheader, and revert changes to nextmatch-filterheader & nextmatch-accountfilter --- api/js/etemplate/et2_extension_nextmatch.js | 90 ++++++++++++++++++++- 1 file changed, 88 insertions(+), 2 deletions(-) diff --git a/api/js/etemplate/et2_extension_nextmatch.js b/api/js/etemplate/et2_extension_nextmatch.js index 8875d346cf..78a61b5419 100644 --- a/api/js/etemplate/et2_extension_nextmatch.js +++ b/api/js/etemplate/et2_extension_nextmatch.js @@ -26,9 +26,9 @@ // Include all widgets the nextmatch extension will create et2_widget_template; et2_widget_grid; + et2_widget_selectbox; + et2_widget_selectAccount; et2_widget_taglist; - et2_widget_taglist_account; - et2_widget_link; et2_extension_customfields; // Include all nextmatch subclasses @@ -3404,6 +3404,92 @@ var et2_nextmatch_accountfilterheader = (function(){ "use strict"; return et2_ta });}).call(this); et2_register_widget(et2_nextmatch_accountfilterheader, ['nextmatch-accountfilter']); +/** + * Filter allowing multiple values to be selected, base on a taglist instead + * of a regular selectbox + * + * @augments et2_taglist + */ +var et2_nextmatch_taglistheader = (function(){ "use strict"; return et2_taglist.extend([et2_INextmatchHeader, et2_IResizeable], +{ + attributes: { + autocomplete_url: { default: ''}, + multiple: { default: 'toggle'}, + onchange: { + default: function(event) { + if(typeof this.nextmatch === 'undefined') + { + // Not fully set up yet + return; + } + var col_filter = {}; + col_filter[this.id] = this.getValue(); + // Set value so it's there for response (otherwise it gets cleared if options are updated) + //event.data.set_value(event.data.input.val()); + + this.nextmatch.applyFilters({col_filter: col_filter}); + } + }, + rows: { default: 2}, + class: {default: 'nm_filterheader_taglist'}, + }, + + /** + * Override to add change handler + * + * @memberOf et2_nextmatch_filterheader + */ + createInputWidget: function() { + // Make sure there's an option for all + if(!this.options.empty_label && (!this.options.select_options || !this.options.select_options[""])) + { + this.options.empty_label = this.options.label ? this.options.label : egw.lang("All"); + } + this._super.apply(this, arguments); + }, + + /** + * Disable toggle if there are 2 or less options + * @param {Object[]} options + */ + set_select_options: function(options) + { + if(options && options.length <= 2 && this.options.multiple == 'toggle') + { + this.set_multiple(false) + } + this._super.apply(this, arguments); + }, + + /** + * Set nextmatch is the function which has to be implemented for the + * et2_INextmatchHeader interface. + * + * @param {et2_nextmatch} _nextmatch + */ + setNextmatch: function(_nextmatch) { + this.nextmatch = _nextmatch; + + // Set current filter value from nextmatch settings + if(this.nextmatch.activeFilters.col_filter && typeof this.nextmatch.activeFilters.col_filter[this.id] != "undefined") + { + this.set_value(this.nextmatch.activeFilters.col_filter[this.id]); + + // Make sure it's set in the nextmatch + _nextmatch.activeFilters.col_filter[this.id] = this.getValue(); + } + }, + + // Make sure selectbox is not longer than the column + resize: function() { + this.div.css("height",''); + this.div.css("max-width",jQuery(this.parentNode).innerWidth() + "px"); + this._super.apply(this, arguments); + } + +});}).call(this); +et2_register_widget(et2_nextmatch_taglistheader, ['nextmatch-taglistheader']); + /** * @augments et2_link_entry */