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