diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-02-25 15:22:20 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2014-06-02 12:53:54 +0200 |
commit | a4cfa9554548c53a3d0aa267495427729deb9352 (patch) | |
tree | 59ec32e21168250a2526a6f5f3392e85d8b65cb9 /settings/js/users/groups.js | |
parent | 480173569fdf729c33c076c62a31a15ad9c57057 (diff) | |
download | nextcloud-server-a4cfa9554548c53a3d0aa267495427729deb9352.tar.gz nextcloud-server-a4cfa9554548c53a3d0aa267495427729deb9352.zip |
restructure group.js and put functions to object, also add group list sorting after adding.
Diffstat (limited to 'settings/js/users/groups.js')
-rw-r--r-- | settings/js/users/groups.js | 91 |
1 files changed, 67 insertions, 24 deletions
diff --git a/settings/js/users/groups.js b/settings/js/users/groups.js index f8f6d3fedcc..7c8b6608f11 100644 --- a/settings/js/users/groups.js +++ b/settings/js/users/groups.js @@ -5,6 +5,61 @@ */ var GroupList = { + addGroup: function(gid) { + var li = $('li[data-gid]').last().clone(); + var ul = $('li[data-gid]').first().parent(); + li.attr('data-gid', gid); + li.attr('data-usercount', 0); + li.find('a span').first().text(gid); + li.find('span[class=usercount]').first().text(''); + + $(li).appendTo(ul); + + GroupList.sortGroups(0); + }, + + sortGroups: function(usercount) { + var lis = $('li[data-gid]').filterAttr('data-usercount', usercount.toString()).get(); + var ul = $(lis).first().parent(); + + lis.sort(function(a, b) { + return UserList.alphanum($(a).find('a span').text(), $(b).find('a span').text()); + }); + + var items = []; + $.each(lis, function(index, li) { + items.push(li); + if(items.length === 100) { + $(ul).append(items); + items = []; + } + }); + if(items.length > 0) { + $(ul).append(items); + } + }, + + createGroup: function(groupname) { + $.post( + OC.filePath('settings', 'ajax', 'creategroup.php'), + { + groupname : groupname + }, + function (result) { + if (result.status !== 'success') { + OC.dialogs.alert(result.data.message, + t('settings', 'Error creating group')); + } else { + if (result.data.groupname) { + var addedGroups = result.data.groupname; + UserList.availableGroups = $.unique($.merge(UserList.availableGroups, addedGroups)); + GroupList.addGroup(result.data.groupname); + } + GroupList.toggleAddGroup(); + } + } + ) + }, delete_group: function (gid) { if(GroupList.deleteGid !=='undefined') { @@ -42,6 +97,16 @@ } }, + isGroupNameValid: function(groupname) { + if ($.trim(groupname) === '') { + OC.dialogs.alert( + t('settings', 'A valid groupname must be provided'), + t('settings', 'Error creating group')); + return false; + } + return true; + }, + finishDelete: function (ready) { if (!GroupList.deleteCanceled && GroupList.deleteGid) { $.ajax({ @@ -87,31 +152,9 @@ $(document).ready( function () { // Responsible for Creating Groups. $('#newgroup-form form').submit(function (event) { event.preventDefault(); - var groupname = $('#newgroupname').val(); - if ($.trim(groupname) === '') { - OC.dialogs.alert( - t('settings', 'A valid groupname must be provided'), - t('settings', 'Error creating group')); - return false; + if(GroupList.isGroupNameValid($('#newgroupname').val())) { + GroupList.createGroup($('#newgroupname').val()); } - $.post( - OC.filePath('settings', 'ajax', 'creategroup.php'), - { - groupname : groupname - }, - function (result) { - if (result.status !== 'success') { - OC.dialogs.alert(result.data.message, - t('settings', 'Error creating group')); - } else { - if (result.data.groupname) { - var addedGroups = result.data.groupname; - UserList.availableGroups = $.unique($.merge(UserList.availableGroups, addedGroups)); - } - GroupList.toggleAddGroup(); - } - } - ) }); // click on group name |