update GroupList when a users is added or removed to a group

This commit is contained in:
Arthur Schiwon 2014-04-16 22:16:55 +02:00
parent 3c9788d40c
commit d87347e64e
2 changed files with 17 additions and 9 deletions

View File

@ -7,15 +7,11 @@
var GroupList = {
addGroup: function(gid, usercount) {
if(usercount === undefined || usercount === 0) {
usercount = '';
}
var li = $('li[data-gid]').last().clone();
var ul = $('li[data-gid]').first().parent();
li.attr('data-gid', gid);
li.attr('data-usercount', usercount);
li.find('a span').first().text(gid);
li.find('span[class=usercount]').first().text(usercount);
GroupList.setUserCount(li, usercount);
$(li).appendTo(ul);
@ -24,6 +20,14 @@
return li;
},
setUserCount: function(groupLiElement, usercount) {
if(usercount === undefined || usercount === 0) {
usercount = '';
}
groupLiElement.attr('data-usercount', usercount);
groupLiElement.find('span[class=usercount]').first().text(usercount);
},
sortGroups: function(usercount) {
var lis = $('li[data-gid]').filterAttr('data-usercount', usercount.toString()).get();
var ul = $(lis).first().parent();
@ -93,6 +97,8 @@
$.each(result.data, function (i, subset) {
$.each(subset, function (index, group) {
if($('li[data-gid="' + group.name + '"]').length > 0) {
var li = $('li[data-gid="' + group.name + '"]');
GroupList.setUserCount(li, group.usercount);
return true;
}
var li = GroupList.addGroup(group.name, group.usercount);

View File

@ -289,10 +289,12 @@ var UserList = {
group: group
},
function (response) {
if(response.status === 'success'
&& UserList.availableGroups.indexOf(response.data.groupname) === -1
&& response.data.action === 'add') {
UserList.availableGroups.push(response.data.groupname);
if(response.status === 'success') {
GroupList.update();
if(UserList.availableGroups.indexOf(response.data.groupname) === -1
&& response.data.action === 'add') {
UserList.availableGroups.push(response.data.groupname);
}
}
if(response.data.message) {
OC.Notification.show(response.data.message);