increase/decrease everyone count on user creation/deletion

This commit is contained in:
Arthur Schiwon 2014-07-08 20:05:51 +02:00 committed by Thomas Müller
parent 5e5a02cc2f
commit e2c935d6fb
3 changed files with 42 additions and 8 deletions

View File

@ -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,7 +28,7 @@ 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);
@ -38,6 +39,20 @@ GroupList = {
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;
},

View File

@ -237,7 +237,7 @@ var UserList = {
show: function(uid) {
UserList.getRow(uid).show();
},
remove: function(uid) {
markRemove: function(uid) {
$tr = UserList.getRow(uid);
groups = $tr.find('.groups .groupsselect').val();
for(i in groups) {
@ -251,9 +251,29 @@ var UserList = {
}
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;
},
@ -271,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 () {
@ -482,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) {
@ -639,6 +657,7 @@ $(document).ready(function () {
UserList.add(username, username, result.data.groups, null, 'default', result.data.storageLocation, 0, true);
}
$('#newusername').focus();
GroupList.incEveryoneCount();
}
}
);

View File

@ -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')); ?>