mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-02-21 01:16:24 +00:00
refactor codes and applied comments
This commit is contained in:
committed by
Francis Lachapelle
parent
c82143fd2e
commit
22faf5c285
@@ -27,22 +27,22 @@
|
||||
|
||||
Acl.prototype.$addUser = function(uid) {
|
||||
var param = {"uid": uid};
|
||||
Acl.$$resource.fetch(this.folder_id, "addUserInAcls", param);
|
||||
return Acl.$$resource.fetch(this.folder_id, "addUserInAcls", param);
|
||||
};
|
||||
|
||||
Acl.prototype.$removeUser = function(uid) {
|
||||
var param = {"uid": uid};
|
||||
Acl.$$resource.fetch(this.folder_id, "removeUserFromAcls", param);
|
||||
return Acl.$$resource.fetch(this.folder_id, "removeUserFromAcls", param);
|
||||
};
|
||||
|
||||
Acl.prototype.$saveUsersRights = function(dirtyObjects) {
|
||||
var param = {"action": "saveUserRights"};
|
||||
Acl.$$resource.save(this.folder_id, dirtyObjects, param);
|
||||
return Acl.$$resource.save(this.folder_id, dirtyObjects, param);
|
||||
};
|
||||
|
||||
Acl.prototype.$subscribeUsers = function(uids) {
|
||||
var param = {"uids": uids};
|
||||
Acl.$$resource.fetch(this.folder_id, "subscribeUsers", param);
|
||||
return Acl.$$resource.fetch(this.folder_id, "subscribeUsers", param);
|
||||
};
|
||||
|
||||
Acl.prototype.$users = function() {
|
||||
|
||||
@@ -111,8 +111,8 @@
|
||||
|
||||
/**
|
||||
* @function fetch
|
||||
* @desc Fetch resources using a specific object, action and/or parameters
|
||||
* @param {string} object_id - the object on which the action will be applied (ex: addressbook, calendar)
|
||||
* @desc Fetch resources using a specific folder, action and/or parameters
|
||||
* @param {string} folder_id - the folder on which the action will be applied (ex: addressbook, calendar)
|
||||
* @param {string} action - the action to be used in the URL
|
||||
* @param {Object} params - Object parameters injected through the $http protocol
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
}];
|
||||
|
||||
/* Factory registration in Angular module */
|
||||
angular.module('SOGo.Common').factory('sgUser', User.factory);
|
||||
angular.module('SOGo.Common').factory('User', User.factory);
|
||||
|
||||
/* Instance methods
|
||||
* Public method, assigned to prototype
|
||||
@@ -21,8 +21,6 @@
|
||||
User.prototype.$filter = function(search) {
|
||||
// return a collections of users for a filter
|
||||
var param = {search: search};
|
||||
return User.$$resource.fetch(null, "usersSearch", param).then(function(results) {
|
||||
return results;
|
||||
})
|
||||
return User.$$resource.fetch(null, "usersSearch", param);
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
this.$unwrap(newAddressBookData);
|
||||
}
|
||||
else if (this.id){
|
||||
this.$acl = new AddressBook.$$acl(this.id);
|
||||
this.$acl = new AddressBook.$$Acl(this.id);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -38,7 +38,7 @@
|
||||
$timeout: $timeout,
|
||||
$$resource: new Resource(Settings.baseURL),
|
||||
$Card: Card,
|
||||
$$acl: Acl
|
||||
$$Acl: Acl
|
||||
});
|
||||
|
||||
return AddressBook; // return constructor
|
||||
@@ -204,7 +204,7 @@
|
||||
_this.cards[i] = new AddressBook.$Card(o);
|
||||
});
|
||||
// Instanciate Acl object
|
||||
_this.$acl = new AddressBook.$$acl(_this.id);
|
||||
_this.$acl = new AddressBook.$$Acl(_this.id);
|
||||
});
|
||||
}, function(data) {
|
||||
AddressBook.$timeout(function() {
|
||||
|
||||
@@ -182,7 +182,7 @@
|
||||
$scope.share = function() {
|
||||
var modal = $modal.open({
|
||||
templateUrl: 'addressbookSharing.html',
|
||||
controller: function($scope, $modalInstance, sgUser) {
|
||||
controller: function($scope, $modalInstance, User) {
|
||||
/* Variables for the scope */
|
||||
var dirtyObjects = {};
|
||||
stateAddressbook.$acl.$users().then(function(users) {
|
||||
@@ -191,8 +191,10 @@
|
||||
user.canSubscribeUser = user.isSubscribed;
|
||||
$scope.users.push(user);
|
||||
})
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occurs while trying to fetch users from the server.'));
|
||||
});
|
||||
$scope.User = new sgUser();
|
||||
$scope.User = new User();
|
||||
/* Functions */
|
||||
$scope.closeModal = function() {
|
||||
$modalInstance.close();
|
||||
@@ -203,13 +205,17 @@
|
||||
if($scope.validateChanges(dirtyObjects["anonymous"])) {
|
||||
Dialog.confirm(l("Warning"), l("Potentially anyone on the Internet will be able to access your folder, even if they do not have an account on this system. Is this information suitable for the public Internet?")).then(function(res){
|
||||
if(res){
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects);
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$modalInstance.close();
|
||||
};
|
||||
}
|
||||
})
|
||||
}
|
||||
else{
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects);
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$modalInstance.close();
|
||||
}
|
||||
}
|
||||
@@ -217,18 +223,24 @@
|
||||
if($scope.validateChanges(dirtyObjects["<default>"])) {
|
||||
Dialog.confirm(l("Warning"), l("Any user with an account on this system will be able to access your folder. Are you certain you trust them all?")).then(function(res){
|
||||
if(res){
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects);
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$modalInstance.close();
|
||||
};
|
||||
})
|
||||
}
|
||||
else{
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects);
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$modalInstance.close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects);
|
||||
stateAddressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
var usersToSubscribe = [];
|
||||
angular.forEach(dirtyObjects, function(dirtyObject){
|
||||
if(dirtyObject.canSubscribeUser && dirtyObject.isSubscribed){
|
||||
@@ -236,7 +248,9 @@
|
||||
}
|
||||
})
|
||||
if(!_.isEmpty(usersToSubscribe))
|
||||
stateAddressbook.$acl.$subscribeUsers(usersToSubscribe);
|
||||
stateAddressbook.$acl.$subscribeUsers(usersToSubscribe).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
|
||||
$modalInstance.close();
|
||||
}
|
||||
@@ -254,7 +268,9 @@
|
||||
if (!_.isEmpty($scope.userSelected)) {
|
||||
if(dirtyObjects[$scope.userSelected.uid])
|
||||
delete dirtyObjects[$scope.userSelected.uid];
|
||||
stateAddressbook.$acl.$removeUser($scope.userSelected.uid);
|
||||
stateAddressbook.$acl.$removeUser($scope.userSelected.uid).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
// Remove from the users list
|
||||
$scope.users = _.reject($scope.users, function(o) {
|
||||
return o.uid == $scope.userSelected.uid;
|
||||
@@ -266,17 +282,17 @@
|
||||
if (user.uid) {
|
||||
// Looks through the list and returns the first value that matches all of the key-value pairs listed
|
||||
if(!_.findWhere($scope.users, {uid: user.uid})) {
|
||||
stateAddressbook.$acl.$addUser(user.uid);
|
||||
stateAddressbook.$acl.$users().then(function(users) {
|
||||
$scope.users = [];
|
||||
angular.forEach(users, function(user){
|
||||
user.canSubscribeUser = user.isSubscribed;
|
||||
$scope.users.push(user);
|
||||
})
|
||||
stateAddressbook.$acl.$addUser(user.uid).then(function() {
|
||||
var displayName = user.cn + " <" + user.c_email + ">";
|
||||
var userClass = user.isGroup ? "group-user" : "normal-user";
|
||||
var newUser = {canSubscribeUser: 0, displayName: displayName, isSubscribed: 0, uid: user.uid, userClass: userClass};
|
||||
$scope.users.push(newUser);
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
}
|
||||
else
|
||||
Dialog.alert(l('Warning'), l('You have already subscribed to that folder!'));
|
||||
Dialog.alert(l('Warning'), l('This user is already in your permissions list.'));
|
||||
}
|
||||
else
|
||||
Dialog.alert(l('Warning'), l('Please select a user inside your domain'));
|
||||
@@ -294,17 +310,17 @@
|
||||
else {
|
||||
stateAddressbook.$acl.$userRights($scope.userSelected.uid).then(function(userRights) {
|
||||
$scope.userSelected.aclOptions = userRights;
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
$scope.markUserAsDirty = function(user) {
|
||||
if(!$scope.userSelected) {
|
||||
if(!$scope.userSelected)
|
||||
$scope.selectUser(user);
|
||||
dirtyObjects[$scope.userSelected.uid] = $scope.userSelected;
|
||||
}
|
||||
else
|
||||
dirtyObjects[$scope.userSelected.uid] = $scope.userSelected;
|
||||
|
||||
dirtyObjects[$scope.userSelected.uid] = $scope.userSelected;
|
||||
};
|
||||
$scope.displayUserRights = function() {
|
||||
return ($scope.userSelected && ($scope.userSelected.uid != "anonymous")) ? true : false;
|
||||
|
||||
@@ -159,7 +159,7 @@
|
||||
// };
|
||||
}])
|
||||
|
||||
.controller('AddressBooksCtrl', ['$scope', '$state', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', 'sgUser', function($scope, $state, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook, sgUser) {
|
||||
.controller('AddressBooksCtrl', ['$scope', '$state', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', 'User', function($scope, $state, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook, User) {
|
||||
// Initialize with data from template
|
||||
$scope.addressbooks = AddressBook.$findAll(contactFolders);
|
||||
$scope.newAddressbook = function() {
|
||||
@@ -182,7 +182,7 @@
|
||||
$ionicActionSheet.show({
|
||||
buttons: [
|
||||
{ text: l('Rename') },
|
||||
{ text: l('Sharing') }
|
||||
{ text: l('Access rights') }
|
||||
],
|
||||
destructiveText: l('Delete'),
|
||||
cancelText: l('Cancel'),
|
||||
@@ -205,10 +205,12 @@
|
||||
}
|
||||
// Variables in scope
|
||||
$scope.$aclEditorModal = modal;
|
||||
$scope.User = new sgUser();
|
||||
$scope.User = new User();
|
||||
var aclUsers = {};
|
||||
addressbook.$acl.$users().then(function(users) {
|
||||
$scope.refreshUsers(users);
|
||||
refreshUsers(users);
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occurs while trying to fetch users from the server.'));
|
||||
});
|
||||
$scope.showDelete = false;
|
||||
$scope.onGoingSearch = false;
|
||||
@@ -217,7 +219,7 @@
|
||||
var dirtyObjects = {};
|
||||
|
||||
// Local functions
|
||||
$scope.refreshUsers = function(users) {
|
||||
function refreshUsers(users) {
|
||||
$scope.users = [];
|
||||
$scope.onGoingSearch = false;
|
||||
angular.forEach(users, function(user){
|
||||
@@ -239,13 +241,17 @@
|
||||
if($scope.validateChanges(dirtyObjects["anonymous"])) {
|
||||
Dialog.confirm(l("Warning"), l("Potentially anyone on the Internet will be able to access your folder, even if they do not have an account on this system. Is this information suitable for the public Internet?")).then(function(res){
|
||||
if(res){
|
||||
addressbook.$acl.$saveUsersRights(dirtyObjects);
|
||||
addressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$scope.$aclEditorModal.remove();
|
||||
};
|
||||
})
|
||||
}
|
||||
else {
|
||||
addressbook.$acl.$saveUsersRights(dirtyObjects);
|
||||
addressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$scope.$aclEditorModal.remove();
|
||||
}
|
||||
}
|
||||
@@ -253,18 +259,24 @@
|
||||
if($scope.validateChanges(dirtyObjects["<default>"])) {
|
||||
Dialog.confirm(l("Warning"), l("Any user with an account on this system will be able to access your folder. Are you certain you trust them all?")).then(function(res){
|
||||
if(res){
|
||||
addressbook.$acl.$saveUsersRights(dirtyObjects);
|
||||
addressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$scope.$aclEditorModal.remove();
|
||||
};
|
||||
})
|
||||
}
|
||||
else {
|
||||
addressbook.$acl.$saveUsersRights(dirtyObjects);
|
||||
addressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
$scope.$aclEditorModal.remove();
|
||||
}
|
||||
}
|
||||
else {
|
||||
addressbook.$acl.$saveUsersRights(dirtyObjects);
|
||||
addressbook.$acl.$saveUsersRights(dirtyObjects).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
var usersToSubscribe = [];
|
||||
angular.forEach(dirtyObjects, function(dirtyObject){
|
||||
if(dirtyObject.canSubscribeUser && dirtyObject.isSubscribed){
|
||||
@@ -272,7 +284,9 @@
|
||||
}
|
||||
})
|
||||
if(!_.isEmpty(usersToSubscribe))
|
||||
addressbook.$acl.$subscribeUsers(usersToSubscribe);
|
||||
addressbook.$acl.$subscribeUsers(usersToSubscribe).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
|
||||
$scope.$aclEditorModal.remove();
|
||||
}
|
||||
@@ -288,7 +302,9 @@
|
||||
};
|
||||
$scope.cancelSearch = function() {
|
||||
addressbook.$acl.$users().then(function(users) {
|
||||
$scope.refreshUsers(users);
|
||||
refreshUsers(users);
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'));
|
||||
});
|
||||
};
|
||||
$scope.toggleDelete = function(boolean) {
|
||||
@@ -299,7 +315,9 @@
|
||||
if(dirtyObjects[user.uid])
|
||||
delete dirtyObjects[user.uid];
|
||||
delete aclUsers[user.uid];
|
||||
addressbook.$acl.$removeUser(user.uid);
|
||||
addressbook.$acl.$removeUser(user.uid).then(null, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
// Remove from the users list
|
||||
$scope.users = _.reject($scope.users, function(o) {
|
||||
return o.uid == user.uid;
|
||||
@@ -310,13 +328,16 @@
|
||||
$scope.addUser = function (user) {
|
||||
if (user.uid) {
|
||||
if(!aclUsers[user.uid]) {
|
||||
addressbook.$acl.$addUser(user.uid);
|
||||
user.inAclList = true;
|
||||
user.canSubscribeUser = (user.isSubscribed) ? false : true;
|
||||
aclUsers[user.uid] = user;
|
||||
addressbook.$acl.$addUser(user.uid).then(function() {
|
||||
user.inAclList = true;
|
||||
user.canSubscribeUser = (user.isSubscribed) ? false : true;
|
||||
aclUsers[user.uid] = user;
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
}
|
||||
else
|
||||
Dialog.alert(l('Warning'), l('You have already subscribed to that folder!'));
|
||||
Dialog.alert(l('Warning'), l('This user is already in your permissions list.'));
|
||||
}
|
||||
else
|
||||
Dialog.alert(l('Warning'), l('Please select a user inside your domain'));
|
||||
@@ -334,6 +355,8 @@
|
||||
// Otherwise, if it's the first time the user consult the user rights; fetch from server
|
||||
addressbook.$acl.$userRights($scope.userSelected.uid).then(function(userRights) {
|
||||
$scope.userSelected.aclOptions = userRights;
|
||||
}, function(data, status) {
|
||||
Dialog.alert(l('Warning'), l('An error occured please try again.'))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,6 +367,7 @@ $column-gutter: 0;
|
||||
#modalACL {
|
||||
height: 25vw;
|
||||
ul {
|
||||
@include block-grid(2);
|
||||
height: 85%;
|
||||
}
|
||||
#usersList {
|
||||
@@ -379,11 +380,14 @@ $column-gutter: 0;
|
||||
$base-style: false
|
||||
);
|
||||
height: 85%;
|
||||
border: 1px solid black;
|
||||
border-top: 1px solid black;
|
||||
border-bottom: 1px solid black;
|
||||
border-left: 1px solid black;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
li {
|
||||
padding: 0;
|
||||
padding-top: 5px;
|
||||
line-height: 45px;
|
||||
background-color: $f-dropdown-list-hover-bg;
|
||||
transition: background 300ms ease;
|
||||
@@ -397,9 +401,13 @@ $column-gutter: 0;
|
||||
}
|
||||
.subscriptionArea {
|
||||
float: right;
|
||||
padding-right: 5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.f-dropdown {
|
||||
height: auto;
|
||||
}
|
||||
#bottomTable {
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
@@ -446,7 +454,7 @@ $column-gutter: 0;
|
||||
);
|
||||
li {
|
||||
padding: 5px;
|
||||
clear: none !important;
|
||||
margin-left: 5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user