]> source.dussan.org Git - nextcloud-server.git/commitdiff
increase/decrease everyone count on user creation/deletion
authorArthur Schiwon <blizzz@owncloud.com>
Tue, 8 Jul 2014 18:05:51 +0000 (20:05 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Wed, 9 Jul 2014 12:32:10 +0000 (14:32 +0200)
settings/js/users/groups.js
settings/js/users/users.js
settings/templates/users/part.grouplist.php

index c3e3d1a50c9afa085ea55ee425adef5768aa7f7d..f74c54bbd873e28fac7bec5ea3a79b8d858b471c 100644 (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;
        },
index 923dd9fcfb900d0a713522ef399707e40df30d31..60e1e1dd31f29cd396e366802e9c9836cd27e7ec 100644 (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();
                                }
                        }
                );
index 588c2e6202cef8209681e0259d5a3050bb2c1e9a..c5e85fa353467edf2b4a6be10e1647c32c100b07 100644 (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')); ?>