diff --git a/src/Umbraco.Web.UI.Client/src/common/services/editor.service.js b/src/Umbraco.Web.UI.Client/src/common/services/editor.service.js index cb6974e7f8..42f3d7b22b 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/editor.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/editor.service.js @@ -80,7 +80,8 @@ var service = { open: open, - close: close + close: close, + getEditors: getEditors }; return service; diff --git a/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js b/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js index 77a233c3e8..25d6719f6d 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js @@ -8,7 +8,9 @@ * The main application controller * */ -function MainController($scope, $rootScope, $location, $routeParams, $timeout, $http, $log, appState, treeService, notificationsService, userService, navigationService, historyService, updateChecker, assetsService, eventsService, umbRequestHelper, tmhDynamicLocale, localStorageService, tourService, editorService) { +function MainController($scope, $rootScope, $location, $routeParams, $timeout, $http, $log, $window, + appState, treeService, notificationsService, userService, navigationService, historyService, + updateChecker, assetsService, eventsService, umbRequestHelper, tmhDynamicLocale, localStorageService, tourService, editorService) { //the null is important because we do an explicit bool check on this in the view $scope.authenticated = null; @@ -20,6 +22,21 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $ notificationsService.remove(index); }; + //listening for unload event to warn users of unsaved changes in case they refresh/leave the page while + //editing in infinite mode + $window.onbeforeunload = function (event) { + var editorsOpen = editorService.getEditors(); + + //most browser stopped supporting custom messages for the pop up window, but I guess is a good + //idea to return one just in case some browser still support it + var message = "You have " + + editorsOpen.length + + " editors open which might have unsaved changes, are you sure you want to leave/refresh the page?"; + + //returning null or undefined will skip the pop up and procede to refresh/leave the page. + return editorsOpen.length > 0 ? message : null; + }; + $scope.closeDialogs = function (event) { //only close dialogs if non-link and non-buttons are clicked var el = event.target.nodeName; @@ -49,8 +66,8 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $ $scope.user = null; })); - evts.push(eventsService.on("app.userRefresh", function(evt) { - userService.refreshCurrentUser().then(function(data) { + evts.push(eventsService.on("app.userRefresh", function (evt) { + userService.refreshCurrentUser().then(function (data) { $scope.user = data; //Load locale file @@ -134,7 +151,7 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $ evts.push(eventsService.on("appState.overlay", function (name, args) { $scope.overlay = args; })); - + // events for tours evts.push(eventsService.on("appState.tour.start", function (name, args) { $scope.tour = args;