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-06-05 23:36:32 +02:00
|
|
|
function maybe_bulk_update_stream_notification_setting(notification_checkbox,
|
|
|
|
propagate_setting_function) {
|
|
|
|
var html = templates.render("propagate_notification_change");
|
|
|
|
// TODO: This seems broken!!!
|
|
|
|
var group = notification_checkbox.closest(".input-group");
|
|
|
|
var checkbox_status = notification_checkbox.prop('checked');
|
|
|
|
group.find(".propagate_stream_notifications_change").html(html);
|
|
|
|
group.find(".yes_propagate_notifications").on("click", function () {
|
|
|
|
propagate_setting_function(checkbox_status);
|
|
|
|
group.find(".propagate_stream_notifications_change").empty();
|
|
|
|
});
|
|
|
|
group.find(".no_propagate_notifications").on("click", function () {
|
|
|
|
group.find(".propagate_stream_notifications_change").empty();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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};
|
2017-06-05 23:36:32 +02:00
|
|
|
var setting_data = $(this).prop('checked');
|
|
|
|
data[setting] = JSON.stringify(setting_data);
|
2017-06-04 19:43:10 +02:00
|
|
|
|
|
|
|
channel.patch({
|
|
|
|
url: '/json/settings/notifications',
|
|
|
|
data: data,
|
|
|
|
success: function () {
|
2017-06-05 23:36:32 +02:00
|
|
|
if (setting_data === true) {
|
2017-06-04 19:43:10 +02:00
|
|
|
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') {
|
2017-06-05 23:36:32 +02:00
|
|
|
maybe_bulk_update_stream_notification_setting($('#' + setting), function () {
|
|
|
|
stream_edit.set_notification_setting_for_all_streams('desktop_notifications', setting_data);
|
|
|
|
});
|
2017-06-04 19:43:10 +02:00
|
|
|
} else if (setting === 'enable_stream_sounds') {
|
2017-06-05 23:36:32 +02:00
|
|
|
maybe_bulk_update_stream_notification_setting($('#' + setting), function () {
|
|
|
|
stream_edit.set_notification_setting_for_all_streams('audible_notifications', setting_data);
|
|
|
|
});
|
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;
|
|
|
|
}
|