From f2dd63c280fc086594973fe8d08e3ce2aee0a2c0 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 24 Apr 2018 15:09:49 +0200 Subject: [PATCH 1/3] Pop up prompt when the user tries to leave/refresh the page while editing in infinite mode. --- .../src/common/services/editor.service.js | 3 ++- .../src/controllers/main.controller.js | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) 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..cbbb365001 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,22 @@ 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 http://issues.umbraco.org/issue/U4-11225 + $window.onbeforeunload = function (event) { + var editorsOpen = editorService.getEditors(); + console.log(editorsOpen.length, editorsOpen); + + //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 + + " open which might have unsaved changes, are you sure you want to leave/refresh the page?"; + + //returning null or undefine 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 +67,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 +152,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; From 9481a2447bdfde5d20163133277028dad6611084 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 24 Apr 2018 15:17:16 +0200 Subject: [PATCH 2/3] Removing console logs --- src/Umbraco.Web.UI.Client/src/controllers/main.controller.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 cbbb365001..f748a495a1 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js @@ -23,10 +23,9 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $ }; //listening for unload event to warn users of unsaved changes in case they refresh/leave the page while - //editing in infinite mode http://issues.umbraco.org/issue/U4-11225 + //editing in infinite mode $window.onbeforeunload = function (event) { var editorsOpen = editorService.getEditors(); - console.log(editorsOpen.length, editorsOpen); //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 From b3fe484b4ec56941fb83ca0d9b18e05ad4542cc8 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Tue, 1 May 2018 15:20:11 +0200 Subject: [PATCH 3/3] Update wording --- src/Umbraco.Web.UI.Client/src/controllers/main.controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f748a495a1..25d6719f6d 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/main.controller.js @@ -31,9 +31,9 @@ function MainController($scope, $rootScope, $location, $routeParams, $timeout, $ //idea to return one just in case some browser still support it var message = "You have " + editorsOpen.length + - " open which might have unsaved changes, are you sure you want to leave/refresh the page?"; + " editors open which might have unsaved changes, are you sure you want to leave/refresh the page?"; - //returning null or undefine will skip the pop up and procede to refresh/leave the page. + //returning null or undefined will skip the pop up and procede to refresh/leave the page. return editorsOpen.length > 0 ? message : null; };