Show More
@@ -133,6 +133,21 b' function showQuoteButton() {' | |||
|
133 | 133 | } |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | function attachAjaxToForms() { | |
|
137 | var forms = $('form.ajax-form'); | |
|
138 | forms.each(function() { | |
|
139 | var form = $(this); | |
|
140 | var options = { | |
|
141 | success: function(response, statusText, xhr, f) { | |
|
142 | afterForm(form, $.parseJSON(response)); | |
|
143 | }, | |
|
144 | url: form.attr('action') + '?ajax' | |
|
145 | }; | |
|
146 | ||
|
147 | form.ajaxForm(options); | |
|
148 | }); | |
|
149 | } | |
|
150 | ||
|
136 | 151 | $(document).ready(function() { |
|
137 | 152 | $('body').on('mouseup', function() { |
|
138 | 153 | showQuoteButton(); |
@@ -140,4 +155,6 b' function showQuoteButton() {' | |||
|
140 | 155 | $("#quote-button").click(function() { |
|
141 | 156 | addQuickQuote(); |
|
142 | 157 | }) |
|
158 | ||
|
159 | attachAjaxToForms(); | |
|
143 | 160 | }); |
@@ -13,18 +13,39 b'' | |||
|
13 | 13 | |
|
14 | 14 | <div class="tag_info"> |
|
15 | 15 | <h2> |
|
16 | <form action="{% url 'thread' opening_post.id %}" method="post" class="post-button-form"> | |
|
16 | <form action="{% url 'thread' opening_post.id %}" method="post" class="post-button-form ajax-form"> | |
|
17 | 17 | {% csrf_token %} |
|
18 | 18 | {% if is_favorite %} |
|
19 |
< |
|
|
19 | <input type="hidden" name="method" value="unsubscribe" /> | |
|
20 | <button id="thread-fav-button" class="fav">β </button> | |
|
20 | 21 | {% else %} |
|
21 |
< |
|
|
22 | <input type="hidden" name="method" value="subscribe" /> | |
|
23 | <button id="thread-fav-button" class="not_fav">β </button> | |
|
22 | 24 | {% endif %} |
|
23 | 25 | </form> |
|
24 | 26 | {{ opening_post.get_title_or_text }} |
|
25 | 27 | </h2> |
|
26 | 28 | </div> |
|
27 | 29 | |
|
30 | <script> | |
|
31 | function afterForm(form, data) { | |
|
32 | if (data.status == 'success') { | |
|
33 | var button = form.children('button'); | |
|
34 | var newMethod; | |
|
35 | if (data.fav == 'true') { | |
|
36 | button.addClass('fav'); | |
|
37 | button.removeClass('not_fav'); | |
|
38 | newMethod = 'unsubscribe'; | |
|
39 | } else { | |
|
40 | button.addClass('not_fav'); | |
|
41 | button.removeClass('fav'); | |
|
42 | newMethod = 'subscribe'; | |
|
43 | } | |
|
44 | form.children('input[name=method]').attr('value', newMethod); | |
|
45 | } | |
|
46 | } | |
|
47 | </script> | |
|
48 | ||
|
28 | 49 | {% if bumpable and thread.has_post_limit %} |
|
29 | 50 | <div class="bar-bg"> |
|
30 | 51 | <div class="bar-value" style="width:{{ bumplimit_progress }}%" id="bumplimit_progress"> |
@@ -1,5 +1,6 b'' | |||
|
1 | import json | |
|
1 | 2 | from django.core.exceptions import ObjectDoesNotExist |
|
2 | from django.http import Http404 | |
|
3 | from django.http import Http404, HttpResponse | |
|
3 | 4 | from django.shortcuts import get_object_or_404, render, redirect |
|
4 | 5 | from django.urls import reverse |
|
5 | 6 | from django.utils.decorators import method_decorator |
@@ -74,9 +75,13 b' class ThreadView(BaseBoardView, FormMixi' | |||
|
74 | 75 | raise Http404 |
|
75 | 76 | |
|
76 | 77 | if PARAMETER_METHOD in request.POST: |
|
77 | self.dispatch_method(request, opening_post) | |
|
78 | result = self.dispatch_method(request, opening_post) | |
|
78 | 79 | |
|
79 | return redirect('thread', post_id) # FIXME Different for different modes | |
|
80 | ajax = 'ajax' in request.GET | |
|
81 | if ajax: | |
|
82 | return HttpResponse(content=json.dumps(result)) | |
|
83 | else: | |
|
84 | return redirect('thread', post_id) # FIXME Different for different modes | |
|
80 | 85 | |
|
81 | 86 | if not opening_post.get_thread().is_archived(): |
|
82 | 87 | form = PostForm(request.POST, request.FILES, |
@@ -112,9 +117,19 b' class ThreadView(BaseBoardView, FormMixi' | |||
|
112 | 117 | settings_manager = get_settings_manager(request) |
|
113 | 118 | settings_manager.add_or_read_fav_thread(opening_post) |
|
114 | 119 | |
|
120 | return { | |
|
121 | 'status': 'success', | |
|
122 | 'fav': 'true' | |
|
123 | } | |
|
124 | ||
|
115 | 125 | def unsubscribe(self, request, opening_post): |
|
116 | 126 | settings_manager = get_settings_manager(request) |
|
117 | 127 | settings_manager.del_fav_thread(opening_post) |
|
118 | 128 | |
|
129 | return { | |
|
130 | 'status': 'success', | |
|
131 | 'fav': 'false' | |
|
132 | } | |
|
133 | ||
|
119 | 134 | def get_rss_url(self, opening_id): |
|
120 | 135 | return reverse('thread', kwargs={'post_id': opening_id}) + 'rss/' |
General Comments 0
You need to be logged in to leave comments.
Login now