Lines 1-97
Link Here
|
1 |
function deleteItemBlock(index) { |
1 |
function addItem( node ) { |
2 |
var aDiv = document.getElementById(index); |
2 |
var index = $(node).parent().attr('id'); |
3 |
aDiv.parentNode.removeChild(aDiv); |
3 |
var current_qty = parseInt($("#quantity").val()); |
4 |
var quantity = document.getElementById('quantity'); |
4 |
var max_qty; |
5 |
quantity.setAttribute('value',parseFloat(quantity.getAttribute('value'))-1); |
5 |
if($("#quantity_to_receive").length != 0){ |
|
|
6 |
max_qty = parseInt($("#quantity_to_receive").val()); |
7 |
} else { |
8 |
max_qty = 99999; |
9 |
} |
10 |
if ( $("#items_list table").find('tr[idblock="' + index + '"]').length == 0 ) { |
11 |
if ( current_qty < max_qty ) { |
12 |
if ( current_qty < max_qty - 1 ) |
13 |
cloneItemBlock(index); |
14 |
addItemInList(index); |
15 |
$("#quantity").val(current_qty + 1); |
16 |
} else if ( current_qty >= max_qty ) { |
17 |
alert(_("You can't receive any more items.")); |
18 |
} |
19 |
} else { |
20 |
if ( current_qty < max_qty ) |
21 |
cloneItemBlock(index); |
22 |
var tr = constructTrNode(index); |
23 |
$("#items_list table").find('tr[idblock="' + index + '"]:first').replaceWith(tr); |
24 |
} |
25 |
$("#" + index).hide(); |
26 |
} |
27 |
|
28 |
function showItem(index) { |
29 |
$("#outeritemblock").children("div").each(function(){ |
30 |
if ( $(this).attr('id') == index ) { |
31 |
$(this).show(); |
32 |
} else { |
33 |
if ( $("#items_list table").find('tr[idblock="' + $(this).attr('id') + '"]').length == 0 ) { |
34 |
$(this).remove(); |
35 |
} else { |
36 |
$(this).hide(); |
37 |
} |
38 |
} |
39 |
}); |
40 |
} |
41 |
|
42 |
function constructTrNode(index) { |
43 |
var barcode = $('#' + index).find("[name='kohafield'][value='items.barcode']").prevAll("[name='field_value']")[0]; |
44 |
barcode = $(barcode).val(); |
45 |
var homebranch = $("#" + index).find("[name='kohafield'][value='items.homebranch']").prevAll("[name='field_value']")[0]; |
46 |
homebranch = $(homebranch).val(); |
47 |
var loc = $("#" + index).find("[name='kohafield'][value='items.location']").prevAll("[name='field_value']")[0]; |
48 |
loc = $(loc).val(); |
49 |
var callnumber = $("#" + index).find("[name='kohafield'][value='items.itemcallnumber']").prevAll("[name='field_value']")[0]; |
50 |
callnumber = $(callnumber).val(); |
51 |
var show_link = "<a href='#items' onclick='showItem(\"" + index + "\");'>Show</a>"; |
52 |
var del_link = "<a href='#' onclick='deleteItemBlock(this, \"" + index + "\");'>Delete</a>"; |
53 |
var result = "<tr idblock='" + index + "'>"; |
54 |
result += "<td>" + barcode + "</td>"; |
55 |
result += "<td>" + homebranch + "</td>"; |
56 |
result += "<td>" + loc + "</td>"; |
57 |
result += "<td>" + callnumber + "</td>"; |
58 |
result += "<td>" + show_link + "</td>"; |
59 |
result += "<td>" + del_link + "</td>"; |
60 |
result += "</tr>"; |
61 |
|
62 |
return result; |
63 |
} |
64 |
|
65 |
function addItemInList(index) { |
66 |
$("#items_list").show(); |
67 |
var tr = constructTrNode(index); |
68 |
$("#items_list table tbody").append(tr); |
6 |
} |
69 |
} |
7 |
function cloneItemBlock(index) { |
70 |
|
8 |
var original = document.getElementById(index); //original <div> |
71 |
function deleteItemBlock(node_a, index) { |
9 |
var clone = original.cloneNode(true); |
72 |
$("#" + index).remove(); |
|
|
73 |
var current_qty = parseInt($("#quantity").val()); |
74 |
var max_qty; |
75 |
if($("#quantity_to_receive").length != 0) { |
76 |
max_qty = parseInt($("#quantity_to_receive").val()); |
77 |
} else { |
78 |
max_qty = 99999; |
79 |
} |
80 |
$("#quantity").val(current_qty - 1); |
81 |
$(node_a).parents('tr').remove(); |
82 |
if(current_qty - 1 == 0) |
83 |
$("#items_list").hide(); |
84 |
|
85 |
if ( $("#quantity").val() <= max_qty - 1) { |
86 |
if ( $("#outeritemblock").children("div :visible").length == 0 ) { |
87 |
$("#outeritemblock").children("div:last").show(); |
88 |
} |
89 |
} |
90 |
if ( $("#quantity").val() == 0 && $("#outeritemblock > div").length == 0) { |
91 |
cloneItemBlock(); |
92 |
} |
93 |
} |
94 |
|
95 |
function cloneItemBlock(index) { |
96 |
var original; |
97 |
if(index) { |
98 |
original = $("#" + index); //original <div> |
99 |
} |
100 |
var dont_copy_fields = ['items.stocknumber', 'items.copynumber', 'items.barcode']; |
101 |
|
10 |
var random = Math.floor(Math.random()*100000); // get a random itemid. |
102 |
var random = Math.floor(Math.random()*100000); // get a random itemid. |
11 |
// set the attribute for the new 'div' subfields |
103 |
var clone = $("<div id='itemblock"+random+"'></div>") |
12 |
clone.setAttribute('id',index + random);//set another id. |
104 |
$.ajax({ |
13 |
var NumTabIndex; |
105 |
url: "/cgi-bin/koha/services/itemrecorddisplay.pl", |
14 |
NumTabIndex = parseInt(original.getAttribute('tabindex')); |
106 |
dataType: 'html', |
15 |
if(isNaN(NumTabIndex)) NumTabIndex = 0; |
107 |
data: { |
16 |
clone.setAttribute('tabindex',NumTabIndex+1); |
108 |
frameworkcode: 'ACQ' |
17 |
var CloneButtonPlus; |
109 |
}, |
18 |
var CloneButtonMinus; |
110 |
success: function(data, textStatus, jqXHR) { |
19 |
// try{ |
111 |
/* Create the item block */ |
20 |
var jclone = $(clone); |
112 |
$(clone).append(data); |
21 |
CloneButtonPlus = $("a.addItem", jclone).get(0); |
113 |
/* Change all itemid fields value */ |
22 |
CloneButtonPlus.setAttribute('onclick',"cloneItemBlock('" + index + random + "')"); |
114 |
$(clone).find("input[name='itemid']").each(function(){ |
23 |
CloneButtonMinus = $("a.delItem", jclone).get(0); |
115 |
$(this).val(random); |
24 |
CloneButtonMinus.setAttribute('onclick',"deleteItemBlock('" + index + random + "')"); |
116 |
}); |
25 |
CloneButtonMinus.setAttribute('style',"display:inline"); |
117 |
/* Add buttons + and Clear */ |
26 |
// change itemids of the clone |
118 |
var buttonPlus = '<a name="buttonPlus" style="cursor:pointer; color:grey; font-size:180%; margin:0 1em;" onclick="addItem(this)">+</a>'; |
27 |
var elems = clone.getElementsByTagName('input'); |
119 |
var buttonClear = '<a name="buttonClear" style="cursor:pointer; color:grey; font-size:180%" onclick="clearItemBlock(this)">Clear</a>'; |
28 |
for( i = 0 ; elems[i] ; i++ ) |
120 |
$(clone).append(buttonPlus).append(buttonClear); |
29 |
{ |
121 |
/* Copy values from the original block (input) */ |
30 |
if(elems[i].name.match(/^itemid/)) { |
122 |
$(original).find("input[name='field_value']").each(function(){ |
31 |
elems[i].value = random; |
123 |
var kohafield = $(this).siblings("input[name='kohafield']").val(); |
|
|
124 |
if($(this).val() && dont_copy_fields.indexOf(kohafield) == -1) { |
125 |
$(this).parent("div").attr("id").match(/^(subfield.)/); |
126 |
var id = RegExp.$1; |
127 |
var value = $(this).val(); |
128 |
$(clone).find("div[id^='"+id+"'] input[name='field_value']").val(value); |
129 |
} |
130 |
}); |
131 |
/* Copy values from the original block (select) */ |
132 |
$(original).find("select[name='field_value']").each(function(){ |
133 |
var kohafield = $(this).siblings("input[name='kohafield']").val(); |
134 |
if($(this).val() && dont_copy_fields.indexOf(kohafield) == -1) { |
135 |
$(this).parent("div").attr("id").match(/^(subfield.)/); |
136 |
var id = RegExp.$1; |
137 |
var value = $(this).val(); |
138 |
$(clone).find("div[id^='"+id+"'] select[name='field_value']").val(value); |
139 |
} |
140 |
}); |
141 |
|
142 |
$("#outeritemblock").append(clone); |
32 |
} |
143 |
} |
33 |
} |
144 |
}); |
34 |
// } |
145 |
} |
35 |
//catch(e){ // do nothig if ButtonPlus & CloneButtonPlus don't exist. |
146 |
|
36 |
//} |
147 |
function clearItemBlock(node) { |
37 |
// insert this line on the page |
148 |
var index = $(node).parent().attr('id'); |
38 |
original.parentNode.insertBefore(clone,original.nextSibling); |
149 |
var block = $("#"+index); |
39 |
var quantity = document.getElementById('quantity'); |
150 |
$(block).find("input[type='text']").each(function(){ |
40 |
quantity.setAttribute('value',parseFloat(quantity.getAttribute('value'))+1); |
151 |
$(this).val(""); |
|
|
152 |
}); |
153 |
$(block).find("select").each(function(){ |
154 |
$(this).find("option:first").attr("selected", true); |
155 |
}); |
41 |
} |
156 |
} |
|
|
157 |
|
42 |
function check_additem() { |
158 |
function check_additem() { |
43 |
var barcodes = document.getElementsByName('barcode'); |
159 |
var success = true; |
44 |
var success = true; |
160 |
var array_fields = ['items.stocknumber', 'items.copynumber', 'items.barcode']; |
45 |
for(i=0;i<barcodes.length;i++){ |
161 |
var url = '../acqui/check_unicity.pl?'; // Url for ajax call |
46 |
for(j=0;j<barcodes.length;j++){ |
162 |
$(".error").empty(); // Clear error div |
47 |
if( (i > j) && (barcodes[i].value == barcodes[j].value) && barcodes[i].value !='') { |
163 |
|
48 |
barcodes[i].className='error'; |
164 |
// Check if a value is duplicated in form |
49 |
barcodes[j].className='error'; |
165 |
for ( field in array_fields ) { |
50 |
success = false; |
166 |
var fieldname = array_fields[field].split('.')[1]; |
51 |
} |
167 |
var values = new Array(); |
52 |
} |
168 |
$("[name='kohafield'][value="+array_fields[field]+"]").each(function(){ |
53 |
} |
169 |
var input = $(this).prevAll("input[name='field_value']")[0]; |
54 |
// TODO : Add AJAX function to test against barcodes already in the database, not just |
170 |
if($(input).val()) { |
55 |
// duplicates within the form. |
171 |
values.push($(input).val()); |
56 |
return success; |
172 |
url += "field=" + fieldname + "&value=" + $(input).val() + "&"; // construct url |
|
|
173 |
} |
174 |
}); |
175 |
|
176 |
var sorted_arr = values.sort(); |
177 |
for (var i = 0; i < sorted_arr.length - 1; i += 1) { |
178 |
if (sorted_arr[i + 1] == sorted_arr[i]) { |
179 |
$(".error").append( fieldname + " '" + sorted_arr[i] + "' is duplicated<br/>"); |
180 |
success = false; |
181 |
} |
182 |
} |
183 |
} |
184 |
|
185 |
// If there is a duplication, we raise an error |
186 |
if ( success == false ) { |
187 |
$(".error").show(); |
188 |
return false; |
189 |
} |
190 |
|
191 |
// Else, we check in DB |
192 |
var xmlhttp = null; |
193 |
xmlhttp = new XMLHttpRequest(); |
194 |
if ( typeof xmlhttp.overrideMimeType != 'undefined') { |
195 |
xmlhttp.overrideMimeType('text/xml'); |
196 |
} |
197 |
|
198 |
xmlhttp.open('GET', url, false); |
199 |
xmlhttp.send(null); |
200 |
|
201 |
xmlhttp.onreadystatechange = function() { |
202 |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {} else {} |
203 |
}; |
204 |
var response = xmlhttp.responseText; |
205 |
var elts = response.split(';'); |
206 |
if ( response.length > 0 && elts.length > 0 ) { |
207 |
for ( var i = 0 ; i < elts.length - 1 ; i += 1 ) { |
208 |
var fieldname = elts[i].split(':')[0]; |
209 |
var value = elts[i].split(':')[1]; |
210 |
$(".error").append( fieldname + " '" + value + "' already exist in database<br/>"); |
211 |
} |
212 |
success = false; |
213 |
} |
214 |
|
215 |
if ( success == false ) { |
216 |
$(".error").show(); |
217 |
} |
218 |
return success; |
57 |
} |
219 |
} |
58 |
$(document).ready(function(){ |
220 |
|
59 |
$(".cloneItemBlock").click(function(){ |
|
|
60 |
var clonedRow = $(this).parent().parent().clone(true); |
61 |
clonedRow.insertAfter($(this).parent().parent()).find("a.deleteItemBlock").show(); |
62 |
// find ID of cloned row so we can increment it for the clone |
63 |
var count = $("input[id^=volinf]",clonedRow).attr("id"); |
64 |
var current = Number(count.replace("volinf","")); |
65 |
var increment = current + 1; |
66 |
// loop over inputs |
67 |
var inputs = ["volinf","barcode"]; |
68 |
jQuery.each(inputs,function() { |
69 |
// increment IDs of labels and inputs in the clone |
70 |
$("label[for="+this+current+"]",clonedRow).attr("for",this+increment); |
71 |
$("input[name="+this+"]",clonedRow).attr("id",this+increment); |
72 |
}); |
73 |
// loop over selects |
74 |
var selects = ["homebranch","location","itemtype","ccode"]; |
75 |
jQuery.each(selects,function() { |
76 |
// increment IDs of labels and selects in the clone |
77 |
$("label[for="+this+current+"]",clonedRow).attr("for",this+increment); |
78 |
$("input[name="+this+"]",clonedRow).attr("id",this+increment); |
79 |
$("select[name="+this+"]",clonedRow).attr("id",this+increment); |
80 |
// find the selected option and select it in the clone |
81 |
var selectedVal = $("select#"+this+current).find("option:selected").attr("value"); |
82 |
$("select[name="+this+"] option[value="+selectedVal+"]",clonedRow).attr("selected","selected"); |
83 |
}); |
84 |
|
85 |
var quantityrec = parseFloat($("#quantityrec").attr("value")); |
86 |
quantityrec++; |
87 |
$("#quantityrec").attr("value",quantityrec); |
88 |
return false; |
89 |
}); |
90 |
$(".deleteItemBlock").click(function(){ |
91 |
$(this).parent().parent().remove(); |
92 |
var quantityrec = parseFloat($("#quantityrec").attr("value")); |
93 |
quantityrec--; |
94 |
$("#quantityrec").attr("value",quantityrec); |
95 |
return false; |
96 |
}); |
97 |
}); |