Compare commits

...

4 Commits

Author SHA1 Message Date
Sebastiaan Janssen edb0a5bf00 Merge branch 'temp-v8-UI-infinite-editing-U4-11225' into temp-v8-UI-infinite-editing 2018-05-01 15:21:14 +02:00
Sebastiaan Janssen b3fe484b4e Update wording 2018-05-01 15:20:11 +02:00
Robert 9481a2447b Removing console logs 2018-04-24 15:17:16 +02:00
Robert f2dd63c280 Pop up prompt when the user tries to leave/refresh the page while editing in infinite mode. 2018-04-24 15:09:49 +02:00
2 changed files with 23 additions and 5 deletions
@@ -80,7 +80,8 @@
var service = {
open: open,
close: close
close: close,
getEditors: getEditors
};
return service;
@@ -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;