[PATCH 02 of 19] autocomplete: factor out matchUsers function

Thomas De Schampheleire patrickdepinguin at gmail.com
Tue Jun 30 16:43:12 EDT 2015


# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1435162968 -7200
#      Wed Jun 24 18:22:48 2015 +0200
# Node ID 29390aec8d12021642c13741a57da8901be9a9a4
# Parent  16fff695ace152d8f165b033980678a68e60822c
autocomplete: factor out matchUsers function

diff --git a/kallithea/public/js/base.js b/kallithea/public/js/base.js
--- a/kallithea/public/js/base.js
+++ b/kallithea/public/js/base.js
@@ -1101,31 +1101,37 @@ var readNotification = function(url, not
     ajaxPOST(sUrl, postData, success, failure);
 };
 
-/** MEMBERS AUTOCOMPLETE WIDGET **/
+/**
+ * Autocomplete functionality
+ */
+
+// Custom search function for the DataSource of users
+var autocompleteMatchUsers = function (sQuery, myUsers) {
+    // Case insensitive matching
+    var query = sQuery.toLowerCase();
+    var i = 0;
+    var l = myUsers.length;
+    var matches = [];
+
+    // Match against each name of each contact
+    for (; i < l; i++) {
+        var contact = myUsers[i];
+        if (((contact.fname+"").toLowerCase().indexOf(query) > -1) ||
+             ((contact.lname+"").toLowerCase().indexOf(query) > -1) ||
+             ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) {
+            matches[matches.length] = contact;
+        }
+    }
+    return matches;
+};
+
 
 var _MembersAutoComplete = function (divid, cont, users_list, groups_list) {
-    var myUsers = users_list;
     var myGroups = groups_list;
 
-    // Define a custom search function for the DataSource of users
     var matchUsers = function (sQuery) {
-            // Case insensitive matching
-            var query = sQuery.toLowerCase();
-            var i = 0;
-            var l = myUsers.length;
-            var matches = [];
-
-            // Match against each name of each contact
-            for (; i < l; i++) {
-                var contact = myUsers[i];
-                if (((contact.fname+"").toLowerCase().indexOf(query) > -1) ||
-                     ((contact.lname+"").toLowerCase().indexOf(query) > -1) ||
-                     ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) {
-                    matches[matches.length] = contact;
-                }
-            }
-            return matches;
-        };
+        return autocompleteMatchUsers(sQuery, users_list);
+    }
 
     // Define a custom search function for the DataSource of userGroups
     var matchGroups = function (sQuery) {
@@ -1145,7 +1151,6 @@ var _MembersAutoComplete = function (div
             return matches;
         };
 
-    //match all
     var matchAll = function (sQuery) {
             var u = matchUsers(sQuery);
             var g = matchGroups(sQuery);
@@ -1284,32 +1289,15 @@ var _MembersAutoComplete = function (div
 }
 
 var MentionsAutoComplete = function (divid, cont, users_list) {
-    var myUsers = users_list;
 
-    // Define a custom search function for the DataSource of users
     var matchUsers = function (sQuery) {
             var org_sQuery = sQuery;
             if(this.mentionQuery == null){
                 return []
             }
             sQuery = this.mentionQuery;
-            // Case insensitive matching
-            var query = sQuery.toLowerCase();
-            var i = 0;
-            var l = myUsers.length;
-            var matches = [];
-
-            // Match against each name of each contact
-            for (; i < l; i++) {
-                var contact = myUsers[i];
-                if (((contact.fname+"").toLowerCase().indexOf(query) > -1) ||
-                     ((contact.lname+"").toLowerCase().indexOf(query) > -1) ||
-                     ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) {
-                    matches[matches.length] = contact;
-                }
-            }
-            return matches
-        };
+            return autocompleteMatchUsers(sQuery, users_list);
+    }
 
     // DataScheme for owner
     var ownerDS = new YAHOO.util.FunctionDataSource(matchUsers);
@@ -1505,27 +1493,10 @@ var removeReviewMember = function(review
 
 /* activate auto completion of users as PR reviewers */
 var PullRequestAutoComplete = function (divid, cont, users_list) {
-    var myUsers = users_list;
 
-    // Define a custom search function for the DataSource of users
     var matchUsers = function (sQuery) {
-            // Case insensitive matching
-            var query = sQuery.toLowerCase();
-            var i = 0;
-            var l = myUsers.length;
-            var matches = [];
-
-            // Match against each name of each contact
-            for (; i < l; i++) {
-                var contact = myUsers[i];
-                if (((contact.fname+"").toLowerCase().indexOf(query) > -1) ||
-                     ((contact.lname+"").toLowerCase().indexOf(query) > -1) ||
-                     ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) {
-                    matches[matches.length] = contact;
-                }
-            }
-            return matches;
-        };
+        return autocompleteMatchUsers(sQuery, users_list);
+    };
 
     // DataScheme for owner
     var ownerDS = new YAHOO.util.FunctionDataSource(matchUsers);


More information about the kallithea-general mailing list