From c852185e9df70a7691f9a0c2fffa485e1396bfbf Mon Sep 17 00:00:00 2001 From: Aastha Gupta Date: Fri, 6 Apr 2018 22:54:14 +0530 Subject: [PATCH] stream settings: Make deactivate stream handler global. Configure the click event handler for #do_deactivate_stream_button once to avoid adding click handlers for it more than once. Fixes #8979 --- static/js/settings_streams.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/static/js/settings_streams.js b/static/js/settings_streams.js index 6f1d2a1f59..b966fcfae8 100644 --- a/static/js/settings_streams.js +++ b/static/js/settings_streams.js @@ -183,21 +183,6 @@ exports.set_up = function () { }); }); - $("#settings_content").on("click", "#do_deactivate_stream_button", function () { - if ($("#deactivation_stream_modal .stream_name").text() !== $(".active_stream_row").find('.stream_name').text()) { - blueslip.error("Stream deactivation canceled due to non-matching fields."); - ui_report.message(i18n.t("Deactivation encountered an error. Please reload and try again."), - $("#home-error"), 'alert-error'); - } - overlays.close_modal('deactivation_stream_modal'); - $("#deactivation_stream_modal").remove(); - $(".active_stream_row button").prop("disabled", true).text(i18n.t("Working…")); - var stream_name = $(".active_stream_row").find('.stream_name').text(); - var stream_id = stream_data.get_sub(stream_name).stream_id; - var row = $(".active_stream_row"); - exports.delete_stream(stream_id, $("#organization-status"), row); - }); - $("#settings_content").on("hide.bs.modal", "#deactivation_stream_modal", function () { $("#deactivation_stream_modal").remove(); }); @@ -215,6 +200,23 @@ exports.delete_stream = function (stream_id, alert_element, stream_row) { }); }; +$(function () { + $("#settings_overlay_container").on("click", "#do_deactivate_stream_button", function () { + if ($("#deactivation_stream_modal .stream_name").text() !== $(".active_stream_row").find('.stream_name').text()) { + blueslip.error("Stream deactivation canceled due to non-matching fields."); + ui_report.message(i18n.t("Deactivation encountered an error. Please reload and try again."), + $("#home-error"), 'alert-error'); + } + overlays.close_modal('deactivation_stream_modal'); + $("#deactivation_stream_modal").remove(); + $(".active_stream_row button").prop("disabled", true).text(i18n.t("Working…")); + var stream_name = $(".active_stream_row").find('.stream_name').text(); + var stream_id = stream_data.get_sub(stream_name).stream_id; + var row = $(".active_stream_row"); + exports.delete_stream(stream_id, $("#organization-status"), row); + }); +}); + return exports; }());