2018-09-25 16:28:26 +00:00
|
|
|
import Mixin from '@ember/object/mixin';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
// this mixin relies on `unload-model-route` also being used
|
2018-09-25 16:28:26 +00:00
|
|
|
export default Mixin.create({
|
2018-04-03 14:16:57 +00:00
|
|
|
actions: {
|
|
|
|
willTransition(transition) {
|
|
|
|
const model = this.controller.get('model');
|
|
|
|
if (!model) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-04-26 16:23:57 +00:00
|
|
|
if (model.hasDirtyAttributes) {
|
2018-04-03 14:16:57 +00:00
|
|
|
if (
|
|
|
|
window.confirm(
|
|
|
|
'You have unsaved changes. Navigating away will discard these changes. Are you sure you want to discard your changes?'
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
this.unloadModel();
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
transition.abort();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|