From afb14a532b3005cb9f48ebe58a4cff0eab145a5e Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Mon, 30 Apr 2012 17:00:50 +0000 Subject: [PATCH] Get nm changing selectbox options / filters working --- etemplate/js/et2_extension_nextmatch.js | 18 ++++++++++++++++++ etemplate/js/et2_widget_selectbox.js | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index eb698f9610..61422beb1b 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -1093,6 +1093,10 @@ var et2_nextmatch_header_bar = et2_DOMWidget.extend(et2_INextmatchHeader, { // Set onChange var input = select.input; + // Tell framework to ignore, or it will reset it to ''/empty when it does loadingFinished() + select.attributes.value.ignore = true; + select.attributes.select_options.ignore = true; + if (this.nextmatch.options.settings[name+"_onchange"]) { // Make sure to get the new value for filtering @@ -1439,6 +1443,13 @@ var et2_nextmatch_filterheader = et2_selectbox.extend(et2_INextmatchHeader, { } event.data.nextmatch.applyFilters(); }); + + }, + + set_select_options: function(_options) { + // Tell framework to ignore, or it will reset it to ''/empty when it does loadingFinished() + this.attributes.select_options.ignore = true; + this._super.apply(this, arguments); }, /** @@ -1452,6 +1463,9 @@ var et2_nextmatch_filterheader = et2_selectbox.extend(et2_INextmatchHeader, { if(this.nextmatch.options.settings.col_filter && this.nextmatch.options.settings.col_filter[this.id]) { this.set_value(this.nextmatch.options.settings.col_filter[this.id]); + + // Tell framework to ignore, or it will reset it to ''/empty when it does loadingFinished() + this.attributes.value.ignore = true; } } @@ -1499,6 +1513,10 @@ var et2_nextmatch_entryheader = et2_link_entry.extend(et2_INextmatchHeader, { if(this.nextmatch.options.settings.col_filter && this.nextmatch.options.settings.col_filter[this.id]) { this.set_value(this.nextmatch.options.settings.col_filter[this.id]); + + // Tell framework to ignore, or it will reset it to ''/empty when it does loadingFinished() + this.attributes.value.ignore = true; + this.attributes.select_options.ignore = true; } var self = this; // Fire on lost focus, clear filter if user emptied box diff --git a/etemplate/js/et2_widget_selectbox.js b/etemplate/js/et2_widget_selectbox.js index 8c46e46fd7..192ee0f7c0 100644 --- a/etemplate/js/et2_widget_selectbox.js +++ b/etemplate/js/et2_widget_selectbox.js @@ -374,6 +374,11 @@ var et2_selectbox = et2_inputWidget.extend({ { if(jQuery("option[value='"+_value+"']", this.input).attr("selected", true).length == 0) { + if(this.options.select_options[_value]) + { + // Options not set yet? Do that now, which will try again. + return this.set_select_options(this.options.select_options); + } this.egw().debug("warning", "Tried to set value that isn't an option", this, _value); } } @@ -415,6 +420,21 @@ var et2_selectbox = et2_inputWidget.extend({ * added after the "option"-widgets were added to selectbox. */ set_select_options: function(_options) { + // Empty current options + if(this.input) + { + this.input.empty(); + } + else if (this.multiOptions) + { + this.multiOptions.empty(); + } + // Re-add empty, it's usually not there + if(this.options.empty_label && typeof _options[''] == 'undefined') + { + _options[''] = this.options.empty_label; + } + // Add the select_options for (var key in _options) {