From 2cda98609bb65d0c12b35a4928455a0359e2058a Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 16 Jul 2013 16:47:30 -0400 Subject: [PATCH] subs: Update checkbox states when values are changed off-page. Previously, if you toggled the in_home_view checkbox either in a different browser or via the button in the sidebar menus, it didn't actually update the visible checkbox state in the streams page, resulting in some potentially very confusing interactions. (imported from commit 3424430231f89a23e970a2f1bfec82c6eb0d6735) --- zephyr/static/js/subs.js | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/zephyr/static/js/subs.js b/zephyr/static/js/subs.js index e7b7866e7a..9d52971f70 100644 --- a/zephyr/static/js/subs.js +++ b/zephyr/static/js/subs.js @@ -196,9 +196,11 @@ function stream_home_view_clicked(e) { subs.toggle_home(stream); } -exports.toggle_home = function (stream_name) { - var sub = get_sub(stream_name); - sub.in_home_view = ! sub.in_home_view; +function update_in_home_view(sub, value) { + if (sub.in_home_view === value) { + return; + } + sub.in_home_view = value; setTimeout(function () { var scroll_offset, saved_ypos; @@ -240,10 +242,24 @@ exports.toggle_home = function (stream_name) { }, 0); exports.maybe_toggle_all_messages(); + stream_list.set_in_home_view(sub.name, sub.in_home_view); + + var in_home_view_checkbox = $("#subscription_" + sub.id + " #sub_setting_in_home_view .sub_setting_control"); + in_home_view_checkbox.attr('checked', value); +} + +exports.toggle_home = function (stream_name) { + var sub = get_sub(stream_name); + update_in_home_view(sub, ! sub.in_home_view); set_stream_property(stream_name, 'in_home_view', sub.in_home_view); - stream_list.set_in_home_view(stream_name, sub.in_home_view); }; +function update_stream_notifications(sub, value) { + var in_home_view_checkbox = $("#subscription_" + sub.id + " #sub_setting_notifications .sub_setting_control"); + in_home_view_checkbox.attr('checked', value); + sub.notifications = value; +} + function stream_notifications_clicked(e) { var sub_row = $(e.target).closest('.subscription_row'); var stream = sub_row.find('.subscription_name').text(); @@ -667,11 +683,10 @@ exports.update_subscription_properties = function (stream_name, property, value) update_stream_color(stream_name, value, {update_historical: true}); break; case 'in_home_view': - sub[property] = value; - stream_list.set_in_home_view(stream_name, sub.in_home_view); + update_in_home_view(sub, value); break; case 'notifications': - sub[property] = value; + update_stream_notifications(sub, value); break; default: blueslip.warn("Unexpected subscription property type", {property: property,