Refactor characteristics/edit
This commit is contained in:
parent
31c4ff4d52
commit
7106696533
5 changed files with 70 additions and 56 deletions
|
@ -1,32 +1,9 @@
|
|||
import Ember from 'ember';
|
||||
import ajaxError from '../../../../utils/ajax-error';
|
||||
import SaveModel from '../../../../mixins/save-model';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
actions: {
|
||||
save: function() {
|
||||
let characteristic = this.get('model');
|
||||
const { Controller } = Ember;
|
||||
|
||||
if (characteristic.get('hasDirtyAttributes')) {
|
||||
characteristic.save().then((characteristic) => {
|
||||
this.transitionToRoute('protected.characteristics.show', characteristic);
|
||||
}, () => {
|
||||
ajaxError(characteristic.get('errors'), this.get('flashMessages'));
|
||||
});
|
||||
} else {
|
||||
characteristic.destroyRecord().then(() => {
|
||||
this.transitionToRoute('protected.characteristics.show', characteristic);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
let characteristic = this.get('model');
|
||||
|
||||
characteristic.get('errors').clear();
|
||||
characteristic.rollbackAttributes();
|
||||
|
||||
this.transitionToRoute('protected.characteristics.show', characteristic);
|
||||
},
|
||||
|
||||
},
|
||||
export default Controller.extend(SaveModel, {
|
||||
// Required for SaveModel mixin
|
||||
fallbackRoute: 'protected.characteristics.show',
|
||||
});
|
||||
|
|
|
@ -1,25 +1,15 @@
|
|||
import Ember from 'ember';
|
||||
import ElevatedAccess from '../../../../mixins/elevated-access';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
currentUser: Ember.inject.service('session-account'),
|
||||
const { Route } = Ember;
|
||||
|
||||
beforeModel: function(transition) {
|
||||
this._super(transition);
|
||||
this.get('currentUser.account').then((user) => {
|
||||
if (user.get('isReader')) {
|
||||
this.transitionTo('protected.characteristics.index');
|
||||
}
|
||||
});
|
||||
},
|
||||
export default Route.extend(ElevatedAccess, {
|
||||
// Required for ElevatedAccess mixin
|
||||
fallbackRouteBefore: 'protected.characteristics.index',
|
||||
fallbackRouteAfter: 'protected.characteristics.show',
|
||||
|
||||
model: function(params) {
|
||||
return this.store.findRecord('characteristic', params.characteristic_id, { reload: true });
|
||||
},
|
||||
|
||||
afterModel: function(model) {
|
||||
if (!model.get('canEdit')) {
|
||||
this.transitionTo('characteristics.show', model.get('id'));
|
||||
}
|
||||
return this.store.findRecord('characteristic', params.characteristic_id);
|
||||
},
|
||||
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{
|
||||
protected/characteristics/characteristic-form
|
||||
characteristic=model
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
on-save=(action "save")
|
||||
on-cancel=(action "cancel")
|
||||
}}
|
||||
|
|
Reference in a new issue