diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-07-05 01:21:18 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-07-10 16:12:53 +0200 |
commit | a310415b098721809d7096e64016da3afcaf82dc (patch) | |
tree | 74024d29e728384f8f1aef82c7dfd1738e9f20be | |
parent | 10bac565516aab972c9a9bf31dd33127601d6939 (diff) | |
download | nextcloud-server-a310415b098721809d7096e64016da3afcaf82dc.tar.gz nextcloud-server-a310415b098721809d7096e64016da3afcaf82dc.zip |
increment group counters when a user is created
decrease user count in affected groups after user delete
increase/decrease everyone count on user creation/deletion
avoid global selector
-rw-r--r-- | settings/js/users/groups.js | 23 | ||||
-rw-r--r-- | settings/js/users/users.js | 51 | ||||
-rw-r--r-- | settings/templates/users/part.grouplist.php | 4 |
3 files changed, 68 insertions, 10 deletions
diff --git a/settings/js/users/groups.js b/settings/js/users/groups.js index dcaf593b886..e3acce5a4bf 100644 --- a/settings/js/users/groups.js +++ b/settings/js/users/groups.js @@ -10,6 +10,7 @@ var $userGroupList; var GroupList; GroupList = { activeGID: '', + everyoneGID: '_everyone', addGroup: function (gid, usercount) { var $li = $userGroupList.find('.isgroup:last-child').clone(); @@ -27,19 +28,37 @@ GroupList = { setUserCount: function (groupLiElement, usercount) { var $groupLiElement = $(groupLiElement); - if (usercount === undefined || usercount === 0) { + if (usercount === undefined || usercount === 0 || usercount < 0) { usercount = ''; } $groupLiElement.data('usercount', usercount); $groupLiElement.find('.usercount').text(usercount); }, + getUserCount: function ($groupLiElement) { + return parseInt($groupLiElement.data('usercount'), 10); + }, + + modEveryoneCount: function(diff) { + $li = GroupList.getGroupLI(GroupList.everyoneGID); + count = GroupList.getUserCount($li) + diff; + GroupList.setUserCount($li, count); + }, + + incEveryoneCount: function() { + GroupList.modEveryoneCount(1); + }, + + decEveryoneCount: function() { + GroupList.modEveryoneCount(-1); + }, + getCurrentGID: function () { return GroupList.activeGID; }, sortGroups: function () { - var lis = $('.isgroup').get(); + var lis = $userGroupList.find('.isgroup').get(); lis.sort(function (a, b) { return UserList.alphanum( diff --git a/settings/js/users/users.js b/settings/js/users/users.js index f84d67b75bc..60e1e1dd31f 100644 --- a/settings/js/users/users.js +++ b/settings/js/users/users.js @@ -91,8 +91,8 @@ var UserList = { } $tdLastLogin = $tr.find('td.lastLogin'); $tdLastLogin.text(lastLoginRel); - //tooltip makes it complicated … to not insert new HTML, we adjust the - //original title. We use a temporary div to get back the html that we + //tooltip makes it complicated … to not insert new HTML, we adjust the + //original title. We use a temporary div to get back the html that we //can pass later. It is also required to initialise tipsy. var tooltip = $('<div>').html($($tdLastLogin.attr('original-title')).text(lastLoginAbs)).html(); $tdLastLogin.tipsy({gravity:'s', fade:true, html:true}); @@ -237,9 +237,43 @@ var UserList = { show: function(uid) { UserList.getRow(uid).show(); }, + markRemove: function(uid) { + $tr = UserList.getRow(uid); + groups = $tr.find('.groups .groupsselect').val(); + for(i in groups) { + var gid = groups[i]; + $li = GroupList.getGroupLI(gid); + userCount = GroupList.getUserCount($li); + if(userCount == 1) { + newUserCount = ''; + } else { + newUserCount = userCount - 1; + } + GroupList.setUserCount($li, newUserCount); + } + GroupList.decEveryoneCount(); + UserList.hide(uid); + }, remove: function(uid) { UserList.getRow(uid).remove(); }, + undoRemove: function(uid) { + $tr = UserList.getRow(uid); + groups = $tr.find('.groups .groupsselect').val(); + for(i in groups) { + var gid = groups[i]; + $li = GroupList.getGroupLI(gid); + userCount = GroupList.getUserCount($li); + if(userCount == 1) { + newUserCount = ''; + } else { + newUserCount = userCount + 1; + } + GroupList.setUserCount($li, newUserCount); + } + GroupList.incEveryoneCount(); + UserList.getRow(uid).show(); + }, has: function(uid) { return UserList.getRow(uid).length > 0; }, @@ -257,14 +291,14 @@ var UserList = { initDeleteHandling: function() { //set up handler UserDeleteHandler = new DeleteHandler('removeuser.php', 'username', - UserList.hide, UserList.remove); + UserList.markRemove, UserList.remove); //configure undo OC.Notification.hide(); var msg = escapeHTML(t('settings', 'deleted {userName}', {userName: '%oid'})) + '<span class="undo">' + escapeHTML(t('settings', 'undo')) + '</span>'; UserDeleteHandler.setNotification(OC.Notification, 'deleteuser', msg, - UserList.show); + UserList.undoRemove); //when to mark user for delete $userListBody.on('click', '.delete', function () { @@ -468,11 +502,9 @@ $(document).ready(function () { UserList.doSort(); UserList.availableGroups = $userList.data('groups'); - UserList.scrollArea = $('#app-content'); UserList.scrollArea.scroll(function(e) {UserList._onScroll(e);}); - $userList.after($('<div class="loading" style="height: 200px; visibility: hidden;"></div>')); $('.groupsselect').each(function (index, element) { @@ -602,6 +634,12 @@ $(document).ready(function () { if (result.data.groups) { var addedGroups = result.data.groups; UserList.availableGroups = $.unique($.merge(UserList.availableGroups, addedGroups)); + for (i in result.data.groups) { + var gid = result.data.groups[i]; + $li = GroupList.getGroupLI(gid); + userCount = GroupList.getUserCount($li); + GroupList.setUserCount($li, userCount + 1); + } } if (result.data.homeExists){ OC.Notification.hide(); @@ -619,6 +657,7 @@ $(document).ready(function () { UserList.add(username, username, result.data.groups, null, 'default', result.data.storageLocation, 0, true); } $('#newusername').focus(); + GroupList.incEveryoneCount(); } } ); diff --git a/settings/templates/users/part.grouplist.php b/settings/templates/users/part.grouplist.php index 28f2236b1d7..c5e85fa3534 100644 --- a/settings/templates/users/part.grouplist.php +++ b/settings/templates/users/part.grouplist.php @@ -12,7 +12,7 @@ </form> </li> <!-- Everyone --> - <li data-gid="" class="isgroup"> + <li data-gid="_everyone" data-usercount="<?php p($_["usercount"]); ?>" class="isgroup"> <a href="#"> <span class="groupname"> <?php p($l->t('Everyone')); ?> @@ -27,7 +27,7 @@ <!-- The Admin Group --> <?php foreach($_["adminGroup"] as $adminGroup): ?> - <li data-gid="admin" class="isgroup"> + <li data-gid="admin" data-usercount="<?php if($adminGroup['usercount'] > 0) { p($adminGroup['usercount']); } ?>" class="isgroup"> <a href="#"><span class="groupname"><?php p($l->t('Admins')); ?></span></a> <span class="utils"> <span class="usercount"><?php if($adminGroup['usercount'] > 0) { p($adminGroup['usercount']); } ?></span> |