diff --git a/app/pods/application/adapter.js b/app/pods/application/adapter.js
index c4b405b..bb89c25 100644
--- a/app/pods/application/adapter.js
+++ b/app/pods/application/adapter.js
@@ -25,11 +25,6 @@ export default DS.RESTAdapter.extend({
});
}
return new DS.InvalidError(errors);
- } else if (jqXHR && jqXHR.status === 500) {
- var response = Ember.$.parseJSON(jqXHR.responseText);
- if (response.error !== undefined) {
- return new DS.InvalidError(response.error);
- }
} else {
return error;
}
diff --git a/app/pods/components/forms/species-form/component.js b/app/pods/components/forms/species-form/component.js
new file mode 100644
index 0000000..0e5912c
--- /dev/null
+++ b/app/pods/components/forms/species-form/component.js
@@ -0,0 +1,12 @@
+import Ember from 'ember';
+
+export default Ember.Component.extend({
+ actions: {
+ save: function() {
+ this.sendAction('save');
+ },
+ cancel: function() {
+ this.sendAction('cancel');
+ },
+ }
+});
diff --git a/app/pods/components/forms/species-form/template.hbs b/app/pods/components/forms/species-form/template.hbs
new file mode 100644
index 0000000..fda54bc
--- /dev/null
+++ b/app/pods/components/forms/species-form/template.hbs
@@ -0,0 +1,42 @@
+
+
+{{#if species.isDirty}}
+
+ Save
+
+{{/if}}
+
+ Cancel
+
diff --git a/app/pods/species/edit/controller.js b/app/pods/species/edit/controller.js
index d0925e2..ca6b05f 100644
--- a/app/pods/species/edit/controller.js
+++ b/app/pods/species/edit/controller.js
@@ -4,15 +4,26 @@ export default Ember.Controller.extend({
actions: {
save: function() {
let species = this.get('species');
+
if (species.get('isDirty')) {
species.save().then((species) => {
this.transitionToRoute('species.show', species.get('id'));
}, (err) => {
- this.get('flashMessages').error(err.message);
+ this.get('flashMessages').error(err.responseJSON.error);
});
} else {
this.transitionToRoute('species.show', species.get('id'));
}
},
- }
+
+ cancel: function() {
+ let species = this.get('species');
+
+ species.get('errors').clear();
+ species.rollback();
+
+ this.transitionToRoute('species.show', species.get('id'));
+ },
+
+ },
});
diff --git a/app/pods/species/edit/template.hbs b/app/pods/species/edit/template.hbs
index 39d135d..6a8db9b 100644
--- a/app/pods/species/edit/template.hbs
+++ b/app/pods/species/edit/template.hbs
@@ -1,37 +1,6 @@
-
-
-
- Save
-
+{{
+ forms/species-form
+ species=species
+ save="save"
+ cancel="cancel"
+}}
diff --git a/app/pods/species/new/controller.js b/app/pods/species/new/controller.js
index a289976..2781a83 100644
--- a/app/pods/species/new/controller.js
+++ b/app/pods/species/new/controller.js
@@ -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');
- }
- }
+ },
+
+ },
});
diff --git a/app/pods/species/new/route.js b/app/pods/species/new/route.js
index b9f79eb..e816ab5 100644
--- a/app/pods/species/new/route.js
+++ b/app/pods/species/new/route.js
@@ -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);
+ },
+
});
diff --git a/app/pods/species/new/template.hbs b/app/pods/species/new/template.hbs
index f38417f..6a8db9b 100644
--- a/app/pods/species/new/template.hbs
+++ b/app/pods/species/new/template.hbs
@@ -1,7 +1,6 @@
{{
- species-details
- species=model
- isEditing=true
+ forms/species-form
+ species=species
save="save"
cancel="cancel"
}}