Bug 31609 - JavaScript error on Additional contents main page
Summary: JavaScript error on Additional contents main page
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Tools (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor (vote)
Assignee: Owen Leonard
QA Contact: Marcel de Rooy
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-09-22 21:33 UTC by Owen Leonard
Modified: 2023-12-28 20:42 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.11.00, 22.05.08


Attachments
Bug 31609: JavaScript error on Additional contents main page (1.78 KB, patch)
2022-09-23 14:42 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 31609: JavaScript error on Additional contents main page (1.83 KB, patch)
2022-09-26 10:47 UTC, David Nind
Details | Diff | Splinter Review
Bug 31609: JavaScript error on Additional contents main page (1.88 KB, patch)
2022-10-24 21:41 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 31609: JavaScript error on Additional contents main page (1.98 KB, patch)
2022-10-25 06:47 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Owen Leonard 2022-09-22 21:33:54 UTC
There is JavaScript on the new Pages page which is supposed to check to see whether the view includes the tabs, i.e. on the edit page. The script needs to be more specific about what DOM elements to look for before it tries to grab information about the tab.
Comment 1 Owen Leonard 2022-09-23 14:42:15 UTC Comment hidden (obsolete)
Comment 2 David Nind 2022-09-23 20:58:22 UTC
Failed QA because after applying the patch and go to go Tools > Additional contents:
- error no longer appears when language is English
- switch to another language installed: the error message reappears.

Steps to reproduce (tested using KTD):
1. Install another language: koha-translate --install fr-CA
2. Add an additional contents entry.
3. Replicate the error as per the test plan.
4. Apply the patch - leave language as English, flush_memcached, restart_all, clear browser cache.
5. From the home page, go to Tools > Additional contents - there should be no error in the browser console.
6. Switch language to Français.
7. The error message is back! (Note that it doesn't happen when you switch back to English.)
Comment 3 Owen Leonard 2022-09-26 09:19:34 UTC
I think the issue is that you have to run the translate "update" command first, to rebuild the other language strings based on the patch's modified template. Then run the "install" command.

Could you try again?
Comment 4 David Nind 2022-09-26 10:47:43 UTC
Created attachment 140975 [details] [review]
Bug 31609: JavaScript error on Additional contents main page

This patch makes a minor modification to the JavaScript
on the Additional contents page to prevent an error when
there are no tabs present on the page.

The JS needs an additional check so that it doesn't run
when there are no tabs.

To test you should have more than one language installed.

- Before the patch, you would see a JavaScript error in
  the console: "Uncaught TypeError: can't access property
  "hash", firstTab[0] is undefined."
- Apply the patch and go to Tools -> Additional
  contents.
- With the patch applied there should be no error on the
  additional contents main page.
- Try creating or editing additional contents entries to
  confirm that the interface still works correctly.

Signed-off-by: David Nind <david@davidnind.com>
Comment 5 David Nind 2022-09-26 10:49:10 UTC
(In reply to Owen Leonard from comment #3)
> I think the issue is that you have to run the translate "update" command
> first, to rebuild the other language strings based on the patch's modified
> template. Then run the "install" command.

Thanks Owen! That made things work.
Comment 6 Marcel de Rooy 2022-09-30 07:53:39 UTC
The error is still present on the list view of Tools/Pages

Uncaught TypeError: firstTab[0] is undefined
    <anonymous> https://master.rijkskoha.nl:28443/cgi-bin/koha/tools/additional-contents.pl?category=pages:1132
    jQuery 13

Template code:
                    let firstTab = $("#tabs a:first");
                    firstTab.tab("show");
                    initTinyMce( firstTab[0].hash );
There should probably be a check on firstTab first :)
The <div id="tabs" class="toptabs"> belongs to the detail page and not to the list view on the main page.
Comment 7 Marcel de Rooy 2022-09-30 07:54:12 UTC
The above proves that it was not trivial :)
Comment 8 Owen Leonard 2022-10-03 19:40:16 UTC
(In reply to Marcel de Rooy from comment #6)
> The error is still present on the list view of Tools/Pages

I don't see this. Could you please look again?
Comment 9 Marcel de Rooy 2022-10-04 11:57:29 UTC
(In reply to Owen Leonard from comment #8)
> (In reply to Marcel de Rooy from comment #6)
> > The error is still present on the list view of Tools/Pages
> 
> I don't see this. Could you please look again?

You need to hit Tools/Pages.
The JS error is on the main page. Not the detail one.
Comment 10 Katrin Fischer 2022-10-24 21:36:56 UTC
I can see the JavaScript error as dscribed on Tools > News:

Uncaught TypeError: firstTab[0] is undefined
    <anonymous> http://localhost:8081/cgi-bin/koha/tools/additional-contents.pl?category=news:1653
    jQuery 13
Comment 11 Katrin Fischer 2022-10-24 21:41:04 UTC
With this patch, all 3, Pages, News and HTML customizations on longer show the error.
Comment 12 Katrin Fischer 2022-10-24 21:41:46 UTC
Created attachment 142574 [details] [review]
Bug 31609: JavaScript error on Additional contents main page

This patch makes a minor modification to the JavaScript
on the Additional contents page to prevent an error when
there are no tabs present on the page.

The JS needs an additional check so that it doesn't run
when there are no tabs.

To test you should have more than one language installed.

- Before the patch, you would see a JavaScript error in
  the console: "Uncaught TypeError: can't access property
  "hash", firstTab[0] is undefined."
- Apply the patch and go to Tools -> Additional
  contents.
- With the patch applied there should be no error on the
  additional contents main page.
- Try creating or editing additional contents entries to
  confirm that the interface still works correctly.

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

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 13 Marcel de Rooy 2022-10-25 06:46:52 UTC
Confirming that I do not see the error either anymore.
Comment 14 Marcel de Rooy 2022-10-25 06:47:31 UTC
Created attachment 142599 [details] [review]
Bug 31609: JavaScript error on Additional contents main page

This patch makes a minor modification to the JavaScript
on the Additional contents page to prevent an error when
there are no tabs present on the page.

The JS needs an additional check so that it doesn't run
when there are no tabs.

To test you should have more than one language installed.

- Before the patch, you would see a JavaScript error in
  the console: "Uncaught TypeError: can't access property
  "hash", firstTab[0] is undefined."
- Apply the patch and go to Tools -> Additional
  contents.
- With the patch applied there should be no error on the
  additional contents main page.
- Try creating or editing additional contents entries to
  confirm that the interface still works correctly.

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

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 15 Tomás Cohen Arazi 2022-10-25 12:46:08 UTC
Pushed to master for 22.11.

Nice work everyone, thanks!
Comment 16 Lucas Gass 2022-12-05 23:17:57 UTC
Backported to 22.05.x for upcoming 22.05.08
Comment 17 Arthur Suzuki 2022-12-16 16:01:21 UTC
patch relies on initTinyMce function, which I can't find defined in 21.11.
Won't apply as is.