From: Lebbeous Fogle-Weekley Date: Tue, 25 Sep 2012 22:17:56 +0000 (-0400) Subject: Saving/loading filter rows for IN, NOT IN operators X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Furl_verify_rebase;p=evergreen%2Fequinox.git Saving/loading filter rows for IN, NOT IN operators Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js b/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js index ef24865896..4c6af87b6b 100644 --- a/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js +++ b/Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js @@ -600,7 +600,7 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { "innerHTML": "[+]", /* XXX i18n? */ "onclick": dojo.hitch(this, function() { _add_or_at_least_select( - this._value_of_widget(entry_widget), + this._value_for_compile(entry_widget), value_widget ); entry_widget.widget.attr("value", ""); /* clear */ @@ -630,7 +630,19 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { return widg; }; - this._value_of_widget = function(widg) { + this._value_for_serialize = function(widg) { + if (!widg.widget) /* widg is */ return dojo.filter( widg.options, @@ -669,13 +681,14 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { this.get_selected_operator_name = function() { var item = this.get_selected_operator(); - if (item) - return this.operator_selector.store.getValue(item, "name") - else + if (item) { + return this.operator_selector.store.getValue(item, "name"); + } else { console.warn( "Could not determine selected operator. " + "Something is about to break." ); + } }; this.update_selected_operator = function(value) { @@ -715,12 +728,22 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { if (this.value_widgets) { values = this.value_widgets.map( - function(widg) { return widg.widget.attr("value"); } + dojo.hitch( + this, function(w) { + return this._value_for_serialize(w); + } + ) ); } + /* The following grew organically to be very silly and confusing. + * Could use a rethink (PCrudFilterRow.initialize() would also need + * matching changes). */ if (values.length == 1) { - serialized.value = values[0]; + if (dojo.isArray(values[0])) + serialized.values = values[0]; + else + serialized.value = values[0]; } else if (values.length > 1) { serialized.values = values; } @@ -731,7 +754,7 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { this.compile = function() { if (this.value_widgets) { var values = this.value_widgets.map( - dojo.hitch(this, this._value_of_widget) + dojo.hitch(this, this._value_for_compile) ); if (!values.length) { @@ -784,10 +807,22 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) { } initializer.values = initializer.values || []; - for (var i = 0; i < initializer.values.length; i++) { - this.value_widgets[i].widget.attr( - "value", initializer.values[i] + if (initializer.operator.match(/^(not ?)in$/)) { + /* "in" and "not in" need special treatement */ + dojo.forEach( + initializer.values, dojo.hitch(this, function(v) { + _add_or_at_least_select( + v, this.value_widgets[0] + ); + }) ); + } else { + /* other operators work this way: */ + for (var i = 0; i < initializer.values.length; i++) { + this.value_widgets[i].widget.attr( + "value", initializer.values[i] + ); + } } } );