settings: Simplify logic to show push notification tooltip in templates.

Instead of having logical expressions in templates, it's always preferred
to calculating them in javascript and pass the results as a context. It
also enhances the readability of templates and testing of such logic is
easier in js over templates.
This commit is contained in:
Pragati Agrawal 2020-03-22 22:33:25 +05:30 committed by Tim Abbott
parent 1871443d10
commit 83933034a4
5 changed files with 19 additions and 18 deletions

View File

@ -3,10 +3,14 @@ zrequire('muting');
zrequire('people');
zrequire('stream_data');
zrequire('unread');
set_global('page_params', {
realm_push_notifications_enabled: false,
});
zrequire('settings_notifications');
const FoldDict = zrequire('fold_dict').FoldDict;
set_global('page_params', {});
set_global('blueslip', {});
set_global('narrow_state', {});
set_global('current_msg_list', {});

View File

@ -114,8 +114,8 @@ exports.build_page = function () {
twenty_four_hour_time_values: settings_config.twenty_four_hour_time_values,
notification_settings: settings_notifications.all_notifications.settings,
desktop_icon_count_display_values: settings_notifications.desktop_icon_count_display_values,
push_notification_tooltip:
settings_notifications.all_notifications.push_notification_tooltip,
show_push_notifications_tooltip:
settings_notifications.all_notifications.show_push_notifications_tooltip,
display_settings: settings_config.get_all_display_settings(),
user_can_change_name: settings_account.user_can_change_name(),
user_can_change_avatar: settings_account.user_can_change_avatar(),

View File

@ -54,10 +54,10 @@ exports.all_notifications = {
mobile_notification_settings: mobile_notification_settings,
email_notification_settings: email_notification_settings,
},
push_notification_tooltip: {
enable_stream_push_notifications: true,
enable_offline_push_notifications: true,
enable_online_push_notifications: true,
show_push_notifications_tooltip: {
enable_stream_push_notifications: !page_params.realm_push_notifications_enabled,
enable_offline_push_notifications: !page_params.realm_push_notifications_enabled,
enable_online_push_notifications: !page_params.realm_push_notifications_enabled,
},
};

View File

@ -12,8 +12,7 @@
setting_name=this
is_checked=(lookup ../page_params this)
label=(lookup ../settings_label this)
realm_push_notifications_enabled=(lookup ../page_params "realm_push_notifications_enabled")
push_notifications_tooltip=(lookup ../push_notification_tooltip this)}}
show_push_notifications_tooltip=(lookup ../show_push_notifications_tooltip this)}}
{{/each}}
<p class="notification-settings-note">
@ -30,8 +29,7 @@
setting_name=this
is_checked=(lookup ../page_params this)
label=(lookup ../settings_label this)
realm_push_notifications_enabled=(lookup ../page_params "realm_push_notifications_enabled")
push_notifications_tooltip=(lookup ../push_notification_tooltip this)}}
show_push_notifications_tooltip=(lookup ../show_push_notifications_tooltip this)}}
{{/each}}
</div>
@ -81,8 +79,7 @@
setting_name=this
is_checked=(lookup ../page_params this)
label=(lookup ../settings_label this)
realm_push_notifications_enabled=(lookup ../page_params "realm_push_notifications_enabled")
push_notifications_tooltip=(lookup ../push_notification_tooltip this)}}
show_push_notifications_tooltip=(lookup ../show_push_notifications_tooltip this)}}
{{/each}}
<h5>{{t "Email" }}</h5>

View File

@ -1,11 +1,11 @@
{{#unless (eq render_only false)}}
<div class="input-group {{#if is_nested}}disableable{{/if}} {{#if (and push_notifications_tooltip (not realm_push_notifications_enabled))}}control-label-disabled{{/if}}">
<div class="input-group {{#if is_nested}}disableable{{/if}} {{#if show_push_notifications_tooltip}}control-label-disabled{{/if}}">
<label class="checkbox">
<input type="checkbox" class="inline-block setting-widget prop-element" name="{{setting_name}}" data-setting-widget-type="bool"
id="{{prefix}}{{setting_name}}"
{{#if (and push_notifications_tooltip (not realm_push_notifications_enabled))}}disabled="disabled"{{/if}}
{{#if show_push_notifications_tooltip}}disabled="disabled"{{/if}}
{{#if is_checked}}
{{#unless (and push_notifications_tooltip (not realm_push_notifications_enabled))}}
{{#unless show_push_notifications_tooltip}}
checked="checked"
{{/unless}}
{{/if}} />
@ -14,8 +14,8 @@
<label for="{{prefix}}{{setting_name}}" class="inline-block" id="{{prefix}}{{setting_name}}_label">
{{{label}}}
</label>
{{#if push_notifications_tooltip}}
<i class="fa fa-question-circle settings-info-icon" {{#if realm_push_notifications_enabled}}style="display:none"{{/if}} data-toggle="tooltip"
{{#if show_push_notifications_tooltip}}
<i class="fa fa-question-circle settings-info-icon" data-toggle="tooltip"
title="{{t 'Mobile push notifications are not configured on this server.' }}"></i>
{{/if}}
</div>