mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-24 08:09:13 -05:00
FIX: Ember deprecations on user preferences
This commit is contained in:
parent
ea51095ef9
commit
bbef5fb3c7
5 changed files with 63 additions and 62 deletions
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -4,20 +4,20 @@
|
|||
|
||||
<div class="control-group save-button" id='save-button-top'>
|
||||
<div class="controls">
|
||||
{{partial 'user/preferences/saveButton'}}
|
||||
{{partial 'user/preferences/save-button'}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group pref-username">
|
||||
<label class="control-label">{{i18n 'user.username.title'}}</label>
|
||||
<div class="controls">
|
||||
<span class='static'>{{username}}</span>
|
||||
{{#if can_edit_username}}
|
||||
<span class='static'>{{model.username}}</span>
|
||||
{{#if model.can_edit_username}}
|
||||
{{#link-to "preferences.username" class="btn btn-small pad-left no-text"}}<i class="fa fa-pencil"></i>{{/link-to}}
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class='instructions'>
|
||||
{{{i18n 'user.username.short_instructions' username=username}}}
|
||||
{{{i18n 'user.username.short_instructions' username=model.username}}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
<div class="control-group pref-name">
|
||||
<label class="control-label">{{i18n 'user.name.title'}}</label>
|
||||
<div class="controls">
|
||||
{{#if can_edit_name}}
|
||||
{{#if model.can_edit_name}}
|
||||
{{text-field value=newNameInput classNames="input-xxlarge"}}
|
||||
{{else}}
|
||||
<span class='static'>{{name}}</span>
|
||||
|
@ -41,7 +41,7 @@
|
|||
<div class="control-group pref-title">
|
||||
<label class="control-label">{{i18n 'user.title.title'}}</label>
|
||||
<div class="controls">
|
||||
<span class="static">{{title}}</span>
|
||||
<span class="static">{{model.title}}</span>
|
||||
{{#link-to "preferences.badgeTitle" class="btn btn-small pad-left no-text"}}{{fa-icon "pencil"}}{{/link-to}}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -53,7 +53,7 @@
|
|||
{{#if model.email}}
|
||||
<div class="controls">
|
||||
<span class='static'>{{model.email}}</span>
|
||||
{{#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}}
|
||||
</div>
|
||||
|
@ -74,7 +74,7 @@
|
|||
<div class="controls">
|
||||
<a href="#" {{action "changePassword"}} class='btn'>
|
||||
{{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 @@
|
|||
<label class="control-label">{{i18n 'user.change_profile_background.title'}}</label>
|
||||
<div class="controls">
|
||||
{{image-uploader uploadUrl=imageUploadUrl
|
||||
imageUrl=profile_background
|
||||
imageUrl=model.profile_background
|
||||
instantDelete="true"
|
||||
type="profile_background"}}
|
||||
</div>
|
||||
|
@ -118,7 +118,7 @@
|
|||
<label class="control-label">{{i18n 'user.change_card_background.title'}}</label>
|
||||
<div class="controls">
|
||||
{{image-uploader uploadUrl=imageUploadUrl
|
||||
imageUrl=card_background
|
||||
imageUrl=model.card_background
|
||||
instantDelete="true"
|
||||
type="card_background"}}
|
||||
</div>
|
||||
|
@ -132,7 +132,7 @@
|
|||
<div class="control-group pref-locale">
|
||||
<label class="control-label">{{i18n 'user.locale.title'}}</label>
|
||||
<div class="controls">
|
||||
{{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"}}
|
||||
</div>
|
||||
<div class='instructions'>
|
||||
{{i18n 'user.locale.instructions'}}
|
||||
|
@ -143,7 +143,7 @@
|
|||
<div class="control-group pref-bio">
|
||||
<label class="control-label">{{i18n 'user.bio'}}</label>
|
||||
<div class="controls bio-composer">
|
||||
{{pagedown-editor value=bio_raw}}
|
||||
{{pagedown-editor value=model.bio_raw}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -154,22 +154,22 @@
|
|||
<div class="control-group pref-location">
|
||||
<label class="control-label">{{i18n 'user.location'}}</label>
|
||||
<div class="controls">
|
||||
{{input type="text" value=location class="input-xxlarge" id='edit-location'}}
|
||||
{{input type="text" value=model.location class="input-xxlarge" id='edit-location'}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group pref-website">
|
||||
<label class="control-label">{{i18n 'user.website'}}</label>
|
||||
<div class="controls">
|
||||
{{input type="text" value=website class="input-xxlarge"}}
|
||||
{{input type="text" value=model.website class="input-xxlarge"}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group pref-card-badge">
|
||||
<label class="control-label">{{i18n 'user.card_badge.title'}}</label>
|
||||
<div class="controls">
|
||||
{{#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}}
|
||||
</div>
|
||||
|
@ -178,17 +178,17 @@
|
|||
<div class="control-group pref-email-settings">
|
||||
<label class="control-label">{{i18n 'user.email_settings'}}</label>
|
||||
{{#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}}
|
||||
<div class='controls controls-dropdown'>
|
||||
{{combo-box valueAttribute="value" content=digestFrequencies value=digest_after_days}}
|
||||
{{combo-box valueAttribute="value" content=digestFrequencies value=model.digest_after_days}}
|
||||
</div>
|
||||
{{/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}}
|
||||
|
||||
<div class='instructions'>
|
||||
{{i18n 'user.email.frequency' count=siteSettings.email_time_window_mins}}
|
||||
|
@ -200,20 +200,20 @@
|
|||
|
||||
<div class="controls controls-dropdown">
|
||||
<label>{{i18n 'user.new_topic_duration.label'}}</label>
|
||||
{{combo-box valueAttribute="value" content=considerNewTopicOptions value=new_topic_duration_minutes}}
|
||||
{{combo-box valueAttribute="value" content=considerNewTopicOptions value=model.new_topic_duration_minutes}}
|
||||
</div>
|
||||
|
||||
<div class="controls controls-dropdown">
|
||||
<label>{{i18n 'user.auto_track_topics'}}</label>
|
||||
{{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}}
|
||||
</div>
|
||||
|
||||
{{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 @@
|
|||
<label class="control-label">{{i18n 'user.categories_settings'}}</label>
|
||||
<div class="controls category-controls">
|
||||
<label>{{i18n 'user.watched_categories'}}</label>
|
||||
{{category-group categories=watchedCategories blacklist=selectedCategories}}
|
||||
{{category-group categories=model.watchedCategories blacklist=selectedCategories}}
|
||||
</div>
|
||||
<div class="instructions">{{i18n 'user.watched_categories_instructions'}}</div>
|
||||
<div class="controls category-controls">
|
||||
<label>{{i18n 'user.tracked_categories'}}</label>
|
||||
{{category-group categories=trackedCategories blacklist=selectedCategories}}
|
||||
{{category-group categories=model.trackedCategories blacklist=selectedCategories}}
|
||||
</div>
|
||||
<div class="instructions">{{i18n 'user.tracked_categories_instructions'}}</div>
|
||||
<div class="controls category-controls">
|
||||
<label>{{i18n 'user.muted_categories'}}</label>
|
||||
{{category-group categories=mutedCategories blacklist=selectedCategories}}
|
||||
{{category-group categories=model.mutedCategories blacklist=selectedCategories}}
|
||||
</div>
|
||||
<div class="instructions">{{i18n 'user.muted_categories_instructions'}}</div>
|
||||
</div>
|
||||
|
@ -242,17 +242,17 @@
|
|||
<label class="control-label">{{i18n 'user.users'}}</label>
|
||||
<div class="controls category-controls">
|
||||
<label>{{i18n 'user.muted_users'}}</label>
|
||||
{{user-selector excludeCurrentUser=true usernames=muted_usernames class="user-selector"}}
|
||||
{{user-selector excludeCurrentUser=true usernames=model.muted_usernames class="user-selector"}}
|
||||
</div>
|
||||
<div class="instructions">{{i18n 'user.muted_users_instructions'}}</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
{{partial 'user/preferences/saveButton'}}
|
||||
{{partial 'user/preferences/save-button'}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{#if canDeleteAccount}}
|
||||
{{#if model.canDeleteAccount}}
|
||||
<div class="control-group delete-account">
|
||||
<hr/>
|
||||
<div class="controls">
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{{#d-button action="save" disabled=model.isSaving class="btn btn-primary save-user"}}
|
||||
{{saveButtonText}}
|
||||
{{/d-button}}
|
||||
|
||||
{{#if saved}}
|
||||
<span class='saved-user'>{{i18n 'saved'}}</span>
|
||||
{{/if}}
|
|
@ -1,4 +0,0 @@
|
|||
<button {{action "save"}} {{bind-attr disabled="saving"}} class="btn btn-primary save-user">{{saveButtonText}}</button>
|
||||
{{#if saved}}
|
||||
<span class='saved-user'>{{i18n 'saved'}}</span>
|
||||
{{/if}}
|
Loading…
Reference in a new issue