Bug 28170 - Downloading some files via Tools - Upload is broken
Summary: Downloading some files via Tools - Upload is broken
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Tools (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low minor (vote)
Assignee: Lari Taskula
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 28175
  Show dependency treegraph
 
Reported: 2021-04-19 14:08 UTC by Lari Taskula
Modified: 2021-05-25 14:26 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Text to go in the release notes:
Version(s) released in:
21.05.00,20.11.06,20.05.12


Attachments
Bug 28170: Fix upload.tt search result buttons for page two onwards (3.29 KB, patch)
2021-04-19 15:09 UTC, Lari Taskula
Details | Diff | Splinter Review
Bug 28170: Fix upload.tt search result buttons for page two onwards (3.34 KB, patch)
2021-04-20 11:34 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 28170: Fix upload.tt search result buttons for page two onwards (3.40 KB, patch)
2021-04-30 08:42 UTC, Julian Maurice
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Lari Taskula 2021-04-19 14:08:30 UTC
"Tools -> Upload -> Search" only lets you download the first 20 results, but anything on page 2 or farther cannot be downloaded.

To reproduce:
1. Go to cgi-bin/koha/tools/upload.pl
2. Make sure you have at least 21 files uploaded
3. Perform a search via "Search term" form so that at least 21 results are returned (e.g. a dot (.) as the search term should return all files with filetype)
4. Press "Download" for the first result row, it should work as expected
5. Go to page 2 of results
6. Press "Download" for the first result in page 2
7. Observe nothing happening

Noticed this bug on a 17.05 installation but it still appears on 20.11.
Comment 1 Lari Taskula 2021-04-19 14:20:31 UTC
Possibly related

From https://datatables.net/faqs/index

Q. My events don't work on the second page
A. When attaching events to cells in a table controlled by DataTables, you need to be careful how it is done. Because DataTables removes nodes from the DOM, events applied with a static event listener might not be able to bind themselves to all nodes in the table. To overcome this, simply use jQuery delegated event listener options, as shown in this example. Additionally, you could use my Visual Event bookmarklet to help debug event issues.
Comment 2 Lari Taskula 2021-04-19 15:09:34 UTC
Created attachment 119865 [details] [review]
Bug 28170: Fix upload.tt search result buttons for page two onwards

From https://datatables.net/faqs/index

"When attaching events to cells in a table controlled by DataTables, you need
to be careful how it is done. Because DataTables removes nodes from the DOM,
events applied with a static event listener might not be able to bind
themselves to all nodes in the table."

Before this patch, there were three non-functional buttons on upload search
result page, "+ Choose", "Download" and "Delete".

This patch binds the handlers to a static element so that the three buttons
in upload.tt on page two onwards are functional again.

To test:
1. This test is for the "Download" and "Delete" buttons
1.1. Before applying patch, go to cgi-bin/koha/tools/upload.pl
1.2. Make sure you have at least 21 files uploaded
1.3. Perform a search via "Search term" form so that at least 21 results are
     returned (e.g. a dot (.) as the search term should return all files with
     filetype)
1.4. Press "Download" and "Delete" for the first result row, it should work
     as expected (no need to actually delete the file - as long as it pops up
     a confirmation, it works as expected)
1.5. Go to page 2 of results
1.6. Press "Download" and "Delete" for the first result in page 2
1.7. Observe nothing happening
1.8. Apply patch
1.9. Repeat steps 3-6
1.10. Observe buttons working as expected

2. This test is for the "+ Choose" button
2.1. Go to cgi-bin/koha/admin/marc_subfields_structure.pl?op=add_form&tagfield=856&frameworkcode=#subufield
2.2. Under "Other options (choose one), for "Plugin", select "upload.pl"
2.3. Find a biblio and click Edit Record
2.4. Go to 856$u and click "Upload"
2.5. Repeat steps 1.1. - 1.10., but this time for the "+ Choose" button
Comment 3 Owen Leonard 2021-04-20 11:34:20 UTC
Created attachment 119905 [details] [review]
Bug 28170: Fix upload.tt search result buttons for page two onwards

From https://datatables.net/faqs/index

"When attaching events to cells in a table controlled by DataTables, you need
to be careful how it is done. Because DataTables removes nodes from the DOM,
events applied with a static event listener might not be able to bind
themselves to all nodes in the table."

Before this patch, there were three non-functional buttons on upload search
result page, "+ Choose", "Download" and "Delete".

This patch binds the handlers to a static element so that the three buttons
in upload.tt on page two onwards are functional again.

To test:
1. This test is for the "Download" and "Delete" buttons
1.1. Before applying patch, go to cgi-bin/koha/tools/upload.pl
1.2. Make sure you have at least 21 files uploaded
1.3. Perform a search via "Search term" form so that at least 21 results are
     returned (e.g. a dot (.) as the search term should return all files with
     filetype)
1.4. Press "Download" and "Delete" for the first result row, it should work
     as expected (no need to actually delete the file - as long as it pops up
     a confirmation, it works as expected)
1.5. Go to page 2 of results
1.6. Press "Download" and "Delete" for the first result in page 2
1.7. Observe nothing happening
1.8. Apply patch
1.9. Repeat steps 3-6
1.10. Observe buttons working as expected

2. This test is for the "+ Choose" button
2.1. Go to cgi-bin/koha/admin/marc_subfields_structure.pl?op=add_form&tagfield=856&frameworkcode=#subufield
2.2. Under "Other options (choose one), for "Plugin", select "upload.pl"
2.3. Find a biblio and click Edit Record
2.4. Go to 856$u and click "Upload"
2.5. Repeat steps 1.1. - 1.10., but this time for the "+ Choose" button

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Comment 4 Julian Maurice 2021-04-30 08:42:38 UTC
Created attachment 120328 [details] [review]
Bug 28170: Fix upload.tt search result buttons for page two onwards

From https://datatables.net/faqs/index

"When attaching events to cells in a table controlled by DataTables, you need
to be careful how it is done. Because DataTables removes nodes from the DOM,
events applied with a static event listener might not be able to bind
themselves to all nodes in the table."

Before this patch, there were three non-functional buttons on upload search
result page, "+ Choose", "Download" and "Delete".

This patch binds the handlers to a static element so that the three buttons
in upload.tt on page two onwards are functional again.

To test:
1. This test is for the "Download" and "Delete" buttons
1.1. Before applying patch, go to cgi-bin/koha/tools/upload.pl
1.2. Make sure you have at least 21 files uploaded
1.3. Perform a search via "Search term" form so that at least 21 results are
     returned (e.g. a dot (.) as the search term should return all files with
     filetype)
1.4. Press "Download" and "Delete" for the first result row, it should work
     as expected (no need to actually delete the file - as long as it pops up
     a confirmation, it works as expected)
1.5. Go to page 2 of results
1.6. Press "Download" and "Delete" for the first result in page 2
1.7. Observe nothing happening
1.8. Apply patch
1.9. Repeat steps 3-6
1.10. Observe buttons working as expected

2. This test is for the "+ Choose" button
2.1. Go to cgi-bin/koha/admin/marc_subfields_structure.pl?op=add_form&tagfield=856&frameworkcode=#subufield
2.2. Under "Other options (choose one), for "Plugin", select "upload.pl"
2.3. Find a biblio and click Edit Record
2.4. Go to 856$u and click "Upload"
2.5. Repeat steps 1.1. - 1.10., but this time for the "+ Choose" button

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Comment 5 Jonathan Druart 2021-04-30 15:17:56 UTC
Pushed to master for 21.05, thanks to everybody involved!
Comment 6 Fridolin Somers 2021-05-11 10:17:18 UTC
Pushed to 20.11.x for 20.11.06
Comment 7 Andrew Fuerste-Henry 2021-05-25 11:59:00 UTC
Pushed to 20.05.x for 20.05.12
Comment 8 Victor Grousset/tuxayo 2021-05-25 14:26:37 UTC
Not backported to oldoldstable (19.11.x). Feel free to ask if it's needed.