Bug 23680 - Can't open 'Edit items' or 'Add item' links in new tab - tab is closed immediately
Summary: Can't open 'Edit items' or 'Add item' links in new tab - tab is closed immedi...
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Staff interface (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor
Assignee: David Gustafsson
QA Contact: Katrin Fischer
URL:
Keywords:
: 23490 23782 24040 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-09-26 09:49 UTC by David Gustafsson
Modified: 2021-06-14 21:28 UTC (History)
9 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
This fixes a problem where the pop-up window or tab immediately closes when attempting to edit or add a bibliographic item.
Version(s) released in:
19.11.00,19.05.05
Circulation function:


Attachments
Bug 23680: Incorrect conversion of Perl boolean to js (1.65 KB, patch)
2019-09-26 10:03 UTC, David Gustafsson
Details | Diff | Splinter Review
Bug 23680: Incorrect conversion of Perl boolean to js (1.70 KB, patch)
2019-09-26 19:31 UTC, David Nind
Details | Diff | Splinter Review
Bug 23680: Incorrect conversion of Perl boolean to js (1.76 KB, patch)
2019-10-03 11:35 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 David Gustafsson 2019-09-26 09:49:15 UTC
In cataloging_additem.inc the javascript variable "popup" is generated as:

var popup = '[% popup | html %]';

So popup will be either '0' or '1'. '0' is a truthy value in javascript, so popup will always be evaluated as true making this condition:

if( popup && op != 'saveitem' ){
  window.close();
}

in cataloging_additem.js (incorrectly) true for every operation except saveitem.

A windows can only be closed by javascript in certain conditions (don't know if all browsers behave exactly the same), but for window.close() to actually close the window it needs to be opened in new window/tab. So to reproduce this bug go to a bibliographic record, expand the "New" menu, and open "New item" in new tab. It should immediately close, which this patch should fix.
Comment 1 David Gustafsson 2019-09-26 10:03:59 UTC Comment hidden (obsolete)
Comment 2 David Gustafsson 2019-09-26 10:07:24 UTC
I think this bug was introduced in Bug 21091.
Comment 3 David Nind 2019-09-26 19:31:23 UTC
Created attachment 93176 [details] [review]
Bug 23680: Incorrect conversion of Perl boolean to js

A Perl boolean value is on the server side converted
to a JS string (resulting in the values '0' or '1).
Since the string '0' is a truthy value in JS this
incorrectly triggers window.close() on the client
in many instances, for example when adding a new item.

To test:

1. Go to a bibliographic record in the staff client.
2. Expand the "New" menu and open "New item" in new tab.
3. The new tab will immediately close.
4. Apply the patch.
5. Perform steps 1-2 again.
6. The tab should now remain open.

Sponsored-by: Gothenburg University Library

Signed-off-by: David Nind <david@davidnind.com>
Comment 4 David Nind 2019-09-26 19:34:45 UTC
I tested this with the latest Firefox and Google Chrome browsers on Ubuntu 18.04.

With pop ups allowed for both browsers:

- On Firefox the behaviour identified didn't occur, that is: the window opened fine in a new tab (both before and after the patch)

- On Google Chrome the behaviour identified occurred and the patch fixed it.
Comment 5 Katrin Fischer 2019-10-03 11:21:44 UTC
Please don't forget to assign the bug to you when you start working on it!
Comment 6 Katrin Fischer 2019-10-03 11:32:12 UTC
(In reply to David Nind from comment #4)
> I tested this with the latest Firefox and Google Chrome browsers on Ubuntu
> 18.04.
> 
> With pop ups allowed for both browsers:
> 
> - On Firefox the behaviour identified didn't occur, that is: the window
> opened fine in a new tab (both before and after the patch)
> 
> - On Google Chrome the behaviour identified occurred and the patch fixed it.

Thx for the hints about Browsers, David!
Comment 7 Katrin Fischer 2019-10-03 11:35:07 UTC
Created attachment 93563 [details] [review]
Bug 23680: Incorrect conversion of Perl boolean to js

A Perl boolean value is on the server side converted
to a JS string (resulting in the values '0' or '1).
Since the string '0' is a truthy value in JS this
incorrectly triggers window.close() on the client
in many instances, for example when adding a new item.

To test:

1. Go to a bibliographic record in the staff client.
2. Expand the "New" menu and open "New item" in new tab.
3. The new tab will immediately close.
4. Apply the patch.
5. Perform steps 1-2 again.
6. The tab should now remain open.

Sponsored-by: Gothenburg University Library

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

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 8 Martin Renvoize (ashimema) 2019-10-07 13:10:45 UTC
Nice work!

Pushed to master for 19.11.00
Comment 9 Katrin Fischer 2019-10-09 05:16:41 UTC
*** Bug 23782 has been marked as a duplicate of this bug. ***
Comment 10 Katrin Fischer 2019-10-11 05:47:29 UTC
*** Bug 23490 has been marked as a duplicate of this bug. ***
Comment 11 Katrin Fischer 2019-10-11 05:49:42 UTC
2 duplicates filed already - changing bug title to make it more readable.
Comment 12 Fridolin Somers 2019-11-14 13:00:41 UTC
Pushed to 19.05.x for 19.05.05
Comment 13 Katrin Fischer 2019-11-24 14:26:00 UTC
*** Bug 24040 has been marked as a duplicate of this bug. ***