From d84e286dfab19088807d3c1a666ad7f7d22d783e Mon Sep 17 00:00:00 2001
From: Owen Leonard <oleonard@myacpl.org>
Date: Wed, 16 Oct 2024 17:24:55 +0000
Subject: [PATCH] Bug 36320: Clicking Edit items from catalogue/detail.pl leads
 to 'Add item' screen

This patch updates the catalog toolbar so that the "Edit items"
choice under the "Edit" menu is replaced with two new options: "Manage
items," which takes you to the top of the add/edit items page; and "Add
item" which takes the user directly to the add item form (scrolling
automatically past the table of existing items).

The patch also adds a "Jump to add item form" link at the top of the
add/edit items page.

To test, apply the patch and search for a bibliographic record in the
staff interface.

- View the detail page for the record.
- Click the "Edit" menu button in the toolbar.
- You should see the two new menu items, "Manage items" and "Add item."
- Clicking the "Manage items" button should take you to the top
  of the add/edit items page in cataloging.
  - You should see a "Jump to add item form" limk under the page
    heading.
  - Clicking it should jump you to the "Add item" form.
- Clicking the "Add item" menu item from the bibliographic detail "Edit"
  menu should take you directly to the add item form, scrolling down
  past the existing items.

Sponsored-by: Athens County Public Libraries
---
 .../intranet-tmpl/prog/en/includes/cat-toolbar.inc  |  3 ++-
 .../prog/en/modules/cataloguing/additem.tt          |  1 +
 .../intranet-tmpl/prog/js/cataloging_additem.js     | 13 +++++++++++++
 3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc
index 4b99bbea27..81ccb4fb91 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc
@@ -60,7 +60,8 @@
             [% END %]
 
             [% IF CAN_user_editcatalogue_edit_items or ( frameworkcode == 'FA' and CAN_user_editcatalogue_fast_cataloging ) %]
-                <li><a class="dropdown-item" id="edititems" href="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber | html %]">Edit items</a></li>
+                <li><a class="dropdown-item" id="manageitems" href="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber | html %]">Manage items</a></li>
+                <li><a class="dropdown-item" id="additems" href="/cgi-bin/koha/cataloguing/additem.pl?biblionumber=[% biblionumber | html %]#cataloguing_additem_newitem">Add item</a></li>
             [% END %]
 
             [% IF ( CAN_user_tools_items_batchmod ) %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
index ae6da07854..75fd44ceb0 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt
@@ -77,6 +77,7 @@
                     </div>
                 [% END %]
 <h1>Items for [% biblio.title | html %] [% IF ( biblio.author ) %] by [% biblio.author | html %][% END %] (Record #[% biblio.biblionumber | html %])</h1>
+<a id="newitem_jump" href="#cataloguing_additem_newitem"><i class="fa fa-arrow-down"></i> Jump to add item form</a>
 
 [% IF ( barcode_not_unique ) %]<div class="alert alert-warning"><strong>Error saving item</strong>: Barcode must be unique.</div>[% END %]
 [% IF ( no_next_barcode ) %]<div class="alert alert-warning"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div>[% END %]
diff --git a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js
index c8a2189b83..e975d66959 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js
+++ b/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js
@@ -138,6 +138,19 @@ $(document).ready(function(){
             return $("#" + $(this).data("item") + "-delete-item-form").submit();
         }
     }) ;
+
+    /* On page load, check for location.hash in the page URL */
+    /* If present the location hash will be used to scroll to the relevant anchor */
+    var hash = location.hash;
+    var hashPieces = hash.split('?');
+    if( hashPieces[0] !== "" ){
+        $( hashPieces[0] )[0].scrollIntoView();
+    }
+
+    $("#newitem_jump").on("click", function(e){
+        e.preventDefault();
+        document.getElementById("cataloguing_additem_newitem").scrollIntoView();
+    });
 });
 
 function CheckTemplateForm(f) {
-- 
2.39.5