From 02e7655c4e274e7b957d98ef9b8a79ac9ac6dd8a Mon Sep 17 00:00:00 2001 From: Yashashvi Dave Date: Fri, 14 Jun 2019 00:53:05 +0530 Subject: [PATCH] display settings: Deduplicate display settings click handlers. --- static/js/settings_display.js | 52 +++++++++++------------------------ 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/static/js/settings_display.js b/static/js/settings_display.js index 4d79016214..502e4fec3b 100644 --- a/static/js/settings_display.js +++ b/static/js/settings_display.js @@ -22,12 +22,6 @@ function change_display_setting(data, status_element, success_msg, sticky) { settings_ui.do_settings_change(channel.patch, '/json/settings/display', data, status_element, opts); } -exports.set_night_mode = function (bool) { - var night_mode = bool; - var data = {night_mode: JSON.stringify(night_mode)}; - change_display_setting(data, '#display-settings-status'); -}; - exports.demote_inactive_streams_values = { automatic: { code: 1, @@ -74,6 +68,22 @@ exports.set_up = function () { overlays.close_modal('default_language_modal'); }); + _.each(exports.all_display_settings.settings.user_display_settings, function (setting) { + $("#" + setting).change(function () { + var data = {}; + data[setting] = JSON.stringify($(this).prop('checked')); + + if (["left_side_userlist"].indexOf(setting) > -1) { + change_display_setting( + data, + "#display-settings-status", + i18n.t("Saved. Please reload for the change to take effect."), true); + } else { + change_display_setting(data, "#display-settings-status"); + } + }); + }); + $("#default_language_modal .language").click(function (e) { e.preventDefault(); e.stopPropagation(); @@ -97,45 +107,15 @@ exports.set_up = function () { overlays.open_modal('default_language_modal'); }); - $("#high_contrast_mode").change(function () { - var data = {high_contrast_mode: JSON.stringify(this.checked)}; - change_display_setting(data, '#display-settings-status'); - }); - - $("#dense_mode").change(function () { - var data = {dense_mode: JSON.stringify(this.checked)}; - change_display_setting(data, '#display-settings-status'); - }); - - $('#starred_message_counts').change(function () { - var data = {starred_message_counts: JSON.stringify(this.checked)}; - change_display_setting(data, '#display-settings-status'); - }); - - $('#fluid_layout_width').change(function () { - var data = {fluid_layout_width: JSON.stringify(this.checked)}; - change_display_setting(data, '#display-settings-status'); - }); - $('#demote_inactive_streams').change(function () { var data = {demote_inactive_streams: this.value}; change_display_setting(data, '#display-settings-status'); }); - $("#night_mode").change(function () { - exports.set_night_mode(this.checked); - }); - $('body').on('click', '.reload_link', function () { window.location.reload(); }); - $("#left_side_userlist").change(function () { - var data = {left_side_userlist: JSON.stringify(this.checked)}; - change_display_setting(data, '#display-settings-status', - i18n.t("Saved. Please reload for the change to take effect."), true); - }); - $("#twenty_four_hour_time").change(function () { var data = {twenty_four_hour_time: JSON.stringify(this.checked)}; change_display_setting(data, '#time-settings-status');