Refactoring strains
This commit is contained in:
parent
5290e7efd7
commit
01a3075655
23 changed files with 275 additions and 223 deletions
|
@ -1,21 +1,30 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
isEditing: true,
|
||||
actions: {
|
||||
save: function() {
|
||||
var strain = this.get('strain');
|
||||
let strain = this.get('strain');
|
||||
|
||||
if (strain.get('isDirty')) {
|
||||
strain.save();
|
||||
strain.save().then((strain) => {
|
||||
this.transitionToRoute('strains.show', strain);
|
||||
}, (err) => {
|
||||
this.get('flashMessages').error(err.responseJSON.error);
|
||||
});
|
||||
} else {
|
||||
this.transitionToRoute('strains.index');
|
||||
}
|
||||
this.transitionToRoute('strains.index');
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
var strain = this.get('strain');
|
||||
let strain = this.get('strain');
|
||||
|
||||
if (strain.get('isNew')) {
|
||||
strain.deleteRecord();
|
||||
}
|
||||
|
||||
this.transitionToRoute('strains.index');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
});
|
||||
|
|
|
@ -5,10 +5,12 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
|||
model: function() {
|
||||
return Ember.RSVP.hash({
|
||||
strain: this.store.createRecord('strain'),
|
||||
species: this.store.findAll('species')
|
||||
species: this.store.findAll('species'),
|
||||
});
|
||||
},
|
||||
|
||||
setupController: function(controller, models) {
|
||||
controller.setProperties(models);
|
||||
},
|
||||
|
||||
});
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
{{
|
||||
strain-details
|
||||
forms/strain-form
|
||||
strain=strain
|
||||
species=species
|
||||
isEditing=true
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
||||
|
|
Reference in a new issue