LP#1154656 MARC Expert Search "Add Rows" adds duplicate row
authorMichael Peters <mpeters@emeralddata.net>
Fri, 5 Dec 2014 16:34:21 +0000 (11:34 -0500)
committerMichael Peters <mpeters@emeralddata.net>
Fri, 5 Dec 2014 16:34:21 +0000 (11:34 -0500)
This patch changes the behavior of the "Add Search Row" link
(JavaScript function from simple.js "addExpertRow()") so that
we are always cloning the initial "empty" row instead of
potentially cloning a row -- by way of cloneNode() -- with user
input in place, and causing duplicate search rows.

Signed-off-by: Michael Peters <mpeters@emeralddata.net>
Open-ILS/web/js/ui/default/opac/simple.js

index b491586..7c49b39 100644 (file)
@@ -13,31 +13,36 @@ function addClass(node, cls) {
 }
 function unHideMe(node) { removeClass(node, "hide_me"); }
 function hideMe(node) { addClass(node, "hide_me"); }
+(function($){
 
-var _search_row_template, _expert_row_template;
+var _search_row_template, _expert_row_template, t;
+var _el_adv_global_row = $("adv_global_row"), _el_adv_expert_row = $("adv_expert_row");
+if (_el_adv_global_row) {
+    t = _el_adv_global_row.cloneNode(true);
+    t.id = null;
+    _search_row_template = t;
+}
 function addSearchRow() {
-    if (!_search_row_template) {
-        t = $("adv_global_row").cloneNode(true);
-        t.id = null;
-        _search_row_template = t;
-    }
-
     $("adv_global_tbody").insertBefore(
         _search_row_template.cloneNode(true),
         $("adv_global_addrow")
     );
 }
-function addExpertRow() {
-    if (!_expert_row_template) {
-        t = $("adv_expert_row").cloneNode(true);
-        t.id = null;
-        _expert_row_template = t;
-    }
 
+if (_el_adv_expert_row) {
+    t = _el_adv_expert_row.cloneNode(true);
+    t.id = null;
+    _expert_row_template = t;
+}
+function addExpertRow() {
     $("adv_expert_rows_here").appendChild(
         _expert_row_template.cloneNode(true)
     );
 }
+
+window.addSearchRow = addSearchRow;
+window.addExpertRow = addExpertRow;
+})($);
 function killRowIfAtLeast(min, link) {
     var row = link.parentNode.parentNode;
     if (row.parentNode.getElementsByTagName("tr").length > min)