[Edit Mode] #627 remove edit concerns from browse controller

This commit is contained in:
Henry
2016-01-26 21:47:19 -08:00
parent 494212a448
commit 549dfab5aa
16 changed files with 402 additions and 100 deletions

View File

@@ -35,7 +35,7 @@ define(
* @constructor
* @param $window the window
*/
function MCTBeforeUnload($window) {
function MCTBeforeUnload($window, navigationService) {
var unloads = [],
oldBeforeUnload = $window.onbeforeunload;
@@ -57,6 +57,7 @@ define(
// Stop using this unload expression
function removeUnload() {
navigationService.removeListener(checkNavigationEvent, "before");
unloads = unloads.filter(function (callback) {
return callback !== unload;
});
@@ -65,17 +66,28 @@ define(
}
}
// Show a dialog before allowing a location change
function checkLocationChange(event) {
function shouldAllowNavigation(){
// Get an unload message (if any)
var warning = unload();
// Prompt the user if there's an unload message
if (warning && !$window.confirm(warning)) {
// ...and prevent the route change if it was confirmed
return !warning || $window.confirm(warning);
}
// Show a dialog before allowing a location change
function checkLocationChange(event) {
if (!shouldAllowNavigation()) {
// Prevent the route change if it was confirmed
event.preventDefault();
}
}
// Show a dialog before allowing a location change
function checkNavigationEvent(event) {
// Return a false value to the navigationService to
// indicate that the navigation event should be prevented
return shouldAllowNavigation();
}
// If this is the first active instance of this directive,
// register as the window's beforeunload handler
if (unloads.length === 0) {
@@ -90,6 +102,8 @@ define(
// Also handle route changes
scope.$on("$locationChangeStart", checkLocationChange);
navigationService.addListener(checkNavigationEvent, "before");
}
return {