2013-11-12 19:29:15 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc controller
|
|
|
|
|
* @name Umbraco.MainController
|
|
|
|
|
* @function
|
|
|
|
|
*
|
|
|
|
|
* @description
|
|
|
|
|
* The main application controller
|
|
|
|
|
*
|
|
|
|
|
*/
|
2014-10-03 13:01:00 +10:00
|
|
|
function MainController($scope, $rootScope, $location, $routeParams, $timeout, $http, $log, appState, treeService, notificationsService, userService, navigationService, historyService, updateChecker, assetsService, eventsService, umbRequestHelper, tmhDynamicLocale) {
|
2013-11-12 19:29:15 +01:00
|
|
|
|
|
|
|
|
//the null is important because we do an explicit bool check on this in the view
|
|
|
|
|
//the avatar is by default the umbraco logo
|
|
|
|
|
$scope.authenticated = null;
|
2015-10-22 18:03:03 +02:00
|
|
|
$scope.avatar = [
|
|
|
|
|
{ value: "assets/img/application/logo.png" },
|
|
|
|
|
{ value: "assets/img/application/logo@2x.png" },
|
|
|
|
|
{ value: "assets/img/application/logo@3x.png" }
|
|
|
|
|
];
|
2013-11-13 16:25:25 +11:00
|
|
|
$scope.touchDevice = appState.getGlobalState("touchDevice");
|
2015-04-01 16:04:19 +11: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;
|
|
|
|
|
var els = ["INPUT","A","BUTTON"];
|
|
|
|
|
|
|
|
|
|
if(els.indexOf(el) >= 0){return;}
|
|
|
|
|
|
|
|
|
|
var parents = $(event.target).parents("a,button");
|
|
|
|
|
if(parents.length > 0){
|
|
|
|
|
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
|
2015-05-07 09:11:39 +10: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
|
|
|
}));
|
2013-11-12 19:29:15 +01:00
|
|
|
|
2013-11-27 17:38:59 +11:00
|
|
|
//when the app is read/user is logged in, setup the data
|
2015-05-07 09:11:39 +10:00
|
|
|
evts.push(eventsService.on("app.ready", function (evt, data) {
|
2013-11-27 17:38:59 +11:00
|
|
|
|
2013-11-12 19:29:15 +01:00
|
|
|
$scope.authenticated = data.authenticated;
|
|
|
|
|
$scope.user = data.user;
|
|
|
|
|
|
|
|
|
|
updateChecker.check().then(function(update){
|
|
|
|
|
if(update && update !== "null"){
|
|
|
|
|
if(update.type !== "None"){
|
|
|
|
|
var notification = {
|
|
|
|
|
headline: "Update available",
|
|
|
|
|
message: "Click to download",
|
|
|
|
|
sticky: true,
|
|
|
|
|
type: "info",
|
|
|
|
|
url: update.url
|
|
|
|
|
};
|
|
|
|
|
notificationsService.add(notification);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-07 09:11:39 +10: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();
|
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-10-16 14:45:49 +02:00
|
|
|
if ($scope.user.emailHash) {
|
|
|
|
|
|
|
|
|
|
//let's attempt to load the avatar, it might not exist or we might not have
|
|
|
|
|
// internet access so we'll detect it first
|
|
|
|
|
$http.get("https://www.gravatar.com/avatar/" + $scope.user.emailHash + ".jpg?s=64&d=404")
|
|
|
|
|
.then(
|
|
|
|
|
function successCallback(response) {
|
|
|
|
|
$("#avatar-img").fadeTo(1000, 0, function () {
|
|
|
|
|
$scope.$apply(function () {
|
|
|
|
|
//this can be null if they time out
|
|
|
|
|
if ($scope.user && $scope.user.emailHash) {
|
2015-10-28 16:56:40 +01:00
|
|
|
var avatarBaseUrl = "https://www.gravatar.com/avatar/",
|
|
|
|
|
hash = $scope.user.emailHash;
|
|
|
|
|
|
|
|
|
|
$scope.avatar = [
|
|
|
|
|
{ value: avatarBaseUrl + hash + ".jpg?s=30&d=mm" },
|
|
|
|
|
{ value: avatarBaseUrl + hash + ".jpg?s=60&d=mm" },
|
|
|
|
|
{ value: avatarBaseUrl + hash + ".jpg?s=90&d=mm" }
|
|
|
|
|
];
|
2015-10-16 14:45:49 +02:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$("#avatar-img").fadeTo(1000, 1);
|
|
|
|
|
});
|
|
|
|
|
}, function errorCallback(response) {
|
|
|
|
|
//cannot load it from the server so we cannot do anything
|
2013-11-12 19:29:15 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-07 09:11:39 +10:00
|
|
|
}));
|
|
|
|
|
|
2015-12-10 21:52:57 +01:00
|
|
|
evts.push(eventsService.on("app.ysod", function(name, error) {
|
|
|
|
|
$scope.ysodOverlay = {
|
|
|
|
|
view: "ysod",
|
|
|
|
|
error: error,
|
|
|
|
|
show: true
|
|
|
|
|
};
|
|
|
|
|
}));
|
|
|
|
|
|
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).
|
|
|
|
|
config(function (tmhDynamicLocaleProvider) {
|
|
|
|
|
//Set url for locale files
|
|
|
|
|
tmhDynamicLocaleProvider.localeLocationPattern('lib/angular/1.1.5/i18n/angular-locale_{{locale}}.js');
|
|
|
|
|
});
|