From 0d34caff853629b7e83aa5767996b4246d49af8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 29 Nov 2017 18:09:44 +0100 Subject: [PATCH] UX: show error message when no gravatar is associated --- .../controllers/avatar-selector.js.es6 | 15 +++-- .../templates/modal/avatar-selector.hbs | 55 ++++++++++--------- app/assets/stylesheets/common/base/user.scss | 10 ++++ app/controllers/user_avatars_controller.rb | 17 ++++-- config/locales/client.en.yml | 1 + 5 files changed, 63 insertions(+), 35 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/avatar-selector.js.es6 b/app/assets/javascripts/discourse/controllers/avatar-selector.js.es6 index ab30fef1572..170f28fc303 100644 --- a/app/assets/javascripts/discourse/controllers/avatar-selector.js.es6 +++ b/app/assets/javascripts/discourse/controllers/avatar-selector.js.es6 @@ -36,10 +36,17 @@ export default Ember.Controller.extend(ModalFunctionality, { refreshGravatar() { this.set("gravatarRefreshDisabled", true); return ajax(`/user_avatar/${this.get("username")}/refresh_gravatar.json`, { method: "POST" }) - .then(result => this.setProperties({ - gravatar_avatar_template: result.gravatar_avatar_template, - gravatar_avatar_upload_id: result.gravatar_upload_id, - })) + .then(result => { + if (!result.gravatar_avatar_upload_id) { + this.set("gravatarFailed", true); + } else { + this.setProperties({ + gravatarFailed: false, + gravatar_avatar_template: result.gravatar_avatar_template, + gravatar_avatar_upload_id: result.gravatar_upload_id, + }); + } + }) .finally(() => this.set("gravatarRefreshDisabled", false)); } } diff --git a/app/assets/javascripts/discourse/templates/modal/avatar-selector.hbs b/app/assets/javascripts/discourse/templates/modal/avatar-selector.hbs index a01f45c76bb..f974216e931 100644 --- a/app/assets/javascripts/discourse/templates/modal/avatar-selector.hbs +++ b/app/assets/javascripts/discourse/templates/modal/avatar-selector.hbs @@ -1,33 +1,34 @@ {{#d-modal-body title="user.change_avatar.title" class="avatar-selector"}} -
-
- {{radio-button id="system-avatar" name="avatar" value="system" selection=selected}} - -
-
- {{radio-button id="gravatar" name="avatar" value="gravatar" selection=selected}} - - {{d-button action="refreshGravatar" title="user.change_avatar.refresh_gravatar_title" disabled=gravatarRefreshDisabled icon="refresh"}} -
- {{#if allowAvatarUpload}} -
- {{radio-button id="uploaded-avatar" name="avatar" value="uploaded" selection=selected}} - - {{avatar-uploader user_id=id - uploadedAvatarTemplate=custom_avatar_template - uploadedAvatarId=custom_avatar_upload_id - uploading=uploading - done="uploadComplete"}} -
+
+ {{radio-button id="system-avatar" name="avatar" value="system" selection=selected}} + +
+
+ {{radio-button id="gravatar" name="avatar" value="gravatar" selection=selected}} + + {{d-button action="refreshGravatar" title="user.change_avatar.refresh_gravatar_title" disabled=gravatarRefreshDisabled icon="refresh"}} + {{#if gravatarFailed}} +

{{I18n 'user.change_avatar.gravatar_failed'}}

{{/if}}
+ {{#if allowAvatarUpload}} +
+ {{radio-button id="uploaded-avatar" name="avatar" value="uploaded" selection=selected}} + + {{avatar-uploader user_id=id + uploadedAvatarTemplate=custom_avatar_template + uploadedAvatarId=custom_avatar_upload_id + uploading=uploading + done="uploadComplete"}} +
+ {{/if}} {{/d-modal-body}}