From 1547e7c9921b78204a79e124c32453089bb5f963 Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Mon, 13 Jan 2020 11:21:09 -0500 Subject: [PATCH] Bug 8643: Code cleanup Merges "AreMandatoriesNotOk" and new "AreImportantsNotOk" into one function "AreFieldsNotOk". It can search for mandatory or important fields depending on the value of it's boolean "mandatory" parameter. To test: This patch should not change current behavior. Follow the test plan from previous patch and check that saving is still prevented for unfilled mandatory fields. Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- .../prog/en/modules/cataloguing/addbiblio.tt | 197 ++++++------------ 1 file changed, 59 insertions(+), 138 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt index 9469921e02..b7e2daacaf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt @@ -284,42 +284,65 @@ } /** - * check if mandatory subfields are written + * check if mandatory/important subfields are written + * @param mandatory true to check for mandatories, false for importants */ - function AreMandatoriesNotOk(){ - var mandatories = new Array(); - var mandatoriesfields = new Array(); + function AreFieldsNotOk (mandatory = true) { + var fields = new Array(); + var subfields = new Array(); var tab = new Array(); var label = new Array(); var flag=0; var tabflag= new Array(); - [% FOREACH BIG_LOO IN BIG_LOOP %] - [% FOREACH innerloo IN BIG_LOO.innerloop %] - [% IF ( innerloo.mandatory ) %] - mandatoriesfields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]")); + var StrAlert = ""; + var notFilledClass = "subfield_not_filled"; + + if (mandatory) { + [% FOREACH BIG_LOO IN BIG_LOOP %] + [% FOREACH innerloo IN BIG_LOO.innerloop %] + [% IF ( innerloo.mandatory ) %] + fields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]")); + [% END %] + [% FOREACH subfield_loo IN innerloo.subfield_loop %] + [% IF ( subfield_loo.mandatory ) %]subfields.push("[% subfield_loo.id | html %]"); + tab.push("[% BIG_LOO.number | html %]"); + label.push("[% subfield_loo.marc_lib | $raw %]"); + [% END %] + [% END %] [% END %] - [% FOREACH subfield_loo IN innerloo.subfield_loop %] - [% IF ( subfield_loo.mandatory ) %]mandatories.push("[% subfield_loo.id | html %]"); - tab.push("[% BIG_LOO.number | html %]"); - label.push("[% subfield_loo.marc_lib | $raw %]"); + [% END %] + StrAlert = _("Can't save this record because the following field aren't filled:"); + } else { + [% FOREACH BIG_LOO IN BIG_LOOP %] + [% FOREACH innerloo IN BIG_LOO.innerloop %] + [% IF ( innerloo.important ) %] + fields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]")); + [% END %] + [% FOREACH subfield_loo IN innerloo.subfield_loop %] + [% IF ( subfield_loo.important ) %]subfields.push("[% subfield_loo.id | html %]"); + tab.push("[% BIG_LOO.number | html %]"); + label.push("[% subfield_loo.marc_lib | $raw %]"); + [% END %] [% END %] [% END %] [% END %] - [% END %] - var StrAlert = _("Can't save this record because the following field aren't filled:"); + StrAlert = _("A few important fields are not filled:"); + notFilledClass = "important_subfield_not_filled"; + } + StrAlert += "\n\n"; - for(var i=0,len=mandatories.length; i= 10){ - elem = document.getElementById(divid); - eleminputs = elem.getElementsByTagName('input'); - for(var j=0,len2=eleminputs.length; j