]> source.dussan.org Git - nextcloud-server.git/commitdiff
show users whose username starts with the search pattern first
authorArthur Schiwon <blizzz@owncloud.com>
Thu, 17 Apr 2014 18:14:51 +0000 (20:14 +0200)
committerArthur Schiwon <blizzz@owncloud.com>
Mon, 2 Jun 2014 10:53:56 +0000 (12:53 +0200)
We may want to switch or extend it to display name. I leave it like this for now, continued work on this needs to have sortable columns in mind

settings/js/users/users.js

index d1cab63eaab7c0b4d8006732b975f19201d6dc53..092998c029f28c504135c4876629f06cd40c6a63 100644 (file)
@@ -145,12 +145,43 @@ var UserList = {
                }
                return aa.length - bb.length;
        },
+       preSortSearchString: function(a, b) {
+               var pattern = filter.getPattern();
+               if(typeof pattern === 'undefined') {
+                       return undefined;
+               }
+               pattern = pattern.toLowerCase();
+               var aMatches = false;
+               var bMatches = false;
+               if(typeof a === 'string' && a.toLowerCase().indexOf(pattern) === 0) {
+                       aMatches = true;
+               }
+               if(typeof b === 'string' && b.toLowerCase().indexOf(pattern) === 0) {
+                       bMatches = true;
+               }
+
+               if((aMatches && bMatches) || (!aMatches && !bMatches)) {
+                       return undefined;
+               }
+
+               if(aMatches) {
+                       return -1;
+               } else {
+                       return 1;
+               }
+       },
        doSort: function() {
                var self = this;
                var rows = $('tbody tr').get();
 
                rows.sort(function(a, b) {
-                       return UserList.alphanum($(a).find('td.name').text(), $(b).find('td.name').text());
+                       a = $(a).find('td.name').text();
+                       b = $(b).find('td.name').text();
+                       var firstSort = UserList.preSortSearchString(a, b);
+                       if(typeof firstSort !== 'undefined') {
+                               return firstSort;
+                       }
+                       return UserList.alphanum(a, b);
                });
 
                var items = [];
@@ -391,6 +422,10 @@ function setQuota (uid, quota, ready) {
 $(document).ready(function () {
        UserList.initDeleteHandling();
 
+       // Implements User Search
+       filter = new UserManagementFilter(
+               $('#usersearchform input'), UserList, GroupList);
+
        UserList.doSort();
        UserList.availableGroups = $('#content table').data('groups');
 
@@ -548,7 +583,5 @@ $(document).ready(function () {
                        }
                );
        });
-       // Implements User Search
-       filter = new UserManagementFilter(
-               $('#usersearchform input'), UserList, GroupList);
+
 });