From 5ffa76abe700a78ca15bd4375b677a48f28df331 Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Tue, 27 Jun 2023 13:40:07 +0000 Subject: [PATCH] Bug 29732: Check alert in cataloguing authorities should be a static message This patch modifies the authority record editor so that form validation errors are collected in a static "dialog" at the top of the page instead of showing in a transient JavaScript alert. The text of the message is roughly the same as it was in the alert, and links have been added so that the user can click to jump directly to the field referenced. If the user scrolls down away from the static error message, a button appears in the floating toolbar to jump back to the message. - Go to Authorities and create a new authority record using a framework which has multiple mandatory fields defined (e.g. an unmodified default framework) - Without entering anything in mandatory fields, click the "Save" button. - You should see a message box appear at the top of the page. - It should list each missing mandatory subfield and tag, each with a "Go to field" link next to it. - Clicking the "Go to field" link should switch you to the correct tab and scroll the mandatory field into view. - When you have scrolled down far enough for the error messages to be offscreen, an "Errors" button should appear in the floating toolbar. Clicking it should scroll the box back into view. - If you fix some but not all of the missing mandatory fields the message should update with only the current issues. - Confirm that the record saves when all issues are resolved. Signed-off-by: Phil Ringnalda Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 5d572ec461adc2693cd3aa35d5180006636416cb) Signed-off-by: Martin Renvoize --- .../en/modules/authorities/authorities.tt | 147 ++++++++++++++---- 1 file changed, 119 insertions(+), 28 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt index b1813e3600..b801922432 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt @@ -42,9 +42,10 @@ Sticky = $("#toolbar"); Sticky.hcSticky({ - stickTo: ".main", + stickTo: "#f", stickyClass: "floating" }); + $("#addauth").click(function(){ if(Check()){ $("#f").submit(); @@ -91,6 +92,21 @@ f.authtypecode.value = authtypecode; f.submit(); }); + + $("body").on("click", ".linkfield", function(e){ + e.preventDefault(); + var tab = $(this).data("tab"); + var field = $(this).data("field"); + var tablink = $("a[data-tabname='tab" + tab + "XX']" ).get(0).hash; + selectTab( tablink ); + window.scrollTo( 0, getScrollto( field, "toolbar" ) ); + }); + + $("body").on("click", ".show-errors", function(e){ + document.getElementById("form-errors").scrollIntoView(); + Sticky.hcSticky('refresh'); + }); + }); function selectTab( tablink ){ @@ -147,44 +163,74 @@ * check if mandatory subfields are written */ function AreMandatoriesNotOk(){ - var mandatories = new Array(); - var mandatoriesfields = new Array(); + var fields = new Array(); + var subfields = new Array(); var tab = new Array(); var label = new Array(); + var flag = false; + var tabflag= new Array(); + var StrAlert = "
"; + var notFilledClass = "subfield_not_filled"; + [% 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 %]")); + fields.push(new Array("[% innerloo.tag | html %]","[% innerloo.index | html %][% innerloo.random | html %]","[% innerloo.index | html %]", "[% BIG_LOO.number | html %]")); [% END %] [% FOREACH subfield_loo IN innerloo.subfield_loop %] - [% IF ( subfield_loo.mandatory ) %]mandatories.push("[% subfield_loo.id | html %]"); + [% IF ( subfield_loo.mandatory ) %]subfields.push("[% subfield_loo.id | html %]"); tab.push("[% BIG_LOO.number | html %]"); - label.push("[% To.json(subfield_loo.marc_lib) | html %]"); + label.push("[% subfield_loo.marc_lib | $raw %]"); [% END %] [% END %] [% END %] [% END %] - var StrAlert = ""; - for(var i=0,len=mandatories.length; i"; + StrAlert += "
    "; + + for(var i=0,len=subfields.length; i ' + _("Go to field") + ''; + flag = true; } } + StrAlert += "
"; + mandatoryFields = new Object(); + /* Check for mandatories field(not subfields) */ - for(var i=0,len=mandatoriesfields.length; i 0 ){ + StrAlert += "

" + _("The following fields aren't filled:") + "

"; + StrAlert += "
    "; + for( var prop in mandatoryFields ){ + if( mandatoryFields[prop]["importance"] == "mandatory" ){ + StrAlert += "
  • " + _("Field %s is mandatory, at least one of its subfields must be filled.").format( prop ) + ' ' + _("Go to field") + '
  • '; + } else { + StrAlert += "
  • " + _("Field %s is important, at least one of its subfields must be filled.").format(prop) + ' ' + _("Go to field") + '
  • '; + } + } + StrAlert += "
"; + } + StrAlert += "
"; + if ( flag ) { + $("#show-errors").html('