acqui-home new links to budget and dealing with budget instead of bookfund
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / js / additem.js
1 function check_additem() {
2         var     barcodes = document.getElementsByName('barcode');
3         var success = true;
4         for(i=0;i<barcodes.length;i++){
5                 for(j=0;j<barcodes.length;j++){
6                         if( (i > j) && (barcodes[i].value == barcodes[j].value) && barcodes[i].value !='') {
7                                 barcodes[i].className='error';
8                                 barcodes[j].className='error';
9                                 success = false;
10                         }
11                 }
12         }
13         // TODO : Add AJAX function to test against barcodes already in the database, not just 
14         // duplicates within the form.  
15         return success;
16 }
17 $(document).ready(function(){
18         $(".cloneItemBlock").click(function(){
19                 var clonedRow = $(this).parent().parent().clone(true);
20                 clonedRow.insertAfter($(this).parent().parent()).find("a.deleteItemBlock").show();
21                 // find ID of cloned row so we can increment it for the clone
22                 var count = $("input[id^=volinf]",clonedRow).attr("id");
23                 var current = Number(count.replace("volinf",""));
24                 var increment = current + 1;
25                 // loop over inputs
26                 var inputs = ["volinf","barcode"];
27                 jQuery.each(inputs,function() {
28                         // increment IDs of labels and inputs in the clone
29                         $("label[for="+this+current+"]",clonedRow).attr("for",this+increment);
30                         $("input[name="+this+"]",clonedRow).attr("id",this+increment);
31                 });
32                 // loop over selects
33                 var selects = ["homebranch","location","itemtype","ccode"];
34                 jQuery.each(selects,function() {
35                         // increment IDs of labels and selects in the clone
36                         $("label[for="+this+current+"]",clonedRow).attr("for",this+increment);
37                         $("input[name="+this+"]",clonedRow).attr("id",this+increment);
38                         $("select[name="+this+"]",clonedRow).attr("id",this+increment);
39                         // find the selected option and select it in the clone
40                         var selectedVal = $("select#"+this+current).find("option:selected").attr("value");
41                         $("select[name="+this+"] option[value="+selectedVal+"]",clonedRow).attr("selected","selected");
42                 });
43                 
44                 var quantityrec = parseFloat($("#quantityrec").attr("value"));
45                 quantityrec++;
46                 $("#quantityrec").attr("value",quantityrec);
47                 return false;
48         });
49         $(".deleteItemBlock").click(function(){
50                 $(this).parent().parent().remove();
51                 var quantityrec = parseFloat($("#quantityrec").attr("value"));
52                 quantityrec--;
53                 $("#quantityrec").attr("value",quantityrec);
54                 return false;
55         });
56 });