Koha/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-authorities.inc
Andreas Roussos 24e54b1fd4
Bug 37226: append a random number to the id attribute of each <li>
When you view the authority details page for a term that contains more
than one terms with broader relationship, clicking on the expand/collapse
arrows next to the top-level terms in the hierarchy tree will not work
properly, i.e. *only one* broader term will show the narrower term under
it at any given time.

This is affecting both the OPAC and the Staff interface.

This is happening because in the HTML source of the page the individual
<li> elements associated with each node do not have unique `id` values,
which confuses the JavaScript library (jsTree) responsible for rendering
the hierarchy tree.

This patch fixes that by appending a random number to each `id` attribute.

Test plan:

0) Enable the AuthDisplayHierarchy System Preference (set to 'Show').

1) Copy the provided MARC21 Authority sample data (sample-data.mrc)
   to your KTD Koha container (it must have MARC21 marc flavour):

   docker cp sample-data.mrc koha-koha-1:/kohadevbox/

2) Import the provided authorities (the sample file contains three
   Geographic Name records):

   WARNING! the --delete switch is passed to bulkmarcimport.pl
   WARNING! this will erase any authority data you have in your instance!
   (this is done to retain the broader/narrower authid associations)

   misc/migration_tools/bulkmarcimport.pl --authorities --file=/kohadevbox/sample-data.mrc --verbose -c=MARC21 --delete -m=ISO2709

3) Visit the authority details page for 'Athens' in OPAC/Staff:

   http://localhost:8080/cgi-bin/koha/opac-authoritiesdetail.pl?authid=3
   http://localhost:8081/cgi-bin/koha/authorities/detail.pl?authid=3

   In the authority hierarchy tree, click the arrows next to 'Europe'
   and 'Greece' to expand and show the narrower term: notice how only
   one item works at any given time.

4) Apply the patch.

5) Repeat step 3) (refresh the pages) -- this time you should be able
   to view 'Athens' as a narrower term of both 'Europe' and 'Greece'
   at the same time.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2024-07-22 09:56:14 +01:00

71 lines
2.9 KiB
HTML

[% USE Math %]
[% BLOCK showhierarchy %]
[% FOREACH tree IN trees %]
[% PROCESS showtree tree = tree marc = marc %]
[% END %]
[% END %]
[% BLOCK showtree %]
<ul class="hierarchy">
[% FOREACH node IN tree %]
<li id="hier[% node.authid | html %]_[% Math.rand( 1 ).remove( '\.' ) | html %]" class="[% node.class | html %] authnode">
[% IF ( node.current_value ) %]
<span class="currentauth">[% node.value | html %]</span>
[% ELSE %]
<a href="opac-authoritiesdetail.pl?authid=[% node.authid | uri %]&marc=[% marc | uri %]" title="Term">[% node.value | html %]</a>
[% END %]
[% IF ( node.children && node.children.size > 0 ) %]
[% PROCESS showtree tree = node.children marc = marc %]
[% END %]
</li>
[% END %]
</ul>
[% END %]
[% BLOCK authtypelabel %]
[% UNLESS ( type=='seefrom' || type=='seealso' || type=='' ) %]
<span class="type">[% FILTER trim %][% SWITCH type %]
[% CASE 'earlier' %]<span>Earlier heading</span>
[% CASE 'later' %]<span>Later heading</span>
[% CASE 'acronym' %]<span>Acronym</span>
[% CASE 'musical' %]<span>Musical composition</span>
[% CASE 'broader' %]<span>Broader heading</span>
[% CASE 'narrower' %]<span>Narrower heading</span>
[% CASE %]<span>[% type | html %]</span>
[% END %][% END %]</span>
[% END %]
[% END %]
[% BLOCK otherscript %]
[% FOREACH heading IN headings %]
[% IF heading.category == wantcategory %]
[% IF heading.direction == 'ltr' %]
<div class="heading otherscript [% heading.category | html %]">
<span class="[% heading.category | html %]">[% heading.term | html %]</span>
</div>
[% ELSIF heading.direction == 'rtl' %]
<div class="heading otherscript [% heading.category | html %] rtl">
<span class="[% heading.category | html %]">[% heading.term | html %]</span>
</div>
[% END %]
[% END %]
[% END %]
[% END %]
[% BLOCK authheadingdisplay %]
[% IF authid %]<a href="/cgi-bin/koha/opac-authoritiesdetail.pl?authid=[% authid | uri %]">[% heading | html %]</a>
[% ELSIF search %]<a href="/cgi-bin/koha/opac-authorities-home.pl?op=do_search&amp;type=opac&amp;operator=contains&amp;marclist=mainentry&amp;and_or=and&amp;orderby=HeadingAsc&amp;value=[% search | uri %]">[% heading | html %]</a>
[% ELSE %][% heading | html %]
[% END %]
[% END %]
[% BLOCK language %]
[% SWITCH lang %]
[% CASE ['en', 'eng'] %]<span>English</span>
[% CASE ['fr', 'fre'] %]<span>French</span>
[% CASE ['it', 'ita'] %]<span>Italian</span>
[% CASE ['de', 'ger', 'deu'] %]<span>German</span>
[% CASE ['es', 'spa'] %]<span>Spanish</span>
[% CASE %]<span>[% lang | html %]</span>
[% END %]
[% END %]