Skip to content

Instantly share code, notes, and snippets.

@bazzel
Created October 28, 2014 13:45
Show Gist options
  • Save bazzel/e5b783357c79c54836fd to your computer and use it in GitHub Desktop.
Save bazzel/e5b783357c79c54836fd to your computer and use it in GitHub Desktop.
import Ember from 'ember';
export default Ember.ObjectController.extend({
isEditing: false,
actions: {
toggleEditing: function() {
this.toggleProperty('isEditing');
this.resetModel();
},
submit: function() {
var _this = this;
this.clearValidationErrors();
this.model.save().then(function() {
_this.set('isEditing', false);
}, function(reason) {
_this.set('validationErrors', reason.errors);
});
},
removeImage: function() {
this.set('image', null);
}
},
clearValidationErrors: function() {
if (!this.model.get('isValid')) {
this.set('validationErrors', null);
this.model.rollback();
}
},
cleanModel: function() {
if (this.model.get('isDirty')) {
this.model.rollback();
}
},
resetModel: function() {
this.clearValidationErrors();
this.cleanModel();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment