mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 02:48:00 +00:00
settings_notifications.js: Refactor using notification_settings variable.
Create an array of all user notification settings and loop through it to update notification settings and display results. Formatting tweaked by tabbott.
This commit is contained in:
@@ -2,6 +2,18 @@ var settings_notifications = (function () {
|
|||||||
|
|
||||||
var exports = {};
|
var exports = {};
|
||||||
|
|
||||||
|
var notification_settings = [
|
||||||
|
"enable_desktop_notifications",
|
||||||
|
"enable_digest_emails",
|
||||||
|
"enable_offline_email_notifications",
|
||||||
|
"enable_offline_push_notifications",
|
||||||
|
"enable_online_push_notifications",
|
||||||
|
"enable_sounds",
|
||||||
|
"enable_stream_desktop_notifications",
|
||||||
|
"enable_stream_sounds",
|
||||||
|
"pm_content_in_desktop_notifications",
|
||||||
|
];
|
||||||
|
|
||||||
exports.set_up = function () {
|
exports.set_up = function () {
|
||||||
$("#notify-settings-status").hide();
|
$("#notify-settings-status").hide();
|
||||||
|
|
||||||
@@ -15,47 +27,11 @@ exports.set_up = function () {
|
|||||||
|
|
||||||
// Stream notification settings.
|
// Stream notification settings.
|
||||||
|
|
||||||
if (result.enable_stream_desktop_notifications !== undefined) {
|
_.each(result, function (v, k) {
|
||||||
page_params.enable_stream_desktop_notifications =
|
if (_.has(notification_settings, k) && result[k] !== undefined) {
|
||||||
result.enable_stream_desktop_notifications;
|
page_params[k] = result[k];
|
||||||
}
|
}
|
||||||
if (result.enable_stream_sounds !== undefined) {
|
});
|
||||||
page_params.enable_stream_sounds = result.enable_stream_sounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PM and @-mention notification settings.
|
|
||||||
|
|
||||||
if (result.enable_desktop_notifications !== undefined) {
|
|
||||||
page_params.enable_desktop_notifications = result.enable_desktop_notifications;
|
|
||||||
}
|
|
||||||
if (result.enable_sounds !== undefined) {
|
|
||||||
page_params.enable_sounds = result.enable_sounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.enable_offline_email_notifications !== undefined) {
|
|
||||||
page_params.enable_offline_email_notifications =
|
|
||||||
result.enable_offline_email_notifications;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.enable_offline_push_notifications !== undefined) {
|
|
||||||
page_params.enable_offline_push_notifications =
|
|
||||||
result.enable_offline_push_notifications;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.enable_online_push_notifications !== undefined) {
|
|
||||||
page_params.enable_online_push_notifications = result.enable_online_push_notifications;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result.pm_content_in_desktop_notifications !== undefined) {
|
|
||||||
page_params.pm_content_in_desktop_notifications
|
|
||||||
= result.pm_content_in_desktop_notifications;
|
|
||||||
}
|
|
||||||
// Other notification settings.
|
|
||||||
|
|
||||||
if (result.enable_digest_emails !== undefined) {
|
|
||||||
page_params.enable_digest_emails = result.enable_digest_emails;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui_report.success(i18n.t("Updated notification settings!"), notify_settings_status);
|
ui_report.success(i18n.t("Updated notification settings!"), notify_settings_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,12 +53,7 @@ exports.set_up = function () {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var updated_settings = {};
|
var updated_settings = {};
|
||||||
_.each(["enable_stream_desktop_notifications", "enable_stream_sounds",
|
_.each(notification_settings, function (setting) {
|
||||||
"enable_desktop_notifications", "pm_content_in_desktop_notifications", "enable_sounds",
|
|
||||||
"enable_offline_email_notifications",
|
|
||||||
"enable_offline_push_notifications", "enable_online_push_notifications",
|
|
||||||
"enable_digest_emails"],
|
|
||||||
function (setting) {
|
|
||||||
updated_settings[setting] = $("#" + setting).is(":checked");
|
updated_settings[setting] = $("#" + setting).is(":checked");
|
||||||
});
|
});
|
||||||
post_notify_settings_changes(updated_settings,
|
post_notify_settings_changes(updated_settings,
|
||||||
@@ -142,15 +113,9 @@ exports.set_up = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function _update_page() {
|
function _update_page() {
|
||||||
$("#enable_stream_desktop_notifications").prop('checked', page_params.enable_stream_desktop_notifications);
|
_.each(notification_settings, function (setting) {
|
||||||
$("#enable_stream_sounds").prop('checked', page_params.enable_stream_sounds);
|
$("#" + setting).prop('checked', page_params[setting]);
|
||||||
$("#enable_desktop_notifications").prop('checked', page_params.enable_desktop_notifications);
|
});
|
||||||
$("#enable_sounds").prop('checked', page_params.enable_sounds);
|
|
||||||
$("#enable_offline_email_notifications").prop('checked', page_params.enable_offline_email_notifications);
|
|
||||||
$("#enable_offline_push_notifications").prop('checked', page_params.enable_offline_push_notifications);
|
|
||||||
$("#enable_online_push_notifications").prop('checked', page_params.enable_online_push_notifications);
|
|
||||||
$("#pm_content_in_desktop_notifications").prop('checked', page_params.pm_content_in_desktop_notifications);
|
|
||||||
$("#enable_digest_emails").prop('checked', page_params.enable_digest_emails);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.update_page = function () {
|
exports.update_page = function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user