Bug 28423 - JavaScript error on MARC modifications page
Summary: JavaScript error on MARC modifications page
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Templates (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor
Assignee: Owen Leonard
QA Contact: Testopia
URL: /cgi-bin/koha/tools/marc_modification...
Keywords:
Depends on:
Blocks: 28418
  Show dependency treegraph
 
Reported: 2021-05-21 17:01 UTC by Owen Leonard
Modified: 2022-06-06 20:24 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This patch makes a minor change to the MARC modifications template (Staff interface > Administration > MARC modification templates) so that the "mmtas" variable isn't defined if there is no JSON to be assigned as its value.
Version(s) released in:
21.11.00,21.05.02,20.11.08
Circulation function:


Attachments
Bug 28423: JavaScript error on MARC modifications page (1.58 KB, patch)
2021-05-21 17:21 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 28423: JavaScript error on MARC modifications page (1.62 KB, patch)
2021-05-23 20:55 UTC, David Nind
Details | Diff | Splinter Review
Bug 28423: JavaScript error on MARC modifications page (1.68 KB, patch)
2021-05-24 13:27 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Owen Leonard 2021-05-21 17:01:38 UTC
This line in the MARC modification template is problematic because if "ActionsLoop" doesn't exist it creates a JS error.

var mmtas = [% ActionsLoop.json | $raw %]

Normally the solution would be to wrap the variable in quotes:

var mmtas = "[% ActionsLoop.json | $raw %]";

...but that causes an error if ActionsLoop *is* defined.

We need some logic for determining how the script is generated.
Comment 1 Owen Leonard 2021-05-21 17:21:35 UTC
Created attachment 121280 [details] [review]
Bug 28423: JavaScript error on MARC modifications page

This patch makes a minor change to the MARC modifications template so
that the "mmtas" variable isn't defined if there is no JSON to be
assigned as its value.

To test, apply the patch and go to Administration -> MARC modification
templates.

 - If necessary, add a template with at least one action.
 - Check the browser console, there should be no errors.
 - Click the "Edit" button corresponding to one of the template actions.
 - The details of the action should load correctly in the edit form and
   there should be no errors in the console.
Comment 2 David Nind 2021-05-23 20:55:04 UTC
Created attachment 121303 [details] [review]
Bug 28423: JavaScript error on MARC modifications page

This patch makes a minor change to the MARC modifications template so
that the "mmtas" variable isn't defined if there is no JSON to be
assigned as its value.

To test, apply the patch and go to Administration -> MARC modification
templates.

 - If necessary, add a template with at least one action.
 - Check the browser console, there should be no errors.
 - Click the "Edit" button corresponding to one of the template actions.
 - The details of the action should load correctly in the edit form and
   there should be no errors in the console.

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2021-05-23 20:58:09 UTC
Testing notes (koha-testing-docker):

- Error message in the browser console when going to Staff interface home > Tools > Catalog > MARC modification templates before applying the patch was:
  "Uncaught SyntaxError: expected expression, got end of script" 
- Adding and editing new templates worked as expected
- After applying the patch there was no console error
Comment 4 Katrin Fischer 2021-05-24 13:27:50 UTC
Created attachment 121327 [details] [review]
Bug 28423: JavaScript error on MARC modifications page

This patch makes a minor change to the MARC modifications template so
that the "mmtas" variable isn't defined if there is no JSON to be
assigned as its value.

To test, apply the patch and go to Administration -> MARC modification
templates.

 - If necessary, add a template with at least one action.
 - Check the browser console, there should be no errors.
 - Click the "Edit" button corresponding to one of the template actions.
 - The details of the action should load correctly in the edit form and
   there should be no errors in the console.

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

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 5 Jonathan Druart 2021-06-21 10:06:01 UTC
Pushed to master for 21.11, thanks to everybody involved!
Comment 6 Kyle M Hall (khall) 2021-07-02 13:09:57 UTC
Pushed to 21.05.x for 21.05.02
Comment 7 Fridolin Somers 2021-07-10 03:19:45 UTC
Pushed to 20.11.x for 20.11.08
Comment 8 Victor Grousset/tuxayo 2021-07-11 02:34:22 UTC
Not backported to oldoldstable (20.05.x). Feel free to ask if it's needed.