Created
December 11, 2014 15:39
-
-
Save skinofstars/ed227192ff8013019ba7 to your computer and use it in GitHub Desktop.
Ember rollback unsaved changes on navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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