Koha/koha-tmpl/intranet-tmpl/prog/js/addorderiso2709.js
Owen Leonard 26ca471424
Bug 32046: When adding a new records from a staged files, there are style issues
This patch modifies the template for adding a record from a staged file
in order to resolve some layout problems introduced by the staff
redesign.

This patch also corrects an problem with addorderiso2709.js: It included
some template markup. The template variables are converted to a JS
variable to prevent a JS error.

Note that the QA tool's js_in_body error is invalid for this template
which requires that the JS stay inside <head>.

To test you must have at least one MARC file staged for import.

- Apply the patch and go to Acquisitions.
- Locate a vendor and create a basket if necessary.
- Add to the basket and choose the option of adding an order from a
  staged file.
- Click "Add orders" next to one of the staged files.
- On the Add orders from MARC file page, test that everything looks
  correct and works correctly:
  - In the first tab, expanding and collapsing order details by checking
    the checkbox or clicking the title.
  - Test the "MARC" and "Card" preview buttons.
  - Under the Item information tab, confirm that the layout looks
    correct and that the form works correctly, including plugin
    operations like auto barcode fill.
  - Test that, under the Default accounting details tab, changing the
    fund automatically sets the fund for each title in the first tab.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2022-11-23 09:34:00 -03:00

161 lines
6 KiB
JavaScript

/* global dataTablesDefaults __ template_path */
$(document).ready(function() {
$("#Aform").preventDoubleFormSubmit();
$("#files").dataTable($.extend(true, {}, dataTablesDefaults, {
"aoColumnDefs": [
{ "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] }
],
"sPaginationType": "full",
"aaSorting": []
}) );
checkOrderBudgets();
var all_budget_id = $("#all_budget_id");
$("#all_budget_id,[name='budget_id'],.budget_code_item,[name='import_record_id']").on("change", function(){
checkOrderBudgets();
});
$(".order_details").hide();
$('input:checkbox[name="import_record_id"]').change(function(){
var container = $(this).parents("tr");
if ( $(this).is(':checked') ) {
$(container).addClass("selected");
$(container).removeClass("unselected");
$(container).find(".order_details").toggle(true);
} else {
$(container).addClass("unselected");
$(container).removeClass("selected");
$(container).find(".order_details").toggle(false);
}
} );
$("input:checkbox").prop("checked", false);
$("div.biblio.unselected select").prop('disabled', false);
$("div.biblio.unselected input").prop('disabled', false);
$("#checkAll").click(function(e){
e.preventDefault();
$("input:checkbox[name='import_record_id']").prop("checked", true).change();
});
$("#unCheckAll").click(function(e){
e.preventDefault();
$("input:checkbox[name='import_record_id']").prop("checked", false).change();
});
$("input#add_order").on("click", function(e){
e.preventDefault();
if ( $("input:checkbox[name='import_record_id']:checked").length < 1 ) {
alert( __("There is no record selected") );
return false;
}
var error = 0;
$("input:checkbox[name='import_record_id']:checked").parents('fieldset').find('input[name="quantity"]').each(function(){
if ( $(this).val().length < 1 || isNaN( $(this).val() ) ) {
error++;
}
});
if ( error > 0 ) {
alert(error + " " + __("quantity values are not filled in or are not numbers") );
return false;
}
error = checkOrderBudgets();
if ( error > 0 ) {
alert( __("Some budgets are not defined in item records") );
return false;
}
if (0 < CheckMandatorySubfields(this.form)) {
// Open the item tab
$('.nav-tabs .items_info').tab('show');
alert(__('Some required item subfields are not set'));
return false;
}
disableUnchecked($(this.form));
$(this.form).submit();
});
$(".previewData").on("click", function(e){
e.preventDefault();
var ltitle = $(this).text();
var page = $(this).attr("href");
$("#dataPreviewLabel").text(ltitle);
$("#dataPreview .modal-body").load(page + " div");
$('#dataPreview').modal({show:true});
});
$("#dataPreview").on("hidden.bs.modal", function(){
$("#dataPreviewLabel").html("");
$("#dataPreview .modal-body").html("<div id=\"loading\"><img src=\"" + template_path + "/img/spinner-small.gif\" alt=\"\" /> " + __("Loading") + "</div>");
});
});
function disableUnchecked(){
$("fieldset.biblio.unselected").each(function(){
$(this).remove();
});
return 1;
}
function checkOrderBudgets(){
var unset_funds = 0;
var all_budget_id = $("#all_budget_id");
// If we don't have an overarching default set we need to check each selected order
if ( !all_budget_id.val() ) {
$("fieldset.biblio.rows.selected").each(function(){
var default_order_fund = $(this).find("[name='budget_id']");
// For each order we see if budget is set for order
if( !default_order_fund.val() ){
$(this).find(".item_fund.required").show();
//If not we need to check each item on the order
var item_funds = $(this).find(".budget_code_item");
if( item_funds.length ){
item_funds.each(function(){
if( !$(this).val() ){
$(this).addClass('required').prop("required", true);
unset_funds++;
} else {
$(this).removeClass('required').prop("required", false);
}
});
} else {
//If the order has no items defined then the order level fund is required
default_order_fund.addClass('required').prop("required", true);
$(this).find(".fund span.required").show();
$(this).find(".item_fund.required").hide();
unset_funds++;
}
} else {
$(this).find(".fund span.required").hide();
// If fund is set for order then none of the others are required
$(this).find(".budget_code_item").each(function(){
if( !$(this).val() ){
$(this).val( default_order_fund.val() );
$(this).removeClass('required').prop("required", false);
}
});
$(this).removeClass('required').prop("required", false);
}
});
} else {
// Default is set overall, we just need to populate it through
// to each order/item
$("[name='budget_id'],.budget_code_item").each(function(){
if( !$(this).val() ){
$(this).val( all_budget_id.val() );
$(this).removeClass('required').prop("required", false);
$(".item_fund.required").hide();
$(".fund span.required").hide();
}
});
}
return unset_funds;
}