diff --git a/app/assets/javascripts/discourse/controllers/preferences/account.js.es6 b/app/assets/javascripts/discourse/controllers/preferences/account.js.es6 index c0a7fc4feb0..ac56e0ec377 100644 --- a/app/assets/javascripts/discourse/controllers/preferences/account.js.es6 +++ b/app/assets/javascripts/discourse/controllers/preferences/account.js.es6 @@ -2,7 +2,7 @@ import { iconHTML } from "discourse-common/lib/icon-library"; import CanCheckEmails from "discourse/mixins/can-check-emails"; import { default as computed } from "ember-addons/ember-computed-decorators"; import PreferencesTabController from "discourse/mixins/preferences-tab-controller"; -import { setting } from "discourse/lib/computed"; +import { propertyNotEqual, setting } from "discourse/lib/computed"; import { popupAjaxError } from "discourse/lib/ajax-error"; import showModal from "discourse/lib/show-modal"; import { findAll } from "discourse/models/login-method"; @@ -40,9 +40,7 @@ export default Ember.Controller.extend( ), reset() { - this.setProperties({ - passwordProgress: null - }); + this.set("passwordProgress", null); }, @computed() @@ -54,10 +52,7 @@ export default Ember.Controller.extend( ); }, - @computed("model.availableTitles") - canSelectTitle(availableTitles) { - return availableTitles.length > 0; - }, + canSelectTitle: Ember.computed.gt("model.availableTitles.length", 0), @computed("model.is_anonymous") canChangePassword(isAnonymous) { @@ -86,15 +81,10 @@ export default Ember.Controller.extend( }; }); - return result.filter(value => { - return value.account || value.method.get("can_connect"); - }); + return result.filter(value => value.account || value.method.can_connect); }, - @computed("model.id") - disableConnectButtons(userId) { - return userId !== this.get("currentUser.id"); - }, + disableConnectButtons: propertyNotEqual("model.id", "currentUser.id"), @computed( "model.second_factor_enabled", @@ -129,25 +119,23 @@ export default Ember.Controller.extend( : tokens.slice(0, DEFAULT_AUTH_TOKENS_COUNT); }, - @computed("model.user_auth_tokens") - canShowAllAuthTokens(tokens) { - return tokens.length > DEFAULT_AUTH_TOKENS_COUNT; - }, + canShowAllAuthTokens: Ember.computed.gt( + "model.user_auth_tokens.length", + DEFAULT_AUTH_TOKENS_COUNT + ), actions: { save() { this.set("saved", false); - const model = this.model; + this.model.setProperties({ + name: this.newNameInput, + title: this.newTitleInput + }); - model.set("name", this.newNameInput); - model.set("title", this.newTitleInput); - - return model + return this.model .save(this.saveAttrNames) - .then(() => { - this.set("saved", true); - }) + .then(() => this.set("saved", true)) .catch(popupAjaxError); }, @@ -178,17 +166,14 @@ export default Ember.Controller.extend( delete() { this.set("deleting", true); - const self = this, - message = I18n.t("user.delete_account_confirm"), + const message = I18n.t("user.delete_account_confirm"), model = this.model, buttons = [ { label: I18n.t("cancel"), class: "d-modal-cancel", link: true, - callback: () => { - this.set("deleting", false); - } + callback: () => this.set("deleting", false) }, { label: @@ -197,14 +182,15 @@ export default Ember.Controller.extend( class: "btn btn-danger", callback() { model.delete().then( - function() { - bootbox.alert(I18n.t("user.deleted_yourself"), function() { - window.location.pathname = Discourse.getURL("/"); - }); + () => { + bootbox.alert( + I18n.t("user.deleted_yourself"), + () => (window.location.pathname = Discourse.getURL("/")) + ); }, - function() { + () => { bootbox.alert(I18n.t("user.delete_yourself_not_allowed")); - self.set("deleting", false); + this.set("deleting", false); } ); } @@ -214,25 +200,23 @@ export default Ember.Controller.extend( }, revokeAccount(account) { - const model = this.model; this.set("revoking", true); - model + + this.model .revokeAssociatedAccount(account.name) .then(result => { if (result.success) { - model.get("associated_accounts").removeObject(account); + this.model.associated_accounts.removeObject(account); } else { bootbox.alert(result.message); } }) .catch(popupAjaxError) - .finally(() => { - this.set("revoking", false); - }); + .finally(() => this.set("revoking", false)); }, toggleShowAllAuthTokens() { - this.set("showAllAuthTokens", !this.showAllAuthTokens); + this.toggleProperty("showAllAuthTokens"); }, revokeAuthToken(token) {