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",
|
2017-08-17 16:55:32 +02:00
|
|
|
"enable_stream_push_notifications",
|
2017-06-04 19:43:10 +02:00
|
|
|
"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-08-23 08:57:20 +02:00
|
|
|
ui_report.success(i18n.t("Enabled: __- setting_name__",
|
2017-06-04 19:43:10 +02:00
|
|
|
context), notify_settings_status);
|
|
|
|
} else {
|
2017-08-23 08:57:20 +02:00
|
|
|
ui_report.success(i18n.t("Disabled: __- setting_name__",
|
2017-06-04 19:43:10 +02:00
|
|
|
context), notify_settings_status);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function (xhr) {
|
2017-08-23 08:57:20 +02:00
|
|
|
ui_report.error(i18n.t('Error updating: __- setting_name__',
|
2017-06-04 19:43:10 +02:00
|
|
|
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-08-17 16:55:32 +02:00
|
|
|
} else if (setting === 'enable_stream_push_notifications') {
|
|
|
|
maybe_bulk_update_stream_notification_setting($('#' + setting), function () {
|
|
|
|
stream_edit.set_notification_setting_for_all_streams('push_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
|
|
|
});
|
2017-07-21 01:04:12 +02:00
|
|
|
|
|
|
|
$("#enable_desktop_notifications").change(function () {
|
|
|
|
if (this.checked) {
|
2017-06-30 00:57:46 +02:00
|
|
|
$("#pm_content_in_desktop_notifications").prop("disabled", false);
|
2017-07-21 01:04:12 +02:00
|
|
|
$("#pm_content_in_desktop_notifications_label").parent().removeClass("control-label-disabled");
|
|
|
|
} else {
|
2017-06-30 00:57:46 +02:00
|
|
|
$("#pm_content_in_desktop_notifications").prop("disabled", true);
|
2017-07-21 01:04:12 +02:00
|
|
|
$("#pm_content_in_desktop_notifications_label").parent().addClass("control-label-disabled");
|
|
|
|
}
|
|
|
|
});
|
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;
|
|
|
|
}
|