# HG changeset patch
# User Brian Neal
# Date 1369685092 18000
# Node ID 92101013d5acdebe0d6a570695eb8441d9a835aa
# Parent 69e8aa135c2ef079b3a97284638d20362f75d71c
For issue #28, add a quick search feature for new forum topics.
diff -r 69e8aa135c2e -r 92101013d5ac forums/forms.py
--- a/forums/forms.py Sun May 26 13:29:44 2013 -0500
+++ b/forums/forms.py Mon May 27 15:04:52 2013 -0500
@@ -68,7 +68,7 @@
locked.
"""
name = forms.CharField(label='Subject', max_length=255,
- widget=forms.TextInput(attrs={'size': 64}))
+ widget=forms.TextInput(attrs={'style': 'width:70%'}))
body = forms.CharField(label='', required=False,
widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'}))
user = None
diff -r 69e8aa135c2e -r 92101013d5ac forums/static/js/forums.js
--- a/forums/static/js/forums.js Sun May 26 13:29:44 2013 -0500
+++ b/forums/static/js/forums.js Mon May 27 15:04:52 2013 -0500
@@ -2,7 +2,6 @@
var postText = $('#id_body');
var postButton = $('#forums-reply-post');
postButton.click(function () {
- var text = $.trim(postText.val());
$(this).attr('disabled', 'disabled').val('Posting reply...');
var attachments = new Array()
@@ -11,7 +10,7 @@
});
$.ajax({
- url: '/forums/quick-reply/',
+ url: '/forums/quick-reply/',
type: 'POST',
data: {
body : postText.val(),
@@ -33,7 +32,7 @@
initAttachments();
},
error: function (xhr, textStatus, ex) {
- alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
+ alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
xhr.responseText);
postButton.removeAttr('disabled').val('Submit Reply');
initAttachments();
@@ -52,7 +51,7 @@
$.ajax({
url: '/forums/flag-post/',
type: 'POST',
- data: {id: id},
+ data: {id: id},
dataType: 'text',
success: function (response, textStatus) {
alert(response);
@@ -73,7 +72,7 @@
$.ajax({
url: '/forums/delete-post/',
type: 'POST',
- data: {id: id},
+ data: {id: id},
dataType: 'text',
success: function (response, textStatus) {
alert(response);
@@ -101,7 +100,7 @@
$('#attach-another').remove();
}
- function processEmbeds(data, textStatus)
+ function processEmbeds(data, textStatus)
{
vidDiv.find('img').remove();
$.each(data, function(index, value) {
@@ -138,7 +137,7 @@
post_id = post_input.val();
vidDiv.prepend('');
$.ajax({
- url: '/forums/fetch_attachments/',
+ url: '/forums/fetch_attachments/',
type: 'GET',
data: {
pid : post_id
@@ -147,7 +146,7 @@
success: processEmbeds,
error: function (xhr, textStatus, ex) {
vidDiv.find('img').remove();
- alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
+ alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
xhr.responseText);
}
});
@@ -161,7 +160,7 @@
});
attachments.remove();
$.ajax({
- url: '/oembed/fetch_saved/',
+ url: '/oembed/fetch_saved/',
type: 'GET',
data: {
embeds: embeds
@@ -171,7 +170,7 @@
success: processEmbeds,
error: function (xhr, textStatus, ex) {
vidDiv.find('img').remove();
- alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
+ alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
xhr.responseText);
}
});
@@ -245,7 +244,7 @@
var button = $(this);
button.attr('disabled', 'disabled');
$.ajax({
- url: '/oembed/fetch/',
+ url: '/oembed/fetch/',
type: 'POST',
data: {
q : vidText.val()
@@ -267,7 +266,7 @@
});
},
error: function (xhr, textStatus, ex) {
- alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
+ alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
xhr.responseText);
button.removeAttr('disabled');
}
@@ -287,4 +286,43 @@
}
initAttachments();
+
+ var topicTitle = $('#id_name');
+ var topicSearchButton = $('#search_topics');
+ var searchBusy = $('#search-busy-icon');
+ topicSearchButton.click(function () {
+ var text = $.trim(topicTitle.val());
+ if (!text) return;
+
+ $(this).attr('disabled', 'disabled');
+ $('#quick-search-results').remove();
+ searchBusy.toggle();
+
+ $.ajax({
+ url: '/search/ajax/',
+ type: 'GET',
+ data: {
+ q : text,
+ models : 'forums.topic'
+ },
+ traditional: true,
+ dataType: 'html',
+ success: function (data, textStatus) {
+ topicSearchButton.removeAttr('disabled');
+ searchBusy.hide();
+ searchBusy.after(data);
+ $('#hide-search-results').click(function() {
+ var results = $('#quick-search-results');
+ results.fadeOut(1500, function() { results.remove(); });
+ });
+ },
+ error: function (xhr, textStatus, ex) {
+ topicSearchButton.removeAttr('disabled');
+ searchBusy.hide();
+ alert('Oops, an error occurred. ' + xhr.statusText + ' - ' +
+ xhr.responseText);
+ }
+ });
+ return false;
+ });
});
diff -r 69e8aa135c2e -r 92101013d5ac sg101/templates/forums/show_form.html
--- a/sg101/templates/forums/show_form.html Sun May 26 13:29:44 2013 -0500
+++ b/sg101/templates/forums/show_form.html Mon May 27 15:04:52 2013 -0500
@@ -2,7 +2,29 @@
+{{ form.body.errors }}{{ form.body }}
+{% if form.sticky %}
+ {{ form.sticky.errors }}{{ form.sticky }}
+{% endif %}
+{% if form.locked %}
+ {{ form.locked.errors }}{{ form.locked }}
+{% endif %}
+
+{% else %}
{{ form.as_p }}
+{% endif %}
+
{% comment_dialogs %}
diff -r 69e8aa135c2e -r 92101013d5ac sg101/templates/search/search_ajax.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sg101/templates/search/search_ajax.html Mon May 27 15:04:52 2013 -0500
@@ -0,0 +1,23 @@
+{% load core_tags %}
+
+
+
+{% endif %}
diff -r 69e8aa135c2e -r 92101013d5ac sg101/urls.py
--- a/sg101/urls.py Sun May 26 13:29:44 2013 -0500
+++ b/sg101/urls.py Mon May 27 15:04:52 2013 -0500
@@ -91,6 +91,10 @@
url(r'^search/$',
search_view_factory(form_class=CustomModelSearchForm, load_all=True),
name='haystack_search'),
+ url(r'^search/ajax/$',
+ search_view_factory(template='search/search_ajax.html',
+ form_class=CustomModelSearchForm, load_all=True),
+ name='haystack_search_ajax'),
)
# For serving media files in development only: