Bug 27508: do nothing if tag label elements don't exist
authorPetro Vashchuk <stalkernoid@gmail.com>
Thu, 21 Jan 2021 12:11:24 +0000 (14:11 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 27 Jan 2021 09:45:54 +0000 (10:45 +0100)
commit43f9758c3d3fe660cff464e1b575bb3e99cb73da
tree33f89d493ee8cb5a9bb1f2b0396266d8bce6a851
parent32d482130749fdb17cb33e2ee48b0ae0acce835a
Bug 27508: do nothing if tag label elements don't exist

When JavaScript make copy of DOM set for MARC tag, it tries to reassign
label elements to another id, the problem is there is no check for
existence of that label element, so in case when option
"advancedMARCeditor" is set to "Don't display", labels were absent
which caused JavaScript to crush in the middle of process with uncaught
exception.

This patch wraps this label assignment in try/catch hook like it's done
in the code around for other elements, to allow the script to proceed
when description labels are not present.

To test:
1) Check in the system preferences interface subsection that
   "advancedMARCeditor" is set to "Display".
2) Go to the "Add MARC record" cataloguing section and press "Repeat
   this tag" button near the MARC tag record to ensure that it makes
   duplicate in the interface as expected.
3) Then again in the system preferences interface subsection change
   "advancedMARCeditor" to "Don't display".
4) Return back to the "Add MARC record" interface, refresh the page to
   have no MARC field labels displayed, and try duplicating the tag
   again.
5) Ensure that it doesn't work, also you can notice a JavaScript error
   "Cannot read property "setAttribute" of undefined..." in the
   JavaScript console of your browser.
6) Apply the patch.
7) Repeat the test sequence (changes will be in the step 5), ensure that
   the tag gets duplicated even when description labels are not present.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
koha-tmpl/intranet-tmpl/prog/js/cataloging.js