2017-04-06 16:01:07 +02:00
|
|
|
var settings_notifications = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2017-06-04 19:43:10 +02:00
|
|
|
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",
|
|
|
|
];
|
|
|
|
|
2017-04-06 16:01:07 +02:00
|
|
|
exports.set_up = function () {
|
2017-06-04 19:43:10 +02:00
|
|
|
var notify_settings_status = $("#notify-settings-status").expectOne();
|
|
|
|
notify_settings_status.hide();
|
2017-04-06 16:01:07 +02:00
|
|
|
|
2017-04-20 07:59:03 +02:00
|
|
|
if (!page_params.realm_show_digest_email) {
|
2017-04-06 22:55:41 +02:00
|
|
|
$("#other_notifications").hide();
|
|
|
|
}
|
|
|
|
|
2017-06-04 19:43:10 +02:00
|
|
|
_.each(notification_settings, function (setting) {
|
|
|
|
$("#" + setting).change(function () {
|
|
|
|
var data = {};
|
|
|
|
var setting_name = $('label[for=' + setting + ']').text().trim();
|
|
|
|
var context = {setting_name: setting_name};
|
|
|
|
data[setting] = JSON.stringify(this.checked);
|
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: '/json/settings/notifications',
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
|
|
|
if (data[setting] === 'true') {
|
|
|
|
ui_report.success(i18n.t("Enabled: __setting_name__",
|
|
|
|
context), notify_settings_status);
|
|
|
|
} else {
|
|
|
|
ui_report.success(i18n.t("Disabled: __setting_name__",
|
|
|
|
context), notify_settings_status);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
|
|
|
ui_report.error(i18n.t('Error updating: __setting_name__',
|
|
|
|
context), xhr, notify_settings_status);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
if (setting === 'enable_stream_desktop_notifications') {
|
|
|
|
stream_edit.set_notification_setting_for_all_streams('desktop_notifications', data[setting]);
|
|
|
|
} else if (setting === 'enable_stream_sounds') {
|
|
|
|
stream_edit.set_notification_setting_for_all_streams('audible_notifications', data[setting]);
|
2017-06-04 19:43:10 +02:00
|
|
|
}
|
|
|
|
});
|
2017-04-06 16:01:07 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function _update_page() {
|
2017-06-04 19:43:10 +02:00
|
|
|
_.each(notification_settings, function (setting) {
|
|
|
|
$("#" + setting).prop('checked', page_params[setting]);
|
|
|
|
});
|
2017-04-06 16:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.update_page = function () {
|
|
|
|
i18n.ensure_i18n(_update_page);
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = settings_notifications;
|
|
|
|
}
|