Bug 27250: Fix stacked event listeners in SMTP delete modal
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 17 Dec 2020 14:53:16 +0000 (11:53 -0300)
committerFridolin Somers <fridolin.somers@biblibre.com>
Wed, 30 Dec 2020 14:46:44 +0000 (15:46 +0100)
commit9af15a37b4f1a216b350152b0f115c74c8a6f176
tree1f1fc5cf5aad27209a274e7f8f886e27f4434718
parent474a12938043c4494fac4effd01ba20dadf9eca0
Bug 27250: Fix stacked event listeners in SMTP delete modal

There is a design issue on the click event listener that makes the modal
get added new event listeners on each row being deleted. This makes the
page call all the event listeners and generates an error.

This patch replaces the flawed logic (adding the event listener inside
the event listener). It makes the event listener be defined at startup
time, and make the .on('click') action just pass information around as
required.

To test:
1. Create at least 2 SMTP servers
2. Open the browser inspector, on the network tab
3. Click "Delete" for server 1
=> SUCCESS: You get a successful message (OK)
4. Click "Delete" for server 2
=> SUCCESS: You get a successful message (OK)
=> FAIL: You get also an alert message about server 1 (KO)
=> FAIL: The inspector shows more than one AJAX call has been made
5. Apply this patch and reload the page
6. Repeat 3-4
=> SUCCESS: Everything goes smooth this time
7. Sign off :-D

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 084d64b84a536c1d88f2fa477865134f97388489)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt