From 457e05d9202d4c687c31471b5efb941c8c14aee1 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 9 May 2016 19:17:04 +0000 Subject: [PATCH] Change filterheaders to extend taglist instead of select --- api/js/etemplate/et2_extension_nextmatch.js | 83 ++++++++++++------- api/src/Etemplate/Widget/Nextmatch.php | 8 ++ .../Widget/Nextmatch/Accountfilter.php | 2 +- .../Widget/Nextmatch/Customfilter.php | 19 +++++ .../Widget/Nextmatch/Filterheader.php | 2 +- api/templates/default/etemplate2.css | 1 + 6 files changed, 81 insertions(+), 34 deletions(-) diff --git a/api/js/etemplate/et2_extension_nextmatch.js b/api/js/etemplate/et2_extension_nextmatch.js index bf7eccfd1e..d0b24963e1 100644 --- a/api/js/etemplate/et2_extension_nextmatch.js +++ b/api/js/etemplate/et2_extension_nextmatch.js @@ -26,8 +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 @@ -3250,10 +3251,30 @@ var et2_nextmatch_sortheader = (function(){ "use strict"; return et2_nextmatch_h et2_register_widget(et2_nextmatch_sortheader, ['nextmatch-sortheader']); /** - * @augments et2_selectbox + * @augments et2_taglist */ -var et2_nextmatch_filterheader = (function(){ "use strict"; return et2_selectbox.extend([et2_INextmatchHeader, et2_IResizeable], +var et2_nextmatch_filterheader = (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}); + } + } + }, + /** * Override to add change handler * @@ -3266,21 +3287,6 @@ var et2_nextmatch_filterheader = (function(){ "use strict"; return et2_selectbox this.options.empty_label = this.options.label ? this.options.label : egw.lang("All"); } this._super.apply(this, arguments); - - this.input.change(this, function(event) { - if(typeof event.data.nextmatch == 'undefined') - { - // Not fully set up yet - return; - } - var col_filter = {}; - col_filter[event.data.id] = event.data.input.val(); - // Set value so it's there for response (otherwise it gets cleared if options are updated) - event.data.set_value(event.data.input.val()); - - event.data.nextmatch.applyFilters({col_filter: col_filter}); - }); - }, /** @@ -3313,8 +3319,33 @@ et2_register_widget(et2_nextmatch_filterheader, ['nextmatch-filterheader']); /** * @augments et2_selectAccount */ -var et2_nextmatch_accountfilterheader = (function(){ "use strict"; return et2_selectAccount.extend([et2_INextmatchHeader, et2_IResizeable], +var et2_nextmatch_accountfilterheader = (function(){ "use strict"; return et2_taglist_account.extend([et2_INextmatchHeader, et2_IResizeable], { + attributes: { + "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(); + if(!col_filter[this.id] || col_filter[this.id].length == 0) + { + col_filter[this.id] = null; + } + // 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}); + } + } + }, + /** * Override to add change handler * @@ -3327,18 +3358,6 @@ var et2_nextmatch_accountfilterheader = (function(){ "use strict"; return et2_se this.options.empty_label = this.options.label ? this.options.label : egw.lang("All"); } this._super.apply(this, arguments); - - this.input.change(this, function(event) { - if(typeof event.data.nextmatch == 'undefined') - { - // Not fully set up yet - return; - } - var col_filter = {}; - col_filter[event.data.id] = event.data.getValue(); - event.data.nextmatch.applyFilters({col_filter: col_filter}); - }); - }, /** diff --git a/api/src/Etemplate/Widget/Nextmatch.php b/api/src/Etemplate/Widget/Nextmatch.php index 3b3a6cc1dc..0df92ad3db 100644 --- a/api/src/Etemplate/Widget/Nextmatch.php +++ b/api/src/Etemplate/Widget/Nextmatch.php @@ -310,6 +310,14 @@ class Nextmatch extends Etemplate\Widget $template->run('validate', array('', $expand, $expand['cont'], &$valid_filters), false); // $respect_disabled=false: as client may disable things, here we validate everything and leave it to the get_rows to interpret $filters = $valid_filters[$form_name]; } + // Avoid empty arrays, they cause problems with db filtering + foreach($filters['col_filter'] as $col => &$val) + { + if(is_array($val) && count($val) == 0) + { + $val = null; + } + } //error_log($this . " Valid filters: " . array2string($filters)); } diff --git a/api/src/Etemplate/Widget/Nextmatch/Accountfilter.php b/api/src/Etemplate/Widget/Nextmatch/Accountfilter.php index dffa781d02..a58b6bb316 100644 --- a/api/src/Etemplate/Widget/Nextmatch/Accountfilter.php +++ b/api/src/Etemplate/Widget/Nextmatch/Accountfilter.php @@ -18,7 +18,7 @@ use EGroupware\Api\Etemplate\Widget; /** * Extend selectbox and change type so proper users / groups get loaded, according to preferences */ -class Accountfilter extends Widget\Select +class Accountfilter extends Widget\Taglist { /** * Parse and set extra attributes from xml in template object diff --git a/api/src/Etemplate/Widget/Nextmatch/Customfilter.php b/api/src/Etemplate/Widget/Nextmatch/Customfilter.php index 15c552cffb..7f13cbe5db 100644 --- a/api/src/Etemplate/Widget/Nextmatch/Customfilter.php +++ b/api/src/Etemplate/Widget/Nextmatch/Customfilter.php @@ -59,5 +59,24 @@ class Customfilter extends Widget\Transformer } parent::beforeSendToClient($cname, $expand); } + + + /** + * Validate input + * + * @param string $cname current namespace + * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont' + * @param array $content + * @param array &$validated=array() validated content + */ + public function validate($cname, array $expand, array $content, &$validated=array()) + { + $value = $value_in = self::get_array($content, $form_name); + + $valid =& self::get_array($validated, $form_name, true); + // returning null instead of array(), as array() will be overwritten by etemplate_new::complete_array_merge() + // with preserved old content and therefore user can not empty a taglist + $valid = $value ? $value : null; + } } Customfilter::registerWidget(__NAMESPACE__.'\\Customfilter', array('nextmatch-customfilter')); \ No newline at end of file diff --git a/api/src/Etemplate/Widget/Nextmatch/Filterheader.php b/api/src/Etemplate/Widget/Nextmatch/Filterheader.php index 8ac44251e1..7f7d0a46a9 100644 --- a/api/src/Etemplate/Widget/Nextmatch/Filterheader.php +++ b/api/src/Etemplate/Widget/Nextmatch/Filterheader.php @@ -18,7 +18,7 @@ use EGroupware\Api\Etemplate\Widget; /** * Extend selectbox so select options get parsed properly before being sent to client */ -class Filterheader extends Widget\Select +class Filterheader extends Widget\Taglist { } diff --git a/api/templates/default/etemplate2.css b/api/templates/default/etemplate2.css index dfc7a80557..318f26fe8f 100644 --- a/api/templates/default/etemplate2.css +++ b/api/templates/default/etemplate2.css @@ -1049,6 +1049,7 @@ ul.et2_link_string { } /* Toggle single / multiple */ .et2_taglist_toggle { + position: relative; } .et2_taglist_toggle > div.ms-ctn { display: inline-block;