[Edit] Add mct-before-unload directive

Add directive for exposing expressions which should be
evaluated for the browser's onbeforeunload event, to
prevent user-initiated navigation from causing a loss
of unsaved changes. WTD-1035.
This commit is contained in:
Victor Woeltjen
2015-03-16 17:28:08 -07:00
parent d86e27504f
commit 783d2f332b
6 changed files with 110 additions and 3 deletions

View File

@ -15,10 +15,12 @@ define(
* @constructor
*/
function EditController($scope, navigationService) {
var navigatedObject;
function setNavigation(domainObject) {
// Wrap the domain object such that all mutation is
// confined to edit mode (until Save)
$scope.navigatedObject =
navigatedObject =
domainObject && new EditableDomainObject(domainObject);
}
@ -27,6 +29,21 @@ define(
$scope.$on("$destroy", function () {
navigationService.removeListener(setNavigation);
});
return {
navigatedObject: function () {
return navigatedObject;
},
getUnloadWarning: function () {
var editorCapability = navigatedObject &&
navigatedObject.getCapability("editor"),
hasChanges = editorCapability && editorCapability.dirty();
return hasChanges ?
"Unsaved changes will be lost if you leave this page." :
undefined;
}
};
}
return EditController;