open-vault/ui/app/mixins/unsaved-model-route.js
Matthew Irish d509588cd2
Ember update (#5386)
Ember update - update ember-cli, ember-data, and ember to 3.4 series
2018-09-25 11:28:26 -05:00

29 lines
732 B
JavaScript

import Mixin from '@ember/object/mixin';
import { get } from '@ember/object';
// this mixin relies on `unload-model-route` also being used
export default Mixin.create({
actions: {
willTransition(transition) {
const model = this.controller.get('model');
if (!model) {
return true;
}
if (get(model, 'hasDirtyAttributes')) {
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;
},
},
});