From 7b8935abdacfa25c55738b0395440c84bf86ffbb Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 17 Apr 2014 20:14:51 +0200 Subject: [PATCH] show users whose username starts with the search pattern first 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 | 41 ++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/settings/js/users/users.js b/settings/js/users/users.js index d1cab63eaab..092998c029f 100644 --- a/settings/js/users/users.js +++ b/settings/js/users/users.js @@ -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); + }); -- 2.39.5