Koha/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt
Owen Leonard 90b89948f1
Bug 35058: Automatically show authority tab 0 if DefaultAuthorityTab is empty
The change to the authority detail page made by Bug 34075 didn't take
into account the possibility that the DefaultAuthorityTab tab preference
might be empty. This leads to a JavaScript error and no tabs being
shown.

We can avoid this situation by initializing the tab_object variable as
an empty object.

To test, apply the patch and go to Authorities to repeat the test plan
for Bug 34075:

1. Locate and view the detail page for an authority record.
2. The page should default to the 0XX or first tab.
3. Go to Administration -> System preferences and set the
   DefaultAuthorityTab preference to a number that won't be found
   in your authority record (e.g. there are no 3XX tags defined).
4. Return to the detail page and verify that the first tab is displayed.
5. Set DefaultAuthorityTab to 1XX or greater, one that exists in your
   record.
6. Reload the detail page and confirm the correct tab is selected.
7. Test the case where DefaultAuthorityTab is undefined by directly
   updating the database. In koha-testing-docker you can run this
   command:

   echo "update systempreferences set value = 3 where variable = 'DefaultAuthorityTab';" | koha-mysql kohadev

   Return to the authority detail tab to confirm that the first tab is
   displayed.

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-10-18 15:41:25 -03:00

184 lines
8.4 KiB
Text

