From be246804bf59697a95020a9fb898ac3f00e4947f Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 21 Feb 2025 18:17:42 +0000 Subject: [PATCH] Bug 25318: Convert authorities_js.inc to JavaScript file This patch creates a new JavaScript file, authorities.js, and includes it on pages which previously used authorities_js.inc. Some minor changes to the JavaScript have been made in order to pass JS variables instead of template variables. To test, apply the patch and go to Authorities. - Perform a search for authorities and test various features on the search result page:: - New from Z39.50/SRU - Actions -> Merge - Actions -> Delete - Action -> MARC preview - View the detail page for an authority record and test: - New from Z39.50/SRU - Edit -> Replace record via Z39.50/SRU - Edit -> Delete record - Go to Cataloging and create a new record. - Go to tab 1 and click the plugin trigger link on 100a. - Confirm that the authority search popup appears and works to add a selected author. Sponsored-by: Athens County Public Libraries --- .../prog/en/includes/authorities_js.inc | 79 ------------ .../modules/authorities/authorities-home.tt | 5 +- .../prog/en/modules/authorities/detail.tt | 6 +- .../prog/en/modules/authorities/merge.tt | 2 +- .../authorities/searchresultlist-auth.tt | 2 + .../modules/authorities/searchresultlist.tt | 6 +- .../prog/js/authorities-detail-modal.js | 2 +- .../intranet-tmpl/prog/js/authorities.js | 112 ++++++++++++++++++ 8 files changed, 130 insertions(+), 84 deletions(-) delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/authorities_js.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/js/authorities.js diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities_js.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/authorities_js.inc deleted file mode 100644 index 9002e952819..00000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/authorities_js.inc +++ /dev/null @@ -1,79 +0,0 @@ - - - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities-home.tt index a229d160e7d..3c75b05c227 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/authorities-home.tt @@ -40,7 +40,10 @@ [%- END -%] [% END %] [% MACRO jsinclude BLOCK %] - [% INCLUDE 'authorities_js.inc' %] + + [% Asset.js("js/authorities.js") | $raw %] [% END %] [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt index 68cd69c4559..2b4a57dcd3e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/detail.tt @@ -134,7 +134,11 @@ [% END %] [% MACRO jsinclude BLOCK %] - [% INCLUDE 'authorities_js.inc' %] + + [% Asset.js("js/authorities.js") | $raw %] [% IF ( displayhierarchy ) %] [% Asset.js("lib/jquery/plugins/jstree/jstree-3.3.12.min.js") | $raw %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/merge.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/merge.tt index 9f4e2a7c052..179da2dd3de 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/merge.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/merge.tt @@ -140,7 +140,7 @@ [% END %] [% MACRO jsinclude BLOCK %] - [% INCLUDE 'authorities_js.inc' %] + [% Asset.js("js/authorities.js") | $raw %] [% Asset.js("js/merge-record.js") | $raw %] [% Asset.js("js/auth-finder-search.js") | $raw %] [% Asset.js("js/authorities-detail-modal.js") | $raw %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt index 0ac1f5ecc52..c510f4e3f44 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt @@ -155,7 +155,11 @@ [% END %] [% MACRO jsinclude BLOCK %] - [% INCLUDE 'authorities_js.inc' %] + + [% Asset.js("js/authorities.js") | $raw %] [% Asset.js("js/authorities-detail-modal.js") | $raw %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/authorities-detail-modal.js b/koha-tmpl/intranet-tmpl/prog/js/authorities-detail-modal.js index b546ae66dda..9b5546b1c77 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/authorities-detail-modal.js +++ b/koha-tmpl/intranet-tmpl/prog/js/authorities-detail-modal.js @@ -1,4 +1,4 @@ -/* global template_path */ +/* global __ template_path */ $(document).ready(function () { $(".authority_preview a").on("click", function (e) { e.preventDefault(); diff --git a/koha-tmpl/intranet-tmpl/prog/js/authorities.js b/koha-tmpl/intranet-tmpl/prog/js/authorities.js new file mode 100644 index 00000000000..96897ce9a97 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/js/authorities.js @@ -0,0 +1,112 @@ +/* global __ Cookies */ +function mergeAuth(authid, summary) { + var alreadySelected = Cookies.get("auth_to_merge"); + if (alreadySelected !== undefined) { + alreadySelected = JSON.parse(alreadySelected); + Cookies.remove("auth_to_merge"); + var refstring = ""; + if (typeof alreadySelected.mergereference !== "undefined") { + refstring = "&mergereference=" + alreadySelected.mergereference; + } + window.location.href = + "/cgi-bin/koha/authorities/merge.pl?authid=" + + authid + + "&authid=" + + alreadySelected.authid + + refstring; + } else { + Cookies.set( + "auth_to_merge", + JSON.stringify({ authid: authid, summary: summary }), + { path: "/", sameSite: "Lax" } + ); + showMergingInProgress(); + } +} + +function showMergingInProgress() { + var alreadySelected = Cookies.get("auth_to_merge"); + if (alreadySelected) { + alreadySelected = JSON.parse(alreadySelected); + $("#merge_in_progress") + .show() + .html( + __("Merging with authority: ") + + "" + + alreadySelected.summary + + " (" + + alreadySelected.authid + + ") " + + __("Cancel merge") + + "" + ); + $("#cancel_merge").click(function (event) { + event.preventDefault(); + Cookies.remove("auth_to_merge"); + $("#merge_in_progress").hide().empty(); + }); + } else { + $("#merge_in_progress").hide().empty(); + } +} + +$(document).ready(function () { + showMergingInProgress(); + + $(".form_delete").submit(function () { + if (confirm(__("Are you sure you want to delete this authority?"))) { + return true; + } + // FIXME Close the dropdown $(this).closest('ul.dropdown-menu').dropdown('toggle'); + return false; + }); + + $(".merge_auth").click(function (event) { + event.preventDefault(); + mergeAuth( + $(this).parents("tr").attr("data-authid"), + $(this).parents("tr").find("div.authorizedheading").text() + ); + }); + + $("#delAuth").click(function () { + $(".form_delete").submit(); + }); + + $("#z3950_new").click(function (e) { + e.preventDefault(); + window.open( + "/cgi-bin/koha/cataloguing/z3950_auth_search.pl", + "z3950search", + "width=800,height=550,location=yes,toolbar=no,scrollbars=yes,resize=yes" + ); + }); + + if (typeof authid !== undefined) { + $("#z3950_replace").click(function (e) { + e.preventDefault(); + window.open( + "/cgi-bin/koha/cataloguing/z3950_auth_search.pl?authid=" + + authid, + "z3950search", + "width=800,height=500,location=yes,toolbar=no,scrollbars=yes,resize=yes" + ); + }); + } + + if (searchType) { + if ("mainmainentry" == searchType.valueOf()) { + $("#header_search a[href='#mainmain_heading_panel']").tab("show"); + } else if ("mainentry" == searchType.valueOf()) { + $("#header_search a[href='#main_heading_panel']").tab("show"); + } else if ("match" == searchType.valueOf()) { + $("#header_search a[href='#matchheading_search_panel']").tab( + "show" + ); + } else if ("all" == searchType.valueOf()) { + $("#header_search a[href='#entire_record_panel']").tab("show"); + } + } +}); -- 2.39.5