[Koha-patches] [PATCH] Fix for Bug 2700, Keeping Data When Adding Multiple Items

Owen Leonard oleonard at myacpl.org
Tue Nov 4 17:21:47 CET 2008


When cloning the set of inputs, the new js
increments the IDs of each form field (to keep them unique) and automatically
selects the option that was selected in the cloned group.
---
 koha-tmpl/intranet-tmpl/prog/en/js/additem.js      |   26 +++++++++++++++++++-
 .../prog/en/modules/acqui/orderreceive.tmpl        |   24 +++++++++---------
 2 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/js/additem.js b/koha-tmpl/intranet-tmpl/prog/en/js/additem.js
index a1e3092..a9eeda9 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/js/additem.js
+++ b/koha-tmpl/intranet-tmpl/prog/en/js/additem.js
@@ -16,7 +16,31 @@ function check_additem() {
 }
 $(document).ready(function(){
 	$(".cloneItemBlock").click(function(){
-		$(this).parent().parent().clone(true).insertAfter($(this).parent().parent()).find("a.deleteItemBlock").show();
+		var clonedRow = $(this).parent().parent().clone(true);
+		clonedRow.insertAfter($(this).parent().parent()).find("a.deleteItemBlock").show();
+		// find ID of cloned row so we can increment it for the clone
+		var count = $("input[id^=volinf]",clonedRow).attr("id");
+		var current = Number(count.replace("volinf",""));
+		var increment = current + 1;
+		// loop over inputs
+		var inputs = ["volinf","barcode"];
+		jQuery.each(inputs,function() {
+			// increment IDs of labels and inputs in the clone
+			$("label[for="+this+current+"]",clonedRow).attr("for",this+increment);
+			$("input[name="+this+"]",clonedRow).attr("id",this+increment);
+		});
+		// loop over selects
+		var selects = ["homebranch","location","itemtype","ccode"];
+		jQuery.each(selects,function() {
+			// increment IDs of labels and selects in the clone
+			$("label[for="+this+current+"]",clonedRow).attr("for",this+increment);
+			$("input[name="+this+"]",clonedRow).attr("id",this+increment);
+			$("select[name="+this+"]",clonedRow).attr("id",this+increment);
+			// find the selected option and select it in the clone
+			var selectedVal = $("select#"+this+current).find("option:selected").attr("value");
+			$("select[name="+this+"] option[value="+selectedVal+"]",clonedRow).attr("selected","selected");
+		});
+		
 		var quantityrec = parseFloat($("#quantityrec").attr("value"));
 		quantityrec++;
 		$("#quantityrec").attr("value",quantityrec);
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl
index 021b2d3..74a16d5 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tmpl
@@ -46,12 +46,12 @@ fieldset.rows .itemblock fieldset.action { padding:.5em; }
   <div id="outeritemblock">
 	<div class="itemblock">
 	<ol>
-	<li> <label for="volinf">Volume/Copy (for serials): </label>
-        <input type="text" size="20" name="volinf" id="volinf" /></li>
-    <li> <label for="barcode">Item barcode: </label>
-        <input type="text" size="20" name="barcode" id="barcode" value="<!-- TMPL_VAR NAME="barcode" -->" /></li>
-    <li> <label for="homebranch">Home library: </label>
-            <select name="homebranch" id="homebranch">            <!-- TMPL_LOOP name="branchloop" -->
+	<li> <label for="volinf1">Volume/Copy (for serials): </label>
+        <input type="text" size="20" name="volinf" id="volinf1" /></li>
+    <li> <label for="barcode1">Item barcode: </label>
+        <input type="text" size="20" name="barcode" id="barcode1" value="<!-- TMPL_VAR NAME="barcode" -->" /></li>
+    <li> <label for="homebranch1">Home library: </label>
+            <select name="homebranch" id="homebranch1">            <!-- TMPL_LOOP name="branchloop" -->
                 <!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="description" --></option>
                 <!-- TMPL_ELSE -->
                 <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="description" --></option>
@@ -59,8 +59,8 @@ fieldset.rows .itemblock fieldset.action { padding:.5em; }
             <!-- /TMPL_LOOP -->
             </select></li>
     <!-- TMPL_IF NAME="locationloop" -->
-		<li> <label for="location">Shelf location: </label>
-            <select name="location" id="location">            <!-- TMPL_LOOP name="locationloop" -->
+		<li> <label for="location1">Shelf location: </label>
+            <select name="location" id="location1"><!-- TMPL_LOOP name="locationloop" -->
                 <!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="description" --></option>
                 <!-- TMPL_ELSE -->
                 <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="description" --></option>
@@ -69,8 +69,8 @@ fieldset.rows .itemblock fieldset.action { padding:.5em; }
             </select></li>
    <!-- /TMPL_IF -->
     <!-- TMPL_IF NAME="itype" -->
-    <li> <label for="itemtype">Item type: </label>
-            <select name="itemtype" id="itemtype"><!-- TMPL_LOOP name="itemtypeloop" -->
+    <li> <label for="itemtype1">Item type: </label>
+            <select name="itemtype" id="itemtype1"><!-- TMPL_LOOP name="itemtypeloop" -->
                 <!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="description" --></option>
                 <!-- TMPL_ELSE -->
                 <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="description" --></option>
@@ -79,8 +79,8 @@ fieldset.rows .itemblock fieldset.action { padding:.5em; }
             </select></li>
    <!-- /TMPL_IF -->
     <!-- TMPL_IF NAME="ccodeloop" -->
-    <li> <label for="ccode">Collection: </label>
-            <select name="ccode" id="ccode">            <!-- TMPL_LOOP name="ccodeloop" -->
+    <li> <label for="ccode1">Collection: </label>
+            <select name="ccode" id="ccode1">            <!-- TMPL_LOOP name="ccodeloop" -->
                 <!-- TMPL_IF NAME="selected" --><option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="description" --></option>
                 <!-- TMPL_ELSE -->
                 <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="description" --></option>
-- 
1.5.5.GIT




More information about the Koha-patches mailing list