Bug 22734: Fund not marked as mandatory when ordering from a staged file
This patch does some refactoring of JavaScript to make handling of
required fields more robust. It also moves some template JavaScript to
the footer and some to a separate file.
A fallback "pattern" attribute is added to the quantity field, requiring
0-9+ values.
The "required" property of the funds dropdown is now dependent on the
value set under the "Default accounting details" tab. If a default is
selected, the individual item funds are preselected and not marked
required.
To test, apply the patch and begin the process of ordering from a staged
file.
- Select all items to import.
- Under each item, the fund should be marked mandatory.
- The quantity field should accept only numbers.
- Select the "Default accounting details" tab and select a default
fund.
- Return to the "Select to import" tab. Your selected default fund
should now be preselected under each item. The fund should no
longer be marked required.
Un-selecting a default fund should result in each item fund
select becoming required.
Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
parent
de20398db3
commit
f0fd89fd9c
|
|
@ -2,6 +2,7 @@
|
|||
[% USE Asset %]
|
||||
[% USE KohaDates %]
|
||||
[% USE Branches %]
|
||||
[% SET footerjs = 1 %]
|
||||
[% INCLUDE 'doc-head-open.inc' %]
|
||||
<title>Koha › Acquisitions › Order staged MARC records
|
||||
[% IF ( batch_details ) %]
|
||||
|
|
@ -12,108 +13,6 @@
|
|||
</title>
|
||||
<style>#dataPreview { width : 80%; } @media (max-width: 767px) { #dataPreview { margin: 0; width : auto; } }</style>
|
||||
[% INCLUDE 'doc-head-close.inc' %]
|
||||
[% Asset.js("js/acquisitions-menu.js") | $raw %]
|
||||
[% INCLUDE 'datatables.inc' %]
|
||||
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
|
||||
[% Asset.js("js/acq.js") | $raw %]
|
||||
[% Asset.js("js/funds_sorts.js") | $raw %]
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$("#files").dataTable($.extend(true, {}, dataTablesDefaults, {
|
||||
"aoColumnDefs": [
|
||||
{ "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
|
||||
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
|
||||
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
|
||||
],
|
||||
"sPaginationType": "four_button",
|
||||
"aaSorting": []
|
||||
} ) );
|
||||
|
||||
$("#records_to_import fieldset.rows div").hide();
|
||||
$('input:checkbox[name="import_record_id"]').change(function(){
|
||||
var container = $(this).parents("fieldset");
|
||||
if ( $(this).is(':checked') ) {
|
||||
$(container).addClass("selected");
|
||||
$(container).removeClass("unselected");
|
||||
$(container).find("div").toggle(true);
|
||||
} else {
|
||||
$(container).addClass("unselected");
|
||||
$(container).removeClass("selected");
|
||||
$(container).find("div").toggle(false);
|
||||
}
|
||||
} );
|
||||
|
||||
$("input:checkbox").prop("checked", false);
|
||||
$("div.biblio.unselected select").prop('disabled', false);
|
||||
$("div.biblio.unselected input").prop('disabled', false);
|
||||
|
||||
$("#checkAll").click(function(){
|
||||
$("#Aform").checkCheckboxes();
|
||||
$("input:checkbox[name='import_record_id']").change();
|
||||
return false;
|
||||
});
|
||||
$("#unCheckAll").click(function(){
|
||||
$("#Aform").unCheckCheckboxes();
|
||||
$("input:checkbox[name='import_record_id']").change();
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#Aform").on("submit", function(){
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
if (! $("#all_budget_id").val() ) {
|
||||
// If there is no default fund
|
||||
var error = 0;
|
||||
$(".selected [name='budget_id']").each(function(){
|
||||
if (!$(this).val()) {
|
||||
error++;
|
||||
}
|
||||
});
|
||||
if ( error > 0 ) {
|
||||
alert(_("Some budgets are not defined in item records"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return disableUnchecked($(this));
|
||||
});
|
||||
$('#tabs').tabs();
|
||||
$(".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=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> "+_("Loading")+"</div>");
|
||||
});
|
||||
});
|
||||
|
||||
function disableUnchecked(form){
|
||||
$("fieldset.biblio.unselected").each(function(){
|
||||
$(this).remove();
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body id="acq_addorderiso2709" class="acq">
|
||||
|
|
@ -211,7 +110,8 @@
|
|||
</li>
|
||||
<li class="quantity">
|
||||
<label for="quantity_record_[% biblio.import_record_id | html %]" class="required">Quantity: </label>
|
||||
<input id="quantity_record_[% biblio.import_record_id | html %]" type="text" value="[% biblio.quantity.length ? biblio.quantity : 1 | html %]" name="quantity" />
|
||||
<input id="quantity_record_[% biblio.import_record_id | html %]" type="text" pattern="[0-9]+" value="[% biblio.quantity.length ? biblio.quantity : 1 | html %]" name="quantity" />
|
||||
<span class="required">Required</span>
|
||||
</li>
|
||||
<li class="price">
|
||||
<label for="price_record_[% biblio.import_record_id | html %]">Price: </label>
|
||||
|
|
@ -220,14 +120,15 @@
|
|||
<li class="discount">
|
||||
<label for="discount_record_[% biblio.import_record_id | html %]">Discount: </label>
|
||||
<input id="discount_record_[% biblio.import_record_id | html %]" type="text" value="[% biblio.discount | html %]" name="discount" size="6" /> %
|
||||
(If empty, discount rate from vendor will be used)
|
||||
<div class="hint">If empty, discount rate from vendor will be used</div>
|
||||
</li>
|
||||
<li class="budget">
|
||||
<label for="fund_record_[% biblio.import_record_id | html %]">Fund: </label>
|
||||
<li class="fund">
|
||||
[% IF ( close ) %]
|
||||
<input type="hidden" size="20" name="budget_id" value="[% budget_id | html %]" />[% Budget_name | html %]
|
||||
<label for="fund_record_[% biblio.import_record_id | html %]">Fund: </label>
|
||||
<input type="hidden" size="20" name="budget_id" value="[% budget_id | html %]" />[% Budget_name | html %]
|
||||
[% ELSE %]
|
||||
<select id="fund_record_[% biblio.import_record_id | html %]" size="1" name="budget_id">
|
||||
<label for="fund_record_[% biblio.import_record_id | html %]">Fund: </label>
|
||||
<select id="fund_record_[% biblio.import_record_id | html %]" size="1" name="budget_id">
|
||||
<option value="">Select a fund</option>
|
||||
[% FOREACH budget IN budget_loop %]
|
||||
[% IF ( budget.b_id == biblio.budget_id ) %]
|
||||
|
|
@ -243,6 +144,7 @@
|
|||
[% END %]
|
||||
[% END %]
|
||||
</select>
|
||||
<span class="required" style="display:none">Required</span>
|
||||
[% END %]
|
||||
</li>
|
||||
<li class="sort1">
|
||||
|
|
@ -525,4 +427,20 @@
|
|||
</div> [% # /div.col-sm-6 %]
|
||||
</div> [% # /div.row %]
|
||||
|
||||
|
||||
[% MACRO jsinclude BLOCK %]
|
||||
[% Asset.js("js/acquisitions-menu.js") | $raw %]
|
||||
[% INCLUDE 'datatables.inc' %]
|
||||
[% Asset.js("lib/jquery/plugins/jquery.checkboxes.min.js") | $raw %]
|
||||
[% Asset.js("js/acq.js") | $raw %]
|
||||
[% Asset.js("js/funds_sorts.js") | $raw %]
|
||||
[% Asset.js("js/addorderiso2709.js") | $raw %]
|
||||
<script>
|
||||
var ERR_NO_RECORD_SELECTED = _("There is no record selected");
|
||||
var ERR_INVALID_QUANTITY = _("quantity values are not filled in or are not numbers");
|
||||
var ERR_FUNDS_MISSING = _("Some budgets are not defined in item records");
|
||||
var MSG_LOADING = _("Loading");
|
||||
</script>
|
||||
[% END %]
|
||||
|
||||
[% INCLUDE 'intranet-bottom.inc' %]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,120 @@
|
|||
/* global dataTablesDefaults ERR_NO_RECORD_SELECTED ERR_INVALID_QUANTITY ERR_FUNDS_MISSING MSG_LOADING */
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#files").dataTable($.extend(true, {}, dataTablesDefaults, {
|
||||
"aoColumnDefs": [
|
||||
{ "bSortable": false, "bSearchable": false, 'aTargets': [ 'NoSort' ] },
|
||||
{ "sType": "anti-the", "aTargets" : [ "anti-the" ] },
|
||||
{ "sType": "title-string", "aTargets" : [ "title-string" ] }
|
||||
],
|
||||
"sPaginationType": "four_button",
|
||||
"aaSorting": []
|
||||
}) );
|
||||
|
||||
var all_budget_id = $("#all_budget_id");
|
||||
|
||||
if( !all_budget_id.val() ){
|
||||
$(".fund label, .fund select").addClass("required").prop("required", true);
|
||||
$(".fund span.required").show();
|
||||
}
|
||||
|
||||
all_budget_id.on("change", function(){
|
||||
if( $(this).val() != "" ){
|
||||
$(".fund label, .fund select").removeClass("required").prop("required", false);
|
||||
$(".fund select").each(function(){
|
||||
if( $(this).val() == '' ){
|
||||
$(this).val( all_budget_id.val() );
|
||||
}
|
||||
});
|
||||
$(".fund span.required").hide();
|
||||
} else {
|
||||
$(".fund label, .fund select").addClass("required").prop("required", true);
|
||||
$(".fund span.required").show();
|
||||
}
|
||||
});
|
||||
|
||||
$("#records_to_import fieldset.rows div").hide();
|
||||
$('input:checkbox[name="import_record_id"]').change(function(){
|
||||
var container = $(this).parents("fieldset");
|
||||
if ( $(this).is(':checked') ) {
|
||||
$(container).addClass("selected");
|
||||
$(container).removeClass("unselected");
|
||||
$(container).find("div").toggle(true);
|
||||
} else {
|
||||
$(container).addClass("unselected");
|
||||
$(container).removeClass("selected");
|
||||
$(container).find("div").toggle(false);
|
||||
}
|
||||
} );
|
||||
|
||||
$("input:checkbox").prop("checked", false);
|
||||
$("div.biblio.unselected select").prop('disabled', false);
|
||||
$("div.biblio.unselected input").prop('disabled', false);
|
||||
|
||||
$("#checkAll").click(function(){
|
||||
$("#Aform").checkCheckboxes();
|
||||
$("input:checkbox[name='import_record_id']").change();
|
||||
return false;
|
||||
});
|
||||
$("#unCheckAll").click(function(){
|
||||
$("#Aform").unCheckCheckboxes();
|
||||
$("input:checkbox[name='import_record_id']").change();
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#Aform").on("submit", function(){
|
||||
if ( $("input:checkbox[name='import_record_id']:checked").length < 1 ) {
|
||||
alert( ERR_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 + " " + ERR_INVALID_QUANTITY );
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if (! all_budget_id.val() ) {
|
||||
// If there is no default fund
|
||||
error = 0;
|
||||
$(".selected [name='budget_id']").each(function(){
|
||||
if (!$(this).val()) {
|
||||
error++;
|
||||
}
|
||||
});
|
||||
if ( error > 0 ) {
|
||||
alert( ERR_FUNDS_MISSING );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return disableUnchecked($(this));
|
||||
});
|
||||
|
||||
$('#tabs').tabs();
|
||||
$(".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=\"[% interface | html %]/[% theme | html %]/img/spinner-small.gif\" alt=\"\" /> " + MSG_LOADING + "</div>");
|
||||
});
|
||||
});
|
||||
|
||||
function disableUnchecked(){
|
||||
$("fieldset.biblio.unselected").each(function(){
|
||||
$(this).remove();
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
Loading…
Reference in New Issue