##// END OF EJS Templates
autocomplete: add flags to show/hide active users, and also display this information...
marcink -
r222:c6ddf19a default
parent child Browse files
Show More
@@ -274,4 +274,11 b' class HomeController(BaseController):'
274 274 @XHRRequired()
275 275 @jsonify
276 276 def user_group_autocomplete_data(self):
277 return {'suggestions': []}
277 query = request.GET.get('query')
278
279 repo_model = RepoModel()
280 _user_groups = repo_model.get_user_groups(name_contains=query)
281 _user_groups = _user_groups
282
283 return {'suggestions': _user_groups}
284
@@ -140,10 +140,12 b' class RepoModel(BaseModel):'
140 140
141 141 return None
142 142
143 def get_users(self, name_contains=None, limit=20):
143 def get_users(self, name_contains=None, limit=20, only_active=True):
144 144 # TODO: mikhail: move this method to the UserModel.
145 145 query = self.sa.query(User)
146 query = query.filter(User.active == true())
146 if only_active:
147 query = query.filter(User.active == true())
148
147 149 if name_contains:
148 150 ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
149 151 query = query.filter(
@@ -165,16 +167,19 b' class RepoModel(BaseModel):'
165 167 'icon_link': h.gravatar_url(user.email, 14),
166 168 'value_display': h.person(user.email),
167 169 'value': user.username,
168 'value_type': 'user'
170 'value_type': 'user',
171 'active': user.active,
169 172 }
170 173 for user in users
171 174 ]
172 175 return _users
173 176
174 def get_user_groups(self, name_contains=None, limit=20):
177 def get_user_groups(self, name_contains=None, limit=20, only_active=True):
175 178 # TODO: mikhail: move this method to the UserGroupModel.
176 179 query = self.sa.query(UserGroup)
177 query = query.filter(UserGroup.users_group_active == true())
180 if only_active:
181 query = query.filter(UserGroup.users_group_active == true())
182
178 183 if name_contains:
179 184 ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
180 185 query = query.filter(
@@ -196,7 +201,8 b' class RepoModel(BaseModel):'
196 201 'value_display': 'Group: %s (%d members)' % (
197 202 group.users_group_name, len(group.members),),
198 203 'value': group.users_group_name,
199 'value_type': 'user_group'
204 'value_type': 'user_group',
205 'active': group.users_group_active,
200 206 }
201 207 for group in user_groups
202 208 ]
@@ -19,19 +19,25 b''
19 19 /**
20 20 * autocomplete formatter that uses gravatar
21 21 * */
22 var autocompleteFormatResult = function(data, value, org_formatter) {
23 var value_display = data.value_display;
22 var autocompleteFormatResult = function (data, value, org_formatter) {
23 var activeUser = data.active || true;
24 var valueDisplay = data.value_display;
25
26 if (!activeUser) {
27 valueDisplay = '<strong>(disabled)</strong> ' + valueDisplay;
28 }
29
24 30 var escapeRegExChars = function (value) {
25 31 return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
26 32 };
27 33 var pattern = '(' + escapeRegExChars(value) + ')';
28 value_display = value_display.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
34 valueDisplay = valueDisplay.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
29 35 var tmpl = '<div class="ac-container-wrap"><img class="gravatar" src="{0}"/>{1}</div>';
30 36 if (data.icon_link === "") {
31 37 tmpl = '<div class="ac-container-wrap">{0}</div>';
32 return tmpl.format(value_display);
38 return tmpl.format(valueDisplay);
33 39 }
34 return tmpl.format(data.icon_link, value_display);
40 return tmpl.format(data.icon_link, valueDisplay);
35 41 };
36 42
37 43 /**
General Comments 0
You need to be logged in to leave comments. Login now