Create and edit characteristics
This commit is contained in:
parent
fb296340c3
commit
de8ac653f6
14 changed files with 180 additions and 1 deletions
30
app/pods/protected/characteristics/edit/controller.js
Normal file
30
app/pods/protected/characteristics/edit/controller.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
actions: {
|
||||
save: function() {
|
||||
let characteristic = this.get('model');
|
||||
|
||||
if (characteristic.get('hasDirtyAttributes')) {
|
||||
characteristic.save().then((characteristic) => {
|
||||
this.transitionToRoute('protected.characteristics.show', characteristic);
|
||||
}, (err) => {
|
||||
this.get('flashMessages').error(err.responseJSON.error);
|
||||
});
|
||||
} else {
|
||||
characteristic.deleteRecord();
|
||||
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);
|
||||
},
|
||||
|
||||
},
|
||||
});
|
15
app/pods/protected/characteristics/edit/route.js
Normal file
15
app/pods/protected/characteristics/edit/route.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import Ember from 'ember';
|
||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
|
||||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
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'));
|
||||
}
|
||||
},
|
||||
|
||||
});
|
6
app/pods/protected/characteristics/edit/template.hbs
Normal file
6
app/pods/protected/characteristics/edit/template.hbs
Normal file
|
@ -0,0 +1,6 @@
|
|||
{{
|
||||
protected/characteristics/characteristic-form
|
||||
characteristic=model
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
Reference in a new issue