Steamlining javascript for cloning additem block and tweaking style.
[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                 $(this).parent().parent().clone(true).insertAfter($(this).parent().parent()).find("a.deleteItemBlock").show();
20                 var quantityrec = parseFloat($("#quantityrec").attr("value"));
21                 quantityrec++;
22                 $("#quantityrec").attr("value",quantityrec);
23                 return false;
24         });
25         $(".deleteItemBlock").click(function(){
26                 $(this).parent().parent().remove();
27                 var quantityrec = parseFloat($("#quantityrec").attr("value"));
28                 quantityrec--;
29                 $("#quantityrec").attr("value",quantityrec);
30                 return false;
31         });
32 });