deactivation-stream-modal: Make stream name a template variable.

In stream deactivation modal, make "stream_name" a template variable,
rather than patching stream name to modal header in javascript.
Add tests for deactivation stream modal.
This commit is contained in:
YJDave
2018-02-21 09:46:45 +05:30
committed by Tim Abbott
parent 8ba91e48c1
commit d36ec962bb
5 changed files with 24 additions and 6 deletions

View File

@@ -577,6 +577,20 @@ function render(template_name, args) {
global.write_handlebars_output("compose_stream_alert", html); global.write_handlebars_output("compose_stream_alert", html);
}()); }());
(function deactivate_stream_modal() {
var args = {
stream_name: "Public stream",
};
var html = render('deactivation-stream-modal', args);
global.write_handlebars_output("deactivation-stream-modal", html);
var modal_header = $(html).find("#deactivation_stream_modal_label");
assert.equal(modal_header.text(), "translated: Delete stream " + args.stream_name);
var button = $(html).find("#do_deactivate_stream_button");
assert.equal(button.text(), "translated: Yes, delete this stream");
}());
(function dev_env_email_access() { (function dev_env_email_access() {
var html = render('dev_env_email_access'); var html = render('dev_env_email_access');
global.write_handlebars_output("dev_env_email_access", html); global.write_handlebars_output("dev_env_email_access", html);

View File

@@ -129,8 +129,9 @@ exports.set_up = function () {
row.addClass("active_stream_row"); row.addClass("active_stream_row");
var stream_name = row.find('.stream_name').text(); var stream_name = row.find('.stream_name').text();
var deactivate_stream_modal = templates.render('deactivation-stream-modal', {stream_name: stream_name});
$("#settings_content .organization-box").append(deactivate_stream_modal);
$("#deactivation_stream_modal .stream_name").text(stream_name);
overlays.open_modal('deactivation_stream_modal'); overlays.open_modal('deactivation_stream_modal');
}); });
@@ -167,19 +168,24 @@ exports.set_up = function () {
default_stream_input[0].value = ""; default_stream_input[0].value = "";
}); });
$("#do_deactivate_stream_button").click(function () { $("#settings_content").on("click", "#do_deactivate_stream_button", function () {
if ($("#deactivation_stream_modal .stream_name").text() !== $(".active_stream_row").find('.stream_name').text()) { if ($("#deactivation_stream_modal .stream_name").text() !== $(".active_stream_row").find('.stream_name').text()) {
blueslip.error("Stream deactivation canceled due to non-matching fields."); blueslip.error("Stream deactivation canceled due to non-matching fields.");
ui_report.message(i18n.t("Deactivation encountered an error. Please reload and try again."), ui_report.message(i18n.t("Deactivation encountered an error. Please reload and try again."),
$("#home-error"), 'alert-error'); $("#home-error"), 'alert-error');
} }
overlays.close_modal('deactivation_stream_modal'); overlays.close_modal('deactivation_stream_modal');
$("#deactivation_stream_modal").remove();
$(".active_stream_row button").prop("disabled", true).text(i18n.t("Working…")); $(".active_stream_row button").prop("disabled", true).text(i18n.t("Working…"));
var stream_name = $(".active_stream_row").find('.stream_name').text(); var stream_name = $(".active_stream_row").find('.stream_name').text();
var stream_id = stream_data.get_sub(stream_name).stream_id; var stream_id = stream_data.get_sub(stream_name).stream_id;
var row = $(".active_stream_row"); var row = $(".active_stream_row");
exports.delete_stream(stream_id, $("#organization-status"), row); exports.delete_stream(stream_id, $("#organization-status"), row);
}); });
$("#settings_content").on("hide.bs.modal", "#deactivation_stream_modal", function () {
$("#deactivation_stream_modal").remove();
});
}; };
exports.delete_stream = function (stream_id, alert_element, stream_row) { exports.delete_stream = function (stream_id, alert_element, stream_row) {

View File

@@ -595,9 +595,8 @@ $(function () {
return; return;
} }
var stream_name = stream_data.maybe_get_stream_name(stream_id); var stream_name = stream_data.maybe_get_stream_name(stream_id);
var deactivate_stream_modal = templates.render("deactivation-stream-modal"); var deactivate_stream_modal = templates.render("deactivation-stream-modal", {stream_name: stream_name});
$(".subscription_settings").append(deactivate_stream_modal); $(".subscription_settings").append(deactivate_stream_modal);
$("#deactivation_stream_modal .stream_name").text(stream_name);
overlays.open_modal('deactivation_stream_modal'); overlays.open_modal('deactivation_stream_modal');
}); });

View File

@@ -1,7 +1,6 @@
<div class="alert" id="organization-status"></div> <div class="alert" id="organization-status"></div>
{{ partial "deactivation-user-modal" }} {{ partial "deactivation-user-modal" }}
{{ partial "deactivation-stream-modal" }}
{{ partial "realm-domains-modal" }} {{ partial "realm-domains-modal" }}
{{ partial "revoke-invite-modal" }} {{ partial "revoke-invite-modal" }}
{{ partial "resend-invite-modal" }} {{ partial "resend-invite-modal" }}

View File

@@ -1,7 +1,7 @@
<div id="deactivation_stream_modal" class="modal modal-bg hide fade" tabindex="-1" role="dialog" aria-labelledby="deactivation_stream_modal_label" aria-hidden="true"> <div id="deactivation_stream_modal" class="modal modal-bg hide fade" tabindex="-1" role="dialog" aria-labelledby="deactivation_stream_modal_label" aria-hidden="true">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="{{t 'Close' }}"><span aria-hidden="true">&times;</span></button> <button type="button" class="close" data-dismiss="modal" aria-label="{{t 'Close' }}"><span aria-hidden="true">&times;</span></button>
<h3 id="deactivation_stream_modal_label">{{t "Delete stream" }} <span class="stream_name"></span></h3> <h3 id="deactivation_stream_modal_label">{{t "Delete stream" }} <span class="stream_name">{{stream_name}}</span></h3>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p>{{t "Deleting this stream will immediately unsubscribe everyone, and the stream's content will not be recoverable." }} <strong>{{t "Are you sure you want to do this?" }}</strong></p> <p>{{t "Deleting this stream will immediately unsubscribe everyone, and the stream's content will not be recoverable." }} <strong>{{t "Are you sure you want to do this?" }}</strong></p>