Skip to content

Instantly share code, notes, and snippets.

@skinofstars
Created December 11, 2014 15:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skinofstars/ed227192ff8013019ba7 to your computer and use it in GitHub Desktop.
Save skinofstars/ed227192ff8013019ba7 to your computer and use it in GitHub Desktop.
Ember rollback unsaved changes on navigation
// Extend from this for a user to get a notification for unsaved model changes
// and rollback the model if they choose to navigate away.
Ember.DSModelRoute = Ember.Route.extend({
deactivate: function() {
var model = this.get('controller.model');
model.rollback();
if (model.get('isNew')) {
model.deleteRecord();
}
},
actions: {
willTransition: function(transition) {
var model = this.get('controller.model');
if (model.get('isDirty') && !confirm('You have unsaved changes. They will be lost if you continue.')) {
transition.abort();
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment