From 3d7a3e7df1eda341202a07336b2392cc4654436b Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 18 Aug 2023 04:32:31 +0000 Subject: [PATCH] Bug 34571: Remove use of "onclick" for ExpandField in cataloguing editors This change replaces the onclick HTML attribute with a Javascript binding to make it more in line with Koha conventions and make it CSP compatible. Test plan: 0. Apply patch 1. Go to http://localhost:8081/cgi-bin/koha/cataloguing/addbiblio.pl?frameworkcode=# 2. Try hiding/unhiding fields 3. Try cloning fields and hiding/unhiding those too 4. Note that everything works as expected 5. Do the same thing for authorities by going to http://localhost:8081/cgi-bin/koha/authorities/authorities.pl?authtypecode=# --- .../prog/en/modules/authorities/authorities.tt | 8 ++++++-- .../prog/en/modules/cataloguing/addbiblio.tt | 9 +++++++-- koha-tmpl/intranet-tmpl/prog/js/cataloging.js | 6 ++++-- 3 files changed, 17 insertions(+), 6 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 7e20732846..b71160a6e4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities.tt @@ -341,6 +341,10 @@ function formatFieldName( string ){ return "" + string + ""; } + + $(document).ready(function(){ + $('body').on('click','.expandfield',ExpandField); + }); [% Asset.css("css/addbiblio.css") | $raw %] @@ -528,7 +532,7 @@
[% UNLESS hide_marc %] [% IF advancedMARCEditor %] - [% innerloo.tag | html %] + [% innerloo.tag | html %] [% ELSE %] [% innerloo.tag | html %] [% END %] @@ -588,7 +592,7 @@ [% END # /UNLESS hide_marc %] [% UNLESS advancedMARCEditor %] - [% innerloo.tag_lib | html %] + [% innerloo.tag_lib | html %] [% END %] [% IF ( innerloo.repeatable ) %] 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 1c1e7db0a3..cadbf08e72 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt @@ -780,6 +780,11 @@ function PopupMARCFieldDoc(field) { function formatFieldName( string ){ return "" + string + ""; } + + $(document).ready(function(){ + $('body').on('click','.expandfield',ExpandField); + }); + [% Asset.css("css/addbiblio.css") | $raw %] @@ -1037,7 +1042,7 @@ function PopupMARCFieldDoc(field) { [% END %]
[% IF advancedMARCEditor %] - [% innerloo.tag | html %] + [% innerloo.tag | html %] [% ELSE %] [% innerloo.tag | html %]  ? @@ -1078,7 +1083,7 @@ function PopupMARCFieldDoc(field) { [% END # /IF innerloo.fixedfield %] - [% UNLESS advancedMARCEditor %] - [% innerloo.tag_lib | html %] + [% innerloo.tag_lib | html %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js index d6f6715cc3..602ae9ceaf 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js +++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging.js @@ -59,7 +59,8 @@ function openAuth(tagsubfieldid,authtype,source) { window.open("../authorities/auth_finder.pl?source="+source+"&authtypecode="+authtype+"&index="+tagsubfieldid+"&value_mainstr="+encodeURIComponent(mainmainstring)+"&value_main="+encodeURIComponent(mainstring), "_blank",'width=700,height=550,toolbar=false,scrollbars=yes'); } -function ExpandField(index) { +function ExpandField() { + let index = this.dataset.field_id; var original = document.getElementById(index); //original
  • var lis = original.getElementsByTagName('li'); for(var i=0,lislen = lis.length ; i