open-vault/ui/app/mixins/unsaved-model-route.js
Hamid Ghaf 27bb03bbc0
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

33 lines
765 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Mixin from '@ember/object/mixin';
// 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 (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;
},
},
});