diff --git a/boards/static/js/thread.js b/boards/static/js/thread.js
--- a/boards/static/js/thread.js
+++ b/boards/static/js/thread.js
@@ -133,6 +133,21 @@ function showQuoteButton() {
}
}
+function attachAjaxToForms() {
+ var forms = $('form.ajax-form');
+ forms.each(function() {
+ var form = $(this);
+ var options = {
+ success: function(response, statusText, xhr, f) {
+ afterForm(form, $.parseJSON(response));
+ },
+ url: form.attr('action') + '?ajax'
+ };
+
+ form.ajaxForm(options);
+ });
+}
+
$(document).ready(function() {
$('body').on('mouseup', function() {
showQuoteButton();
@@ -140,4 +155,6 @@ function showQuoteButton() {
$("#quote-button").click(function() {
addQuickQuote();
})
+
+ attachAjaxToForms();
});
diff --git a/boards/templates/boards/thread_normal.html b/boards/templates/boards/thread_normal.html
--- a/boards/templates/boards/thread_normal.html
+++ b/boards/templates/boards/thread_normal.html
@@ -13,18 +13,39 @@
-
{{ opening_post.get_title_or_text }}
+
+
{% if bumpable and thread.has_post_limit %}
diff --git a/boards/views/thread/thread.py b/boards/views/thread/thread.py
--- a/boards/views/thread/thread.py
+++ b/boards/views/thread/thread.py
@@ -1,5 +1,6 @@
+import json
from django.core.exceptions import ObjectDoesNotExist
-from django.http import Http404
+from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404, render, redirect
from django.urls import reverse
from django.utils.decorators import method_decorator
@@ -74,9 +75,13 @@ class ThreadView(BaseBoardView, FormMixi
raise Http404
if PARAMETER_METHOD in request.POST:
- self.dispatch_method(request, opening_post)
+ result = self.dispatch_method(request, opening_post)
- return redirect('thread', post_id) # FIXME Different for different modes
+ ajax = 'ajax' in request.GET
+ if ajax:
+ return HttpResponse(content=json.dumps(result))
+ else:
+ return redirect('thread', post_id) # FIXME Different for different modes
if not opening_post.get_thread().is_archived():
form = PostForm(request.POST, request.FILES,
@@ -112,9 +117,19 @@ class ThreadView(BaseBoardView, FormMixi
settings_manager = get_settings_manager(request)
settings_manager.add_or_read_fav_thread(opening_post)
+ return {
+ 'status': 'success',
+ 'fav': 'true'
+ }
+
def unsubscribe(self, request, opening_post):
settings_manager = get_settings_manager(request)
settings_manager.del_fav_thread(opening_post)
+ return {
+ 'status': 'success',
+ 'fav': 'false'
+ }
+
def get_rss_url(self, opening_id):
return reverse('thread', kwargs={'post_id': opening_id}) + 'rss/'