Koha/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js
Jonathan Druart c9927a97ab Bug 22669: Fix item editing on receiving an order
Since
  commit 1253975389
  Bug 21091: Move add item template JavaScript to a separate file

items cannot longer be edited when receiving an order.
When moving the code to the JS file, the JS variable "opisadd" was
always set to "true":
  var opisadd = '[% opisadd | html %]';
Even if the TT variable is 0, opisadd will be "0", which is evaluated to
true in Javascript

To clean the situation it is easier to remove this variable and use "op"
instead.

Test plan:
- Make sure acqcreateitem is set to "when placing an order"
- Create a basket with some orders
- Close the basket
- Go to your vendor and receive an order
- On the receive page, try to edit your item
=> Without the patch, the pop up page will open and then close, not allowing the item to be edited.
=> With this patch applied you will see the item edit form. Save and
confirm that the parent window is updated with the new value (actually
it's refreshed)

Signed-off-by: Claire Gravely <claire.gravely@bsz-bw.de>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-04-26 10:17:21 +00:00

117 lines
4.8 KiB
JavaScript

/* global KOHA searchid biblionumber frameworkcode popup op LABEL_EDIT_ITEM LABEL_DELETE_ITEM MSG_FORM_NOT_SUBMITTED MSG_MANDATORY_FIELDS_EMPTY MSG_ADD_MULTIPLE_ITEMS MSG_ENTER_NUM_ITEMS MSG_CONFIRM_DELETE_ITEM MSG_CONFIRM_ADD_ITEM columns_settings CheckMandatorySubfields CheckMultipleAdd */
var browser = KOHA.browser(searchid, parseInt(biblionumber, 10));
browser.show();
$(document).ready(function(){
// Remove the onclick event defined in browser.js,
// otherwise the deletion confirmation will not work correctly
$('a[href*="biblionumber="]').off('click');
if( popup && op != 'saveitem' ){
window.close();
}
$("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit");
/* Inline edit/delete links */
var biblionumber = $("input[name='biblionumber']").attr("value");
$("tr.editable").each(function(){
$(this).find("td:not(:first)").on('click', function(){
var rowid = $(this).parent().attr("id");
var num_rowid = rowid.replace("row","");
$(".linktools").remove();
var edit_link = $('<a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&frameworkcode=' + frameworkcode + '&biblionumber=' + biblionumber + '&itemnumber=' + num_rowid + '&searchid=' + searchid + '#edititem"></a>');
$(edit_link).text( LABEL_EDIT_ITEM );
var delete_link = $('<a href="/cgi-bin/koha/cataloguing/additem.pl?op=delitem&frameworkcode=' + frameworkcode + '&biblionumber=' + biblionumber + '&itemnumber=' + num_rowid + '&searchid=' + searchid + '"></a>');
$(delete_link).text( LABEL_DELETE_ITEM );
$(delete_link).on('click', function() {
return confirm_deletion();
});
var tools_node = $('<span class="linktools"></span>');
$(tools_node).append(edit_link);
$(tools_node).append(delete_link);
$(this).append(tools_node);
});
});
$("#addnewitem").click(function(){
if ( confirm( MSG_CONFIRM_ADD_ITEM ) ){
window.location.href = "/cgi-bin/koha/cataloguing/additem.pl?biblionumber=" + biblionumber;
}
});
// Skip the first column
columns_settings.unshift( { cannot_be_toggled: "1" } );
var itemst = KohaTable("itemst", {
"aoColumnDefs": [
{ "aTargets": [ 0 ], "bSortable": false, "bSearchable": false },
],
'bPaginate': false,
'bInfo': false,
"bAutoWidth": false,
"bKohaColumnsUseNames": true
}, columns_settings);
var multiCopyControl = $("#add_multiple_copies_span");
var addMultipleBlock = $("#addmultiple");
var addSingleBlock = $("#addsingle");
multiCopyControl.hide();
$("#add_multiple_copies").on("click",function(e){
e.preventDefault;
addMultipleBlock.toggle();
addSingleBlock.toggle();
multiCopyControl.toggle();
$('body,html').animate({ scrollTop: $('body').height() }, 100);
});
$("#cancel_add_multiple").on("click",function(e){
e.preventDefault();
addMultipleBlock.toggle();
addSingleBlock.toggle();
multiCopyControl.toggle();
});
$('.subfield_line select').select2();
});
function Check(f) {
var total_errors = CheckMandatorySubfields(f);
if (total_errors==0) {
// Explanation about this line:
// In case of limited edition permission, we have to prevent user from modifying some fields.
// But there is no such thing as readonly attribute for select elements.
// So we use disabled instead. But disabled prevent values from being passed through the form at submit.
// So we "un-disable" the elements just before submitting.
// That's a bit clumsy, and if someone comes up with a better solution, feel free to improve that.
$("select[name=field_value]").prop('disabled', false);
return true;
} else {
var alertString2 = MSG_FORM_NOT_SUBMITTED;
alertString2 += "\n------------------------------------------------------------------------------------\n";
alertString2 += "\n- " + "%s " + MSG_MANDATORY_FIELDS_EMPTY.format(total_errors);
alert(alertString2);
return false;
}
}
function CheckMultipleAdd(f) {
if (!f || isNaN(f) || !parseInt(f) == f || f <= 0) {
alert( MSG_ENTER_NUM_ITEMS );
return false;
}
// Add a soft-limit of 99 with a reminder about potential data entry error
if (f>99) {
return confirm( MSG_ADD_MULTIPLE_ITEMS.format(f));
}
}
function Dopop(link,i) {
var defaultvalue=document.forms[0].field_value[i].value;
var newin=window.open(link+"&result=" + defaultvalue,"valuebuilder",'width=500,height=400,toolbar=false,scrollbars=yes');
}
function confirm_deletion() {
return confirm( MSG_CONFIRM_DELETE_ITEM );
}