Continuing with species refactor
This commit is contained in:
parent
622cd0faaf
commit
9aed858982
8 changed files with 99 additions and 60 deletions
|
@ -1,21 +1,30 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
isEditing: true,
|
||||
actions: {
|
||||
save: function() {
|
||||
var species = this.get('model');
|
||||
let species = this.get('species');
|
||||
|
||||
if (species.get('isDirty')) {
|
||||
species.save();
|
||||
species.save().then((species) => {
|
||||
this.transitionToRoute('species.show', species.get('id'));
|
||||
}, (err) => {
|
||||
this.get('flashMessages').error(err.responseJSON.error);
|
||||
});
|
||||
} else {
|
||||
this.transitionToRoute('species.index');
|
||||
}
|
||||
this.transitionToRoute('species.index');
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
var species = this.get('model');
|
||||
let species = this.get('species');
|
||||
|
||||
if (species.get('isNew')) {
|
||||
species.deleteRecord();
|
||||
}
|
||||
|
||||
this.transitionToRoute('species.index');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
});
|
||||
|
|
|
@ -3,11 +3,13 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi
|
|||
|
||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||
model: function() {
|
||||
return this.store.createRecord('species');
|
||||
return Ember.RSVP.hash({
|
||||
species: this.store.createRecord('species'),
|
||||
});
|
||||
},
|
||||
actions: {
|
||||
cancelSpecies: function() {
|
||||
this.transitionTo('species.index');
|
||||
}
|
||||
}
|
||||
|
||||
setupController: function(controller, model) {
|
||||
controller.setProperties(model);
|
||||
},
|
||||
|
||||
});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
{{
|
||||
species-details
|
||||
species=model
|
||||
isEditing=true
|
||||
forms/species-form
|
||||
species=species
|
||||
save="save"
|
||||
cancel="cancel"
|
||||
}}
|
||||
|
|
Reference in a new issue