+function addItem( node, unique_item_fields ) {
+ var index = $(node).parent().attr('id');
+ var current_qty = parseInt($("#quantity").val());
+ var max_qty;
+ if($("#quantity_to_receive").length != 0){
+ max_qty = parseInt($("#quantity_to_receive").val());
+ } else {
+ max_qty = 99999;
+ }
+ if ( $("#items_list table").find('tr[idblock="' + index + '"]').length == 0 ) {
+ if ( current_qty < max_qty ) {
+ if ( current_qty < max_qty - 1 )
+ cloneItemBlock(index, unique_item_fields);
+ addItemInList(index, unique_item_fields);
+ $("#" + index).find("a[name='buttonPlus']").text("Update");
+ $("#quantity").val(current_qty + 1).change();
+ } else if ( current_qty >= max_qty ) {
+ alert(window.MSG_ADDITEM_JS_CANT_RECEIVE_MORE_ITEMS
+ || "You can't receive any more items.");
+ }
+ } else {
+ if ( current_qty < max_qty )
+ cloneItemBlock(index, unique_item_fields);
+ var tr = constructTrNode(index);
+ $("#items_list table").find('tr[idblock="' + index + '"]:first').replaceWith(tr);
+ }
+ $("#" + index).hide();
+}
+
+function showItem(index) {
+ $("#outeritemblock").children("div").each(function(){
+ if ( $(this).attr('id') == index ) {
+ $(this).show();
+ } else {
+ if ( $("#items_list table").find('tr[idblock="' + $(this).attr('id') + '"]').length == 0 ) {
+ $(this).remove();
+ } else {
+ $(this).hide();
+ }
+ }
+ });
+}
+
+function constructTrNode(index, unique_item_fields) {
+ var fields = ['barcode', 'homebranch', 'holdingbranch', 'notforloan',
+ 'restricted', 'location', 'itemcallnumber', 'copynumber',
+ 'stocknumber', 'ccode', 'itype', 'materials', 'itemnotes'];
+
+ var result = "<tr idblock='" + index + "'>";
+ var edit_link = "<a href='#itemfieldset' style='text-decoration:none' onclick='showItem(\"" + index + "\");'>"
+ + (window.MSG_ADDITEM_JS_EDIT || "Edit") + "</a>";
+ var del_link = "<a style='cursor:pointer' "
+ + "onclick='deleteItemBlock(this, \"" + index + "\", \"" + unique_item_fields + "\");'>"
+ + (window.MSG_ADDITEM_JS_DELETE || "Delete") + "</a>";
+ result += "<td>" + edit_link + "</td>";
+ result += "<td>" + del_link + "</td>";
+ for(i in fields) {
+ var field = fields[i];
+ var field_elt = $("#" + index)
+ .find("[name='kohafield'][value='items."+field+"']")
+ .prevAll("[name='field_value']")[0];
+ var field_value;
+ if($(field_elt).is('select')) {
+ field_value = $(field_elt).find("option:selected").text();
+ } else {
+ field_value = $(field_elt).val();
+ }
+ if (field_value == undefined) {
+ field_value = '';
+ }
+ result += "<td>" + field_value + "</td>";
+ }
+ result += "</tr>";
+
+ return result;
+}
+
+function addItemInList(index, unique_item_fields) {
+ $("#items_list").show();
+ var tr = constructTrNode(index, unique_item_fields);
+ $("#items_list table tbody").append(tr);