From d87347e64ef90b89b1ff2b2221514b6fe1c57086 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 16 Apr 2014 22:16:55 +0200 Subject: [PATCH] update GroupList when a users is added or removed to a group --- settings/js/users/groups.js | 16 +++++++++++----- settings/js/users/users.js | 10 ++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/settings/js/users/groups.js b/settings/js/users/groups.js index 25b865cf18..4c555bd4c8 100644 --- a/settings/js/users/groups.js +++ b/settings/js/users/groups.js @@ -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); diff --git a/settings/js/users/users.js b/settings/js/users/users.js index e9c85d20e9..d1cab63eaa 100644 --- a/settings/js/users/users.js +++ b/settings/js/users/users.js @@ -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);