2015-07-28 16:53:29 +02:00
|
|
|
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ngInject
|
|
|
|
*/
|
2017-12-18 21:31:43 +01:00
|
|
|
AclController.$inject = ['$document', '$timeout', '$mdDialog', 'Dialog', 'usersWithACL', 'User', 'folder'];
|
|
|
|
function AclController($document, $timeout, $mdDialog, Dialog, usersWithACL, User, folder) {
|
2015-07-28 16:53:29 +02:00
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
vm.users = usersWithACL; // ACL users
|
|
|
|
vm.folder = folder;
|
|
|
|
vm.selectedUser = null;
|
2015-10-09 22:49:08 +02:00
|
|
|
vm.selectedUid = null;
|
2015-07-28 16:53:29 +02:00
|
|
|
vm.userToAdd = '';
|
|
|
|
vm.searchText = '';
|
2017-12-19 15:53:48 +01:00
|
|
|
vm.folderClassName = folderClassName;
|
2017-12-18 21:31:43 +01:00
|
|
|
vm.templateName = templateName;
|
2015-07-28 16:53:29 +02:00
|
|
|
vm.userFilter = userFilter;
|
|
|
|
vm.closeModal = closeModal;
|
|
|
|
vm.saveModal = saveModal;
|
|
|
|
vm.confirmChange = confirmChange;
|
|
|
|
vm.removeUser = removeUser;
|
|
|
|
vm.addUser = addUser;
|
2016-06-20 22:10:52 +02:00
|
|
|
vm.selectAllRights = selectAllRights;
|
2015-07-28 16:53:29 +02:00
|
|
|
vm.selectUser = selectUser;
|
2017-01-26 18:48:21 +01:00
|
|
|
vm.showRights = showRights;
|
2015-08-06 02:23:11 +02:00
|
|
|
vm.confirmation = { showing: false,
|
|
|
|
message: ''};
|
2015-07-28 16:53:29 +02:00
|
|
|
|
2017-12-19 15:53:48 +01:00
|
|
|
function folderClassName() {
|
|
|
|
if (angular.isFunction(folder.getClassName))
|
|
|
|
return folder.getClassName('bg');
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-18 21:31:43 +01:00
|
|
|
function templateName(user) {
|
|
|
|
// Check if user is anonymous and if a specific template must be used
|
|
|
|
var isAnonymous = $document[0].getElementById('UIxAnonymousUserRightsEditor') && user.$isAnonymous();
|
|
|
|
return 'UIx' + (isAnonymous? 'Anonymous' : '') + 'UserRightsEditor';
|
|
|
|
}
|
|
|
|
|
2015-07-28 16:53:29 +02:00
|
|
|
function userFilter($query) {
|
|
|
|
return User.$filter($query, folder.$acl.users);
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeModal() {
|
|
|
|
folder.$acl.$resetUsersRights(); // cancel changes
|
|
|
|
$mdDialog.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveModal() {
|
|
|
|
folder.$acl.$saveUsersRights().then(function() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
}, function(data, status) {
|
|
|
|
Dialog.alert(l('Warning'), l('An error occured please try again.'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function confirmChange(user) {
|
2016-02-23 16:20:10 +01:00
|
|
|
var confirmation = user.$confirmRights(vm.folder);
|
2015-07-28 16:53:29 +02:00
|
|
|
if (confirmation) {
|
2015-08-06 02:23:11 +02:00
|
|
|
vm.confirmation.showing = true;
|
|
|
|
vm.confirmation.message = confirmation;
|
2015-07-28 16:53:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeUser(user) {
|
2016-06-20 22:10:52 +02:00
|
|
|
$timeout(function() {
|
|
|
|
folder.$acl.$removeUser(user.uid);
|
|
|
|
}, 500); // wait for CSS transition to complete (see card.scss)
|
2016-06-20 15:10:50 +02:00
|
|
|
}
|
|
|
|
|
2015-07-28 16:53:29 +02:00
|
|
|
function addUser(data) {
|
|
|
|
if (data) {
|
2015-10-27 16:28:42 +01:00
|
|
|
folder.$acl.$addUser(data).then(function(user) {
|
2015-07-28 16:53:29 +02:00
|
|
|
vm.userToAdd = '';
|
|
|
|
vm.searchText = '';
|
2015-10-27 16:28:42 +01:00
|
|
|
vm.selectedUid = null;
|
|
|
|
if (user)
|
|
|
|
selectUser(user);
|
2015-07-28 16:53:29 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-20 22:10:52 +02:00
|
|
|
function selectAllRights(user) {
|
|
|
|
folder.$acl.$selectAllRights(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectUser(user, $event) {
|
|
|
|
if ($event && $event.target.parentNode.classList.contains('md-secondary'))
|
|
|
|
return false;
|
2015-10-09 22:49:08 +02:00
|
|
|
if (vm.selectedUid == user.uid) {
|
|
|
|
vm.selectedUid = null;
|
2015-08-03 20:44:11 +02:00
|
|
|
}
|
|
|
|
else {
|
2015-10-09 22:49:08 +02:00
|
|
|
vm.selectedUid = user.uid;
|
2015-07-28 16:53:29 +02:00
|
|
|
vm.selectedUser = user;
|
2017-01-27 18:22:22 +01:00
|
|
|
if (!user.inactive)
|
|
|
|
vm.selectedUser.$rights();
|
2015-07-28 16:53:29 +02:00
|
|
|
}
|
|
|
|
}
|
2017-01-26 18:48:21 +01:00
|
|
|
|
|
|
|
function showRights(user) {
|
2017-01-27 18:22:22 +01:00
|
|
|
return vm.selectedUid == user.uid && !user.inactive;
|
2017-01-26 18:48:21 +01:00
|
|
|
}
|
2015-07-28 16:53:29 +02:00
|
|
|
}
|
|
|
|
|
2015-08-07 17:02:34 +02:00
|
|
|
angular
|
|
|
|
.module('SOGo.Common')
|
|
|
|
.controller('AclController', AclController);
|
2015-07-28 16:53:29 +02:00
|
|
|
})();
|