diff --git a/app/assets/javascripts/discourse/controllers/preferences.js.es6 b/app/assets/javascripts/discourse/controllers/preferences.js.es6 index 7b5810ff3..ecd9033de 100644 --- a/app/assets/javascripts/discourse/controllers/preferences.js.es6 +++ b/app/assets/javascripts/discourse/controllers/preferences.js.es6 @@ -1,5 +1,6 @@ import ObjectController from 'discourse/controllers/object'; import CanCheckEmails from 'discourse/mixins/can-check-emails'; +import { popupAjaxError } from 'discourse/lib/ajax-error'; export default ObjectController.extend(CanCheckEmails, { @@ -10,8 +11,10 @@ export default ObjectController.extend(CanCheckEmails, { editHistoryVisible: Discourse.computed.setting('edit_history_visible_to_public'), selectedCategories: function(){ - return [].concat(this.get("watchedCategories"), this.get("trackedCategories"), this.get("mutedCategories")); - }.property("watchedCategories", "trackedCategories", "mutedCategories"), + return [].concat(this.get("model.watchedCategories"), + this.get("model.trackedCategories"), + this.get("model.mutedCategories")); + }.property("model.watchedCategories", "model.trackedCategories", "model.mutedCategories"), // By default we haven't saved anything saved: false, @@ -21,7 +24,7 @@ export default ObjectController.extend(CanCheckEmails, { userFields: function() { let siteUserFields = this.site.get('user_fields'); if (!Ember.isEmpty(siteUserFields)) { - const userFields = this.get('user_fields'); + const userFields = this.get('model.user_fields'); // Staff can edit fields that are not `editable` if (!this.get('currentUser.staff')) { @@ -32,7 +35,7 @@ export default ObjectController.extend(CanCheckEmails, { return Ember.Object.create({ value, field }); }); } - }.property('user_fields.@each.value'), + }.property('model.user_fields.@each.value'), cannotDeleteAccount: Em.computed.not('can_delete_account'), deleteDisabled: Em.computed.or('saving', 'deleting', 'cannotDeleteAccount'), @@ -84,19 +87,20 @@ export default ObjectController.extend(CanCheckEmails, { { name: I18n.t('user.new_topic_duration.last_here'), value: -2 }], saveButtonText: function() { - return this.get('saving') ? I18n.t('saving') : I18n.t('save'); - }.property('saving'), + return this.get('model.isSaving') ? I18n.t('saving') : I18n.t('save'); + }.property('model.isSaving'), - imageUploadUrl: Discourse.computed.url('username', '/users/%@/preferences/user_image'), + passwordProgress: null, + imageUploadUrl: Discourse.computed.url('model.username', '/users/%@/preferences/user_image'), actions: { save() { const self = this; - this.setProperties({ saving: true, saved: false }); + this.set('saved', false); - const model = this.get('model'), - userFields = this.get('userFields'); + const model = this.get('model'); + const userFields = this.get('userFields'); // Update the user fields if (!Ember.isEmpty(userFields)) { @@ -111,22 +115,12 @@ export default ObjectController.extend(CanCheckEmails, { // Cook the bio for preview model.set('name', this.get('newNameInput')); return model.save().then(function() { - // model was saved - self.set('saving', false); if (Discourse.User.currentProp('id') === model.get('id')) { Discourse.User.currentProp('name', model.get('name')); } - self.set('bio_cooked', Discourse.Markdown.cook(Discourse.Markdown.sanitize(self.get('bio_raw')))); + model.set('bio_cooked', Discourse.Markdown.cook(Discourse.Markdown.sanitize(model.get('bio_raw')))); self.set('saved', true); - }, function(error) { - // model failed to save - self.set('saving', false); - if (error && error.responseText) { - alert($.parseJSON(error.responseText).errors[0]); - } else { - alert(I18n.t('generic_error')); - } - }); + }).catch(popupAjaxError); }, changePassword() { diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6 index d03ca5b00..fea4ec5ca 100644 --- a/app/assets/javascripts/discourse/models/user.js.es6 +++ b/app/assets/javascripts/discourse/models/user.js.es6 @@ -204,6 +204,8 @@ const User = RestModel.extend({ data['edit_history_public'] = this.get('edit_history_public'); } + // TODO: We can remove this when migrated fully to rest model. + this.set('isSaving', true); return Discourse.ajax("/users/" + this.get('username_lower'), { data: data, type: 'PUT' @@ -212,6 +214,8 @@ const User = RestModel.extend({ var userProps = self.getProperties('enable_quoting', 'external_links_in_new_tab', 'dynamic_favicon'); Discourse.User.current().setProperties(userProps); + }).finally(() => { + this.set('isSaving', false); }); }, diff --git a/app/assets/javascripts/discourse/templates/user/preferences.hbs b/app/assets/javascripts/discourse/templates/user/preferences.hbs index 9d653754b..324d977bc 100644 --- a/app/assets/javascripts/discourse/templates/user/preferences.hbs +++ b/app/assets/javascripts/discourse/templates/user/preferences.hbs @@ -4,20 +4,20 @@
- {{partial 'user/preferences/saveButton'}} + {{partial 'user/preferences/save-button'}}
- {{username}} - {{#if can_edit_username}} + {{model.username}} + {{#if model.can_edit_username}} {{#link-to "preferences.username" class="btn btn-small pad-left no-text"}}{{/link-to}} {{/if}}
- {{{i18n 'user.username.short_instructions' username=username}}} + {{{i18n 'user.username.short_instructions' username=model.username}}}
@@ -25,7 +25,7 @@
- {{#if can_edit_name}} + {{#if model.can_edit_name}} {{text-field value=newNameInput classNames="input-xxlarge"}} {{else}} {{name}} @@ -41,7 +41,7 @@
- {{title}} + {{model.title}} {{#link-to "preferences.badgeTitle" class="btn btn-small pad-left no-text"}}{{fa-icon "pencil"}}{{/link-to}}
@@ -53,7 +53,7 @@ {{#if model.email}}
{{model.email}} - {{#if can_edit_email}} + {{#if model.can_edit_email}} {{#link-to "preferences.email" class="btn btn-small pad-left no-text"}}{{fa-icon "pencil"}}{{/link-to}} {{/if}}
@@ -74,7 +74,7 @@
{{fa-icon "envelope"}} - {{#if no_password}} + {{#if model.no_password}} {{i18n 'user.change_password.set_password'}} {{else}} {{i18n 'user.change_password.action'}} @@ -105,7 +105,7 @@
{{image-uploader uploadUrl=imageUploadUrl - imageUrl=profile_background + imageUrl=model.profile_background instantDelete="true" type="profile_background"}}
@@ -118,7 +118,7 @@
{{image-uploader uploadUrl=imageUploadUrl - imageUrl=card_background + imageUrl=model.card_background instantDelete="true" type="card_background"}}
@@ -132,7 +132,7 @@
- {{combo-box valueAttribute="value" content=availableLocales value=locale none="user.locale.default"}} + {{combo-box valueAttribute="value" content=availableLocales value=model.locale none="user.locale.default"}}
{{i18n 'user.locale.instructions'}} @@ -143,7 +143,7 @@
- {{pagedown-editor value=bio_raw}} + {{pagedown-editor value=model.bio_raw}}
@@ -154,22 +154,22 @@
- {{input type="text" value=location class="input-xxlarge" id='edit-location'}} + {{input type="text" value=model.location class="input-xxlarge" id='edit-location'}}
- {{input type="text" value=website class="input-xxlarge"}} + {{input type="text" value=model.website class="input-xxlarge"}}
- {{#if card_image_badge}} - {{icon-or-image card_image_badge}} + {{#if model.card_image_badge}} + {{icon-or-image model.card_image_badge}} {{/if}} {{#link-to "preferences.card-badge" class="btn btn-small pad-left no-text"}}{{fa-icon "pencil"}}{{/link-to}}
@@ -178,17 +178,17 @@
{{#if canReceiveDigest}} - {{preference-checkbox labelKey="user.email_digests.title" checked=email_digests}} - {{#if email_digests}} + {{preference-checkbox labelKey="user.email_digests.title" checked=model.email_digests}} + {{#if model.email_digests}}
- {{combo-box valueAttribute="value" content=digestFrequencies value=digest_after_days}} + {{combo-box valueAttribute="value" content=digestFrequencies value=model.digest_after_days}}
{{/if}} {{/if}} - {{preference-checkbox labelKey="user.email_private_messages" checked=email_private_messages}} - {{preference-checkbox labelKey="user.email_direct" checked=email_direct}} - {{preference-checkbox labelKey="user.mailing_list_mode" checked=mailing_list_mode}} - {{preference-checkbox labelKey="user.email_always" checked=email_always}} + {{preference-checkbox labelKey="user.email_private_messages" checked=model.email_private_messages}} + {{preference-checkbox labelKey="user.email_direct" checked=model.email_direct}} + {{preference-checkbox labelKey="user.mailing_list_mode" checked=model.mailing_list_mode}} + {{preference-checkbox labelKey="user.email_always" checked=model.email_always}}
{{i18n 'user.email.frequency' count=siteSettings.email_time_window_mins}} @@ -200,20 +200,20 @@
- {{combo-box valueAttribute="value" content=considerNewTopicOptions value=new_topic_duration_minutes}} + {{combo-box valueAttribute="value" content=considerNewTopicOptions value=model.new_topic_duration_minutes}}
- {{combo-box valueAttribute="value" content=autoTrackDurations value=auto_track_topics_after_msecs}} + {{combo-box valueAttribute="value" content=autoTrackDurations value=model.auto_track_topics_after_msecs}}
- {{preference-checkbox labelKey="user.external_links_in_new_tab" checked=external_links_in_new_tab}} - {{preference-checkbox labelKey="user.enable_quoting" checked=enable_quoting}} - {{preference-checkbox labelKey="user.dynamic_favicon" checked=dynamic_favicon}} - {{preference-checkbox labelKey="user.disable_jump_reply" checked=disable_jump_reply}} + {{preference-checkbox labelKey="user.external_links_in_new_tab" checked=model.external_links_in_new_tab}} + {{preference-checkbox labelKey="user.enable_quoting" checked=model.enable_quoting}} + {{preference-checkbox labelKey="user.dynamic_favicon" checked=model.dynamic_favicon}} + {{preference-checkbox labelKey="user.disable_jump_reply" checked=model.disable_jump_reply}} {{#unless editHistoryVisible}} - {{preference-checkbox labelKey="user.edit_history_public" checked=edit_history_public}} + {{preference-checkbox labelKey="user.edit_history_public" checked=model.edit_history_public}} {{/unless}} {{plugin-outlet "user_custom_preferences"}} @@ -223,17 +223,17 @@
- {{category-group categories=watchedCategories blacklist=selectedCategories}} + {{category-group categories=model.watchedCategories blacklist=selectedCategories}}
{{i18n 'user.watched_categories_instructions'}}
- {{category-group categories=trackedCategories blacklist=selectedCategories}} + {{category-group categories=model.trackedCategories blacklist=selectedCategories}}
{{i18n 'user.tracked_categories_instructions'}}
- {{category-group categories=mutedCategories blacklist=selectedCategories}} + {{category-group categories=model.mutedCategories blacklist=selectedCategories}}
{{i18n 'user.muted_categories_instructions'}}
@@ -242,17 +242,17 @@
- {{user-selector excludeCurrentUser=true usernames=muted_usernames class="user-selector"}} + {{user-selector excludeCurrentUser=true usernames=model.muted_usernames class="user-selector"}}
{{i18n 'user.muted_users_instructions'}}
- {{partial 'user/preferences/saveButton'}} + {{partial 'user/preferences/save-button'}}
- {{#if canDeleteAccount}} + {{#if model.canDeleteAccount}}