TPac; repairs to advanced search query propagation
authorBill Erickson <berick@esilibrary.com>
Tue, 11 Oct 2011 15:33:28 +0000 (11:33 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 11 Oct 2011 15:47:09 +0000 (11:47 -0400)
In some cases, TPac will duplicate components of an advanced search
query into the advanced search rows.  This patch fixes that with
better array handling, particularly with CGI param search components
that do not have corresponding analogs at a given array position (i.e.
starting out with arrays of different sizes)

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/opac/parts/advanced/global_row.tt2

index 66ecea4..02aa5d1 100644 (file)
@@ -7,20 +7,14 @@
     ];
     contains = CGI.param('contains');
     queries = CGI.param('query');
-    bools = CGI.param('bool') || ['and' x 3];
-    qtypes = CGI.param('qtype') || ['keyword' x 3];
+    bools = CGI.param('bool');
+    qtypes = CGI.param('qtype');
+    rowcount = 3;
 
-    IF !qtypes.0; # not an array
-        qtypes = [qtypes];
-        bools = [bools];
-        queries = [queries];
-    END;
-
-    WHILE qtypes.size < 3;
-        qtypes.push('keyword');
-        bools.push('and');
-        queries.push('');
-    END;
+    # scalar.merge treats the scalar as a 1-item array
+    WHILE queries.size < rowcount; queries = queries.merge(['']); END;
+    WHILE bools.size < rowcount; bools = bools.merge(['and']); END;
+    WHILE qtypes.size < rowcount; qtypes = qtypes.merge(['keyword']); END;
 
     FOR qtype IN qtypes;
         c = contains.shift;