Bug 33744

Summary: Plugins not working on duplicated MARC fields
Product: Koha Reporter: Matt Blenkinsop <matt.blenkinsop>
Component: CatalogingAssignee: Matt Blenkinsop <matt.blenkinsop>
Status: RESOLVED FIXED QA Contact: Marcel de Rooy <m.de.rooy>
Severity: trivial    
Priority: P5 - low CC: david, fridolin.somers, m.de.rooy, patrick.robitaille
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=30975
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.11.00,23.05.04,22.11.10
Circulation function:
Attachments: Bug 33744: Fix deprecated use of .data('events')
Bug 33744: Fix deprecated use of .data('events')
Bug 33744: Fix deprecated use of .data('events')
Bug 33744: Fix cloning (sub)fields with framework plugins

Description Matt Blenkinsop 2023-05-16 11:12:35 UTC
AddEventHandlers in cataloging.js uses .data('events') which is now deprecated. This means that a duplicated field with the upload.pl plugin doesn't function as expected as the event handler doesn't pass to the duplicated field.

To reproduce:
1) In Administration > MARC frameworks, choose a framework and through the actions button click on MARC structure
2) Search for field 856
3) Click on edit subfields
4) Select subfield "u" using the tabs at the top
5) At the bottom, in the dropdown menu called "Plugin", select "upload.pl" (bottom of the list) and save
6) Navigate to Cataloging and create a new record using the framework you have just edited
7) Click on tab 8 and check you have field 856. Click on the Upload button and the pop up should open as expected allowing you to upload a file
8) Click on the "Repeat this tag" button for the 856 tag
9) Click on the Upload button and nothing will happen
10) Delete the cloned tag
11) On the original tag, click the "Repeat this subfield" button next to the "Upload" button.
12) Click the "Upload" button on the new subfield and the same issue will occur.
Comment 1 Marcel de Rooy 2023-05-16 11:14:20 UTC
Looks like this is addressed under bug 30975.
Comment 2 Marcel de Rooy 2023-05-16 11:14:37 UTC

*** This bug has been marked as a duplicate of bug 30975 ***
Comment 3 Matt Blenkinsop 2023-05-16 11:17:13 UTC
Created attachment 151270 [details] [review]
Bug 33744: Fix deprecated use of .data('events')

This patch removes a deprecated internal data structure no longer supported in jQuery. This means that AddEventHandlers now correctly passes events to cloned fields in the MARC record

Test plan:
1) Apply patch
2) Repeat steps in the original bug description
3) This time clicking on the Upload button for a cloned field should launch the uploads pop up.
Comment 4 Marcel de Rooy 2023-05-16 11:53:41 UTC
> This patch removes a deprecated internal data structure no longer supported in jQuery.

 // Note: This code depends on the jQuery data for events; this structure
 // is moved to _data as of jQuery 1.8.
-    var ev= $(oldcontrol).data('events');
+    var ev = $._data(oldcontrol, "events");

You are using an internal structure here. Where we really dont know how long it will be supported.
Comment 5 Marcel de Rooy 2023-05-16 11:54:52 UTC
Perhaps we can use it as a temporary workaround until 30975 gets in ?
Comment 6 Matt Blenkinsop 2023-07-17 10:55:26 UTC
30975 is still blocked so maybe Marcel is right and we should use this patch as a temporary fix - I'll rebase and re-submit
Comment 7 Matt Blenkinsop 2023-07-17 10:56:49 UTC
Created attachment 153538 [details] [review]
Bug 33744: Fix deprecated use of .data('events')

This patch removes a deprecated internal data structure no longer supported in jQuery. This means that AddEventHandlers now correctly passes events to cloned fields in the MARC record

Test plan:
1) Apply patch
2) Repeat steps in the original bug description
3) This time clicking on the Upload button for a cloned field should launch the uploads pop up.
Comment 8 David Nind 2023-08-25 10:26:27 UTC
Created attachment 154796 [details] [review]
Bug 33744: Fix deprecated use of .data('events')

This patch removes a deprecated internal data structure no longer supported in jQuery. This means that AddEventHandlers now correctly passes events to cloned fields in the MARC record

Test plan:
1) Apply patch
2) Repeat steps in the original bug description
3) This time clicking on the Upload button for a cloned field should launch the uploads pop up.

Signed-off-by: David Nind <david@davidnind.com>
Comment 9 David Nind 2023-08-25 10:29:43 UTC
I've added some comments to bug 30975 (comment 45) on whether to go ahead with 30975 as is, or go ahead with this one as a temporary measure.

From the user perspective, maybe getting cloning of subfields with plugins/value builders should be the priority?
Comment 10 Marcel de Rooy 2023-09-01 09:11:21 UTC
Looking here
Comment 11 Marcel de Rooy 2023-09-01 09:28:20 UTC
Created attachment 155081 [details] [review]
Bug 33744: Fix cloning (sub)fields with framework plugins

This patch is meant as a temporary measure for fixing the problem.
Bug 30975 may resolve it further, but this is good for now.

Note: The original commit message referred to removing a deprecated internal
structure. But this patch actually still uses the structure which has been
moved to _data in jQuery now.

Test plan:
1) Apply patch
2) Repeat steps in the original bug description
3) This time clicking on the Upload button for a cloned field should launch the uploads pop up.

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 12 Marcel de Rooy 2023-09-01 09:29:14 UTC
(In reply to David Nind from comment #8)
> This patch removes a deprecated internal data structure no longer supported
> in jQuery. This means that AddEventHandlers now correctly passes events to
> cloned fields in the MARC record

Took the liberty to further clarify this statement in the commit message.
Comment 13 Tomás Cohen Arazi (tcohen) 2023-09-01 14:10:11 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 14 Fridolin Somers 2023-09-08 00:45:14 UTC
Pushed to 23.05.x for 23.05.04
Comment 15 Matt Blenkinsop 2023-09-08 09:47:50 UTC
Nice work everyone!

Pushed to oldstable for 22.11.x