Bug 31323

Summary: Edit item highlighting problem
Product: Koha Reporter: Lucas Gass (lukeg) <lucas>
Component: CatalogingAssignee: Phil Ringnalda <phil>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: minor    
Priority: P5 - low CC: andrew, m.de.rooy, phil, sbcornell
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=39570
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 27526    
Bug Blocks:    
Attachments: Bug 31323: Don't highlight an item when it isn't being edited
Bug 31323: Don't highlight an item when it isn't being edited

Description Lucas Gass (lukeg) 2022-08-08 21:40:05 UTC
To reproduce:

1 search the catalog
2 find a record with 1 item
3 click the edit button in the item table (to the right of Spine Label)
4 when I click "save changes" the item is still highlighted yellow


It appears like the '.active' class is lingering. I think this might be caused by Bug 27526?
Comment 1 Andrew Fuerste-Henry 2025-04-03 12:36:45 UTC
From Lucas's description it sounds like this used to only apply to edits to records with only 1 item. Currently I'm also seeing this behavior on records with multiple items.
Comment 2 Sarah Cornell 2025-04-03 13:24:50 UTC
This highlighting behavior is very confusing to staff. It causes them to accidentally create new items when they think they're editing an existing item.  The js that Lucas put in our system in 2022 when we discovered this has started to cause other cascading problems so I'd like to bump this up to a community solution.  Thanks!
Comment 3 Phil Ringnalda 2025-04-04 18:57:35 UTC
Attachment 125605 [details] from bug 27526 removed an uncommented and thus unclear "$itemnumber = q{};" which used to unset the itemnumber once the code for editing an existing item was done using it.

My first impulse was to just fix this problem in the template by making the condition for setting the active class be "[% IF op == 'cud-saveitem' AND item.itemnumber == itemnumber %]" rather than just "[% IF item.itemnumber == itemnumber %]" since op == 'cud-saveitem' is what we use elsewhere to know whether we are adding or editing, but then realizing we have bug 39570 made me think we should probably go back to not passing an itemnumber when we don't mean it.
Comment 4 Phil Ringnalda 2025-04-04 20:17:40 UTC
Except that doesn't work, because the elsif ( $op eq "cud-saveitem" ) has its own     my $itemnumber = $input->param('itemnumber'); for some reason I don't understand, which means that the $itemnumber you unset there isn't the $itemnumber that $template->param will eventually use to set itemnumber.
Comment 5 Phil Ringnalda 2025-04-04 22:03:30 UTC
Created attachment 180685 [details] [review]
Bug 31323: Don't highlight an item when it isn't being edited

The thing that tells us whether we are editing an item or adding a new item
in additem.tt is whether or not the op is cud-saveitem: if it isn't, the
heading on the form is 'Add item', if it is it's 'Edit item', and the same
for which set of buttons are at the bottom of the form. We should check that
before deciding to highlight an item as being edited, rather than just counting
on the script to not pass an itemnumber param unless that itemnumber is being
edited.

Test plan:
1. Without the patch, find any biblio with one or more items attached
2. Click the Edit button for an item in the holdings table
3. Scroll up, and verify that the item you are editing has a yellow background
   in the list of items
4. Click Save changes (no need to make any changes)
5. When the page reloads, you'll have an Add item form at the bottom, but the
   item that you just edited, and are no longer editing, will have a yellow
   background
6. Apply patch, return to the bib details page
7. Repeat steps 2-4, but this time verify that the item you just edited is now
   not highlighted while you have an Add item form.

Sponsored-by: Chetco Community Public Library
Comment 6 Brendan Gallagher 2025-04-07 21:48:29 UTC
Created attachment 180711 [details] [review]
Bug 31323: Don't highlight an item when it isn't being edited

The thing that tells us whether we are editing an item or adding a new item
in additem.tt is whether or not the op is cud-saveitem: if it isn't, the
heading on the form is 'Add item', if it is it's 'Edit item', and the same
for which set of buttons are at the bottom of the form. We should check that
before deciding to highlight an item as being edited, rather than just counting
on the script to not pass an itemnumber param unless that itemnumber is being
edited.

Test plan:
1. Without the patch, find any biblio with one or more items attached
2. Click the Edit button for an item in the holdings table
3. Scroll up, and verify that the item you are editing has a yellow background
   in the list of items
4. Click Save changes (no need to make any changes)
5. When the page reloads, you'll have an Add item form at the bottom, but the
   item that you just edited, and are no longer editing, will have a yellow
   background
6. Apply patch, return to the bib details page
7. Repeat steps 2-4, but this time verify that the item you just edited is now
   not highlighted while you have an Add item form.

Sponsored-by: Chetco Community Public Library
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>