2013-11-12 19:29:15 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc controller
|
|
|
|
|
* @name Umbraco.MainController
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* The main application controller
|
|
|
|
|
*
|
|
|
|
|
*/
|
2019-05-07 10:46:52 +02:00
|
|
|
function MainController($scope, $location, appState, treeService, notificationsService,
|
2019-07-02 13:37:40 +10:00
|
|
|
userService, historyService, updateChecker, navigationService, eventsService,
|
|
|
|
|
tmhDynamicLocale, localStorageService, editorService, overlayService) {
|
2013-11-12 19:29:15 +01:00
|
|
|
|
|
|
|
|
//the null is important because we do an explicit bool check on this in the view
|
|
|
|
|
$scope.authenticated = null;
|
2013-11-13 16:25:25 +11:00
|
|
|
$scope.touchDevice = appState.getGlobalState("touchDevice");
|
2018-11-28 10:13:48 +01:00
|
|
|
$scope.infiniteMode = false;
|
2018-04-05 14:35:47 +02:00
|
|
|
$scope.overlay = {};
|
2018-09-19 15:13:55 +02:00
|
|
|
$scope.drawer = {};
|
|
|
|
|
$scope.search = {};
|
2018-11-09 09:59:36 +01:00
|
|
|
$scope.login = {};
|
2019-04-20 20:05:18 +01:00
|
|
|
$scope.tabbingActive = false;
|
2018-05-04 00:58:18 +10:00
|
|
|
|
2019-04-20 20:05:18 +01:00
|
|
|
// There are a number of ways to detect when a focus state should be shown when using the tab key and this seems to be the simplest solution.
|
|
|
|
|
// For more information about this approach, see https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
|
|
|
|
|
function handleFirstTab(evt) {
|
|
|
|
|
if (evt.keyCode === 9) {
|
|
|
|
|
$scope.tabbingActive = true;
|
2019-05-02 10:54:59 +02:00
|
|
|
$scope.$digest();
|
2019-04-20 20:05:18 +01:00
|
|
|
window.removeEventListener('keydown', handleFirstTab);
|
2019-04-24 15:56:37 +02:00
|
|
|
window.addEventListener('mousedown', disableTabbingActive);
|
2019-04-20 20:05:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-24 15:56:37 +02:00
|
|
|
|
|
|
|
|
function disableTabbingActive(evt) {
|
|
|
|
|
$scope.tabbingActive = false;
|
2019-05-02 10:54:59 +02:00
|
|
|
$scope.$digest();
|
2019-04-24 15:56:37 +02:00
|
|
|
window.removeEventListener('mousedown', disableTabbingActive);
|
|
|
|
|
window.addEventListener("keydown", handleFirstTab);
|
|
|
|
|
}
|
2019-04-20 20:05:18 +01:00
|
|
|
|
|
|
|
|
window.addEventListener("keydown", handleFirstTab);
|
|
|
|
|
|
|
|
|
|
|
2013-11-12 19:29:15 +01:00
|
|
|
$scope.removeNotification = function (index) {
|
|
|
|
|
notificationsService.remove(index);
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-19 16:01:12 +02:00
|
|
|
$scope.closeSearch = function() {
|
|
|
|
|
appState.setSearchState("show", false);
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-13 10:41:09 +01:00
|
|
|
$scope.showLoginScreen = function(isTimedOut) {
|
|
|
|
|
$scope.login.isTimedOut = isTimedOut;
|
|
|
|
|
$scope.login.show = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.hideLoginScreen = function() {
|
|
|
|
|
$scope.login.show = false;
|
|
|
|
|
};
|
|
|
|
|
|
2015-05-07 09:11:39 +10:00
|
|
|
var evts = [];
|
2018-11-09 09:59:36 +01:00
|
|
|
|
2013-11-12 19:29:15 +01:00
|
|
|
//when a user logs out or timesout
|
2018-11-09 09:59:36 +01:00
|
|
|
evts.push(eventsService.on("app.notAuthenticated", function (evt, data) {
|
2013-11-12 19:29:15 +01:00
|
|
|
$scope.authenticated = null;
|
|
|
|
|
$scope.user = null;
|
2018-11-13 10:41:09 +01:00
|
|
|
const isTimedOut = data && data.isTimedOut ? true : false;
|
|
|
|
|
$scope.showLoginScreen(isTimedOut);
|
2015-05-07 09:11:39 +10:00
|
|
|
}));
|
2016-05-24 16:20:20 +02:00
|
|
|
|
2017-07-25 20:51:58 +10:00
|
|
|
evts.push(eventsService.on("app.userRefresh", function(evt) {
|
|
|
|
|
userService.refreshCurrentUser().then(function(data) {
|
|
|
|
|
$scope.user = data;
|
|
|
|
|
|
|
|
|
|
//Load locale file
|
|
|
|
|
if ($scope.user.locale) {
|
|
|
|
|
tmhDynamicLocale.set($scope.user.locale);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
//when the app is ready/user is logged in, setup the data
|
2015-05-07 09:11:39 +10:00
|
|
|
evts.push(eventsService.on("app.ready", function (evt, data) {
|
2016-05-24 16:20:20 +02:00
|
|
|
|
2013-11-12 19:29:15 +01:00
|
|
|
$scope.authenticated = data.authenticated;
|
|
|
|
|
$scope.user = data.user;
|
|
|
|
|
|
2017-05-26 02:15:37 +10:00
|
|
|
updateChecker.check().then(function (update) {
|
2016-05-24 16:20:20 +02:00
|
|
|
if (update && update !== "null") {
|
|
|
|
|
if (update.type !== "None") {
|
2013-11-12 19:29:15 +01:00
|
|
|
var notification = {
|
2016-05-24 16:20:20 +02:00
|
|
|
headline: "Update available",
|
|
|
|
|
message: "Click to download",
|
|
|
|
|
sticky: true,
|
|
|
|
|
type: "info",
|
|
|
|
|
url: update.url
|
2013-11-12 19:29:15 +01:00
|
|
|
};
|
|
|
|
|
notificationsService.add(notification);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-05-24 16:20:20 +02:00
|
|
|
});
|
2013-11-12 19:29:15 +01:00
|
|
|
|
|
|
|
|
//if the user has changed we need to redirect to the root so they don't try to continue editing the
|
2013-11-13 20:35:53 +11:00
|
|
|
//last item in the URL (NOTE: the user id can equal zero, so we cannot just do !data.lastUserId since that will resolve to true)
|
2013-11-13 20:14:33 +11:00
|
|
|
if (data.lastUserId !== undefined && data.lastUserId !== null && data.lastUserId !== data.user.id) {
|
2019-07-02 13:37:40 +10:00
|
|
|
|
|
|
|
|
var section = appState.getSectionState("currentSection");
|
|
|
|
|
if (section) {
|
|
|
|
|
//if there's a section already assigned, reload it so the tree is cleared
|
|
|
|
|
navigationService.reloadSection(section);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-12 19:29:15 +01:00
|
|
|
$location.path("/").search("");
|
|
|
|
|
historyService.removeAll();
|
2013-11-13 19:57:34 +11:00
|
|
|
treeService.clearCache();
|
2018-08-24 21:06:48 +02:00
|
|
|
editorService.closeAll();
|
|
|
|
|
overlayService.close();
|
2017-01-31 15:40:02 +11:00
|
|
|
|
|
|
|
|
//if the user changed, clearout local storage too - could contain sensitive data
|
|
|
|
|
localStorageService.clearAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if this is a new login (i.e. the user entered credentials), then clear out local storage - could contain sensitive data
|
2017-05-26 02:15:37 +10:00
|
|
|
if (data.loginType === "credentials") {
|
2017-01-31 15:40:02 +11:00
|
|
|
localStorageService.clearAll();
|
2013-11-12 19:29:15 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-03 13:01:00 +10:00
|
|
|
//Load locale file
|
|
|
|
|
if ($scope.user.locale) {
|
|
|
|
|
tmhDynamicLocale.set($scope.user.locale);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-07 09:11:39 +10:00
|
|
|
}));
|
|
|
|
|
|
2018-09-19 15:13:55 +02:00
|
|
|
// events for search
|
|
|
|
|
evts.push(eventsService.on("appState.searchState.changed", function (e, args) {
|
|
|
|
|
if (args.key === "show") {
|
|
|
|
|
$scope.search.show = args.value;
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
|
2018-04-05 14:35:47 +02:00
|
|
|
// events for drawer
|
2017-09-20 15:46:33 +02:00
|
|
|
// manage the help dialog by subscribing to the showHelp appState
|
|
|
|
|
evts.push(eventsService.on("appState.drawerState.changed", function (e, args) {
|
|
|
|
|
// set view
|
|
|
|
|
if (args.key === "view") {
|
|
|
|
|
$scope.drawer.view = args.value;
|
|
|
|
|
}
|
|
|
|
|
// set custom model
|
|
|
|
|
if (args.key === "model") {
|
|
|
|
|
$scope.drawer.model = args.value;
|
|
|
|
|
}
|
|
|
|
|
// show / hide drawer
|
|
|
|
|
if (args.key === "showDrawer") {
|
|
|
|
|
$scope.drawer.show = args.value;
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
|
2018-04-05 14:35:47 +02:00
|
|
|
// events for overlays
|
|
|
|
|
evts.push(eventsService.on("appState.overlay", function (name, args) {
|
|
|
|
|
$scope.overlay = args;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// events for tours
|
2017-10-16 13:52:34 +02:00
|
|
|
evts.push(eventsService.on("appState.tour.start", function (name, args) {
|
2017-10-13 12:29:44 +02:00
|
|
|
$scope.tour = args;
|
|
|
|
|
$scope.tour.show = true;
|
2017-10-04 09:19:33 +02:00
|
|
|
}));
|
|
|
|
|
|
2017-10-16 13:52:34 +02:00
|
|
|
evts.push(eventsService.on("appState.tour.end", function () {
|
2017-10-13 12:29:44 +02:00
|
|
|
$scope.tour = null;
|
2017-10-04 09:19:33 +02:00
|
|
|
}));
|
|
|
|
|
|
2017-10-16 13:52:34 +02:00
|
|
|
evts.push(eventsService.on("appState.tour.complete", function () {
|
|
|
|
|
$scope.tour = null;
|
|
|
|
|
}));
|
|
|
|
|
|
2018-04-05 14:35:47 +02:00
|
|
|
// events for backdrop
|
2017-10-09 10:19:49 +02:00
|
|
|
evts.push(eventsService.on("appState.backdrop", function (name, args) {
|
|
|
|
|
$scope.backdrop = args;
|
|
|
|
|
}));
|
|
|
|
|
|
2018-09-19 15:13:55 +02:00
|
|
|
// event for infinite editors
|
2018-11-28 10:13:48 +01:00
|
|
|
evts.push(eventsService.on("appState.editors.open", function (name, args) {
|
|
|
|
|
$scope.infiniteMode = args && args.editors.length > 0 ? true : false;
|
2018-04-25 17:55:27 +02:00
|
|
|
}));
|
|
|
|
|
|
2018-11-28 10:13:48 +01:00
|
|
|
evts.push(eventsService.on("appState.editors.close", function (name, args) {
|
|
|
|
|
$scope.infiniteMode = args && args.editors.length > 0 ? true : false;
|
2018-02-07 13:44:48 +01:00
|
|
|
}));
|
|
|
|
|
|
2015-05-07 09:11:39 +10:00
|
|
|
//ensure to unregister from all events!
|
|
|
|
|
$scope.$on('$destroy', function () {
|
|
|
|
|
for (var e in evts) {
|
|
|
|
|
eventsService.unsubscribe(evts[e]);
|
|
|
|
|
}
|
2013-11-12 19:29:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//register it
|
2014-10-03 13:01:00 +10:00
|
|
|
angular.module('umbraco').controller("Umbraco.MainController", MainController).
|
2017-05-26 02:15:37 +10:00
|
|
|
config(function (tmhDynamicLocaleProvider) {
|
|
|
|
|
//Set url for locale files
|
2018-06-15 11:42:43 +10:00
|
|
|
tmhDynamicLocaleProvider.localeLocationPattern('lib/angular-i18n/angular-locale_{{locale}}.js');
|
2017-05-26 02:15:37 +10:00
|
|
|
});
|