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)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sat, 26 Dec 2020 17:14:11 +0000 (18:14 +0100)
commit084d64b84a536c1d88f2fa477865134f97388489
tree623c8a958316cc2d77b5b7ee9c7762ffac4a8921
parent2498cdcc88be798b88d6a23bf6e592cff5a80f45
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>
koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt