mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-16 08:55:24 +00:00
Created user-modal.js, code refactoring
Conflicts: UI/Common/UIxAclEditor.m UI/Common/UIxUserRightsEditor.m UI/Common/product.plist UI/Contacts/UIxContactsUserRightsEditor.m UI/Templates/ContactsUI/UIxContactFoldersView.wox UI/WebServerResources/js/Common/resource.js UI/WebServerResources/js/ContactsUI.js
This commit is contained in:
committed by
Francis Lachapelle
parent
ff5b25972f
commit
3f27e9bb57
@@ -1,10 +1,8 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
function AclUsers(addressbook) {
|
||||
this.addressbook_id = addressbook.id;
|
||||
this.addressbook_name = addressbook.name;
|
||||
this.addressbook_owner = addressbook.owner;
|
||||
function AclUsers(folder) {
|
||||
this.folder_id = folder.id;
|
||||
}
|
||||
|
||||
/* The factory we'll use to register with Angular */
|
||||
@@ -24,36 +22,29 @@
|
||||
/* Instance methods
|
||||
* Public method, assigned to prototype
|
||||
*/
|
||||
AclUsers.prototype.getUsers = function() {
|
||||
return AclUsers.$$resource.fetch(this.addressbook_id, "getUsersForObject");
|
||||
AclUsers.prototype.userRights = function(uid) {
|
||||
var param = {"uid": uid};
|
||||
return AclUsers.$$resource.fetch(this.folder_id, "userRights", param);
|
||||
};
|
||||
|
||||
AclUsers.prototype.searchUsers = function(inputText) {
|
||||
var param = "search=" + inputText;
|
||||
return AclUsers.$$resource.fetch(null, "usersSearch", param);
|
||||
};
|
||||
|
||||
AclUsers.prototype.openRightsForUserId = function(user) {
|
||||
var param = "uid=" + user;
|
||||
return AclUsers.$$resource.fetch(this.addressbook_id, "userRights", param);
|
||||
AclUsers.prototype.addUser = function(uid) {
|
||||
var param = {"uid": uid};
|
||||
AclUsers.$$resource.fetch(this.folder_id, "addUserInAcls", param);
|
||||
};
|
||||
|
||||
AclUsers.prototype.addUser = function(user) {
|
||||
var param = "uid=" + user;
|
||||
AclUsers.$$resource.fetch(this.addressbook_id, "addUserInAcls", param);
|
||||
};
|
||||
|
||||
AclUsers.prototype.subscribeUsers = function(users) {
|
||||
var param = "uids=" + users;
|
||||
AclUsers.$$resource.fetch(this.addressbook_id, "subscribeUsers", param);
|
||||
};
|
||||
|
||||
AclUsers.prototype.removeUser = function(user) {
|
||||
var userId = "uid=" + user.uid;
|
||||
AclUsers.$$resource.fetch(this.addressbook_id, "removeUserFromAcls", userId);
|
||||
AclUsers.prototype.removeUser = function(uid) {
|
||||
var param = {"uid": uid};
|
||||
AclUsers.$$resource.fetch(this.folder_id, "removeUserFromAcls", param);
|
||||
};
|
||||
|
||||
AclUsers.prototype.saveUsersRights = function(dirtyObjects) {
|
||||
AclUsers.$$resource.saveAclUsers(this.addressbook_id, "saveUserRights", dirtyObjects);
|
||||
var param = {"action": "saveUserRights"};
|
||||
AclUsers.$$resource.save(this.folder_id, dirtyObjects, param);
|
||||
};
|
||||
|
||||
AclUsers.prototype.subscribeUsers = function(uids) {
|
||||
var param = {"uids": uids};
|
||||
AclUsers.$$resource.fetch(this.folder_id, "subscribeUsers", param);
|
||||
};
|
||||
|
||||
})();
|
||||
@@ -84,10 +84,10 @@
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
Resource.prototype.save = function(uid, newValue, options) {
|
||||
Resource.prototype.save = function(id, newValue, options) {
|
||||
var deferred = this._q.defer(),
|
||||
action = (options && options.action)? options.action : 'save',
|
||||
path = this._path + '/' + uid + '/' + action;
|
||||
path = this._path + '/' + id + '/' + action;
|
||||
|
||||
this._http
|
||||
.post(path, newValue)
|
||||
@@ -108,4 +108,29 @@
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* @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)
|
||||
* @param {string} action - the action to be used in the URL
|
||||
* @param {Object} params - Object parameters injected through the $http protocol
|
||||
*/
|
||||
Resource.prototype.fetch = function(folder_id, action, params) {
|
||||
var deferred = this._q.defer();
|
||||
var folder_id_path = folder_id ? ("/" + folder_id) : "";
|
||||
var action_path = action ? ("/" + action) : "";
|
||||
|
||||
var path = this._path + folder_id_path + action_path;
|
||||
|
||||
this._http({
|
||||
method: 'GET',
|
||||
url: path,
|
||||
params: params
|
||||
})
|
||||
.success(deferred.resolve)
|
||||
.error(deferred.reject);
|
||||
|
||||
return deferred.promise;
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
* Public method, assigned to prototype
|
||||
*/
|
||||
User.prototype.$filter = function(search) {
|
||||
// return a collections of users for a filter
|
||||
// return a collections of users for a filter
|
||||
var param = {search: search};
|
||||
return User.$$resource.fetch(null, "usersSearch", param).then(function(results) {
|
||||
return User.$$resource.fetch(null, "usersSearch", param).then(function(results) {
|
||||
return results;
|
||||
})
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -178,10 +178,91 @@
|
||||
$scope.share = function() {
|
||||
var modal = $modal.open({
|
||||
templateUrl: 'addressbookSharing.html',
|
||||
controller: function($scope, $modalInstance) {
|
||||
controller: function($scope, $http, $modalInstance, sgAclUsers, sgUser) {
|
||||
/* Variables for the scope */
|
||||
$scope.AclUsers = new sgAclUsers($rootScope.addressbook);
|
||||
$scope.User = new sgUser($rootScope.addressbook);
|
||||
var dirtyObjects = {};
|
||||
$scope.User.$acls().then(function(users) {
|
||||
$scope.users = [];
|
||||
angular.forEach(users, function(user){
|
||||
user.canSubscribeUser = (user.isSubscribed) ? false : true;
|
||||
$scope.users.push(user);
|
||||
})
|
||||
});
|
||||
|
||||
/* Functions */
|
||||
$scope.closeModal = function() {
|
||||
$modalInstance.close();
|
||||
};
|
||||
$scope.saveModal = function() {
|
||||
if(!_.isEmpty(dirtyObjects)) {
|
||||
$scope.AclUsers.saveUsersRights(dirtyObjects);
|
||||
}
|
||||
$modalInstance.close();
|
||||
};
|
||||
$scope.removeUser = function() {
|
||||
if (!_.isEmpty($scope.userSelected)) {
|
||||
if(dirtyObjects[$scope.userSelected.uid])
|
||||
delete dirtyObjects[$scope.userSelected.uid];
|
||||
$scope.AclUsers.removeUser($scope.userSelected.uid);
|
||||
// Remove from the users list
|
||||
$scope.users = _.reject($scope.users, function(o) {
|
||||
return o.uid == $scope.userSelected.uid;
|
||||
});
|
||||
$scope.userSelected = {};
|
||||
}
|
||||
};
|
||||
$scope.addUser = function(user) {
|
||||
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})) {
|
||||
$scope.AclUsers.addUser(user.uid);
|
||||
$scope.User.$acls().then(function(users) {
|
||||
$scope.users = [];
|
||||
angular.forEach(users, function(user){
|
||||
user.canSubscribeUser = (user.isSubscribed) ? false : true;
|
||||
$scope.users.push(user);
|
||||
})
|
||||
});
|
||||
}
|
||||
else
|
||||
Dialog.alert(l('Warning'), l('You have already subscribed to that folder!'));
|
||||
}
|
||||
else
|
||||
Dialog.alert(l('Warning'), l('Please select a user inside your domain'));
|
||||
};
|
||||
$scope.selectUser = function(user) {
|
||||
// Check if it is a different user
|
||||
if ($scope.userSelected != user){
|
||||
$scope.userSelected = {};
|
||||
$scope.selected = user;
|
||||
$scope.userSelected = user;
|
||||
|
||||
if (dirtyObjects[$scope.userSelected.uid]) {
|
||||
$scope.userSelected.aclOptions = dirtyObjects[$scope.userSelected.uid].aclOptions;
|
||||
}
|
||||
else {
|
||||
$scope.AclUsers.userRights($scope.userSelected.uid).then(function(userRights) {
|
||||
$scope.userSelected.aclOptions = userRights;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
$scope.markUserAsDirty = function(user) {
|
||||
if(!$scope.userSelected) {
|
||||
$scope.selectUser(user);
|
||||
dirtyObjects[$scope.userSelected.uid] = $scope.userSelected;
|
||||
}
|
||||
else
|
||||
dirtyObjects[$scope.userSelected.uid] = $scope.userSelected;
|
||||
};
|
||||
$scope.displayUserRights = function() {
|
||||
return ($scope.userSelected && ($scope.userSelected.uid != "anonymous")) ? true : false;
|
||||
};
|
||||
$scope.userIsReadOnly = function() {
|
||||
return (!$scope.userSelected || $scope.userSelected.userClass == "public-user");
|
||||
};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -128,13 +128,10 @@
|
||||
if (attrs.source) {
|
||||
scope.$watch('search.value', function (newValue, oldValue) {
|
||||
if (newValue.length > attrs.minLength) {
|
||||
scope.getData({str: newValue}).then(function (results) {
|
||||
scope.getData({search: newValue}).then(function (results) {
|
||||
scope.model = results;
|
||||
});
|
||||
}
|
||||
else {
|
||||
scope.model = [];
|
||||
}
|
||||
});
|
||||
}
|
||||
scope.clearSearch = function() {
|
||||
@@ -144,7 +141,7 @@
|
||||
},
|
||||
template: '<div class="item-input-wrapper">' +
|
||||
'<i class="icon ion-android-search"></i>' +
|
||||
'<input type="search" placeholder="{{placeholder}}" ng-model="search.value">' +
|
||||
'<input type="search" placeholder="{{placeholder}}" ng-model="search.value" id="searchInput">' +
|
||||
'<i ng-if="search.value.length > 0" ng-click="clearSearch()" class="icon ion-close"></i>' +
|
||||
'</div>'
|
||||
};
|
||||
@@ -162,7 +159,7 @@
|
||||
// };
|
||||
}])
|
||||
|
||||
.controller('AddressBooksCtrl', ['$scope', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', 'sgAclUsers', function($scope, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook, sgAclUsers) {
|
||||
.controller('AddressBooksCtrl', ['$scope', '$rootScope', '$ionicModal', '$ionicListDelegate', '$ionicActionSheet', 'sgDialog', 'sgAddressBook', 'sgAclUsers', 'sgUser', function($scope, $rootScope, $ionicModal, $ionicListDelegate, $ionicActionSheet, Dialog, AddressBook, sgAclUsers, sgUser) {
|
||||
// Initialize with data from template
|
||||
$scope.addressbooks = AddressBook.$findAll(contactFolders);
|
||||
$scope.newAddressbook = function() {
|
||||
@@ -210,12 +207,13 @@
|
||||
$scope.$aclEditorModal = modal;
|
||||
$scope.addressbook = addressbook;
|
||||
$scope.AclUsers = new sgAclUsers(addressbook);
|
||||
$scope.User = new sgUser(addressbook);
|
||||
var aclUsers = {};
|
||||
$scope.AclUsers.getUsers().then(function(users) {
|
||||
$scope.User.$acls().then(function(users) {
|
||||
$scope.refreshUsers(users);
|
||||
});
|
||||
$scope.showDelete = false;
|
||||
$scope.onGoingSearch = true;
|
||||
$scope.onGoingSearch = false;
|
||||
|
||||
// Variables in javascript
|
||||
var dirtyObjects = {};
|
||||
@@ -223,7 +221,7 @@
|
||||
// Local functions
|
||||
$scope.refreshUsers = function(users) {
|
||||
$scope.users = [];
|
||||
$scope.onGoingSearch = true;
|
||||
$scope.onGoingSearch = false;
|
||||
angular.forEach(users, function(user){
|
||||
user.inAclList = true;
|
||||
user.canSubscribeUser = (user.isSubscribed) ? false : true;
|
||||
@@ -237,16 +235,22 @@
|
||||
$scope.$aclEditorModal.remove();
|
||||
};
|
||||
$scope.saveModal = function() {
|
||||
if(Object.keys(dirtyObjects).length > 0) {
|
||||
if(!_.isEmpty(dirtyObjects)) {
|
||||
if(dirtyObjects["anonymous"])
|
||||
{
|
||||
Dialog.confirm(l("Warning"), l("Any user with an account on this system will be able to access your mailbox \"%{0}\". Are you certain you trust them all?")).then(function(res){
|
||||
if(res){Dialog.alert("okay!")};
|
||||
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){
|
||||
$scope.AclUsers.saveUsersRights(dirtyObjects);
|
||||
$scope.$aclEditorModal.remove();
|
||||
};
|
||||
})
|
||||
}
|
||||
else if (dirtyObjects["<default>"]) {
|
||||
Dialog.confirm(l("Warning"), l("Potentially anyone on the Internet will be able to access your calendar \"%{0}\", even if they do not have an account on this system. Is this information suitable for the public Internet?")).then(function(res){
|
||||
if(res){Dialog.alert("okay!")};
|
||||
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){
|
||||
$scope.AclUsers.saveUsersRights(dirtyObjects);
|
||||
$scope.$aclEditorModal.remove();
|
||||
};
|
||||
})
|
||||
}
|
||||
else {
|
||||
@@ -257,13 +261,17 @@
|
||||
usersToSubscribe.push(dirtyObject.uid);
|
||||
}
|
||||
})
|
||||
$scope.AclUsers.subscribeUsers(usersToSubscribe);
|
||||
if(!_.isEmpty(usersToSubscribe))
|
||||
$scope.AclUsers.subscribeUsers(usersToSubscribe);
|
||||
|
||||
$scope.$aclEditorModal.remove();
|
||||
}
|
||||
}
|
||||
$scope.$aclEditorModal.remove();
|
||||
else
|
||||
$scope.$aclEditorModal.remove();
|
||||
};
|
||||
$scope.cancelSearch = function() {
|
||||
$scope.AclUsers.getUsers().then(function(users) {
|
||||
$scope.User.$acls().then(function(users) {
|
||||
$scope.refreshUsers(users);
|
||||
});
|
||||
};
|
||||
@@ -275,24 +283,27 @@
|
||||
if(dirtyObjects[user.uid])
|
||||
delete dirtyObjects[user.uid];
|
||||
delete aclUsers[user.uid];
|
||||
$scope.AclUsers.removeUser(user);
|
||||
$scope.AclUsers.getUsers().then(function(users) {
|
||||
$scope.refreshUsers(users);
|
||||
$scope.AclUsers.removeUser(user.uid);
|
||||
// Remove from the users list
|
||||
$scope.users = _.reject($scope.users, function(o) {
|
||||
return o.uid == user.uid;
|
||||
});
|
||||
$scope.userSelected = {};
|
||||
}
|
||||
};
|
||||
$scope.addUser = function (user) {
|
||||
if (user) {
|
||||
$scope.AclUsers.addUser(user.uid);
|
||||
$scope.AclUsers.getUsers().then(function(users) {
|
||||
$scope.refreshUsers(users);
|
||||
});
|
||||
}
|
||||
else {
|
||||
// TODO : Write a better msg and add the string inside the .string
|
||||
Dialog.alert(l('Warning'), l('This user is already added to your AclUsers list'));
|
||||
if (user.uid) {
|
||||
if(!aclUsers[user.uid]) {
|
||||
$scope.AclUsers.addUser(user.uid);
|
||||
user.inAclList = true;
|
||||
user.canSubscribeUser = (user.isSubscribed) ? false : true;
|
||||
aclUsers[user.uid] = user;
|
||||
}
|
||||
else
|
||||
Dialog.alert(l('Warning'), l('You have already subscribed to that folder!'));
|
||||
}
|
||||
else
|
||||
Dialog.alert(l('Warning'), l('Please select a user inside your domain'));
|
||||
};
|
||||
$scope.editUser = function(user) {
|
||||
if ($scope.userSelected != user){
|
||||
@@ -305,17 +316,17 @@
|
||||
}
|
||||
else {
|
||||
// Otherwise, if it's the first time the user consult the user rights; fetch from server
|
||||
$scope.AclUsers.openRightsForUserId($scope.userSelected.uid).then(function(userRights) {
|
||||
$scope.AclUsers.userRights($scope.userSelected.uid).then(function(userRights) {
|
||||
$scope.userSelected.aclOptions = userRights;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
$scope.getContacts = function(value){
|
||||
$scope.searchUsers = function(search){
|
||||
$scope.users = [];
|
||||
$scope.onGoingSearch = false;
|
||||
return $scope.AclUsers.searchUsers(value).then(function(usersFound) {
|
||||
angular.forEach(usersFound, function(userFound){
|
||||
$scope.onGoingSearch = true;
|
||||
return $scope.User.$filter(search).then(function(results) {
|
||||
angular.forEach(results, function(userFound){
|
||||
userFound.inAclList = (aclUsers[userFound.uid]) ? true : false;
|
||||
$scope.users.push(userFound);
|
||||
})
|
||||
@@ -343,7 +354,7 @@
|
||||
};
|
||||
$scope.displayUserRights = function() {
|
||||
// Does the rights applies on the user/group
|
||||
return ($scope.userSelected && $scope.userSelected.uid != "anonymous") ? true : false;
|
||||
return ($scope.userSelected && ($scope.userSelected.uid != "anonymous")) ? true : false;
|
||||
};
|
||||
$scope.displaySubscribeUser = function() {
|
||||
// Is the user/group available for subscription
|
||||
|
||||
Reference in New Issue
Block a user