Mercurial > public > sg101
comparison forums/static/js/forums.js @ 673:92101013d5ac
For issue #28, add a quick search feature for new forum topics.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 27 May 2013 15:04:52 -0500 |
parents | 99f7917702ca |
children | 130ac1e98cf4 |
comparison
equal
deleted
inserted
replaced
672:69e8aa135c2e | 673:92101013d5ac |
---|---|
1 $(document).ready(function() { | 1 $(document).ready(function() { |
2 var postText = $('#id_body'); | 2 var postText = $('#id_body'); |
3 var postButton = $('#forums-reply-post'); | 3 var postButton = $('#forums-reply-post'); |
4 postButton.click(function () { | 4 postButton.click(function () { |
5 var text = $.trim(postText.val()); | |
6 $(this).attr('disabled', 'disabled').val('Posting reply...'); | 5 $(this).attr('disabled', 'disabled').val('Posting reply...'); |
7 | 6 |
8 var attachments = new Array() | 7 var attachments = new Array() |
9 $('#attachment div input').each(function(index) { | 8 $('#attachment div input').each(function(index) { |
10 attachments[index] = $(this).val(); | 9 attachments[index] = $(this).val(); |
11 }); | 10 }); |
12 | 11 |
13 $.ajax({ | 12 $.ajax({ |
14 url: '/forums/quick-reply/', | 13 url: '/forums/quick-reply/', |
15 type: 'POST', | 14 type: 'POST', |
16 data: { | 15 data: { |
17 body : postText.val(), | 16 body : postText.val(), |
18 topic_id : $('#id_topic_id').val(), | 17 topic_id : $('#id_topic_id').val(), |
19 attachment : attachments | 18 attachment : attachments |
31 lastTr.fadeIn(3000); | 30 lastTr.fadeIn(3000); |
32 postButton.removeAttr('disabled').val('Submit Reply'); | 31 postButton.removeAttr('disabled').val('Submit Reply'); |
33 initAttachments(); | 32 initAttachments(); |
34 }, | 33 }, |
35 error: function (xhr, textStatus, ex) { | 34 error: function (xhr, textStatus, ex) { |
36 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + | 35 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + |
37 xhr.responseText); | 36 xhr.responseText); |
38 postButton.removeAttr('disabled').val('Submit Reply'); | 37 postButton.removeAttr('disabled').val('Submit Reply'); |
39 initAttachments(); | 38 initAttachments(); |
40 } | 39 } |
41 }); | 40 }); |
50 'A moderator will be notified and will review the post. ' + | 49 'A moderator will be notified and will review the post. ' + |
51 'Are you sure you want to flag this post?')) { | 50 'Are you sure you want to flag this post?')) { |
52 $.ajax({ | 51 $.ajax({ |
53 url: '/forums/flag-post/', | 52 url: '/forums/flag-post/', |
54 type: 'POST', | 53 type: 'POST', |
55 data: {id: id}, | 54 data: {id: id}, |
56 dataType: 'text', | 55 dataType: 'text', |
57 success: function (response, textStatus) { | 56 success: function (response, textStatus) { |
58 alert(response); | 57 alert(response); |
59 }, | 58 }, |
60 error: function (xhr, textStatus, ex) { | 59 error: function (xhr, textStatus, ex) { |
71 id = RegExp.$1; | 70 id = RegExp.$1; |
72 if (confirm('Are you sure you want to delete this post?')) { | 71 if (confirm('Are you sure you want to delete this post?')) { |
73 $.ajax({ | 72 $.ajax({ |
74 url: '/forums/delete-post/', | 73 url: '/forums/delete-post/', |
75 type: 'POST', | 74 type: 'POST', |
76 data: {id: id}, | 75 data: {id: id}, |
77 dataType: 'text', | 76 dataType: 'text', |
78 success: function (response, textStatus) { | 77 success: function (response, textStatus) { |
79 alert(response); | 78 alert(response); |
80 $('#post-' + id).fadeOut(3000); | 79 $('#post-' + id).fadeOut(3000); |
81 }, | 80 }, |
99 { | 98 { |
100 $('#attachment div').remove(); | 99 $('#attachment div').remove(); |
101 $('#attach-another').remove(); | 100 $('#attach-another').remove(); |
102 } | 101 } |
103 | 102 |
104 function processEmbeds(data, textStatus) | 103 function processEmbeds(data, textStatus) |
105 { | 104 { |
106 vidDiv.find('img').remove(); | 105 vidDiv.find('img').remove(); |
107 $.each(data, function(index, value) { | 106 $.each(data, function(index, value) { |
108 var html = '<div id="video-' + index + '">' + value.html + | 107 var html = '<div id="video-' + index + '">' + value.html + |
109 '<span class="link">' + | 108 '<span class="link">' + |
136 if (post_input.length == 1) | 135 if (post_input.length == 1) |
137 { | 136 { |
138 post_id = post_input.val(); | 137 post_id = post_input.val(); |
139 vidDiv.prepend('<img src="/static/icons/ajax_busy.gif" alt="Busy" />'); | 138 vidDiv.prepend('<img src="/static/icons/ajax_busy.gif" alt="Busy" />'); |
140 $.ajax({ | 139 $.ajax({ |
141 url: '/forums/fetch_attachments/', | 140 url: '/forums/fetch_attachments/', |
142 type: 'GET', | 141 type: 'GET', |
143 data: { | 142 data: { |
144 pid : post_id | 143 pid : post_id |
145 }, | 144 }, |
146 dataType: 'json', | 145 dataType: 'json', |
147 success: processEmbeds, | 146 success: processEmbeds, |
148 error: function (xhr, textStatus, ex) { | 147 error: function (xhr, textStatus, ex) { |
149 vidDiv.find('img').remove(); | 148 vidDiv.find('img').remove(); |
150 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + | 149 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + |
151 xhr.responseText); | 150 xhr.responseText); |
152 } | 151 } |
153 }); | 152 }); |
154 } | 153 } |
155 else if (attachments.length > 0) | 154 else if (attachments.length > 0) |
159 attachments.each(function(index) { | 158 attachments.each(function(index) { |
160 embeds[index] = $(this).val(); | 159 embeds[index] = $(this).val(); |
161 }); | 160 }); |
162 attachments.remove(); | 161 attachments.remove(); |
163 $.ajax({ | 162 $.ajax({ |
164 url: '/oembed/fetch_saved/', | 163 url: '/oembed/fetch_saved/', |
165 type: 'GET', | 164 type: 'GET', |
166 data: { | 165 data: { |
167 embeds: embeds | 166 embeds: embeds |
168 }, | 167 }, |
169 traditional: true, | 168 traditional: true, |
170 dataType: 'json', | 169 dataType: 'json', |
171 success: processEmbeds, | 170 success: processEmbeds, |
172 error: function (xhr, textStatus, ex) { | 171 error: function (xhr, textStatus, ex) { |
173 vidDiv.find('img').remove(); | 172 vidDiv.find('img').remove(); |
174 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + | 173 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + |
175 xhr.responseText); | 174 xhr.responseText); |
176 } | 175 } |
177 }); | 176 }); |
178 } | 177 } |
179 else | 178 else |
243 | 242 |
244 $('#' + id + ' button').click(function() { | 243 $('#' + id + ' button').click(function() { |
245 var button = $(this); | 244 var button = $(this); |
246 button.attr('disabled', 'disabled'); | 245 button.attr('disabled', 'disabled'); |
247 $.ajax({ | 246 $.ajax({ |
248 url: '/oembed/fetch/', | 247 url: '/oembed/fetch/', |
249 type: 'POST', | 248 type: 'POST', |
250 data: { | 249 data: { |
251 q : vidText.val() | 250 q : vidText.val() |
252 }, | 251 }, |
253 dataType: 'json', | 252 dataType: 'json', |
265 relabelAttachLink(); | 264 relabelAttachLink(); |
266 return false; | 265 return false; |
267 }); | 266 }); |
268 }, | 267 }, |
269 error: function (xhr, textStatus, ex) { | 268 error: function (xhr, textStatus, ex) { |
270 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + | 269 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + |
271 xhr.responseText); | 270 xhr.responseText); |
272 button.removeAttr('disabled'); | 271 button.removeAttr('disabled'); |
273 } | 272 } |
274 }); | 273 }); |
275 }); | 274 }); |
285 } | 284 } |
286 ++vid; | 285 ++vid; |
287 } | 286 } |
288 | 287 |
289 initAttachments(); | 288 initAttachments(); |
289 | |
290 var topicTitle = $('#id_name'); | |
291 var topicSearchButton = $('#search_topics'); | |
292 var searchBusy = $('#search-busy-icon'); | |
293 topicSearchButton.click(function () { | |
294 var text = $.trim(topicTitle.val()); | |
295 if (!text) return; | |
296 | |
297 $(this).attr('disabled', 'disabled'); | |
298 $('#quick-search-results').remove(); | |
299 searchBusy.toggle(); | |
300 | |
301 $.ajax({ | |
302 url: '/search/ajax/', | |
303 type: 'GET', | |
304 data: { | |
305 q : text, | |
306 models : 'forums.topic' | |
307 }, | |
308 traditional: true, | |
309 dataType: 'html', | |
310 success: function (data, textStatus) { | |
311 topicSearchButton.removeAttr('disabled'); | |
312 searchBusy.hide(); | |
313 searchBusy.after(data); | |
314 $('#hide-search-results').click(function() { | |
315 var results = $('#quick-search-results'); | |
316 results.fadeOut(1500, function() { results.remove(); }); | |
317 }); | |
318 }, | |
319 error: function (xhr, textStatus, ex) { | |
320 topicSearchButton.removeAttr('disabled'); | |
321 searchBusy.hide(); | |
322 alert('Oops, an error occurred. ' + xhr.statusText + ' - ' + | |
323 xhr.responseText); | |
324 } | |
325 }); | |
326 return false; | |
327 }); | |
290 }); | 328 }); |