# HG changeset patch # User Brian Neal # Date 1477242004 18000 # Node ID 6abcecd3d277b6b04eae3c618be187f1c242ff31 # Parent ba1df459f3a8194e7d6f31d8980cea3787894938 Fix user autocomplete on private messages. diff -r ba1df459f3a8 -r 6abcecd3d277 messages/forms.py --- a/messages/forms.py Thu Oct 13 19:47:21 2016 -0500 +++ b/messages/forms.py Sun Oct 23 12:00:04 2016 -0500 @@ -13,7 +13,6 @@ from core.html import ImageCheckError from core.html import image_check from core.markup import site_markup -from core.widgets import AutoCompleteUserInput import messages from messages.models import Flag, Message, Options @@ -28,9 +27,9 @@ """ receiver = forms.CharField(label='To', max_length=30, - widget=AutoCompleteUserInput()) - subject = forms.CharField(max_length=120, widget=forms.TextInput(attrs={'size': 52})) - message = forms.CharField(widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) + widget=forms.TextInput(attrs={'class': 'sg101-user-autocomplete'})) + subject = forms.CharField(max_length=120) + message = forms.CharField(widget=forms.Textarea) attach_signature = forms.BooleanField(label='Attach Signature?', required=False) parent_id = forms.IntegerField(required=False, widget=forms.HiddenInput) diff -r ba1df459f3a8 -r 6abcecd3d277 sg101/static/js/v3/user_autocomplete.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sg101/static/js/v3/user_autocomplete.js Sun Oct 23 12:00:04 2016 -0500 @@ -0,0 +1,36 @@ +$(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 ba1df459f3a8 -r 6abcecd3d277 sg101/templates/messages/compose.html --- a/sg101/templates/messages/compose.html Thu Oct 13 19:47:21 2016 -0500 +++ b/sg101/templates/messages/compose.html Sun Oct 23 12:00:04 2016 -0500 @@ -2,6 +2,9 @@ {% load core_tags %} {% load script_tags %} {% load static from staticfiles %} +{% block custom_css %} +{% css_tags 'jquery-ui' %} +{% endblock %} {% block messages_content %}

Compose Private Message

Use this form to send a new private message to another user.

@@ -42,5 +45,7 @@ {% include 'core/v3/post_box_modals.html' %} {% endblock %} {% block custom_js %} +{% js_tags 'jquery-ui' %} + {% endblock %}