Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Using Ember Data's change tracking to reset the value
Browse files Browse the repository at this point in the history
Closes #9472
- changes according to pr #964 comment
- using Ember Data's change tracking to reset the value
  • Loading branch information
hey24sheep committed Mar 9, 2018
1 parent 120ded4 commit 8b7171a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
20 changes: 12 additions & 8 deletions app/controllers/settings/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export default Controller.extend({
_scratchFacebook: null,
_scratchTwitter: null,

_initialPasswordVal: null,

isDatedPermalinks: computed('settings.permalinks', {
set(key, value) {
this.set('settings.permalinks', value ? '/:year/:month/:day/:slug/' : '/:slug/');
Expand Down Expand Up @@ -105,14 +103,20 @@ export default Controller.extend({
},

toggleIsPrivate(isPrivate) {
this.set('settings.isPrivate', isPrivate);
this.get('settings.errors').remove('password');
let settings = this.get('settings');

settings.set('isPrivate', isPrivate);
settings.get('errors').remove('password');

let changedAttrs = settings.changedAttributes();

// set a new random password when isPrivate is enabled
if (isPrivate && this.get('settings.hasDirtyAttributes')) {
this.get('settings').set('password', randomPassword());
} else {
this.get('settings').set('password', this._initialPasswordVal);
if (isPrivate && changedAttrs.isPrivate) {
settings.set('password', randomPassword());

// reset the password when isPrivate is disabled
} else if (changedAttrs.password) {
settings.set('password', changedAttrs.password[0]);
}
},

Expand Down
1 change: 0 additions & 1 deletion app/routes/settings/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export default AuthenticatedRoute.extend(styleBody, CurrentUserSettings, {
// reset the leave setting transition
controller.set('leaveSettingsTransition', null);
controller.set('availableTimezones', models.availableTimezones);
controller.set('_initialPasswordVal', models.settings.get('password'));
},

actions: {
Expand Down
4 changes: 4 additions & 0 deletions app/services/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@ export default Service.extend(_ProxyMixin, ValidationEngine, {

rollbackAttributes() {
return this.get('content').rollbackAttributes();
},

changedAttributes() {
return this.get('content').changedAttributes();
}
});

0 comments on commit 8b7171a

Please sign in to comment.