[% USE raw %]
[% USE Koha %]
[% USE Asset %]
[% PROCESS 'i18n.inc' %]
[% SET footerjs = 1 %]
[% PROCESS 'authorities.inc' %]
[% INCLUDE 'doc-head-open.inc' %]
<title>[% FILTER collapse %]
[% IF ( unknownauthid ) %]
[% t("Unknown authority record") | html %]
[% ELSE %]
[% tx("Details for authority #{authid} ({authtypetext})", { authid = authid, authtypetext = authtypetext }) | html %]
[% END %] &rsaquo;
[% t("Authorities") | html %] &rsaquo;
[% t("Koha") | html %]
[% END %]</title>
[% INCLUDE 'doc-head-close.inc' %]
[% Asset.css("css/addbiblio.css") | $raw %]
[% IF ( displayhierarchy ) %]
[% Asset.css("lib/jquery/plugins/jstree/themes/default/style.min.css") | $raw %]
[% END %]
</head>
<body id="auth_detail" class="auth">
[% WRAPPER 'header.inc' %]
[% INCLUDE 'authorities-search.inc' %]
[% END %]
[% WRAPPER 'sub-header.inc' %]
[% WRAPPER breadcrumbs %]
[% WRAPPER breadcrumb_item %]
<a href="/cgi-bin/koha/authorities/authorities-home.pl">Authorities</a>
[% END %]
[% WRAPPER breadcrumb_item bc_active= 1 %]
[% IF ( unknownauthid ) %]
<span>Unknown authority record</span>
[% ELSE %]
<span>Details for authority #[% authid | html %] ([% authtypetext | html %])</span>
[% END %]
[% END %]
[% END #/ WRAPPER breadcrumbs %]
[% END #/ WRAPPER sub-header.inc %]
<div class="main container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
[% INCLUDE 'authorities-toolbar.inc' %]
[% IF ( displayhierarchy ) %]
<div id="hierarchies">
[% PROCESS showhierarchy trees = loophierarchies %]
</div>
[% END %]
[% IF ( unknownauthid ) %]
<h1>Authority does not exist</h1>
<div class="dialog message">The authority record you requested does not exist ([% errauthid | html %]).</div>
[% ELSE %]
<h1>Authority #[% authid | html %] ([% authtypetext | html %])</h1>
<div id="action">
[% IF count %]
Used in <a href="/cgi-bin/koha/catalogue/search.pl?type=intranet&amp;op=do_search&amp;q=an:[% authid | uri %]">[% count | html %] record(s)</a>
[% ELSE %]
This authority is not used in any records.
[% END %]
</div>
[% WRAPPER tabs id= "authoritiestabs" %]
[% WRAPPER tabs_nav %]
[% FOREACH BIG_LOO IN BIG_LOOP %]
[% WRAPPER tab_item tabname= "tab${ BIG_LOO.number }XX" %]
[% BIG_LOO.number | html %]
[% END %]
[% END %]
[% END # /WRAPPER tabs_nav %]
[% WRAPPER tab_panels %]
[% FOREACH BIG_LOO IN BIG_LOOP %]
[% WRAPPER tab_panel tabname="tab${ BIG_LOO.number }XX" %]
[% FOREACH innerloo IN BIG_LOO.innerloop %]
[% IF ( innerloo.tag_number ) %]
<div class="tag">
<div class="tag_title">
<span class="tag_num marc_field">[% innerloo.tag_number | html %]</span>
[% IF (innerloo.defined("ind1") ) %]
<span class="tag_ind1">[% innerloo.ind1 | html %]</span><span class="tag_ind2">[% innerloo.ind2 | html %]</span>
[% END %]
[% IF (innerloo.tag_desc) %]
<span class="dashwrapper"> -</span> <span class="tag_desc marc_field">[% innerloo.tag_desc | html %]</span>
[% END %]
</div> <!-- /.tag_title -->
[% ELSE %]
<div class="tag">
[% END # /IF ( innerloo.tag_number ) %]
[% FOREACH subfiel IN innerloo.subfield %]
<div class="auth_subfield">
<div class="subfield_info marc_field">
[% UNLESS ( subfiel.hide_marc ) %]
<span class="marc_subfield">[% subfiel.marc_subfield | html %]</span>
[% END %]
<span class="marc_subfield_desc">[% subfiel.long_desc | html %]</span>
</div> <!-- /.subfield_info.marc_field -->
<div class="subfield_content marc_field">
<span class="subfield_value">
[% IF ( subfiel.is_url ) %]
<a href="[% subfiel.marc_value | url %]">[% subfiel.marc_value | html %]</a>
[% ELSE %]
[% subfiel.marc_value | html %]
[% END %]
</span>
</div> <!-- /.subfield_content.marc_field -->
</div> <!-- /.auth_subfield -->
[% END #/FOREACH subfiel %]
</div> <!-- /.tag -->
[% END # /FOREACH innerloo %]
[% END # /tab_panel#tab${ BIG_LOO.number }XX %]
[% END # /FOREACH BIG_LOO %]
[% END # /WRAPPER tab_panels %]
[% END # /WRAPPER tabs %]
[% END # /IF ( unknownauthid ) %]
</div> <!-- /.col-md-8 col-md-offset-2 -->
</div> <!-- /.row -->
[% MACRO jsinclude BLOCK %]
[% INCLUDE 'authorities_js.inc' %]
[% IF ( displayhierarchy ) %]
[% Asset.js("lib/jquery/plugins/jstree/jstree-3.3.12.min.js") | $raw %]
[% END %]
<script>
$(document).ready(function() {
if( $("#authoritiestabs .tab-pane.active").length < 1 ){
let tab_object = [];
[% SET DefaultAuthorityTab = Koha.Preference('DefaultAuthorityTab') %]
[% IF DefaultAuthorityTab %]
tab_object = $("#authoritiestabs #tab[% DefaultAuthorityTab | html %]XX-tab");
[% END %]
if( tab_object.length > 0 ){
tab_object.tab("show");
} else {
$("#authoritiestabs a:first").tab("show");
}
}
var editAuth = $("#editAuth");
var editAuthLink = editAuth.attr("href");
$("a[data-toggle='tab']").on("shown.bs.tab", function (e) {
var newTabId = $(this).attr("href");
editAuth.attr("href", editAuthLink + newTabId );
});
[% IF ( displayhierarchy ) %]
$('#hierarchies').jstree({
"types" : {
"default" : {
"icon" : "fa-solid fa-file"
}
},
"plugins" : [ "types" ]
}).on('ready.jstree', function(){
$(this).jstree('open_all');
$("#hier"+[% authid | html %]+"_anchor").on("click",
function(e){e.preventDefault(); return false;}
).css("text-decoration", "none").css("color", "#333");
$(".currentauth").css("text-decoration", "none").css("color", "#333");
}).bind("select_node.jstree", function (e, data) {
e.preventDefault();
document.location.href = data.node.a_attr.href;
});
[% END # /IF ( displayhierarchy ) %]
});
</script>
[% END %]
[% INCLUDE 'intranet-bottom.inc' %]