2015-09-14 20:09:29 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* JavaScript for SOGoAdministration */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
2015-10-06 22:38:16 +02:00
|
|
|
angular.module('SOGo.AdministrationUI', ['ngSanitize', 'ui.router', 'SOGo.Common', 'SOGo.Authentication', 'SOGo.PreferencesUI', 'SOGo.ContactsUI', 'SOGo.SchedulerUI'])
|
2015-09-14 20:09:29 +02:00
|
|
|
.config(configure)
|
|
|
|
.run(runBlock);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
configure.$inject = ['$stateProvider', '$urlRouterProvider'];
|
|
|
|
function configure($stateProvider, $urlRouterProvider) {
|
|
|
|
$stateProvider
|
|
|
|
.state('administration', {
|
|
|
|
abstract: true,
|
|
|
|
views: {
|
|
|
|
administration: {
|
|
|
|
templateUrl: 'administration.html',
|
|
|
|
controller: 'AdministrationController',
|
|
|
|
controllerAs: 'app'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.state('administration.rights', {
|
|
|
|
url: '/rights',
|
|
|
|
views: {
|
|
|
|
module: {
|
|
|
|
templateUrl: 'rights.html'
|
|
|
|
}
|
|
|
|
}
|
2015-10-06 22:38:16 +02:00
|
|
|
})
|
|
|
|
.state('administration.rights.edit', {
|
|
|
|
url: '/:userId/:folderId/edit',
|
|
|
|
views: {
|
|
|
|
acl: {
|
|
|
|
templateUrl: 'UIxAdministrationAclEditor', // UI/Templates/Administration/UIxAdministrationAclEditor.wox
|
|
|
|
controller: 'AdministrationAclController',
|
|
|
|
controllerAs: 'acl'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resolve: {
|
2015-10-09 22:10:39 +02:00
|
|
|
stateUser: stateUser,
|
2015-10-06 22:38:16 +02:00
|
|
|
stateFolder: stateFolder
|
|
|
|
}
|
2015-09-14 20:09:29 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// if none of the above states are matched, use this as the fallback
|
|
|
|
$urlRouterProvider.otherwise('/rights');
|
|
|
|
}
|
2015-10-09 22:10:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateUser.$inject = ['$q', '$stateParams', 'User'];
|
|
|
|
function stateUser($q, $stateParams, User) {
|
|
|
|
var user;
|
|
|
|
|
|
|
|
user = _.find(User.$users, function(user) {
|
2015-10-06 22:38:16 +02:00
|
|
|
return user.uid == $stateParams.userId;
|
|
|
|
});
|
2015-09-14 20:09:29 +02:00
|
|
|
|
2015-10-09 22:10:39 +02:00
|
|
|
if (angular.isUndefined(user)) {
|
|
|
|
return User.$filter($stateParams.userId).then(function(users) {
|
|
|
|
user = _.find(User.$users, function(user) {
|
|
|
|
return user.uid == $stateParams.userId;
|
|
|
|
});
|
|
|
|
if (angular.isUndefined(user)) {
|
|
|
|
return $q.reject('User with ID ' + $stateParams.userId + ' not found');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Resolve folders
|
|
|
|
return user.$folders().then(function() {
|
|
|
|
return user;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return user;
|
|
|
|
});
|
|
|
|
}
|
2015-10-06 22:38:16 +02:00
|
|
|
|
2015-10-09 22:10:39 +02:00
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
|
|
|
stateFolder.$inject = ['$state', '$stateParams', 'decodeUriFilter', 'stateUser', 'AddressBook', 'Calendar'];
|
|
|
|
function stateFolder($state, $stateParams, decodeUriFilter, stateUser, AddressBook, Calendar) {
|
|
|
|
var folder, o,
|
|
|
|
folderId = decodeUriFilter($stateParams.folderId);
|
|
|
|
|
|
|
|
folder = _.find(stateUser.$$folders, function(folder) {
|
|
|
|
return folder.name == folderId;
|
|
|
|
});
|
2015-10-06 22:38:16 +02:00
|
|
|
|
|
|
|
if (folder.type == "Appointment") {
|
2015-10-09 22:10:39 +02:00
|
|
|
o = new Calendar({ id: folder.name.split('/').pop(),
|
|
|
|
owner: folder.owner,
|
|
|
|
name: folder.displayName });
|
2015-10-06 22:38:16 +02:00
|
|
|
} else {
|
2015-10-09 22:10:39 +02:00
|
|
|
o = new AddressBook({ id: folder.name.split('/').pop(),
|
|
|
|
owner: folder.owner,
|
|
|
|
name: folder.displayName });
|
2015-10-06 22:38:16 +02:00
|
|
|
}
|
2015-10-09 22:10:39 +02:00
|
|
|
|
2015-10-13 20:30:09 +02:00
|
|
|
stateUser.selectedFolder = o.id;
|
|
|
|
|
2015-10-06 22:38:16 +02:00
|
|
|
return o;
|
2015-09-14 20:09:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2015-10-09 22:10:39 +02:00
|
|
|
runBlock.$inject = ['$log', '$rootScope', '$state'];
|
|
|
|
function runBlock($log, $rootScope, $state) {
|
|
|
|
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
|
|
|
|
$log.error(error);
|
|
|
|
$state.go('administration.rights');
|
|
|
|
});
|
2015-09-14 20:09:29 +02:00
|
|
|
$rootScope.$on('$routeChangeError', function(event, current, previous, rejection) {
|
2015-10-09 22:10:39 +02:00
|
|
|
$log.error(event, current, previous, rejection);
|
2015-09-14 20:09:29 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|