From: Lebbeous Fogle-Weekley Date: Sat, 7 Jan 2012 23:10:54 +0000 (-0500) Subject: pcrudfilterdialog: fix "not between" and "not like", which are not X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2260453c65179682e248c91d83d9d9b05cfb0315;p=working%2FEvergreen.git pcrudfilterdialog: fix "not between" and "not like", which are not operators to json_query. All in all these changes to pcrudfilterdialog are pretty much done. For some reason when you add multiple rows, you often lose the ability to change the selector dropdown in the old rows with errors about "Invalid item argument" from dojo.data.ItemFileReadStore. Tired of fighting this for the moment. Also, although you can have AutoGrid give you a filter link, note the filter does not play together with other filtering things that might be set up on the same page, like a context org unit selector. Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/web/js/dojo/openils/widget/PCrudFilterDialog.js b/Open-ILS/web/js/dojo/openils/widget/PCrudFilterDialog.js index 22194e091b..c42f958c51 100644 --- a/Open-ILS/web/js/dojo/openils/widget/PCrudFilterDialog.js +++ b/Open-ILS/web/js/dojo/openils/widget/PCrudFilterDialog.js @@ -121,6 +121,25 @@ if(!dojo._hasResource['openils.widget.PCrudFilterDialog']) { ); }; + /* This helps convert things that pcrud won't accept ("not between", "not + * like") into proper JSON query expressions later in this file. + * It returns false if a clause doesn't have any such negative operator, + * or it returns true AND gets rid of the "not " part in the clause + * object itself. It's up to the caller to wrap it in {"-not": {}} in + * the right place. */ + function _clause_was_negative(clause) { + /* clause objects really only ever have one property */ + var ops = openils.Util.objectProperties(clause); + var op = ops.pop(); + var matches = op.match(/^not (\w+)$/); + if (matches) { + clause[matches[1]] = clause[op]; + delete clause[op]; + return true; + } + return false; + } + /* This is not the dijit per se. Search further in this file for * "dojo.declare" for the beginning of the dijit. */ function PCrudFilterRowManager() { @@ -169,12 +188,25 @@ if(!dojo._hasResource['openils.widget.PCrudFilterDialog']) { var list = first_pass[field]; if (list.length == 1) { var obj = {}; - obj[field] = list.pop(); + var clause = list.pop(); + if (_clause_was_negative(clause)) { + obj["-not"] = {}; + obj["-not"][field] = clause; + } else { + obj[field] = clause; + } and.push(obj); } else { var or = list.map( - function(expr) { - var obj = {}; obj[field] = expr; return obj; + function(clause) { + var obj = {}; + if (_clause_was_negative(clause)) { + obj["-not"] = {}; + obj["-not"][field] = clause; + } else { + obj[field] = clause; + } + return obj; } ); and.push({"-or": or}); @@ -293,7 +325,7 @@ if(!dojo._hasResource['openils.widget.PCrudFilterDialog']) { this._remove_operator_selector = function() { if (this.operator_selector) { - var old_value = this.operator_selector.attr("value"); + var old_value = this.operator_selector.getValue(); this.operator_selector.destroy(); dojo.empty(this.operator_slot); @@ -328,11 +360,8 @@ if(!dojo._hasResource['openils.widget.PCrudFilterDialog']) { { "identity": old_operator, "onItem": function(item) { - if (item) { /* sic, necessary */ - self.operator_selector.attr( - "value", old_operator - ); - } + if (item) /* sic, necessary */ + self.operator_selector.setValue(old_operator); } } );