mirror of https://github.com/zulip/zulip.git
org settings: Minor refactor to add notification stream id data in widget.
As the part of making notification stream settings to change using "save/discard" widget instead of immediate saving, we need to access the stream id which is being selected at the moment.
This commit is contained in:
parent
a1426d78b1
commit
48b6734b73
|
@ -890,12 +890,12 @@ run_test('misc', () => {
|
|||
assert.equal(stream_id, 42);
|
||||
return { name: 'some_stream' };
|
||||
};
|
||||
settings_org.render_notifications_stream_ui(42, elem);
|
||||
settings_org.render_notifications_stream_ui(42, "notifications");
|
||||
assert.equal(elem.text(), '#some_stream');
|
||||
assert(!elem.hasClass('text-warning'));
|
||||
|
||||
stream_data.get_sub_by_id = noop;
|
||||
settings_org.render_notifications_stream_ui(undefined, elem);
|
||||
settings_org.render_notifications_stream_ui(undefined, "notifications");
|
||||
assert.equal(elem.text(), 'translated: Disabled');
|
||||
assert(elem.hasClass('text-warning'));
|
||||
|
||||
|
@ -907,12 +907,12 @@ run_test('misc', () => {
|
|||
assert.equal(stream_id, 75);
|
||||
return { name: 'some_stream' };
|
||||
};
|
||||
settings_org.render_notifications_stream_ui(75, elem);
|
||||
settings_org.render_notifications_stream_ui(75, "signup_notifications");
|
||||
assert.equal(elem.text(), '#some_stream');
|
||||
assert(!elem.hasClass('text-warning'));
|
||||
|
||||
stream_data.get_sub_by_id = noop;
|
||||
settings_org.render_notifications_stream_ui(undefined, elem);
|
||||
settings_org.render_notifications_stream_ui(undefined, "signup_notifications");
|
||||
assert.equal(elem.text(), 'translated: Disabled');
|
||||
assert(elem.hasClass('text-warning'));
|
||||
|
||||
|
|
|
@ -142,12 +142,10 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
|||
}
|
||||
} else if (event.property === 'notifications_stream_id') {
|
||||
settings_org.render_notifications_stream_ui(
|
||||
page_params.realm_notifications_stream_id,
|
||||
$('#realm_notifications_stream_name'));
|
||||
page_params.realm_notifications_stream_id, 'notifications');
|
||||
} else if (event.property === 'signup_notifications_stream_id') {
|
||||
settings_org.render_notifications_stream_ui(
|
||||
page_params.realm_signup_notifications_stream_id,
|
||||
$('#realm_signup_notifications_stream_name'));
|
||||
page_params.realm_signup_notifications_stream_id, 'signup_notifications');
|
||||
}
|
||||
|
||||
if (event.property === 'name' && window.electron_bridge !== undefined) {
|
||||
|
@ -293,14 +291,12 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
|
|||
if (page_params.realm_notifications_stream_id === stream.stream_id) {
|
||||
page_params.realm_notifications_stream_id = -1;
|
||||
settings_org.render_notifications_stream_ui(
|
||||
page_params.realm_notifications_stream_id,
|
||||
$('#realm_notifications_stream_name'));
|
||||
page_params.realm_notifications_stream_id, 'notifications');
|
||||
}
|
||||
if (page_params.realm_signup_notifications_stream_id === stream.stream_id) {
|
||||
page_params.realm_signup_notifications_stream_id = -1;
|
||||
settings_org.render_notifications_stream_ui(
|
||||
page_params.realm_signup_notifications_stream_id,
|
||||
$('#realm_signup_notifications_stream_name'));
|
||||
page_params.realm_signup_notifications_stream_id, 'signup_notifications');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -407,10 +407,13 @@ function insert_tip_box() {
|
|||
.prepend(tip_box);
|
||||
}
|
||||
|
||||
exports.render_notifications_stream_ui = function (stream_id, elem) {
|
||||
|
||||
exports.render_notifications_stream_ui = function (stream_id, notification_type) {
|
||||
const name = stream_data.maybe_get_stream_name(stream_id);
|
||||
|
||||
$(`#id_realm_${notification_type}_stream`).data("stream-id", stream_id);
|
||||
|
||||
const elem = $(`#realm_${notification_type}_stream_name`);
|
||||
|
||||
if (!name) {
|
||||
elem.text(i18n.t("Disabled"));
|
||||
elem.addClass("text-warning");
|
||||
|
@ -628,10 +631,8 @@ exports.build_page = function () {
|
|||
exports.populate_notifications_stream_dropdown(streams);
|
||||
exports.populate_signup_notifications_stream_dropdown(streams);
|
||||
}
|
||||
exports.render_notifications_stream_ui(page_params.realm_notifications_stream_id,
|
||||
$('#realm_notifications_stream_name'));
|
||||
exports.render_notifications_stream_ui(page_params.realm_signup_notifications_stream_id,
|
||||
$('#realm_signup_notifications_stream_name'));
|
||||
exports.render_notifications_stream_ui(page_params.realm_notifications_stream_id, 'notifications');
|
||||
exports.render_notifications_stream_ui(page_params.realm_signup_notifications_stream_id, 'signup_notifications');
|
||||
|
||||
// Populate realm domains
|
||||
exports.populate_realm_domains(page_params.realm_domains);
|
||||
|
@ -1069,8 +1070,7 @@ exports.build_page = function () {
|
|||
});
|
||||
|
||||
function notification_stream_update(stream_id, notification_type) {
|
||||
exports.render_notifications_stream_ui(stream_id,
|
||||
$(`#realm_${notification_type}_stream_name`));
|
||||
exports.render_notifications_stream_ui(stream_id, notification_type);
|
||||
exports.save_organization_settings({
|
||||
[`${notification_type}_stream_id`]: JSON.stringify(parseInt(stream_id, 10)),
|
||||
}, $("#org-submit-notifications"));
|
||||
|
|
Loading…
Reference in New Issue