2018-01-22 13:01:38 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
2018-08-02 22:17:27 +02:00
|
|
|
/* global angular:false */
|
2018-04-02 11:35:02 +02:00
|
|
|
/* global Clipboard:false */
|
2018-08-02 22:17:27 +02:00
|
|
|
/* global asyncForEach:false */
|
2018-01-24 16:20:56 +01:00
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
angular.module('Application').controller('UsersController', ['$scope', '$location', '$timeout', 'Client', function ($scope, $location, $timeout, Client) {
|
2018-05-01 11:44:47 -07:00
|
|
|
Client.onReady(function () { if (!Client.hasScope('users')) $location.path('/'); });
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.ready = false;
|
|
|
|
|
$scope.users = [];
|
2018-07-24 22:20:00 -07:00
|
|
|
$scope.usersById = [];
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groups = [];
|
|
|
|
|
$scope.groupsById = { };
|
|
|
|
|
$scope.config = Client.getConfig();
|
|
|
|
|
$scope.userInfo = Client.getUserInfo();
|
2018-01-23 17:09:47 +01:00
|
|
|
|
2018-07-26 23:58:25 -07:00
|
|
|
$scope.groupMembers = function (group) {
|
2018-08-02 22:16:55 +02:00
|
|
|
return group.userIds.filter(function (uid) { return !!$scope.usersById[uid]; }).map(function (uid) { return $scope.usersById[uid].username || $scope.usersById[uid].email; }).join(', ');
|
2018-07-26 23:58:25 -07:00
|
|
|
};
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.userremove = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
userInfo: {},
|
|
|
|
|
password: '',
|
|
|
|
|
|
|
|
|
|
show: function (userInfo) {
|
|
|
|
|
$scope.userremove.error.username = null;
|
|
|
|
|
$scope.userremove.error.password = null;
|
|
|
|
|
$scope.userremove.password = '';
|
|
|
|
|
$scope.userremove.userInfo = userInfo;
|
|
|
|
|
|
|
|
|
|
$scope.userremove_form.$setPristine();
|
|
|
|
|
$scope.userremove_form.$setUntouched();
|
|
|
|
|
|
|
|
|
|
$('#userRemoveModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.userremove.error.password = null;
|
|
|
|
|
$scope.userremove.busy = true;
|
|
|
|
|
|
2018-07-05 13:32:45 -07:00
|
|
|
// transfer to self for now. not transferred to owner because this user probably wants to "manage" it immediately
|
|
|
|
|
// FIXME: this may awkwardly transfer resources but fail with incorrect password
|
|
|
|
|
Client.transferOwnership($scope.userremove.userInfo.id, $scope.userInfo.id, function (error) {
|
|
|
|
|
if (error) return console.error('Unable to transfer resources.', error);
|
|
|
|
|
|
|
|
|
|
Client.removeUser($scope.userremove.userInfo.id, $scope.userremove.password, function (error) {
|
|
|
|
|
$scope.userremove.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error && error.statusCode === 403) {
|
|
|
|
|
$scope.userremove.error.password = 'Wrong password';
|
|
|
|
|
$scope.userremove.password = '';
|
|
|
|
|
$scope.userremove_form.password.$setPristine();
|
|
|
|
|
$('#inputUserRemovePassword').focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (error) return console.error('Unable to delete user.', error);
|
|
|
|
|
|
|
|
|
|
$scope.userremove.userInfo = {};
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.userremove.password = '';
|
|
|
|
|
|
2018-07-05 13:32:45 -07:00
|
|
|
$scope.userremove_form.$setPristine();
|
|
|
|
|
$scope.userremove_form.$setUntouched();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-05 13:32:45 -07:00
|
|
|
refresh();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-05 13:32:45 -07:00
|
|
|
$('#userRemoveModal').modal('hide');
|
|
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.useradd = {
|
|
|
|
|
busy: false,
|
|
|
|
|
alreadyTaken: false,
|
|
|
|
|
error: {},
|
|
|
|
|
email: '',
|
|
|
|
|
username: '',
|
|
|
|
|
displayName: '',
|
|
|
|
|
sendInvite: true,
|
2018-07-24 22:38:53 -07:00
|
|
|
selectedGroups: [],
|
2018-07-26 15:45:52 -07:00
|
|
|
admin: false,
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
show: function () {
|
|
|
|
|
$scope.useradd.error = {};
|
|
|
|
|
$scope.useradd.email = '';
|
|
|
|
|
$scope.useradd.username = '';
|
|
|
|
|
$scope.useradd.displayName = '';
|
2018-07-24 22:38:53 -07:00
|
|
|
$scope.useradd.selectedGroups = [];
|
2018-07-26 15:45:52 -07:00
|
|
|
$scope.useradd.admin = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.useradd_form.$setUntouched();
|
|
|
|
|
$scope.useradd_form.$setPristine();
|
|
|
|
|
|
|
|
|
|
$('#userAddModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.useradd.busy = true;
|
|
|
|
|
|
|
|
|
|
$scope.useradd.alreadyTaken = false;
|
|
|
|
|
$scope.useradd.error.email = null;
|
|
|
|
|
$scope.useradd.error.username = null;
|
|
|
|
|
$scope.useradd.error.displayName = null;
|
|
|
|
|
|
2018-07-26 15:52:06 -07:00
|
|
|
var user = {
|
|
|
|
|
username: $scope.useradd.username || null,
|
|
|
|
|
email: $scope.useradd.email,
|
|
|
|
|
displayName: $scope.useradd.displayName,
|
2018-07-26 15:45:52 -07:00
|
|
|
sendInvite: $scope.useradd.sendInvite,
|
|
|
|
|
admin: $scope.useradd.admin
|
2018-07-26 15:52:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Client.createUser(user, function (error, newUserInfo) {
|
2018-07-24 22:38:53 -07:00
|
|
|
if (error) {
|
|
|
|
|
$scope.useradd.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
if (error.message.toLowerCase().indexOf('email') !== -1) {
|
|
|
|
|
$scope.useradd.error.email = 'Email already taken';
|
|
|
|
|
$scope.useradd_form.email.$setPristine();
|
|
|
|
|
$('#inputUserAddEmail').focus();
|
|
|
|
|
} else if (error.message.toLowerCase().indexOf('username') !== -1 || error.message.toLowerCase().indexOf('mailbox') !== -1) {
|
|
|
|
|
$scope.useradd.error.username = 'Username already taken';
|
|
|
|
|
$scope.useradd_form.username.$setPristine();
|
|
|
|
|
$('#inputUserAddUsername').focus();
|
|
|
|
|
} else {
|
|
|
|
|
// should not happen!!
|
|
|
|
|
console.error(error.message);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
} else if (error.statusCode === 400) {
|
|
|
|
|
if (error.message.toLowerCase().indexOf('email') !== -1) {
|
|
|
|
|
$scope.useradd.error.email = 'Invalid Email';
|
|
|
|
|
$scope.useradd.error.emailAttempted = $scope.useradd.email;
|
|
|
|
|
$scope.useradd_form.email.$setPristine();
|
|
|
|
|
$('#inputUserAddEmail').focus();
|
|
|
|
|
} else if (error.message.toLowerCase().indexOf('username') !== -1) {
|
|
|
|
|
$scope.useradd.error.username = error.message;
|
|
|
|
|
$scope.useradd_form.username.$setPristine();
|
|
|
|
|
$('#inputUserAddUsername').focus();
|
|
|
|
|
} else {
|
|
|
|
|
console.error('Unable to create user.', error.statusCode, error.message);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2018-01-22 13:01:38 -08:00
|
|
|
} else {
|
2018-07-24 22:38:53 -07:00
|
|
|
return console.error('Unable to create user.', error.statusCode, error.message);
|
2018-01-22 13:01:38 -08:00
|
|
|
}
|
|
|
|
|
}
|
2018-07-24 22:38:53 -07:00
|
|
|
|
|
|
|
|
var groupIds = $scope.useradd.selectedGroups.map(function (g) { return g.id; });
|
|
|
|
|
|
|
|
|
|
Client.setGroups(newUserInfo.id, groupIds, function (error) {
|
|
|
|
|
$scope.useradd.busy = false;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-24 22:38:53 -07:00
|
|
|
if (error) return console.error('Unable to update groups for user:', error);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-24 22:38:53 -07:00
|
|
|
refresh();
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-07-24 22:38:53 -07:00
|
|
|
$('#userAddModal').modal('hide');
|
|
|
|
|
});
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.useredit = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
userInfo: {},
|
|
|
|
|
email: '',
|
|
|
|
|
fallbackEmail: '',
|
2018-01-25 18:17:40 +01:00
|
|
|
aliases: {},
|
2018-07-24 15:17:51 -07:00
|
|
|
displayName: '',
|
2018-07-26 15:45:52 -07:00
|
|
|
admin: false,
|
2018-07-24 21:36:50 -07:00
|
|
|
selectedGroups: [],
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
show: function (userInfo) {
|
|
|
|
|
$scope.useredit.error = {};
|
|
|
|
|
$scope.useredit.email = userInfo.email;
|
2018-07-24 15:17:51 -07:00
|
|
|
$scope.useredit.displayName = userInfo.displayName;
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.useredit.fallbackEmail = userInfo.fallbackEmail;
|
|
|
|
|
$scope.useredit.userInfo = userInfo;
|
2018-07-24 21:36:50 -07:00
|
|
|
$scope.useredit.selectedGroups = userInfo.groupIds.map(function (gid) { return $scope.groupsById[gid]; });
|
2018-07-26 15:45:52 -07:00
|
|
|
$scope.useredit.admin = userInfo.admin;
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
$scope.useredit_form.$setPristine();
|
|
|
|
|
$scope.useredit_form.$setUntouched();
|
|
|
|
|
|
|
|
|
|
$('#userEditModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.useredit.error = {};
|
|
|
|
|
$scope.useredit.busy = true;
|
|
|
|
|
|
2018-01-26 15:39:35 +01:00
|
|
|
var userId = $scope.useredit.userInfo.id;
|
2018-01-22 13:01:38 -08:00
|
|
|
var data = {
|
2018-01-26 15:39:35 +01:00
|
|
|
id: userId,
|
2018-01-24 16:20:56 +01:00
|
|
|
email: $scope.useredit.email,
|
2018-07-24 15:17:51 -07:00
|
|
|
displayName: $scope.useredit.displayName,
|
2018-07-26 15:45:52 -07:00
|
|
|
fallbackEmail: $scope.useredit.fallbackEmail,
|
|
|
|
|
admin: $scope.useredit.admin
|
2018-01-22 13:01:38 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Client.updateUser(data, function (error) {
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.useredit.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
$scope.useredit.error.email = 'Email already taken';
|
|
|
|
|
$scope.useredit_form.email.$setPristine();
|
|
|
|
|
$('#inputUserEditEmail').focus();
|
|
|
|
|
} else {
|
|
|
|
|
console.error('Unable to update user:', error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-24 21:36:50 -07:00
|
|
|
var groupIds = $scope.useredit.selectedGroups.map(function (g) { return g.id; });
|
|
|
|
|
|
|
|
|
|
Client.setGroups(data.id, groupIds, function (error) {
|
2018-04-01 20:53:49 +02:00
|
|
|
$scope.useredit.busy = false;
|
2018-07-24 22:38:53 -07:00
|
|
|
|
|
|
|
|
if (error) return console.error('Unable to update groups for user:', error);
|
2018-04-01 20:53:49 +02:00
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
|
|
|
|
|
$('#userEditModal').modal('hide');
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.groupAdd = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
name: '',
|
|
|
|
|
|
|
|
|
|
show: function () {
|
|
|
|
|
$scope.groupAdd.busy = false;
|
|
|
|
|
|
|
|
|
|
$scope.groupAdd.error = {};
|
|
|
|
|
$scope.groupAdd.name = '';
|
|
|
|
|
|
|
|
|
|
$scope.groupAddForm.$setUntouched();
|
|
|
|
|
$scope.groupAddForm.$setPristine();
|
|
|
|
|
|
|
|
|
|
$('#groupAddModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.groupAdd.busy = true;
|
|
|
|
|
$scope.groupAdd.error = {};
|
|
|
|
|
|
2018-07-26 11:38:20 -07:00
|
|
|
Client.createGroup($scope.groupAdd.name, function (error) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groupAdd.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error && error.statusCode === 409) {
|
|
|
|
|
$scope.groupAdd.error.name = 'Name already taken';
|
|
|
|
|
$scope.groupAddForm.name.$setPristine();
|
|
|
|
|
$('#groupAddName').focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (error && error.statusCode === 400) {
|
|
|
|
|
$scope.groupAdd.error.name = error.message;
|
|
|
|
|
$scope.groupAddForm.name.$setPristine();
|
|
|
|
|
$('#groupAddName').focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (error) return console.error('Unable to create group.', error.statusCode, error.message);
|
|
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
$('#groupAddModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-18 17:45:09 -07:00
|
|
|
$scope.groupEdit = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
groupInfo: {},
|
|
|
|
|
name: '',
|
2018-07-24 22:20:00 -07:00
|
|
|
selectedUsers: [],
|
|
|
|
|
|
2018-06-18 17:45:09 -07:00
|
|
|
show: function (groupInfo) {
|
|
|
|
|
$scope.groupEdit.error = {};
|
|
|
|
|
$scope.groupEdit.groupInfo = groupInfo;
|
|
|
|
|
$scope.groupEdit.name = groupInfo.name;
|
2018-07-24 22:20:00 -07:00
|
|
|
$scope.groupEdit.selectedUsers = groupInfo.userIds.map(function (uid) { return $scope.usersById[uid]; });
|
2018-06-18 17:45:09 -07:00
|
|
|
|
|
|
|
|
$scope.groupEdit_form.$setPristine();
|
|
|
|
|
$scope.groupEdit_form.$setUntouched();
|
|
|
|
|
|
|
|
|
|
$('#groupEditModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.groupEdit.busy = true;
|
|
|
|
|
$scope.groupEdit.error = {};
|
|
|
|
|
|
2018-07-26 11:38:20 -07:00
|
|
|
Client.updateGroup($scope.groupEdit.groupInfo.id, $scope.groupEdit.name, function (error) {
|
2018-07-24 22:31:22 -07:00
|
|
|
if (error) {
|
|
|
|
|
$scope.groupEdit.busy = false;
|
2018-06-18 17:45:09 -07:00
|
|
|
|
2018-07-24 22:31:22 -07:00
|
|
|
if (error.statusCode === 409) {
|
|
|
|
|
$scope.groupEdit.error.name = 'Name already taken';
|
|
|
|
|
$scope.groupEditForm.name.$setPristine();
|
|
|
|
|
$('#groupEditName').focus();
|
|
|
|
|
return;
|
|
|
|
|
} else if (error.statusCode === 400) {
|
|
|
|
|
$scope.groupEdit.error.name = error.message;
|
|
|
|
|
$scope.groupEditForm.name.$setPristine();
|
|
|
|
|
$('#groupEditName').focus();
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
return console.error('Unable to edit group.', error.statusCode, error.message);
|
|
|
|
|
}
|
2018-06-18 17:45:09 -07:00
|
|
|
}
|
|
|
|
|
|
2018-07-24 22:20:00 -07:00
|
|
|
var userIds = $scope.groupEdit.selectedUsers.map(function (u) { return u.id; });
|
|
|
|
|
|
|
|
|
|
Client.setGroupMembers($scope.groupEdit.groupInfo.id, userIds, function (error) {
|
|
|
|
|
$scope.groupEdit.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) return console.error('Unable to edit group.', error.statusCode, error.message);
|
2018-06-18 17:45:09 -07:00
|
|
|
|
2018-07-24 22:20:00 -07:00
|
|
|
refresh();
|
|
|
|
|
|
|
|
|
|
$('#groupEditModal').modal('hide');
|
|
|
|
|
});
|
2018-06-18 17:45:09 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.inviteSent = {
|
|
|
|
|
email: '',
|
|
|
|
|
setupLink: ''
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.groupRemove = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
group: null,
|
|
|
|
|
password: '',
|
|
|
|
|
memberCount: 0,
|
|
|
|
|
|
|
|
|
|
show: function (group) {
|
|
|
|
|
$scope.groupRemove.busy = false;
|
|
|
|
|
|
|
|
|
|
$scope.groupRemove.error = {};
|
|
|
|
|
$scope.groupRemove.password = '';
|
|
|
|
|
|
|
|
|
|
$scope.groupRemove.group = angular.copy(group);
|
|
|
|
|
|
|
|
|
|
$scope.groupRemoveForm.$setUntouched();
|
|
|
|
|
$scope.groupRemoveForm.$setPristine();
|
|
|
|
|
|
|
|
|
|
Client.getGroup(group.id, function (error, result) {
|
|
|
|
|
if (error) return console.error('Unable to fetch group information.', error.statusCode, error.message);
|
|
|
|
|
|
|
|
|
|
$scope.groupRemove.memberCount = result.userIds.length;
|
|
|
|
|
|
|
|
|
|
$('#groupRemoveModal').modal('show');
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.groupRemove.busy = true;
|
|
|
|
|
$scope.groupRemove.error = {};
|
|
|
|
|
|
|
|
|
|
Client.removeGroup($scope.groupRemove.group.id, $scope.groupRemove.password, function (error) {
|
|
|
|
|
$scope.groupRemove.busy = false;
|
|
|
|
|
|
2018-06-18 18:57:00 -07:00
|
|
|
if (error && error.statusCode === 403) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groupRemove.error.password = 'Wrong password';
|
|
|
|
|
$scope.groupRemove.password = '';
|
|
|
|
|
$scope.groupRemoveForm.password.$setPristine();
|
|
|
|
|
$('#groupRemovePasswordInput').focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (error) return console.error('Unable to remove group.', error.statusCode, error.message);
|
|
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
$('#groupRemoveModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.isMe = function (user) {
|
|
|
|
|
return user.username === Client.getUserInfo().username;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.sendInvite = function (user) {
|
|
|
|
|
$scope.inviteSent.email = user.fallbackEmail;
|
|
|
|
|
$scope.inviteSent.setupLink = '';
|
|
|
|
|
|
|
|
|
|
Client.sendInvite(user, function (error, resetToken) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
// Client.notify('', 'Invitation was successfully sent to ' + user.email + '.', false, 'success');
|
|
|
|
|
|
2018-07-04 11:10:13 +02:00
|
|
|
$scope.inviteSent.setupLink = location.origin + '/api/v1/session/account/setup.html?reset_token=' + resetToken + '&email=' + encodeURIComponent(user.email);
|
2018-01-22 13:01:38 -08:00
|
|
|
$('#inviteSentModal').modal('show');
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-18 18:34:13 -07:00
|
|
|
$scope.copyToClipboard = function (/*value*/) {
|
2018-01-22 13:01:38 -08:00
|
|
|
document.execCommand('copy');
|
|
|
|
|
};
|
|
|
|
|
|
2018-06-25 16:14:14 -07:00
|
|
|
function getUsers(callback) {
|
|
|
|
|
var users = [ ];
|
|
|
|
|
|
|
|
|
|
Client.getUsers(function (error, results) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
asyncForEach(results, function (result, iteratorDone) {
|
|
|
|
|
Client.getUser(result.id, function (error, user) {
|
|
|
|
|
if (error) return iteratorDone(error);
|
|
|
|
|
|
|
|
|
|
users.push(user);
|
|
|
|
|
|
|
|
|
|
iteratorDone();
|
|
|
|
|
});
|
|
|
|
|
}, function (error) {
|
|
|
|
|
callback(error, users);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getGroups(callback) {
|
|
|
|
|
var groups = [ ];
|
|
|
|
|
|
|
|
|
|
Client.getGroups(function (error, results) {
|
|
|
|
|
if (error) return console.error(error);
|
|
|
|
|
|
|
|
|
|
asyncForEach(results, function (result, iteratorDone) {
|
|
|
|
|
Client.getGroup(result.id, function (error, group) {
|
|
|
|
|
if (error) return iteratorDone(error);
|
|
|
|
|
|
|
|
|
|
groups.push(group);
|
|
|
|
|
|
|
|
|
|
iteratorDone();
|
|
|
|
|
});
|
|
|
|
|
}, function (error) {
|
|
|
|
|
callback(error, groups);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-22 13:01:38 -08:00
|
|
|
function refresh() {
|
2018-06-25 16:14:14 -07:00
|
|
|
getGroups(function (error, result) {
|
2018-01-22 13:01:38 -08:00
|
|
|
if (error) return console.error('Unable to get group listing.', error);
|
|
|
|
|
|
2018-07-24 22:20:00 -07:00
|
|
|
angular.copy(result, $scope.groups);
|
2018-01-22 13:01:38 -08:00
|
|
|
$scope.groupsById = { };
|
|
|
|
|
for (var i = 0; i < result.length; i++) {
|
|
|
|
|
$scope.groupsById[result[i].id] = result[i];
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 16:14:14 -07:00
|
|
|
getUsers(function (error, result) {
|
2018-01-22 13:01:38 -08:00
|
|
|
if (error) return console.error('Unable to get user listing.', error);
|
|
|
|
|
|
2018-07-24 22:20:00 -07:00
|
|
|
angular.copy(result, $scope.users);
|
|
|
|
|
$scope.usersById = { };
|
|
|
|
|
for (var i = 0; i < result.length; i++) {
|
|
|
|
|
$scope.usersById[result[i].id] = result[i];
|
|
|
|
|
}
|
2018-01-22 13:01:38 -08:00
|
|
|
|
2018-05-01 15:22:45 -07:00
|
|
|
$scope.ready = true;
|
2018-01-22 13:01:38 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-23 17:09:47 +01:00
|
|
|
Client.onReady(refresh);
|
2018-01-22 13:01:38 -08:00
|
|
|
|
|
|
|
|
// setup all the dialog focus handling
|
2018-06-18 17:45:09 -07:00
|
|
|
['userAddModal', 'userRemoveModal', 'userEditModal', 'groupAddModal', 'groupEditModal', 'groupRemoveModal'].forEach(function (id) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$('#' + id).on('shown.bs.modal', function () {
|
|
|
|
|
$(this).find("[autofocus]:first").focus();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var clipboard = new Clipboard('#setupLinkButton');
|
|
|
|
|
|
|
|
|
|
clipboard.on('success', function(e) {
|
|
|
|
|
$('#setupLinkButton').tooltip({
|
|
|
|
|
title: 'Copied!',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
}).tooltip('show');
|
|
|
|
|
|
|
|
|
|
$timeout(function () { $('#setupLinkButton').tooltip('hide'); }, 2000);
|
|
|
|
|
|
|
|
|
|
e.clearSelection();
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-18 18:34:13 -07:00
|
|
|
clipboard.on('error', function(/*e*/) {
|
2018-01-22 13:01:38 -08:00
|
|
|
$('#setupLinkButton').tooltip({
|
|
|
|
|
title: 'Press Ctrl+C to copy',
|
|
|
|
|
trigger: 'manual'
|
|
|
|
|
}).tooltip('show');
|
|
|
|
|
|
|
|
|
|
$timeout(function () { $('#setupLinkButton').tooltip('hide'); }, 2000);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.modal-backdrop').remove();
|
|
|
|
|
}]);
|