/** * Copyright (c) 2014, Arthur Schiwon * Copyright (c) 2014, Raghu Nayyar * Copyright (c) 2011, Robin Appelman * This file is licensed under the Affero General Public License version 3 or later. * See the COPYING-README file. */ var $userList; var $userListBody; var filter; var UserList = { availableGroups: [], offset: 30, //The first 30 users are there. No prob, if less in total. //hardcoded in settings/users.php usersToLoad: 10, //So many users will be loaded when user scrolls down currentGid: '', /** * 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); }, add: function (username, displayname, groups, subadmin, quota, storageLocation, lastLogin, sort) { var $tr = $userListBody.find('tr:first-child').clone(); var subAdminsEl; var subAdminSelect; var groupsSelect; if ($tr.find('div.avatardiv').length){ $tr.find('.avatardiv').imageplaceholder(username, displayname); $('div.avatardiv', $tr).avatar(username, 32); } $tr.data('uid', username); $tr.data('displayname', displayname); $tr.find('td.name').text(username); $tr.find('td.displayName > span').text(displayname); // make them look like the multiselect buttons // until they get time to really get initialized groupsSelect = $('') .data('username', username) .data('user-groups', groups); if ($tr.find('td.subadmins').length > 0) { subAdminSelect = $(''); $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)); } } ); $input.blur(); } else { $input.blur(); } } }) .blur(function () { $(this).replaceWith($('●●●●●●●')); $td.find('img').show(); }); }); $('input:password[id="recoveryPassword"]').keyup(function() { OC.Notification.hide(); }); $userListBody.on('click', '.displayName', function (event) { event.stopPropagation(); var $td = $(this).closest('td'); var $tr = $td.closest('tr'); var uid = UserList.getUID($td); var displayName = escapeHTML(UserList.getDisplayName($td)); var $input = $(''); $td.find('img').hide(); $td.children('span').replaceWith($input); $input .focus() .keypress(function (event) { if (event.keyCode === 13) { if ($(this).val().length > 0) { $tr.find('.avatardiv').imageplaceholder(uid, displayName); $.post( OC.filePath('settings', 'ajax', 'changedisplayname.php'), {username: uid, displayName: $(this).val()}, function (result) { if (result && result.status==='success'){ $tr.find('.avatardiv').avatar(result.data.username, 32); } } ); $input.blur(); } else { $input.blur(); } } }) .blur(function () { var displayName = $input.val(); $tr.data('displayname', displayName); $input.replaceWith('' + escapeHTML(displayName) + ''); $td.find('img').show(); }); }); // 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); }); $('#newuser').submit(function (event) { event.preventDefault(); var username = $('#newusername').val(); var password = $('#newuserpassword').val(); if ($.trim(username) === '') { OC.dialogs.alert( t('settings', 'A valid username must be provided'), t('settings', 'Error creating user')); return false; } if ($.trim(password) === '') { OC.dialogs.alert( t('settings', 'A valid password must be provided'), t('settings', 'Error creating user')); return false; } var groups = $('#newusergroups').val(); $('#newuser').get(0).reset(); $.post( OC.filePath('settings', 'ajax', 'createuser.php'), { username: username, password: password, groups: groups }, function (result) { if (result.status !== 'success') { OC.dialogs.alert(result.data.message, t('settings', 'Error creating user')); } else { if (result.data.groups) { var addedGroups = result.data.groups; for (var i in result.data.groups) { var gid = result.data.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); } } if (result.data.homeExists){ OC.Notification.hide(); OC.Notification.show(t('settings', 'Warning: Home directory for user "{user}" already exists', {user: result.data.username})); if (UserList.notificationTimeout){ window.clearTimeout(UserList.notificationTimeout); } UserList.notificationTimeout = window.setTimeout( function(){ OC.Notification.hide(); UserList.notificationTimeout = null; }, 10000); } if(!UserList.has(username)) { UserList.add(username, username, result.data.groups, null, 'default', result.data.storageLocation, 0, true); } $('#newusername').focus(); GroupList.incEveryoneCount(); } } ); }); });