Show validation errors on save

Fixes #17.
This commit is contained in:
Matthew Dillon 2015-10-14 10:27:18 -07:00
parent 007de178d8
commit 8577c38a9f
11 changed files with 40 additions and 29 deletions

View file

@ -1,4 +1,5 @@
import Ember from 'ember';
import ajaxError from '../../../../utils/ajax-error';
export default Ember.Controller.extend({
actions: {
@ -8,8 +9,8 @@ export default Ember.Controller.extend({
if (strain.get('hasDirtyAttributes')) {
strain.save().then((strain) => {
this.transitionToRoute('protected.strains.show', strain);
}, (err) => {
this.get('flashMessages').error(err.responseJSON.error);
}, () => {
ajaxError(strain.get('errors'), this.get('flashMessages'));
});
} else {
strain.deleteRecord();

View file

@ -1,4 +1,5 @@
import Ember from 'ember';
import ajaxError from '../../../../utils/ajax-error';
export default Ember.Controller.extend({
actions: {
@ -8,8 +9,8 @@ export default Ember.Controller.extend({
if (strain.get('hasDirtyAttributes')) {
strain.save().then((strain) => {
this.transitionToRoute('protected.strains.show', strain);
}, (err) => {
this.get('flashMessages').error(err.responseJSON.error);
}, () => {
ajaxError(strain.get('errors'), this.get('flashMessages'));
});
} else {
this.transitionToRoute('protected.strains.index');

View file

@ -1,4 +1,5 @@
import Ember from 'ember';
import ajaxError from '../../../../../utils/ajax-error';
export default Ember.Component.extend({
tagName: 'tr',
@ -22,9 +23,15 @@ export default Ember.Component.extend({
},
save: function() {
this.toggleProperty('isEditing');
if (this.get('rowChanged')) {
this.get('row').save();
this.get('row').save().then(() => {
this.get('flashMessages').clearMessage();
this.toggleProperty('isEditing');
}, () => {
ajaxError(this.get('row.errors'), this.get('flashMessages'));
});
} else {
this.toggleProperty('isEditing');
}
},

View file

@ -3,11 +3,6 @@ import Ember from 'ember';
export default Ember.Component.extend({
actions: {
save: function() {
// Need to override the string id for some reason
// TODO: check this
let strain = this.get('strain');
let id = strain.get('species.id');
strain.set('species.id', +id);
this.sendAction('save');
},