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=#

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
David Cook 2023-08-18 04:32:31 +00:00 committed by Tomas Cohen Arazi
parent 0b992dd12e
commit 8341ffe13d
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
3 changed files with 17 additions and 6 deletions

View file

@ -350,6 +350,10 @@
function formatFieldName( string ){
return "<strong><em>" + string + "</em></strong>";
}
$(document).ready(function(){
$('body').on('click','.expandfield',ExpandField);
});
</script>
[% Asset.css("css/addbiblio.css") | $raw %]
@ -537,7 +541,7 @@
<div class="tag_title" id="div_indicator_tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]">
[% UNLESS hide_marc %]
[% IF advancedMARCEditor %]
<a href="#" tabindex="1" class="tagnum" title="[% innerloo.tag_lib | html %] - Click to expand this tag" onclick="ExpandField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]'); return false;">[% innerloo.tag | html %]</a>
<a href="#" tabindex="1" class="tagnum" title="[% innerloo.tag_lib | html %] - Click to expand this tag" data-field_id="tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]'">[% innerloo.tag | html %]</a>
[% ELSE %]
<span class="tagnum" title="[% innerloo.tag_lib | html %]">[% innerloo.tag | html %]</span>
[% END %]
@ -597,7 +601,7 @@
[% END # /UNLESS hide_marc %]
[% UNLESS advancedMARCEditor %]
<a href="#" tabindex="1" class="expandfield" onclick="ExpandField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]'); return false;" title="Click to expand this tag">[% innerloo.tag_lib | html %]</a>
<a href="#" tabindex="1" class="expandfield" data-field_id="tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]" title="Click to expand this tag">[% innerloo.tag_lib | html %]</a>
[% END %]
<span class="field_controls">
[% IF ( innerloo.repeatable ) %]

View file

@ -787,6 +787,11 @@ $(document).ready(function(){
function formatFieldName( string ){
return "<strong><em>" + string + "</em></strong>";
}
$(document).ready(function(){
$('body').on('click','.expandfield',ExpandField);
});
</script>
[% Asset.css("css/addbiblio.css") | $raw %]
</head>
@ -1044,7 +1049,7 @@ $(document).ready(function(){
[% END %]
<div class="tag_title" id="div_indicator_tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]">
[% IF advancedMARCEditor %]
<a href="#" tabindex="1" class="tagnum" title="[% innerloo.tag_lib | html %] - Click to expand this tag" onclick="ExpandField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]'); return false;">[% innerloo.tag | html %]</a>
<a href="#" tabindex="1" class="tagnum" title="[% innerloo.tag_lib | html %] - Click to expand this tag" data-field_id="tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]">[% innerloo.tag | html %]</a>
[% ELSE %]
<span class="tagnum" title="[% innerloo.tag_lib | html %]">[% innerloo.tag | html %]</span>
<a href="#" class="marcdocs" data-tag="[% innerloo.tag | html %]">&nbsp;?</a>
@ -1085,7 +1090,7 @@ $(document).ready(function(){
[% END # /IF innerloo.fixedfield %] -
[% UNLESS advancedMARCEditor %]
<a href="#" tabindex="1" class="expandfield" onclick="ExpandField('tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]'); return false;" title="Click to expand this tag">[% innerloo.tag_lib | html %]</a>
<a href="#" tabindex="1" class="expandfield" data-field_id="tag_[% innerloo.tag | html %]_[% innerloo.index | html %][% innerloo.random | html %]" title="Click to expand this tag">[% innerloo.tag_lib | html %]</a>
[% END %]
<span class="field_controls">

View file

@ -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 <li>
var lis = original.getElementsByTagName('li');
for(var i=0,lislen = lis.length ; i<lislen ; i++){ // foreach li
@ -77,6 +78,7 @@ function ExpandField(index) {
}
}
}
return false;
}
var current_select2;
@ -307,7 +309,7 @@ function CloneField(index, hideMarc, advancedMARCEditor) {
} else if (anchors[j].getAttribute('class') == 'buttonMinus') {
anchors[j].setAttribute('onclick',"UnCloneField('" + new_id + "'); return false;");
} else if (anchors[j].getAttribute('class') == 'expandfield') {
anchors[j].setAttribute('onclick',"ExpandField('" + new_id + "'); return false;");
anchors[j].setAttribute('data-field_id',new_id);
}
}
}