##// END OF EJS Templates
Image alias autocomplete
neko259 -
r1702:cc5f5f4a default
parent child Browse files
Show More
@@ -1,4 +1,6 b''
1 var ITEM_FILE_SOURCE = 'fileSource';
1 var ITEM_FILE_SOURCE = 'fileSource';
2 var URL_STICKERS = '/api/stickers'
3 var MIN_INPUT_LENGTH = 3;
2
4
3 $('input[name=image]').wrap($('<div class="file_wrap"></div>'));
5 $('input[name=image]').wrap($('<div class="file_wrap"></div>'));
4
6
@@ -138,4 +140,32 b' function selectFileChoice() {'
138 } else {
140 } else {
139 $fileSourceButton.hide();
141 $fileSourceButton.hide();
140 }
142 }
143
144 $('#id_file_url').autocomplete({
145 source: function( request, response ) {
146 $.getJSON(URL_STICKERS, {
147 term: request.term
148 }, response);
149 },
150 search: function() {
151 // custom minLength
152 var term = this.value;
153 if (term.length < MIN_INPUT_LENGTH) {
154 return false;
155 }
156 },
157 focus: function() {
158 // prevent value inserted on focus
159 return false;
160 },
161 select: function( event, ui ) {
162 this.value = ui.item.alias;
163 return false;
164 }
165 })
166 .autocomplete( "instance" )._renderItem = function( ul, item ) {
167 return $( "<li>" )
168 .append( "<div>" + '<img src="' + item.thumb + '">' + '<br />' + item.alias + "</div>" )
169 .appendTo( ul );
170 };
141 });
171 });
@@ -75,6 +75,7 b' urlpatterns = ['
75 name='api_notifications'),
75 name='api_notifications'),
76 url(r'^api/preview/$', api.api_get_preview, name='preview'),
76 url(r'^api/preview/$', api.api_get_preview, name='preview'),
77 url(r'^api/new_posts/$', api.api_get_new_posts, name='new_posts'),
77 url(r'^api/new_posts/$', api.api_get_new_posts, name='new_posts'),
78 url(r'^api/stickers/$', api.api_get_stickers, name='get_stickers'),
78
79
79 # Sync protocol API
80 # Sync protocol API
80 url(r'^api/sync/list/$', response_list, name='api_sync_list'),
81 url(r'^api/sync/list/$', response_list, name='api_sync_list'),
@@ -10,11 +10,12 b' from django.views.decorators.csrf import'
10 from boards.abstracts.settingsmanager import get_settings_manager
10 from boards.abstracts.settingsmanager import get_settings_manager
11 from boards.forms import PostForm, PlainErrorList
11 from boards.forms import PostForm, PlainErrorList
12 from boards.mdx_neboard import Parser
12 from boards.mdx_neboard import Parser
13 from boards.models import Post, Thread, Tag
13 from boards.models import Post, Thread, Tag, Attachment
14 from boards.models.thread import STATUS_ARCHIVE
14 from boards.models.thread import STATUS_ARCHIVE
15 from boards.models.user import Notification
15 from boards.models.user import Notification
16 from boards.utils import datetime_to_epoch
16 from boards.utils import datetime_to_epoch
17 from boards.views.thread import ThreadView
17 from boards.views.thread import ThreadView
18 from boards.models.attachment.viewers import FILE_TYPES_IMAGE
18
19
19 __author__ = 'neko259'
20 __author__ = 'neko259'
20
21
@@ -188,6 +189,21 b' def api_get_tags(request):'
188 return HttpResponse(content=json.dumps(tag_names))
189 return HttpResponse(content=json.dumps(tag_names))
189
190
190
191
192 def api_get_stickers(request):
193 attachments = Attachment.objects.filter(mimetype__in=FILE_TYPES_IMAGE)\
194 .exclude(alias='').exclude(alias=None)
195
196 term = request.GET.get('term')
197 if term:
198 attachments = attachments.filter(alias__startswith=term)
199
200 image_dict = [{'thumb': attachment.get_thumb_url(),
201 'alias': attachment.alias}
202 for attachment in attachments]
203
204 return HttpResponse(content=json.dumps(image_dict))
205
206
191 # TODO The result can be cached by the thread last update time
207 # TODO The result can be cached by the thread last update time
192 # TODO Test this
208 # TODO Test this
193 def api_get_thread_posts(request, opening_post_id):
209 def api_get_thread_posts(request, opening_post_id):
General Comments 0
You need to be logged in to leave comments. Login now