Bug 34115: Use a global tab select function for activating Bootstrap tabs based on location hash

This patch fixes automatic tab selection by location.hash in the MARC
subfield editor. This allows links which target a specific subfield to
open the page with the subfield tab selected.

I've put this into a global function since it can be reused in multiple
places: The about page and the checkout page have variations of this
functionality which can be replaced with this function.

The patch also corrects two links in Koha pointing to the About
page which included the wrong location hash (changed in the switch to
Bootstrap tab wrappers).

To test, apply the patch and go to Adminstration -> Bibliographic
frameworks.

- View the MARC structure for any framework.
  - In the "Search for tag" input field, submit a tag and subfield which
    will be found in that framework, e.g. "245$a"
  - When you submit the form you should be sent to the MARC subfield
   structure page for that tag with the subfield tab automatically
   selected.
- View the MARC subfield structure for any framework.
  - In the table of subfields, click the subfield link in the first
    column. You should be taken to the edit form with the corresponding
    tab selected.
- Go to Circulation and check out to a patron. Append a tab anchor to
  the URL, e.g. "#holds_panel" and submit. You may have to shift-reload
  the page to see the change. (As far as I know no links in Koha take
  advantage of this)
- Perform the same test on the patron detail page
- Go to the About page and perform the same test with a tab anchor like
  "#team_panel" or "#sysinfo_panel"

Signed-off-by: Sam Lau <samalau@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit cb6dd4e82b)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Owen Leonard 2023-06-23 16:02:43 +00:00 committed by Fridolin Somers
parent f5e151c1f8
commit 72364bb34c
6 changed files with 20 additions and 12 deletions

View file

@ -1218,9 +1218,7 @@
[% MACRO jsinclude BLOCK %]
<script>
$(document).ready(function(){
/* Bootstrap doesn't support automatic targeting of tabs by location hash */
var activeTab = $("[href='" + location.hash + "']");
activeTab && activeTab.tab('show');
selectBsTabByHash( "abouttabs" );
});
</script>
[% END %]

View file

@ -371,7 +371,7 @@
<p class="problem ret_foreverdebarred"><strong>Reminder: </strong>Patron has an indefinite restriction.</p>
[% END %]
[% IF errmsgloo.data_corrupted %]
<p class="problem ret_datacorrupt">The item has not been checked in due to a configuration issue in your system. You must ask an administrator to take a look at the <a href="/cgi-bin/koha/about.pl#sysinfo">about page</a> and correct all errors shown on the "System information" tab</p>
<p class="problem ret_datacorrupt">The item has not been checked in due to a configuration issue in your system. You must ask an administrator to take a look at the <a href="/cgi-bin/koha/about.pl#sysinfo_panel">about page</a> and correct all errors shown on the "System information" tab</p>
[% END %]
[% END # /FOREACH errmsgloo %]
</div> <!-- /.dialog.dialog-alert -->

View file

@ -111,7 +111,7 @@
[% END %]
<div id="interlibraryloans">
[% IF !backends_available || !has_branch %]
<div class="dialog message">ILL module configuration problem. Take a look at the <a href="/cgi-bin/koha/about.pl#sysinfo">about page</a></div>
<div class="dialog message">ILL module configuration problem. Take a look at the <a href="/cgi-bin/koha/about.pl#sysinfo_panel">about page</a></div>
[% ELSE %]
[% INCLUDE 'ill-toolbar.inc' %]

View file

@ -1,4 +1,4 @@
/* global dataTablesDefaults tagsubfield */
/* global dataTablesDefaults tagsubfield selectBsTabByHash */
$(document).ready(function() {
if( tagsubfield && tagsubfield == "@"){
$("#subfieldtabs a[href='#subATfield']").tab("show");
@ -39,6 +39,9 @@ $(document).ready(function() {
aaSorting: [],
paginate: false
}));
selectBsTabByHash("subfieldtabs");
});
/* Function to enable/disable hidden values checkboxes when Flag is (de)selected */

View file

@ -1,4 +1,4 @@
/* global borrowernumber */
/* global borrowernumber selectBsTabByHash */
$(document).ready(function() {
$("#CheckAllExports").on("click",function(){
$(".export:visible").prop("checked", true);
@ -91,11 +91,7 @@ $(document).ready(function() {
});
/* Preselect Bootstrap tab based on location hash */
var hash = window.location.hash.substring(1);
if( hash ){
var activeTab = $('a[href="#' + hash + '"]');
activeTab && activeTab.tab('show');
}
selectBsTabByHash("finesholdsissues");
if ( $('#clubs_panel').length ) {
$('#clubs-tab').on('click', function() {

View file

@ -598,3 +598,14 @@ function buildPatronSearchQuery(term, options) {
}
return q;
}
function selectBsTabByHash( tabs_container_id ){
/* Check for location.hash in the page URL */
/* If present the location hash will be used to activate the correct tab */
var hash = document.location.hash;
if( hash !== "" ){
$('#' + tabs_container_id + ' a[href="' + hash + '"]').tab('show');
} else {
$('#' + tabs_container_id + ' a:first').tab('show');
}
}