account_settings: Refactor avatar settings hbs.

This refactor removes some slightly complex conditional logic for
displaying avatar controls from the handlebar template to js.
This commit is contained in:
YashRE42 2019-08-11 20:04:42 +05:30 committed by Tim Abbott
parent 71f0fecda7
commit 248fbadfb6
3 changed files with 13 additions and 4 deletions

View File

@ -119,6 +119,7 @@ exports.build_page = function () {
settings_notifications.all_notifications.push_notification_tooltip, settings_notifications.all_notifications.push_notification_tooltip,
display_settings: settings_display.all_display_settings, display_settings: settings_display.all_display_settings,
user_can_change_name: settings_account.user_can_change_name(), user_can_change_name: settings_account.user_can_change_name(),
user_can_change_avatar: settings_account.user_can_change_avatar(),
}); });
$(".settings-box").html(rendered_settings_tab); $(".settings-box").html(rendered_settings_tab);

View File

@ -39,6 +39,16 @@ exports.user_can_change_name = function () {
return true; return true;
}; };
exports.user_can_change_avatar = function () {
if (page_params.is_admin) {
return true;
}
if (page_params.realm_avatar_changes_disabled || page_params.server_avatar_changes_disabled) {
return false;
}
return true;
};
exports.update_name_change_display = function () { exports.update_name_change_display = function () {
if (!exports.user_can_change_name()) { if (!exports.user_can_change_name()) {
$('#full_name').attr('disabled', 'disabled'); $('#full_name').attr('disabled', 'disabled');
@ -60,9 +70,7 @@ exports.update_email_change_display = function () {
}; };
exports.update_avatar_change_display = function () { exports.update_avatar_change_display = function () {
if ((page_params.realm_avatar_changes_disabled || if (!exports.user_can_change_avatar()) {
page_params.server_avatar_changes_disabled)
&& !page_params.is_admin) {
$('#user_avatar_upload_button .button').attr('disabled', 'disabled'); $('#user_avatar_upload_button .button').attr('disabled', 'disabled');
$('#user_avatar_delete_button .button').attr('disabled', 'disabled'); $('#user_avatar_delete_button .button').attr('disabled', 'disabled');
} else { } else {

View File

@ -156,7 +156,7 @@
<div id="user-settings-avatar"> <div id="user-settings-avatar">
<div id="user-avatar-block" style="background-image: url({{ page_params.avatar_url_medium }})" {{#if page_params.is_guest}} class="guest-avatar"{{/if}}/> <div id="user-avatar-block" style="background-image: url({{ page_params.avatar_url_medium }})" {{#if page_params.is_guest}} class="guest-avatar"{{/if}}/>
<span id="user_avatar_delete_button" aria-label="{{t 'Delete profile picture'}}" role="button" tabindex="0" <span id="user_avatar_delete_button" aria-label="{{t 'Delete profile picture'}}" role="button" tabindex="0"
{{#unless page_params.is_admin}}{{#if page_params.realm_avatar_changes_disabled}}style="display:none"{{else}}{{#if page_params.server_avatar_changes_disabled}}style="display:none"{{/if}}{{/if}}{{/unless}}> {{#unless user_can_change_avatar}}style="display:none"{{/unless}}>
&times; &times;
</span> </span>
<div id="user-avatar-source"> <div id="user-avatar-source">