# HG changeset patch # User Brian Neal # Date 1477243023 18000 # Node ID 0e93eaa323e7b7ec4b0afce4d08438932d70d62b # Parent 6abcecd3d277b6b04eae3c618be187f1c242ff31 Fix user autocomplete for private messages the right V3 way. diff -r 6abcecd3d277 -r 0e93eaa323e7 messages/forms.py --- a/messages/forms.py Sun Oct 23 12:00:04 2016 -0500 +++ b/messages/forms.py Sun Oct 23 12:17:03 2016 -0500 @@ -27,7 +27,7 @@ """ receiver = forms.CharField(label='To', max_length=30, - widget=forms.TextInput(attrs={'class': 'sg101-user-autocomplete'})) + widget=forms.TextInput(attrs={'class': 'sg101-autocomplete'})) subject = forms.CharField(max_length=120) message = forms.CharField(widget=forms.Textarea) attach_signature = forms.BooleanField(label='Attach Signature?', required=False) @@ -38,6 +38,8 @@ self.user = user options = Options.objects.for_user(user) self.fields['attach_signature'].initial = options.attach_signature + url = reverse('core-ajax_users') + self.fields['receiver'].widget.attrs['data-autocomplete-url'] = url def clean_receiver(self): receiver = self.cleaned_data['receiver'] diff -r 6abcecd3d277 -r 0e93eaa323e7 sg101/static/js/v3/user_autocomplete.js --- a/sg101/static/js/v3/user_autocomplete.js Sun Oct 23 12:00:04 2016 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -$(function() { - var cache = {}; - var cacheSize = 0; - $(".sg101-user-autocomplete").autocomplete({ - delay: 400, - minLength: 1, - source: function(request, response) { - if (cache[request.term]) { - response(cache[request.term]); - return; - } - $.ajax({ - url: "/core/ajax/users/", - type: "GET", - data: { - q: request.term, - limit: 15 - }, - dataType: "json", - success: function(data, textStatus) { - if (cacheSize >= 32) { - cache = {}; - cacheSize = 0; - } - cache[request.term] = data; - ++cacheSize; - response(data); - }, - error: function(xhr, textStatus, ex) { - alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + - xhr.responseText); - } - }); - } - }); -}); diff -r 6abcecd3d277 -r 0e93eaa323e7 sg101/templates/messages/compose.html --- a/sg101/templates/messages/compose.html Sun Oct 23 12:00:04 2016 -0500 +++ b/sg101/templates/messages/compose.html Sun Oct 23 12:17:03 2016 -0500 @@ -46,6 +46,6 @@ {% endblock %} {% block custom_js %} {% js_tags 'jquery-ui' %} - + {% endblock %}