Fix PCrudFilterPane generating illegal queries when using the "not like" and "not... user/paxed/pcrudfilterpane-fix
authorPasi Kallinen <pasi.kallinen@pttk.fi>
Thu, 29 Aug 2013 14:36:37 +0000 (17:36 +0300)
committerPasi Kallinen <pasi.kallinen@pttk.fi>
Fri, 30 Aug 2013 15:00:34 +0000 (18:00 +0300)
Make the window remember the user-input value even when changing the operator.

Signed-off-by: Pasi Kallinen <pasi.kallinen@pttk.fi>
Open-ILS/web/js/dojo/openils/widget/PCrudFilterPane.js

index 4c6af87..01278ee 100644 (file)
@@ -165,9 +165,9 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) {
 
         var ops = openils.Util.objectProperties(clause);
         var op = ops.pop();
-        var matches = op.match(/^not [lb].+$/); /* "not in" needs no change */
+        var matches = op.match(/^(not) ([lb].+)$/); /* "not in" needs no change */
         if (matches) {
-            clause[matches[1]] = clause[op];
+            clause[matches[2]] = clause[op];
             delete clause[op];
             return true;
         }
@@ -531,15 +531,20 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) {
         };
 
         this._clear_value_slot = function() {
+           var old_widget_values = [];
             if (this.value_widgets) {
                 this.value_widgets.forEach(
                     function(autowidg) {
-                        if (autowidg.widget)
+                        if (autowidg.widget) {
+                           old_widget_values.push({'value' : autowidg.widget.attr("value"),
+                                                   'type' : autowidg.widget.attr("type") });
                             autowidg.widget.destroy();
+                       }
                     }
                 );
                 delete this.value_widgets;
             }
+           this.old_widget_values = old_widget_values;
 
             dojo.empty(this.value_slot);
         };
@@ -575,8 +580,14 @@ if (!dojo._hasResource['openils.widget.PCrudFilterPane']) {
                     this.value_widgets.push(
                         this._build_one_value_widget(constr)
                     );
+                   if (typeof this.old_widget_values != "undefined" &&
+                       typeof this.old_widget_values[i] != "undefined" &&
+                       this.value_widgets[i].widget.attr("type") == this.old_widget_values[i].type) {
+                       this.value_widgets[i].widget.attr("value", this.old_widget_values[i].value);
+                   }
                 }
             }
+           delete this.old_widget_values;
         };
 
         this._build_set_value_widgets = function(constr) {