2013-11-12 19:29:15 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc controller
|
|
|
|
|
* @name Umbraco.MainController
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* The main application controller
|
|
|
|
|
*
|
|
|
|
|
*/
|
2018-02-07 13:44:48 +01:00
|
|
|
function MainController($scope, $rootScope, $location, $routeParams, $timeout, $http, $log, appState, treeService, notificationsService, userService, navigationService, historyService, updateChecker, assetsService, eventsService, umbRequestHelper, tmhDynamicLocale, localStorageService, tourService, editorService) {
|
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-02-07 13:44:48 +01:00
|
|
|
$scope.editors = [];
|
2018-04-05 14:35:47 +02:00
|
|
|
$scope.overlay = {};
|
2018-05-04 00:58:18 +10:00
|
|
|
|
2013-11-12 19:29:15 +01:00
|
|
|
$scope.removeNotification = function (index) {
|
|
|
|
|
notificationsService.remove(index);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.closeDialogs = function (event) {
|
|
|
|
|
//only close dialogs if non-link and non-buttons are clicked
|
|
|
|
|
var el = event.target.nodeName;
|
2016-05-24 16:20:20 +02:00
|
|
|
var els = ["INPUT", "A", "BUTTON"];
|
2013-11-12 19:29:15 +01:00
|
|
|
|
2016-05-24 16:20:20 +02:00
|
|
|
if (els.indexOf(el) >= 0) { return; }
|
2013-11-12 19:29:15 +01:00
|
|
|
|
|
|
|
|
var parents = $(event.target).parents("a,button");
|
2016-05-24 16:20:20 +02:00
|
|
|
if (parents.length > 0) {
|
2013-11-12 19:29:15 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//SD: I've updated this so that we don't close the dialog when clicking inside of the dialog
|
2013-11-16 10:38:14 +01:00
|
|
|
var nav = $(event.target).parents("#dialog");
|
2013-11-12 19:29:15 +01:00
|
|
|
if (nav.length === 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-02 13:51:03 +01:00
|
|
|
eventsService.emit("app.closeDialogs", event);
|
2013-11-12 19:29:15 +01:00
|
|
|
};
|
|
|
|
|
|
2015-05-07 09:11:39 +10:00
|
|
|
var evts = [];
|
|
|
|
|
|
2013-11-12 19:29:15 +01:00
|
|
|
//when a user logs out or timesout
|
2016-05-24 16:20:20 +02:00
|
|
|
evts.push(eventsService.on("app.notAuthenticated", function () {
|
2013-11-12 19:29:15 +01:00
|
|
|
$scope.authenticated = null;
|
|
|
|
|
$scope.user = null;
|
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) {
|
2013-11-12 19:29:15 +01:00
|
|
|
$location.path("/").search("");
|
|
|
|
|
historyService.removeAll();
|
2013-11-13 19:57:34 +11:00
|
|
|
treeService.clearCache();
|
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
|
|
|
}));
|
|
|
|
|
|
2016-05-24 16:20:20 +02:00
|
|
|
evts.push(eventsService.on("app.ysod", function (name, error) {
|
2015-12-10 21:52:57 +01:00
|
|
|
$scope.ysodOverlay = {
|
|
|
|
|
view: "ysod",
|
|
|
|
|
error: error,
|
2016-05-24 16:20:20 +02:00
|
|
|
show: true
|
2015-12-10 21:52:57 +01:00
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
|
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
|
|
|
|
|
$scope.drawer = {};
|
|
|
|
|
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-04-25 17:55:27 +02:00
|
|
|
evts.push(eventsService.on("appState.editors.add", function (name, args) {
|
|
|
|
|
$scope.editors = args.editors;
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
evts.push(eventsService.on("appState.editors.remove", function (name, args) {
|
|
|
|
|
$scope.editors = args.editors;
|
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
|
|
|
|
|
tmhDynamicLocaleProvider.localeLocationPattern('lib/angular/1.1.5/i18n/angular-locale_{{locale}}.js');
|
|
|
|
|
});
|