Create and edit characteristics
This commit is contained in:
parent
fb296340c3
commit
de8ac653f6
14 changed files with 180 additions and 1 deletions
24
app/pods/protected/characteristics/new/controller.js
Normal file
24
app/pods/protected/characteristics/new/controller.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
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 {
|
||||
this.transitionToRoute('protected.characteristics.index');
|
||||
}
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
this.transitionToRoute('protected.characteristics.index');
|
||||
},
|
||||
|
||||
},
|
||||
});
|
26
app/pods/protected/characteristics/new/route.js
Normal file
26
app/pods/protected/characteristics/new/route.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
beforeModel: function(transition) {
|
||||
this._super(transition);
|
||||
if (this.get('session.currentUser.role') === 'R') {
|
||||
this.transitionTo('characteristics.index');
|
||||
}
|
||||
},
|
||||
|
||||
model: function() {
|
||||
return this.store.createRecord('characteristic');
|
||||
},
|
||||
|
||||
actions: {
|
||||
willTransition: function(/*transition*/) {
|
||||
let controller = this.get('controller');
|
||||
let characteristic = controller.get('model');
|
||||
|
||||
if (characteristic.get('isNew')) {
|
||||
characteristic.deleteRecord();
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
});
|
6
app/pods/protected/characteristics/new/template.hbs
Normal file
6
app/pods/protected/characteristics/new/template.hbs
Normal file
|
@ -0,0 +1,6 @@
|
|||
{{
|
||||
protected/characteristics/characteristic-form
|
||||
characteristic=model
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
Reference in a new issue