2011-08-23 03:40:13 +04:00
|
|
|
/**
|
2014-03-06 11:05:44 +04:00
|
|
|
* Copyright (c) 2014, Arthur Schiwon <blizzz@owncloud.com>
|
|
|
|
* Copyright (c) 2014, Raghu Nayyar <beingminimal@gmail.com>
|
2011-08-23 03:40:13 +04:00
|
|
|
* Copyright (c) 2011, Robin Appelman <icewind1991@gmail.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2014-05-06 06:41:54 +04:00
|
|
|
var $userList;
|
|
|
|
var $userListBody;
|
|
|
|
|
2015-10-07 17:17:38 +03:00
|
|
|
var UserDeleteHandler;
|
2012-12-20 12:59:09 +04:00
|
|
|
var UserList = {
|
2013-03-19 17:49:02 +04:00
|
|
|
availableGroups: [],
|
2014-12-11 17:37:56 +03:00
|
|
|
offset: 0,
|
2013-04-30 21:51:28 +04:00
|
|
|
usersToLoad: 10, //So many users will be loaded when user scrolls down
|
2015-10-28 13:18:10 +03:00
|
|
|
initialUsersToLoad: 250, //initial number of users to load
|
2014-02-20 21:42:03 +04:00
|
|
|
currentGid: '',
|
2015-08-05 18:29:20 +03:00
|
|
|
filter: '',
|
2012-07-04 17:28:08 +04:00
|
|
|
|
2014-08-11 18:37:48 +04:00
|
|
|
/**
|
|
|
|
* Initializes the user list
|
|
|
|
* @param $el user list table element
|
|
|
|
*/
|
|
|
|
initialize: function($el) {
|
|
|
|
this.$el = $el;
|
|
|
|
|
|
|
|
// initially the list might already contain user entries (not fully ajaxified yet)
|
|
|
|
// initialize these entries
|
|
|
|
this.$el.find('.quota-user').singleSelect().on('change', this.onQuotaSelect);
|
|
|
|
},
|
|
|
|
|
2014-12-15 14:43:42 +03:00
|
|
|
/**
|
|
|
|
* Add a user row from user object
|
|
|
|
*
|
|
|
|
* @param user object containing following keys:
|
|
|
|
* {
|
|
|
|
* 'name': 'username',
|
|
|
|
* 'displayname': 'Users display name',
|
|
|
|
* 'groups': ['group1', 'group2'],
|
|
|
|
* 'subadmin': ['group4', 'group5'],
|
|
|
|
* 'quota': '10 GB',
|
|
|
|
* 'storageLocation': '/srv/www/owncloud/data/username',
|
|
|
|
* 'lastLogin': '1418632333'
|
|
|
|
* 'backend': 'LDAP',
|
|
|
|
* 'email': 'username@example.org'
|
2015-01-23 19:45:45 +03:00
|
|
|
* 'isRestoreDisabled':false
|
2014-12-15 14:43:42 +03:00
|
|
|
* }
|
|
|
|
* @param sort
|
|
|
|
* @returns table row created for this user
|
|
|
|
*/
|
|
|
|
add: function (user, sort) {
|
2015-04-12 17:22:21 +03:00
|
|
|
if (this.currentGid && this.currentGid !== '_everyone' && _.indexOf(user.groups, this.currentGid) < 0) {
|
2015-03-27 02:09:35 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-06 06:41:54 +04:00
|
|
|
var $tr = $userListBody.find('tr:first-child').clone();
|
2014-12-11 17:37:56 +03:00
|
|
|
// this removes just the `display:none` of the template row
|
|
|
|
$tr.removeAttr('style');
|
2014-07-09 18:36:51 +04:00
|
|
|
var subAdminsEl;
|
|
|
|
var subAdminSelect;
|
2014-02-03 21:00:39 +04:00
|
|
|
var groupsSelect;
|
2014-12-11 17:37:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Avatar or placeholder
|
|
|
|
*/
|
2014-05-06 06:41:54 +04:00
|
|
|
if ($tr.find('div.avatardiv').length){
|
2015-12-04 12:42:11 +03:00
|
|
|
$('div.avatardiv', $tr).avatar(user.name, 32, undefined, undefined, undefined, user.displayname);
|
2013-10-07 19:00:15 +04:00
|
|
|
}
|
2014-12-11 17:37:56 +03:00
|
|
|
|
|
|
|
/**
|
2015-01-23 19:45:45 +03:00
|
|
|
* add username and displayname to row (in data and visible markup)
|
2014-12-11 17:37:56 +03:00
|
|
|
*/
|
2014-12-15 14:43:42 +03:00
|
|
|
$tr.data('uid', user.name);
|
|
|
|
$tr.data('displayname', user.displayname);
|
|
|
|
$tr.data('mailAddress', user.email);
|
2015-01-23 19:45:45 +03:00
|
|
|
$tr.data('restoreDisabled', user.isRestoreDisabled);
|
2015-04-13 18:12:06 +03:00
|
|
|
$tr.find('.name').text(user.name);
|
2014-12-15 14:43:42 +03:00
|
|
|
$tr.find('td.displayName > span').text(user.displayname);
|
|
|
|
$tr.find('td.mailAddress > span').text(user.email);
|
2015-08-07 15:00:44 +03:00
|
|
|
$tr.find('td.displayName > .action').tooltip({placement: 'top'});
|
|
|
|
$tr.find('td.mailAddress > .action').tooltip({placement: 'top'});
|
|
|
|
$tr.find('td.password > .action').tooltip({placement: 'top'});
|
2014-02-03 21:00:39 +04:00
|
|
|
|
2014-12-12 11:59:42 +03:00
|
|
|
/**
|
|
|
|
* groups and subadmins
|
|
|
|
*/
|
2014-02-03 21:00:39 +04:00
|
|
|
// make them look like the multiselect buttons
|
|
|
|
// until they get time to really get initialized
|
2014-11-07 23:56:48 +03:00
|
|
|
groupsSelect = $('<select multiple="multiple" class="groupsselect multiselect button" data-placehoder="Groups" title="' + t('settings', 'no group') + '"></select>')
|
2014-12-15 14:43:42 +03:00
|
|
|
.data('username', user.name)
|
|
|
|
.data('user-groups', user.groups);
|
2014-05-06 06:41:54 +04:00
|
|
|
if ($tr.find('td.subadmins').length > 0) {
|
2014-10-23 00:08:55 +04:00
|
|
|
subAdminSelect = $('<select multiple="multiple" class="subadminsselect multiselect button" data-placehoder="subadmins" title="' + t('settings', 'no group') + '">')
|
2014-12-15 14:43:42 +03:00
|
|
|
.data('username', user.name)
|
|
|
|
.data('user-groups', user.groups)
|
|
|
|
.data('subadmin', user.subadmin);
|
2014-05-06 06:41:54 +04:00
|
|
|
$tr.find('td.subadmins').empty();
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2013-03-19 17:49:02 +04:00
|
|
|
$.each(this.availableGroups, function (i, group) {
|
2013-03-04 03:11:46 +04:00
|
|
|
groupsSelect.append($('<option value="' + escapeHTML(group) + '">' + escapeHTML(group) + '</option>'));
|
2014-07-09 18:36:51 +04:00
|
|
|
if (typeof subAdminSelect !== 'undefined' && group !== 'admin') {
|
|
|
|
subAdminSelect.append($('<option value="' + escapeHTML(group) + '">' + escapeHTML(group) + '</option>'));
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
|
|
|
});
|
2014-05-06 06:41:54 +04:00
|
|
|
$tr.find('td.groups').empty().append(groupsSelect);
|
2014-07-09 18:36:51 +04:00
|
|
|
subAdminsEl = $tr.find('td.subadmins');
|
|
|
|
if (subAdminsEl.length > 0) {
|
|
|
|
subAdminsEl.append(subAdminSelect);
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2014-12-12 11:59:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* remove action
|
|
|
|
*/
|
2014-12-15 14:43:42 +03:00
|
|
|
if ($tr.find('td.remove img').length === 0 && OC.currentUser !== user.name) {
|
2014-05-07 19:37:33 +04:00
|
|
|
var deleteImage = $('<img class="svg action">').attr({
|
2013-02-11 18:18:14 +04:00
|
|
|
src: OC.imagePath('core', 'actions/delete')
|
|
|
|
});
|
2014-05-07 19:37:33 +04:00
|
|
|
var deleteLink = $('<a class="action delete">')
|
2013-02-14 15:59:59 +04:00
|
|
|
.attr({ href: '#', 'original-title': t('settings', 'Delete')})
|
2014-05-07 19:37:33 +04:00
|
|
|
.append(deleteImage);
|
2014-05-06 06:41:54 +04:00
|
|
|
$tr.find('td.remove').append(deleteLink);
|
2014-12-15 14:43:42 +03:00
|
|
|
} else if (OC.currentUser === user.name) {
|
2014-05-06 06:41:54 +04:00
|
|
|
$tr.find('td.remove a').remove();
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2014-12-12 11:59:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* quota
|
|
|
|
*/
|
2014-05-06 06:41:54 +04:00
|
|
|
var $quotaSelect = $tr.find('.quota-user');
|
2014-12-15 14:43:42 +03:00
|
|
|
if (user.quota === 'default') {
|
2014-05-06 06:41:54 +04:00
|
|
|
$quotaSelect
|
|
|
|
.data('previous', 'default')
|
|
|
|
.find('option').attr('selected', null)
|
|
|
|
.first().attr('selected', 'selected');
|
2013-02-11 18:18:14 +04:00
|
|
|
} else {
|
2014-12-15 14:43:42 +03:00
|
|
|
if ($quotaSelect.find('option').filterAttr('value', user.quota).length > 0) {
|
|
|
|
$quotaSelect.find('option').filterAttr('value', user.quota).attr('selected', 'selected');
|
2013-02-11 18:18:14 +04:00
|
|
|
} else {
|
2014-12-15 14:43:42 +03:00
|
|
|
$quotaSelect.append('<option value="' + escapeHTML(user.quota) + '" selected="selected">' + escapeHTML(user.quota) + '</option>');
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
|
|
|
}
|
2014-12-12 11:59:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* storage location
|
|
|
|
*/
|
2014-12-15 14:43:42 +03:00
|
|
|
$tr.find('td.storageLocation').text(user.storageLocation);
|
2014-06-19 16:30:22 +04:00
|
|
|
|
2014-12-12 12:21:50 +03:00
|
|
|
/**
|
|
|
|
* user backend
|
|
|
|
*/
|
2014-12-15 14:43:42 +03:00
|
|
|
$tr.find('td.userBackend').text(user.backend);
|
2014-12-12 12:21:50 +03:00
|
|
|
|
2014-12-12 11:59:42 +03:00
|
|
|
/**
|
|
|
|
* last login
|
|
|
|
*/
|
2014-07-09 18:36:51 +04:00
|
|
|
var lastLoginRel = t('settings', 'never');
|
|
|
|
var lastLoginAbs = lastLoginRel;
|
2014-12-15 14:43:42 +03:00
|
|
|
if(user.lastLogin !== 0) {
|
|
|
|
lastLoginRel = OC.Util.relativeModifiedDate(user.lastLogin);
|
|
|
|
lastLoginAbs = OC.Util.formatDate(user.lastLogin);
|
2014-02-18 21:37:10 +04:00
|
|
|
}
|
2014-07-09 18:36:51 +04:00
|
|
|
var $tdLastLogin = $tr.find('td.lastLogin');
|
2014-06-19 16:30:22 +04:00
|
|
|
$tdLastLogin.text(lastLoginRel);
|
2015-08-07 15:00:44 +03:00
|
|
|
$tdLastLogin.attr('title', lastLoginAbs);
|
|
|
|
// setup tooltip with #app-content as container to prevent the td to resize on hover
|
|
|
|
$tdLastLogin.tooltip({placement: 'top', container: '#app-content'});
|
2014-12-12 11:59:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* append generated row to user list
|
|
|
|
*/
|
2014-05-06 06:41:54 +04:00
|
|
|
$tr.appendTo($userList);
|
2014-02-19 14:40:07 +04:00
|
|
|
if(UserList.isEmpty === true) {
|
|
|
|
//when the list was emptied, one row was left, necessary to keep
|
|
|
|
//add working and the layout unbroken. We need to remove this item
|
2014-05-06 06:41:54 +04:00
|
|
|
$tr.show();
|
|
|
|
$userListBody.find('tr:first').remove();
|
2014-02-19 14:40:07 +04:00
|
|
|
UserList.isEmpty = false;
|
2014-04-02 23:55:57 +04:00
|
|
|
UserList.checkUsersToLoad();
|
2014-02-19 14:40:07 +04:00
|
|
|
}
|
2014-12-12 11:59:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* sort list
|
|
|
|
*/
|
2013-02-11 18:18:14 +04:00
|
|
|
if (sort) {
|
2013-03-19 05:48:08 +04:00
|
|
|
UserList.doSort();
|
|
|
|
}
|
2013-04-10 16:12:54 +04:00
|
|
|
|
2014-08-11 18:37:48 +04:00
|
|
|
$quotaSelect.on('change', UserList.onQuotaSelect);
|
2014-02-03 21:00:39 +04:00
|
|
|
|
|
|
|
// defer init so the user first sees the list appear more quickly
|
|
|
|
window.setTimeout(function(){
|
2014-05-06 06:41:54 +04:00
|
|
|
$quotaSelect.singleSelect();
|
|
|
|
UserList.applyGroupSelect(groupsSelect);
|
2014-07-09 18:36:51 +04:00
|
|
|
if (subAdminSelect) {
|
|
|
|
UserList.applySubadminSelect(subAdminSelect);
|
2014-02-03 21:00:39 +04:00
|
|
|
}
|
|
|
|
}, 0);
|
2014-05-06 06:41:54 +04:00
|
|
|
return $tr;
|
2013-03-19 05:48:08 +04:00
|
|
|
},
|
|
|
|
// From http://my.opera.com/GreyWyvern/blog/show.dml/1671288
|
|
|
|
alphanum: function(a, b) {
|
|
|
|
function chunkify(t) {
|
|
|
|
var tz = [], x = 0, y = -1, n = 0, i, j;
|
|
|
|
|
|
|
|
while (i = (j = t.charAt(x++)).charCodeAt(0)) {
|
2014-05-07 19:37:33 +04:00
|
|
|
var m = (i === 46 || (i >=48 && i <= 57));
|
|
|
|
if (m !== n) {
|
|
|
|
tz[++y] = "";
|
|
|
|
n = m;
|
|
|
|
}
|
|
|
|
tz[y] += j;
|
2013-03-19 05:48:08 +04:00
|
|
|
}
|
|
|
|
return tz;
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2013-03-19 05:48:08 +04:00
|
|
|
|
|
|
|
var aa = chunkify(a.toLowerCase());
|
|
|
|
var bb = chunkify(b.toLowerCase());
|
|
|
|
|
2014-05-07 19:37:33 +04:00
|
|
|
for (var x = 0; aa[x] && bb[x]; x++) {
|
2013-03-19 05:48:08 +04:00
|
|
|
if (aa[x] !== bb[x]) {
|
2014-05-07 19:37:33 +04:00
|
|
|
var c = Number(aa[x]), d = Number(bb[x]);
|
|
|
|
if (c === aa[x] && d === bb[x]) {
|
|
|
|
return c - d;
|
|
|
|
} else {
|
|
|
|
return (aa[x] > bb[x]) ? 1 : -1;
|
|
|
|
}
|
2013-03-19 05:48:08 +04:00
|
|
|
}
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2013-03-19 05:48:08 +04:00
|
|
|
return aa.length - bb.length;
|
2013-02-11 18:18:14 +04:00
|
|
|
},
|
2014-04-17 22:14:51 +04:00
|
|
|
preSortSearchString: function(a, b) {
|
2015-08-05 18:29:20 +03:00
|
|
|
var pattern = this.filter;
|
2014-04-17 22:14:51 +04:00
|
|
|
if(typeof pattern === 'undefined') {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
pattern = pattern.toLowerCase();
|
|
|
|
var aMatches = false;
|
|
|
|
var bMatches = false;
|
|
|
|
if(typeof a === 'string' && a.toLowerCase().indexOf(pattern) === 0) {
|
|
|
|
aMatches = true;
|
|
|
|
}
|
|
|
|
if(typeof b === 'string' && b.toLowerCase().indexOf(pattern) === 0) {
|
|
|
|
bMatches = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((aMatches && bMatches) || (!aMatches && !bMatches)) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(aMatches) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
},
|
2013-03-19 05:48:08 +04:00
|
|
|
doSort: function() {
|
2014-05-06 06:41:54 +04:00
|
|
|
var rows = $userListBody.find('tr').get();
|
2013-03-19 05:48:08 +04:00
|
|
|
|
|
|
|
rows.sort(function(a, b) {
|
2014-02-18 15:29:05 +04:00
|
|
|
// FIXME: inefficient way of getting the names,
|
|
|
|
// better use a data attribute
|
2015-04-13 18:12:06 +03:00
|
|
|
a = $(a).find('.name').text();
|
|
|
|
b = $(b).find('.name').text();
|
2014-04-17 22:14:51 +04:00
|
|
|
var firstSort = UserList.preSortSearchString(a, b);
|
|
|
|
if(typeof firstSort !== 'undefined') {
|
|
|
|
return firstSort;
|
|
|
|
}
|
2014-02-18 15:29:05 +04:00
|
|
|
return OC.Util.naturalSortCompare(a, b);
|
2013-03-19 05:48:08 +04:00
|
|
|
});
|
2012-12-20 12:59:09 +04:00
|
|
|
|
2013-03-19 05:48:08 +04:00
|
|
|
var items = [];
|
|
|
|
$.each(rows, function(index, row) {
|
|
|
|
items.push(row);
|
|
|
|
if(items.length === 100) {
|
2014-05-06 06:41:54 +04:00
|
|
|
$userListBody.append(items);
|
2013-03-19 05:48:08 +04:00
|
|
|
items = [];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(items.length > 0) {
|
2014-05-06 06:41:54 +04:00
|
|
|
$userListBody.append(items);
|
2013-03-19 05:48:08 +04:00
|
|
|
}
|
|
|
|
},
|
2014-04-02 23:55:57 +04:00
|
|
|
checkUsersToLoad: function() {
|
|
|
|
//30 shall be loaded initially, from then on always 10 upon scrolling
|
|
|
|
if(UserList.isEmpty === false) {
|
|
|
|
UserList.usersToLoad = 10;
|
|
|
|
} else {
|
2015-10-28 13:18:10 +03:00
|
|
|
UserList.usersToLoad = UserList.initialUsersToLoad;
|
2014-04-02 23:55:57 +04:00
|
|
|
}
|
|
|
|
},
|
2014-02-19 14:40:07 +04:00
|
|
|
empty: function() {
|
|
|
|
//one row needs to be kept, because it is cloned to add new rows
|
2014-05-06 06:41:54 +04:00
|
|
|
$userListBody.find('tr:not(:first)').remove();
|
|
|
|
var $tr = $userListBody.find('tr:first');
|
|
|
|
$tr.hide();
|
2014-04-02 00:44:08 +04:00
|
|
|
//on an update a user may be missing when the username matches with that
|
|
|
|
//of the hidden row. So change this to a random string.
|
2014-05-06 06:41:54 +04:00
|
|
|
$tr.data('uid', Math.random().toString(36).substring(2));
|
2014-02-19 14:40:07 +04:00
|
|
|
UserList.isEmpty = true;
|
|
|
|
UserList.offset = 0;
|
2014-04-02 23:55:57 +04:00
|
|
|
UserList.checkUsersToLoad();
|
2014-02-19 14:40:07 +04:00
|
|
|
},
|
2014-02-26 21:04:55 +04:00
|
|
|
hide: function(uid) {
|
2014-05-06 18:52:14 +04:00
|
|
|
UserList.getRow(uid).hide();
|
2014-02-26 21:04:55 +04:00
|
|
|
},
|
|
|
|
show: function(uid) {
|
2014-05-06 18:52:14 +04:00
|
|
|
UserList.getRow(uid).show();
|
2014-02-26 21:04:55 +04:00
|
|
|
},
|
2014-07-08 22:05:51 +04:00
|
|
|
markRemove: function(uid) {
|
2014-07-09 18:36:51 +04:00
|
|
|
var $tr = UserList.getRow(uid);
|
|
|
|
var groups = $tr.find('.groups .groupsselect').val();
|
|
|
|
for(var i in groups) {
|
2014-07-05 04:14:08 +04:00
|
|
|
var gid = groups[i];
|
2014-07-09 18:36:51 +04:00
|
|
|
var $li = GroupList.getGroupLI(gid);
|
|
|
|
var userCount = GroupList.getUserCount($li);
|
2015-11-10 12:28:23 +03:00
|
|
|
GroupList.setUserCount($li, userCount - 1);
|
2014-07-05 04:14:08 +04:00
|
|
|
}
|
2014-07-08 22:05:51 +04:00
|
|
|
GroupList.decEveryoneCount();
|
|
|
|
UserList.hide(uid);
|
|
|
|
},
|
|
|
|
remove: function(uid) {
|
2014-05-06 18:52:14 +04:00
|
|
|
UserList.getRow(uid).remove();
|
2014-05-06 06:41:54 +04:00
|
|
|
},
|
2014-07-08 22:05:51 +04:00
|
|
|
undoRemove: function(uid) {
|
2014-07-09 18:36:51 +04:00
|
|
|
var $tr = UserList.getRow(uid);
|
|
|
|
var groups = $tr.find('.groups .groupsselect').val();
|
|
|
|
for(var i in groups) {
|
2014-07-08 22:05:51 +04:00
|
|
|
var gid = groups[i];
|
2014-07-09 18:36:51 +04:00
|
|
|
var $li = GroupList.getGroupLI(gid);
|
|
|
|
var userCount = GroupList.getUserCount($li);
|
2015-11-10 12:28:23 +03:00
|
|
|
GroupList.setUserCount($li, userCount + 1);
|
2014-07-08 22:05:51 +04:00
|
|
|
}
|
|
|
|
GroupList.incEveryoneCount();
|
|
|
|
UserList.getRow(uid).show();
|
|
|
|
},
|
2014-05-06 06:41:54 +04:00
|
|
|
has: function(uid) {
|
2014-05-06 18:52:14 +04:00
|
|
|
return UserList.getRow(uid).length > 0;
|
|
|
|
},
|
|
|
|
getRow: function(uid) {
|
|
|
|
return $userListBody.find('tr').filter(function(){
|
|
|
|
return UserList.getUID(this) === uid;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getUID: function(element) {
|
|
|
|
return ($(element).closest('tr').data('uid') || '').toString();
|
|
|
|
},
|
|
|
|
getDisplayName: function(element) {
|
|
|
|
return ($(element).closest('tr').data('displayname') || '').toString();
|
2014-02-26 21:04:55 +04:00
|
|
|
},
|
2014-12-15 14:43:42 +03:00
|
|
|
getMailAddress: function(element) {
|
|
|
|
return ($(element).closest('tr').data('mailAddress') || '').toString();
|
|
|
|
},
|
2015-01-23 19:45:45 +03:00
|
|
|
getRestoreDisabled: function(element) {
|
|
|
|
return ($(element).closest('tr').data('restoreDisabled') || '');
|
|
|
|
},
|
2014-02-26 21:04:55 +04:00
|
|
|
initDeleteHandling: function() {
|
|
|
|
//set up handler
|
2014-12-04 16:15:55 +03:00
|
|
|
UserDeleteHandler = new DeleteHandler('/settings/users/users', 'username',
|
2014-07-08 22:05:51 +04:00
|
|
|
UserList.markRemove, UserList.remove);
|
2014-02-26 21:04:55 +04:00
|
|
|
|
|
|
|
//configure undo
|
|
|
|
OC.Notification.hide();
|
2014-06-05 22:30:20 +04:00
|
|
|
var msg = escapeHTML(t('settings', 'deleted {userName}', {userName: '%oid'})) + '<span class="undo">' +
|
|
|
|
escapeHTML(t('settings', 'undo')) + '</span>';
|
2014-02-26 21:04:55 +04:00
|
|
|
UserDeleteHandler.setNotification(OC.Notification, 'deleteuser', msg,
|
2014-07-08 22:05:51 +04:00
|
|
|
UserList.undoRemove);
|
2014-02-26 21:04:55 +04:00
|
|
|
|
|
|
|
//when to mark user for delete
|
2014-05-06 06:41:54 +04:00
|
|
|
$userListBody.on('click', '.delete', function () {
|
2014-02-26 21:04:55 +04:00
|
|
|
// Call function for handling delete/undo
|
2014-05-06 18:52:14 +04:00
|
|
|
var uid = UserList.getUID(this);
|
2014-02-26 21:04:55 +04:00
|
|
|
UserDeleteHandler.mark(uid);
|
|
|
|
});
|
|
|
|
|
|
|
|
//delete a marked user when leaving the page
|
|
|
|
$(window).on('beforeunload', function () {
|
2014-07-17 15:13:03 +04:00
|
|
|
UserDeleteHandler.deleteEntry();
|
2014-02-26 21:04:55 +04:00
|
|
|
});
|
|
|
|
},
|
2014-12-12 19:58:01 +03:00
|
|
|
update: function (gid, limit) {
|
2013-03-19 05:48:08 +04:00
|
|
|
if (UserList.updating) {
|
|
|
|
return;
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2014-12-12 19:58:01 +03:00
|
|
|
if(!limit) {
|
|
|
|
limit = UserList.usersToLoad;
|
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
$userList.siblings('.loading').css('visibility', 'visible');
|
2013-03-19 05:48:08 +04:00
|
|
|
UserList.updating = true;
|
2014-02-19 14:40:07 +04:00
|
|
|
if(gid === undefined) {
|
|
|
|
gid = '';
|
|
|
|
}
|
2014-02-20 21:42:03 +04:00
|
|
|
UserList.currentGid = gid;
|
2015-08-05 18:29:20 +03:00
|
|
|
var pattern = this.filter;
|
2014-05-06 06:41:54 +04:00
|
|
|
$.get(
|
2014-12-04 16:15:55 +03:00
|
|
|
OC.generateUrl('/settings/users/users'),
|
2014-12-12 19:58:01 +03:00
|
|
|
{ offset: UserList.offset, limit: limit, gid: gid, pattern: pattern },
|
2014-05-06 06:41:54 +04:00
|
|
|
function (result) {
|
|
|
|
var loadedUsers = 0;
|
|
|
|
var trs = [];
|
Expose backend type via REST API
This change will expose the user backend via the REST API which is a pre-requisite for https://github.com/owncloud/core/issues/12620.
For example:
````json
[{"name":"9707A09E-CA9A-4ABE-A66A-3F632F16C409","displayname":"Document Conversion User Account","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/9707A09E-CA9A-4ABE-A66A-3F632F16C409","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"ED86733E-745C-4E4D-90CB-278A9737DB3C","displayname":"Hacker","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/ED86733E-745C-4E4D-90CB-278A9737DB3C","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"71CDF45B-E125-450D-983C-D9192F36EC88","displayname":"admin","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/71CDF45B-E125-450D-983C-D9192F36EC88","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"admin","displayname":"admin","groups":["admin"],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/admin","lastLogin":"1418057287","backend":"OC_User_Database"},{"name":"test","displayname":"test","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/test","lastLogin":0,"backend":"OC_User_Database"}]
```
2014-12-09 00:38:54 +03:00
|
|
|
//The offset does not mirror the amount of users available,
|
|
|
|
//because it is backend-dependent. For correct retrieval,
|
|
|
|
//always the limit(requested amount of users) needs to be added.
|
|
|
|
$.each(result, function (index, user) {
|
|
|
|
if(UserList.has(user.name)) {
|
|
|
|
return true;
|
2013-03-19 05:48:08 +04:00
|
|
|
}
|
2014-12-15 14:43:42 +03:00
|
|
|
var $tr = UserList.add(user, user.lastLogin, false, user.backend);
|
Expose backend type via REST API
This change will expose the user backend via the REST API which is a pre-requisite for https://github.com/owncloud/core/issues/12620.
For example:
````json
[{"name":"9707A09E-CA9A-4ABE-A66A-3F632F16C409","displayname":"Document Conversion User Account","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/9707A09E-CA9A-4ABE-A66A-3F632F16C409","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"ED86733E-745C-4E4D-90CB-278A9737DB3C","displayname":"Hacker","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/ED86733E-745C-4E4D-90CB-278A9737DB3C","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"71CDF45B-E125-450D-983C-D9192F36EC88","displayname":"admin","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/71CDF45B-E125-450D-983C-D9192F36EC88","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"admin","displayname":"admin","groups":["admin"],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/admin","lastLogin":"1418057287","backend":"OC_User_Database"},{"name":"test","displayname":"test","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/test","lastLogin":0,"backend":"OC_User_Database"}]
```
2014-12-09 00:38:54 +03:00
|
|
|
trs.push($tr);
|
|
|
|
loadedUsers++;
|
|
|
|
});
|
|
|
|
if (result.length > 0) {
|
|
|
|
UserList.doSort();
|
|
|
|
$userList.siblings('.loading').css('visibility', 'hidden');
|
2014-12-12 19:58:01 +03:00
|
|
|
// reset state on load
|
|
|
|
UserList.noMoreEntries = false;
|
Expose backend type via REST API
This change will expose the user backend via the REST API which is a pre-requisite for https://github.com/owncloud/core/issues/12620.
For example:
````json
[{"name":"9707A09E-CA9A-4ABE-A66A-3F632F16C409","displayname":"Document Conversion User Account","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/9707A09E-CA9A-4ABE-A66A-3F632F16C409","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"ED86733E-745C-4E4D-90CB-278A9737DB3C","displayname":"Hacker","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/ED86733E-745C-4E4D-90CB-278A9737DB3C","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"71CDF45B-E125-450D-983C-D9192F36EC88","displayname":"admin","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/71CDF45B-E125-450D-983C-D9192F36EC88","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"admin","displayname":"admin","groups":["admin"],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/admin","lastLogin":"1418057287","backend":"OC_User_Database"},{"name":"test","displayname":"test","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/test","lastLogin":0,"backend":"OC_User_Database"}]
```
2014-12-09 00:38:54 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
UserList.noMoreEntries = true;
|
|
|
|
$userList.siblings('.loading').remove();
|
2014-05-06 06:41:54 +04:00
|
|
|
}
|
2015-02-04 19:19:11 +03:00
|
|
|
UserList.offset += limit;
|
Expose backend type via REST API
This change will expose the user backend via the REST API which is a pre-requisite for https://github.com/owncloud/core/issues/12620.
For example:
````json
[{"name":"9707A09E-CA9A-4ABE-A66A-3F632F16C409","displayname":"Document Conversion User Account","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/9707A09E-CA9A-4ABE-A66A-3F632F16C409","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"ED86733E-745C-4E4D-90CB-278A9737DB3C","displayname":"Hacker","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/ED86733E-745C-4E4D-90CB-278A9737DB3C","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"71CDF45B-E125-450D-983C-D9192F36EC88","displayname":"admin","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/71CDF45B-E125-450D-983C-D9192F36EC88","lastLogin":0,"backend":"OCA\\user_ldap\\USER_LDAP"},{"name":"admin","displayname":"admin","groups":["admin"],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/admin","lastLogin":"1418057287","backend":"OC_User_Database"},{"name":"test","displayname":"test","groups":[],"subadmin":[],"quota":"default","storageLocation":"\/Users\/lreschke\/Programming\/core\/data\/test","lastLogin":0,"backend":"OC_User_Database"}]
```
2014-12-09 00:38:54 +03:00
|
|
|
}).always(function() {
|
2014-05-06 06:41:54 +04:00
|
|
|
UserList.updating = false;
|
2014-07-09 18:36:51 +04:00
|
|
|
});
|
2013-02-11 18:18:14 +04:00
|
|
|
},
|
2012-12-20 12:59:09 +04:00
|
|
|
|
2014-05-06 06:41:54 +04:00
|
|
|
applyGroupSelect: function (element) {
|
2013-02-11 18:18:14 +04:00
|
|
|
var checked = [];
|
2014-05-06 06:41:54 +04:00
|
|
|
var $element = $(element);
|
2014-05-06 18:52:14 +04:00
|
|
|
var user = UserList.getUID($element);
|
2014-05-06 06:41:54 +04:00
|
|
|
|
|
|
|
if ($element.data('user-groups')) {
|
2014-07-15 15:44:41 +04:00
|
|
|
if (typeof $element.data('user-groups') === 'string') {
|
2014-07-15 09:52:04 +04:00
|
|
|
checked = $element.data('user-groups').split(", ");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
checked = $element.data('user-groups');
|
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
}
|
2014-05-06 18:52:14 +04:00
|
|
|
var checkHandler = null;
|
|
|
|
if(user) { // Only if in a user row, and not the #newusergroups select
|
|
|
|
checkHandler = function (group) {
|
|
|
|
if (user === OC.currentUser && group === 'admin') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!oc_isadmin && checked.length === 1 && checked[0] === group) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$.post(
|
|
|
|
OC.filePath('settings', 'ajax', 'togglegroups.php'),
|
|
|
|
{
|
|
|
|
username: user,
|
|
|
|
group: group
|
|
|
|
},
|
|
|
|
function (response) {
|
|
|
|
if (response.status === 'success') {
|
|
|
|
GroupList.update();
|
2014-07-09 18:48:26 +04:00
|
|
|
var groupName = response.data.groupname;
|
|
|
|
if (UserList.availableGroups.indexOf(groupName) === -1 &&
|
2014-05-06 18:52:14 +04:00
|
|
|
response.data.action === 'add'
|
|
|
|
) {
|
2014-07-09 18:48:26 +04:00
|
|
|
UserList.availableGroups.push(groupName);
|
2014-05-06 18:52:14 +04:00
|
|
|
}
|
2014-07-09 17:29:38 +04:00
|
|
|
|
2015-10-02 09:55:53 +03:00
|
|
|
if (response.data.action === 'add') {
|
|
|
|
GroupList.incGroupCount(groupName);
|
|
|
|
} else {
|
|
|
|
GroupList.decGroupCount(groupName);
|
|
|
|
}
|
2014-05-06 18:52:14 +04:00
|
|
|
}
|
|
|
|
if (response.data.message) {
|
|
|
|
OC.Notification.show(response.data.message);
|
2014-05-06 06:41:54 +04:00
|
|
|
}
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2014-05-06 18:52:14 +04:00
|
|
|
);
|
2014-07-09 16:30:28 +04:00
|
|
|
};
|
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
var addGroup = function (select, group) {
|
|
|
|
$('select[multiple]').each(function (index, element) {
|
|
|
|
$element = $(element);
|
2014-07-09 18:52:52 +04:00
|
|
|
if ($element.find('option').filterAttr('value', group).length === 0 &&
|
2014-07-09 18:36:51 +04:00
|
|
|
select.data('msid') !== $element.data('msid')) {
|
2014-05-06 06:41:54 +04:00
|
|
|
$element.append('<option value="' + escapeHTML(group) + '">' + escapeHTML(group) + '</option>');
|
|
|
|
}
|
2013-02-11 18:18:14 +04:00
|
|
|
});
|
2014-05-06 06:41:54 +04:00
|
|
|
GroupList.addGroup(escapeHTML(group));
|
|
|
|
};
|
|
|
|
var label;
|
|
|
|
if (oc_isadmin) {
|
|
|
|
label = t('settings', 'add group');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
label = null;
|
|
|
|
}
|
|
|
|
$element.multiSelect({
|
|
|
|
createCallback: addGroup,
|
|
|
|
createText: label,
|
|
|
|
selectedFirst: true,
|
|
|
|
checked: checked,
|
|
|
|
oncheck: checkHandler,
|
|
|
|
onuncheck: checkHandler,
|
|
|
|
minWidth: 100
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
applySubadminSelect: function (element) {
|
|
|
|
var checked = [];
|
|
|
|
var $element = $(element);
|
2014-05-06 18:52:14 +04:00
|
|
|
var user = UserList.getUID($element);
|
2014-05-06 06:41:54 +04:00
|
|
|
|
|
|
|
if ($element.data('subadmin')) {
|
2014-07-15 15:44:41 +04:00
|
|
|
if (typeof $element.data('subadmin') === 'string') {
|
2014-07-15 09:52:04 +04:00
|
|
|
checked = $element.data('subadmin').split(", ");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
checked = $element.data('subadmin');
|
|
|
|
}
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
var checkHandler = function (group) {
|
|
|
|
if (group === 'admin') {
|
|
|
|
return false;
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
$.post(
|
|
|
|
OC.filePath('settings', 'ajax', 'togglesubadmins.php'),
|
|
|
|
{
|
|
|
|
username: user,
|
|
|
|
group: group
|
|
|
|
},
|
|
|
|
function () {
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
);
|
|
|
|
};
|
2012-12-20 12:59:09 +04:00
|
|
|
|
2014-05-06 06:41:54 +04:00
|
|
|
var addSubAdmin = function (group) {
|
|
|
|
$('select[multiple]').each(function (index, element) {
|
2014-07-09 18:52:52 +04:00
|
|
|
if ($(element).find('option').filterAttr('value', group).length === 0) {
|
2014-05-06 06:41:54 +04:00
|
|
|
$(element).append('<option value="' + escapeHTML(group) + '">' + escapeHTML(group) + '</option>');
|
|
|
|
}
|
2013-02-11 18:18:14 +04:00
|
|
|
});
|
2014-05-06 06:41:54 +04:00
|
|
|
};
|
|
|
|
$element.multiSelect({
|
|
|
|
createCallback: addSubAdmin,
|
|
|
|
createText: null,
|
|
|
|
checked: checked,
|
|
|
|
oncheck: checkHandler,
|
|
|
|
onuncheck: checkHandler,
|
|
|
|
minWidth: 100
|
|
|
|
});
|
2014-02-03 21:00:39 +04:00
|
|
|
},
|
|
|
|
|
2014-05-06 18:52:14 +04:00
|
|
|
_onScroll: function() {
|
2014-02-03 21:00:39 +04:00
|
|
|
if (!!UserList.noMoreEntries) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-20 21:42:03 +04:00
|
|
|
if (UserList.scrollArea.scrollTop() + UserList.scrollArea.height() > UserList.scrollArea.get(0).scrollHeight - 500) {
|
2014-12-12 19:58:01 +03:00
|
|
|
UserList.update(UserList.currentGid);
|
2014-02-03 21:00:39 +04:00
|
|
|
}
|
2014-08-11 18:37:48 +04:00
|
|
|
},
|
2012-08-12 00:01:43 +04:00
|
|
|
|
2014-08-11 18:37:48 +04:00
|
|
|
/**
|
|
|
|
* Event handler for when a quota has been changed through a single select.
|
|
|
|
* This will save the value.
|
|
|
|
*/
|
|
|
|
onQuotaSelect: function(ev) {
|
|
|
|
var $select = $(ev.target);
|
|
|
|
var uid = UserList.getUID($select);
|
|
|
|
var quota = $select.val();
|
|
|
|
UserList._updateQuota(uid, quota, function(returnedQuota){
|
|
|
|
if (quota !== returnedQuota) {
|
|
|
|
$select.find(':selected').text(returnedQuota);
|
2014-02-19 11:44:18 +04:00
|
|
|
}
|
2014-08-11 18:37:48 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the quota for the given user
|
|
|
|
* @param {String} [uid] optional user id, sets default quota if empty
|
|
|
|
* @param {String} quota quota value
|
|
|
|
* @param {Function} ready callback after save
|
|
|
|
*/
|
|
|
|
_updateQuota: function(uid, quota, ready) {
|
|
|
|
$.post(
|
|
|
|
OC.filePath('settings', 'ajax', 'setquota.php'),
|
|
|
|
{username: uid, quota: quota},
|
|
|
|
function (result) {
|
|
|
|
if (ready) {
|
|
|
|
ready(result.data.quota);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2014-02-19 11:44:18 +04:00
|
|
|
|
2012-12-20 12:59:09 +04:00
|
|
|
$(document).ready(function () {
|
2014-05-06 06:41:54 +04:00
|
|
|
$userList = $('#userlist');
|
|
|
|
$userListBody = $userList.find('tbody');
|
|
|
|
|
2014-02-26 21:04:55 +04:00
|
|
|
UserList.initDeleteHandling();
|
2012-12-20 12:59:09 +04:00
|
|
|
|
2014-04-17 22:14:51 +04:00
|
|
|
// Implements User Search
|
2015-08-05 18:29:20 +03:00
|
|
|
OCA.Search.users= new UserManagementFilter(UserList, GroupList);
|
2014-04-17 22:14:51 +04:00
|
|
|
|
2013-03-19 05:48:08 +04:00
|
|
|
UserList.doSort();
|
2014-05-06 06:41:54 +04:00
|
|
|
UserList.availableGroups = $userList.data('groups');
|
2014-04-01 17:59:53 +04:00
|
|
|
|
|
|
|
UserList.scrollArea = $('#app-content');
|
|
|
|
UserList.scrollArea.scroll(function(e) {UserList._onScroll(e);});
|
|
|
|
|
2014-05-06 06:41:54 +04:00
|
|
|
$userList.after($('<div class="loading" style="height: 200px; visibility: hidden;"></div>'));
|
2012-12-20 12:59:09 +04:00
|
|
|
|
2014-08-11 18:37:48 +04:00
|
|
|
// TODO: move other init calls inside of initialize
|
|
|
|
UserList.initialize($('#userlist'));
|
|
|
|
|
2014-05-06 06:41:54 +04:00
|
|
|
$('.groupsselect').each(function (index, element) {
|
|
|
|
UserList.applyGroupSelect(element);
|
|
|
|
});
|
|
|
|
$('.subadminsselect').each(function (index, element) {
|
|
|
|
UserList.applySubadminSelect(element);
|
2013-02-11 18:18:14 +04:00
|
|
|
});
|
2012-12-20 12:59:09 +04:00
|
|
|
|
2014-05-06 06:41:54 +04:00
|
|
|
$userListBody.on('click', '.password', function (event) {
|
2013-02-11 18:18:14 +04:00
|
|
|
event.stopPropagation();
|
2014-05-06 06:41:54 +04:00
|
|
|
|
|
|
|
var $td = $(this).closest('td');
|
2015-01-23 19:45:45 +03:00
|
|
|
var $tr = $(this).closest('tr');
|
2014-05-06 18:52:14 +04:00
|
|
|
var uid = UserList.getUID($td);
|
2014-05-06 06:41:54 +04:00
|
|
|
var $input = $('<input type="password">');
|
2015-01-23 19:45:45 +03:00
|
|
|
var isRestoreDisabled = UserList.getRestoreDisabled($td) === true;
|
|
|
|
if(isRestoreDisabled) {
|
|
|
|
$tr.addClass('row-warning');
|
|
|
|
// add tipsy if the password change could cause data loss - no recovery enabled
|
2015-04-15 13:25:10 +03:00
|
|
|
$input.tipsy({gravity:'s'});
|
2015-01-23 19:45:45 +03:00
|
|
|
$input.attr('title', t('settings', 'Changing the password will result in data loss, because data recovery is not available for this user'));
|
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
$td.find('img').hide();
|
|
|
|
$td.children('span').replaceWith($input);
|
|
|
|
$input
|
|
|
|
.focus()
|
|
|
|
.keypress(function (event) {
|
|
|
|
if (event.keyCode === 13) {
|
|
|
|
if ($(this).val().length > 0) {
|
|
|
|
var recoveryPasswordVal = $('input:password[id="recoveryPassword"]').val();
|
|
|
|
$.post(
|
|
|
|
OC.generateUrl('/settings/users/changepassword'),
|
|
|
|
{username: uid, password: $(this).val(), recoveryPassword: recoveryPasswordVal},
|
|
|
|
function (result) {
|
|
|
|
if (result.status != 'success') {
|
|
|
|
OC.Notification.show(t('admin', result.data.message));
|
|
|
|
}
|
2013-05-16 17:19:53 +04:00
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
);
|
|
|
|
$input.blur();
|
|
|
|
} else {
|
|
|
|
$input.blur();
|
|
|
|
}
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
})
|
|
|
|
.blur(function () {
|
|
|
|
$(this).replaceWith($('<span>●●●●●●●</span>'));
|
|
|
|
$td.find('img').show();
|
2015-01-23 19:45:45 +03:00
|
|
|
// remove highlight class from users without recovery ability
|
|
|
|
$tr.removeClass('row-warning');
|
2014-05-06 06:41:54 +04:00
|
|
|
});
|
2013-02-11 18:18:14 +04:00
|
|
|
});
|
2014-05-06 06:41:54 +04:00
|
|
|
$('input:password[id="recoveryPassword"]').keyup(function() {
|
2013-05-16 18:01:40 +04:00
|
|
|
OC.Notification.hide();
|
|
|
|
});
|
|
|
|
|
2014-05-06 06:41:54 +04:00
|
|
|
$userListBody.on('click', '.displayName', function (event) {
|
2013-02-11 18:18:14 +04:00
|
|
|
event.stopPropagation();
|
2014-05-06 06:41:54 +04:00
|
|
|
var $td = $(this).closest('td');
|
|
|
|
var $tr = $td.closest('tr');
|
2014-05-06 18:52:14 +04:00
|
|
|
var uid = UserList.getUID($td);
|
|
|
|
var displayName = escapeHTML(UserList.getDisplayName($td));
|
2014-05-06 06:41:54 +04:00
|
|
|
var $input = $('<input type="text" value="' + displayName + '">');
|
|
|
|
$td.find('img').hide();
|
|
|
|
$td.children('span').replaceWith($input);
|
|
|
|
$input
|
|
|
|
.focus()
|
|
|
|
.keypress(function (event) {
|
|
|
|
if (event.keyCode === 13) {
|
|
|
|
if ($(this).val().length > 0) {
|
2014-10-07 13:09:07 +04:00
|
|
|
var $div = $tr.find('div.avatardiv');
|
2014-10-07 12:44:36 +04:00
|
|
|
if ($div.length) {
|
|
|
|
$div.imageplaceholder(uid, displayName);
|
2014-10-06 10:53:12 +04:00
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
$.post(
|
2015-11-09 00:08:19 +03:00
|
|
|
OC.generateUrl('/settings/users/{id}/displayName', {id: uid}),
|
2014-05-06 06:41:54 +04:00
|
|
|
{username: uid, displayName: $(this).val()},
|
|
|
|
function (result) {
|
2014-10-07 12:44:36 +04:00
|
|
|
if (result && result.status==='success' && $div.length){
|
|
|
|
$div.avatar(result.data.username, 32);
|
2014-05-06 06:41:54 +04:00
|
|
|
}
|
2013-10-07 19:00:15 +04:00
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
);
|
|
|
|
$input.blur();
|
|
|
|
} else {
|
|
|
|
$input.blur();
|
|
|
|
}
|
2013-02-11 18:18:14 +04:00
|
|
|
}
|
2014-05-06 06:41:54 +04:00
|
|
|
})
|
|
|
|
.blur(function () {
|
|
|
|
var displayName = $input.val();
|
|
|
|
$tr.data('displayname', displayName);
|
|
|
|
$input.replaceWith('<span>' + escapeHTML(displayName) + '</span>');
|
|
|
|
$td.find('img').show();
|
|
|
|
});
|
2013-02-11 18:18:14 +04:00
|
|
|
});
|
2012-08-12 00:01:43 +04:00
|
|
|
|
2014-12-15 14:43:42 +03:00
|
|
|
$userListBody.on('click', '.mailAddress', function (event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
var $td = $(this).closest('td');
|
|
|
|
var $tr = $td.closest('tr');
|
|
|
|
var uid = UserList.getUID($td);
|
|
|
|
var mailAddress = escapeHTML(UserList.getMailAddress($td));
|
|
|
|
var $input = $('<input type="text">').val(mailAddress);
|
|
|
|
$td.children('span').replaceWith($input);
|
|
|
|
$input
|
|
|
|
.focus()
|
|
|
|
.keypress(function (event) {
|
|
|
|
if (event.keyCode === 13) {
|
|
|
|
if ($(this).val().length > 0) {
|
|
|
|
$input.blur();
|
|
|
|
$.ajax({
|
|
|
|
type: 'PUT',
|
|
|
|
url: OC.generateUrl('/settings/users/{id}/mailAddress', {id: uid}),
|
|
|
|
data: {
|
|
|
|
mailAddress: $(this).val()
|
|
|
|
}
|
|
|
|
}).fail(function (result) {
|
|
|
|
OC.Notification.show(result.responseJSON.data.message);
|
|
|
|
// reset the values
|
|
|
|
$tr.data('mailAddress', mailAddress);
|
|
|
|
$tr.children('.mailAddress').children('span').text(mailAddress);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$input.blur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.blur(function () {
|
|
|
|
var mailAddress = $input.val();
|
|
|
|
var $span = $('<span>').text(mailAddress);
|
|
|
|
$tr.data('mailAddress', mailAddress);
|
|
|
|
$input.replaceWith($span);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-08-11 18:37:48 +04:00
|
|
|
// init the quota field select box after it is shown the first time
|
|
|
|
$('#app-settings').one('show', function() {
|
|
|
|
$(this).find('#default_quota').singleSelect().on('change', UserList.onQuotaSelect);
|
2013-02-11 18:18:14 +04:00
|
|
|
});
|
2012-08-12 00:01:43 +04:00
|
|
|
|
2013-02-11 18:18:14 +04:00
|
|
|
$('#newuser').submit(function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var username = $('#newusername').val();
|
|
|
|
var password = $('#newuserpassword').val();
|
2014-12-16 11:08:38 +03:00
|
|
|
var email = $('#newemail').val();
|
2013-04-17 17:32:03 +04:00
|
|
|
if ($.trim(username) === '') {
|
2013-02-11 18:18:14 +04:00
|
|
|
OC.dialogs.alert(
|
|
|
|
t('settings', 'A valid username must be provided'),
|
|
|
|
t('settings', 'Error creating user'));
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-17 17:32:03 +04:00
|
|
|
if ($.trim(password) === '') {
|
2013-02-11 18:18:14 +04:00
|
|
|
OC.dialogs.alert(
|
|
|
|
t('settings', 'A valid password must be provided'),
|
|
|
|
t('settings', 'Error creating user'));
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-16 11:08:38 +03:00
|
|
|
if(!$('#CheckboxMailOnUserCreate').is(':checked')) {
|
|
|
|
email = '';
|
|
|
|
}
|
|
|
|
if ($('#CheckboxMailOnUserCreate').is(':checked') && $.trim(email) === '') {
|
|
|
|
OC.dialogs.alert(
|
|
|
|
t('settings', 'A valid email must be provided'),
|
|
|
|
t('settings', 'Error creating user'));
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-07 17:17:38 +03:00
|
|
|
|
|
|
|
var promise;
|
|
|
|
if (UserDeleteHandler) {
|
|
|
|
promise = UserDeleteHandler.deleteEntry();
|
|
|
|
} else {
|
|
|
|
promise = $.Deferred().resolve().promise();
|
|
|
|
}
|
|
|
|
|
|
|
|
promise.then(function() {
|
|
|
|
var groups = $('#newusergroups').val() || [];
|
|
|
|
$.post(
|
|
|
|
OC.generateUrl('/settings/users/users'),
|
|
|
|
{
|
|
|
|
username: username,
|
|
|
|
password: password,
|
|
|
|
groups: groups,
|
|
|
|
email: email
|
|
|
|
},
|
|
|
|
function (result) {
|
|
|
|
if (result.groups) {
|
|
|
|
for (var i in result.groups) {
|
|
|
|
var gid = result.groups[i];
|
|
|
|
if(UserList.availableGroups.indexOf(gid) === -1) {
|
|
|
|
UserList.availableGroups.push(gid);
|
|
|
|
}
|
|
|
|
$li = GroupList.getGroupLI(gid);
|
|
|
|
userCount = GroupList.getUserCount($li);
|
|
|
|
GroupList.setUserCount($li, userCount + 1);
|
2014-07-05 03:21:18 +04:00
|
|
|
}
|
2013-07-03 23:06:09 +04:00
|
|
|
}
|
2015-10-07 17:17:38 +03:00
|
|
|
if(!UserList.has(username)) {
|
|
|
|
UserList.add(result, true);
|
|
|
|
}
|
|
|
|
$('#newusername').focus();
|
|
|
|
GroupList.incEveryoneCount();
|
|
|
|
}).fail(function(result, textStatus, errorThrown) {
|
|
|
|
OC.dialogs.alert(result.responseJSON.message, t('settings', 'Error creating user'));
|
|
|
|
}).success(function(){
|
|
|
|
$('#newuser').get(0).reset();
|
|
|
|
});
|
|
|
|
});
|
2013-02-11 18:18:14 +04:00
|
|
|
});
|
2014-04-17 22:14:51 +04:00
|
|
|
|
2015-09-25 07:24:08 +03:00
|
|
|
if ($('#CheckboxStorageLocation').is(':checked')) {
|
|
|
|
$("#userlist .storageLocation").show();
|
|
|
|
}
|
2014-07-17 00:23:15 +04:00
|
|
|
// Option to display/hide the "Storage location" column
|
|
|
|
$('#CheckboxStorageLocation').click(function() {
|
|
|
|
if ($('#CheckboxStorageLocation').is(':checked')) {
|
2014-12-12 12:21:50 +03:00
|
|
|
$("#userlist .storageLocation").show();
|
2015-09-25 07:24:08 +03:00
|
|
|
OC.AppConfig.setValue('core', 'umgmt_show_storage_location', 'true');
|
2014-07-17 00:23:15 +04:00
|
|
|
} else {
|
2014-12-12 12:21:50 +03:00
|
|
|
$("#userlist .storageLocation").hide();
|
2015-09-25 07:24:08 +03:00
|
|
|
OC.AppConfig.setValue('core', 'umgmt_show_storage_location', 'false');
|
2014-07-17 00:23:15 +04:00
|
|
|
}
|
|
|
|
});
|
2015-09-25 07:24:08 +03:00
|
|
|
|
|
|
|
if ($('#CheckboxLastLogin').is(':checked')) {
|
|
|
|
$("#userlist .lastLogin").show();
|
|
|
|
}
|
2014-07-17 00:23:15 +04:00
|
|
|
// Option to display/hide the "Last Login" column
|
|
|
|
$('#CheckboxLastLogin').click(function() {
|
|
|
|
if ($('#CheckboxLastLogin').is(':checked')) {
|
2014-12-12 12:21:50 +03:00
|
|
|
$("#userlist .lastLogin").show();
|
2015-09-25 07:24:08 +03:00
|
|
|
OC.AppConfig.setValue('core', 'umgmt_show_last_login', 'true');
|
2014-12-12 12:21:50 +03:00
|
|
|
} else {
|
|
|
|
$("#userlist .lastLogin").hide();
|
2015-09-25 07:24:08 +03:00
|
|
|
OC.AppConfig.setValue('core', 'umgmt_show_last_login', 'false');
|
2014-12-12 12:21:50 +03:00
|
|
|
}
|
|
|
|
});
|
2015-09-25 07:24:08 +03:00
|
|
|
|
|
|
|
if ($('#CheckboxEmailAddress').is(':checked')) {
|
|
|
|
$("#userlist .mailAddress").show();
|
|
|
|
}
|
2014-12-15 14:43:42 +03:00
|
|
|
// Option to display/hide the "Mail Address" column
|
|
|
|
$('#CheckboxEmailAddress').click(function() {
|
|
|
|
if ($('#CheckboxEmailAddress').is(':checked')) {
|
|
|
|
$("#userlist .mailAddress").show();
|
2015-09-25 07:24:08 +03:00
|
|
|
OC.AppConfig.setValue('core', 'umgmt_show_email', 'true');
|
2014-12-15 14:43:42 +03:00
|
|
|
} else {
|
|
|
|
$("#userlist .mailAddress").hide();
|
2015-09-25 07:24:08 +03:00
|
|
|
OC.AppConfig.setValue('core', 'umgmt_show_email', 'false');
|
2014-12-15 14:43:42 +03:00
|
|
|
}
|
|
|
|
});
|
2015-09-25 07:24:08 +03:00
|
|
|
|
|
|
|
if ($('#CheckboxUserBackend').is(':checked')) {
|
|
|
|
$("#userlist .userBackend").show();
|
|
|
|
}
|
2014-12-15 14:43:42 +03:00
|
|
|
// Option to display/hide the "User Backend" column
|
2014-12-12 12:21:50 +03:00
|
|
|
$('#CheckboxUserBackend').click(function() {
|
|
|
|
if ($('#CheckboxUserBackend').is(':checked')) {
|
|
|
|
$("#userlist .userBackend").show();
|
2015-09-25 07:24:08 +03:00
|
|
|
OC.AppConfig.setValue('core', 'umgmt_show_backend', 'true');
|
2014-07-17 00:23:15 +04:00
|
|
|
} else {
|
2014-12-12 12:21:50 +03:00
|
|
|
$("#userlist .userBackend").hide();
|
2015-09-25 07:24:08 +03:00
|
|
|
OC.AppConfig.setValue('core', 'umgmt_show_backend', 'false');
|
2014-07-17 00:23:15 +04:00
|
|
|
}
|
|
|
|
});
|
2015-09-25 07:24:08 +03:00
|
|
|
|
|
|
|
if ($('#CheckboxMailOnUserCreate').is(':checked')) {
|
|
|
|
$("#newemail").show();
|
|
|
|
}
|
2014-12-16 11:08:38 +03:00
|
|
|
// Option to display/hide the "E-Mail" input field
|
|
|
|
$('#CheckboxMailOnUserCreate').click(function() {
|
|
|
|
if ($('#CheckboxMailOnUserCreate').is(':checked')) {
|
|
|
|
$("#newemail").show();
|
2015-09-25 07:24:08 +03:00
|
|
|
OC.AppConfig.setValue('core', 'umgmt_send_email', 'true');
|
2014-12-16 11:08:38 +03:00
|
|
|
} else {
|
|
|
|
$("#newemail").hide();
|
2015-09-25 07:24:08 +03:00
|
|
|
OC.AppConfig.setValue('core', 'umgmt_send_email', 'false');
|
2014-12-16 11:08:38 +03:00
|
|
|
}
|
|
|
|
});
|
2014-07-17 00:23:15 +04:00
|
|
|
|
2014-12-12 19:58:01 +03:00
|
|
|
// calculate initial limit of users to load
|
2015-10-28 13:18:10 +03:00
|
|
|
var initialUserCountLimit = UserList.initialUsersToLoad,
|
2014-12-12 19:58:01 +03:00
|
|
|
containerHeight = $('#app-content').height();
|
|
|
|
if(containerHeight > 40) {
|
|
|
|
initialUserCountLimit = Math.floor(containerHeight/40);
|
2015-10-28 13:18:10 +03:00
|
|
|
if (initialUserCountLimit < UserList.initialUsersToLoad) {
|
|
|
|
initialUserCountLimit = UserList.initialUsersToLoad;
|
2015-02-04 19:19:11 +03:00
|
|
|
}
|
2014-12-12 19:58:01 +03:00
|
|
|
}
|
2015-10-28 13:18:10 +03:00
|
|
|
//realign initialUserCountLimit with usersToLoad as a safeguard
|
|
|
|
while((initialUserCountLimit % UserList.usersToLoad) !== 0) {
|
|
|
|
// must be a multiple of this, otherwise LDAP freaks out.
|
|
|
|
// FIXME: solve this in LDAP backend in 8.1
|
|
|
|
initialUserCountLimit = initialUserCountLimit + 1;
|
|
|
|
}
|
2014-12-12 19:58:01 +03:00
|
|
|
|
2014-12-11 17:37:56 +03:00
|
|
|
// trigger loading of users on startup
|
2014-12-12 19:58:01 +03:00
|
|
|
UserList.update(UserList.currentGid, initialUserCountLimit);
|
2014-07-17 00:23:15 +04:00
|
|
|
|
2015-07-29 12:01:51 +03:00
|
|
|
_.defer(function() {
|
|
|
|
$('#app-content').trigger($.Event('apprendered'));
|
|
|
|
});
|
|
|
|
|
2011-08-09 17:25:18 +04:00
|
|
|
});
|