[PATCH 13 of 19] autocomplete: fix completion of repository owner

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


# HG changeset patch
# User Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
# Date 1435592559 -7200
#      Mon Jun 29 17:42:39 2015 +0200
# Node ID f1d674589538cbf1c6d066b203016009d7c679b2
# Parent  2d3ead418f13410650da664144462a54a0312163
autocomplete: fix completion of repository owner

The owner field of a repository setting was supposed to be autocompletable,
but never really did (at least not in Kallithea, probably it once did in
Rhodecode).

Instead of making yet another 'OwnerAutoComplete', make a generic
SimpleUserAutoComplete that can be reused in other places that only need
completion of a text input field.

diff --git a/kallithea/controllers/admin/repos.py b/kallithea/controllers/admin/repos.py
--- a/kallithea/controllers/admin/repos.py
+++ b/kallithea/controllers/admin/repos.py
@@ -370,6 +370,8 @@ class ReposController(BaseRepoController
 
         c.repo_fields = RepositoryField.query()\
             .filter(RepositoryField.repository == c.repo_info).all()
+        repo_model = RepoModel()
+        c.users_array = repo_model.get_users_js()
         c.active = 'settings'
         return htmlfill.render(
             render('admin/repos/repo_edit.html'),
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
@@ -1236,24 +1236,34 @@ var autocompleteCreate = function (input
     return autocomplete;
 }
 
-var _MembersAutoComplete = function (divid, cont, users_list, groups_list) {
+var SimpleUserAutoComplete = function (divid, cont, users_list) {
 
     var matchUsers = function (sQuery) {
         return autocompleteMatchUsers(sQuery, users_list);
     }
-    var matchGroups = function (sQuery) {
-        return autocompleteMatchGroups(sQuery, groups_list);
-    }
+
+    var userAC = autocompleteCreate(divid, cont, matchUsers);
+
+    // Handler for selection of an entry
+    var itemSelectHandler = function (sType, aArgs) {
+        var myAC = aArgs[0]; // reference back to the AC instance
+        var elLI = aArgs[1]; // reference to the selected LI element
+        var oData = aArgs[2]; // object literal of selected item's result data
+        myAC.getInputEl().value = oData.nname;
+    };
+    userAC.itemSelectEvent.subscribe(itemSelectHandler);
+}
+
+var _MembersAutoComplete = function (divid, cont, users_list, groups_list) {
+
     var matchAll = function (sQuery) {
-        var u = matchUsers(sQuery);
-        var g = matchGroups(sQuery);
+        var u = autocompleteMatchUsers(sQuery, users_list);
+        var g = autocompleteMatchGroups(sQuery, groups_list);
         return u.concat(g);
     };
 
     var membersAC = autocompleteCreate(divid, cont, matchAll);
 
-    var ownerAC = autocompleteCreate("user", "owner_container", matchUsers);
-
     // Handler for selection of an entry
     var itemSelectHandler = function (sType, aArgs) {
         var nextId = divid.split('perm_new_member_name_')[1];
@@ -1272,7 +1282,6 @@ var _MembersAutoComplete = function (div
         }
     };
     membersAC.itemSelectEvent.subscribe(itemSelectHandler);
-    ownerAC.itemSelectEvent.subscribe(itemSelectHandler);
 }
 
 var MentionsAutoComplete = function (divid, cont, users_list) {
diff --git a/kallithea/templates/admin/repos/repo_edit_settings.html b/kallithea/templates/admin/repos/repo_edit_settings.html
--- a/kallithea/templates/admin/repos/repo_edit_settings.html
+++ b/kallithea/templates/admin/repos/repo_edit_settings.html
@@ -162,5 +162,9 @@
             'dropdownAutoWidth': true
         });
 
+        // autocomplete
+        var _USERS_AC_DATA = ${c.users_array|n};
+        SimpleUserAutoComplete('user', 'owner_container', _USERS_AC_DATA);
+
     });
 </script>


More information about the kallithea-general mailing list