Bug 28423

Summary: JavaScript error on MARC modifications page
Product: Koha Reporter: Owen Leonard <oleonard>
Component: TemplatesAssignee: Owen Leonard <oleonard>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: minor    
Priority: P5 - low CC: david, fridolin.somers, kyle, victor
Version: Main   
Hardware: All   
OS: All   
URL: /cgi-bin/koha/tools/marc_modification_templates.pl
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
Bug Depends on:    
Bug Blocks: 28418    
Attachments: Bug 28423: JavaScript error on MARC modifications page
Bug 28423: JavaScript error on MARC modifications page
Bug 28423: JavaScript error on MARC modifications page

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 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.