From 747e79709237cf521a35575cf4ed8b0163ce681a Mon Sep 17 00:00:00 2001 From: Pragati Agrawal Date: Fri, 26 Apr 2019 18:44:53 +0530 Subject: [PATCH] stream settings: Disable Mobile notifications if push bouncer not set up. This commit disables "Mobile notifications" if `push_notifications` are not enabled. It also adds a tooltip explaining why this is disabled. Fixes #12208 --- frontend_tests/node_tests/templates.js | 7 +++++++ static/js/stream_edit.js | 5 +++++ static/styles/subscriptions.scss | 3 ++- static/templates/stream-settings-checkbox.handlebars | 10 ++++++++-- static/templates/subscription_settings.handlebars | 1 + 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/frontend_tests/node_tests/templates.js b/frontend_tests/node_tests/templates.js index f58ee4f11b..9ac9d65c94 100644 --- a/frontend_tests/node_tests/templates.js +++ b/frontend_tests/node_tests/templates.js @@ -3,6 +3,7 @@ zrequire('templates'); zrequire('settings_notifications'); set_global('i18n', global.stub_i18n); +set_global('page_params', {}); zrequire('stream_edit'); const { JSDOM } = require("jsdom"); @@ -1268,9 +1269,15 @@ run_test('subscription_settings', () => { }; var html = ''; + page_params.realm_push_notifications_enabled = false; + var check_realm_setting = { + push_notifications: !page_params.realm_push_notifications_enabled, + }; + html += render('subscription_settings', { sub: sub, settings: stream_edit.stream_settings(sub), + realm_settings: check_realm_setting, }); var div = $(html).find(".subscription-type"); diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index 0bc0ce8118..dd5153532b 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -238,6 +238,10 @@ var settings_labels = { pin_to_top: i18n.t("Pin stream to top of left sidebar"), }; +var check_realm_setting = { + push_notifications: !page_params.realm_push_notifications_enabled, +}; + exports.stream_settings = function (sub) { var settings = []; _.each(Object.keys(settings_labels), function (setting) { @@ -267,6 +271,7 @@ exports.show_settings_for = function (node) { var html = templates.render('subscription_settings', { sub: sub, settings: exports.stream_settings(sub), + realm_settings: check_realm_setting, }); ui.get_content_element($('.subscriptions .right .settings')).html(html); diff --git a/static/styles/subscriptions.scss b/static/styles/subscriptions.scss index 63c70438a8..145200a45c 100644 --- a/static/styles/subscriptions.scss +++ b/static/styles/subscriptions.scss @@ -144,7 +144,8 @@ white-space: normal; } -.muted-sub { +.muted-sub, +.control-label-disabled { color: hsl(0, 0%, 64%); } diff --git a/static/templates/stream-settings-checkbox.handlebars b/static/templates/stream-settings-checkbox.handlebars index 8fb6eb1394..5f8c92cd8b 100644 --- a/static/templates/stream-settings-checkbox.handlebars +++ b/static/templates/stream-settings-checkbox.handlebars @@ -1,7 +1,13 @@ -
- +{{!-- If setting is disabled on realm level, then render setting as control-label-disabled and do not set setting value. Setting status should not change on any click handler, as it is disabled at realm level. --}} +
+ + + {{!-- Tooltips for settings --}} {{#if_equal setting_name "is_muted"}}

{{t "Muted streams don't show up in \"All messages\" or generate notifications unless you are mentioned." }}

{{/if_equal}} + {{#if_equal setting_name "push_notifications"}} + + {{/if_equal}}
diff --git a/static/templates/subscription_settings.handlebars b/static/templates/subscription_settings.handlebars index ee55b4b8a7..e834581972 100644 --- a/static/templates/subscription_settings.handlebars +++ b/static/templates/subscription_settings.handlebars @@ -59,6 +59,7 @@ "is_muted" (lookup ../sub "is_muted") "stream_id" (lookup ../sub "stream_id") "notification_setting" is_notification_setting + "realm_setting_disabled" (lookup ../realm_settings name) "label" label}} {{/each}}