Rafał Pitoń 10 лет назад
Родитель
Сommit
6f3f6970c5

+ 14 - 0
misago/static/misago/js/misago-posting.js

@@ -118,6 +118,20 @@ $(function() {
         _this.update_affix()
       });
 
+      this.$container.find('button[name="submit"]').click(function() {
+        var form_data = _this.$form.serialize() + '&submit=1';
+        $.post(_this.api_url, form_data, function(data) {
+          if (data.thread_url !== undefined) {
+            window.location.replace(data.thread_url);
+          } else if (data.errors !== undefined) {
+            Misago.Alerts.error(data.errors[0]);
+          } else {
+            Misago.Alerts.error();
+          }
+        });
+        return false;
+      })
+
     }
 
     this.update_affix_end = function() {

+ 3 - 3
misago/threads/forms/posting.py

@@ -116,8 +116,8 @@ class ThreadPinForm(forms.Form):
 
     is_pinned = forms.YesNoSwitch(
         label=_("Pin thread"),
-        yes_label=_("Pin thread"),
-        no_label=_("Unpin thread"))
+        yes_label=_("Pinned thread"),
+        no_label=_("Unpinned thread"))
 
 
 class ThreadCloseForm(forms.Form):
@@ -127,5 +127,5 @@ class ThreadCloseForm(forms.Form):
 
     is_closed = forms.YesNoSwitch(
         label=_("Close thread"),
-        yes_label=_("Close thread"),
+        yes_label=_("Closed thread"),
         no_label=_("Open thread"))

+ 2 - 0
misago/threads/posting/__init__.py

@@ -121,6 +121,8 @@ class EditorFormset(object):
         for form in self.get_forms_list():
             if not form.is_valid():
                 all_forms_valid = False
+                for error in form.non_field_errors():
+                    self.errors.append(unicode(error))
         return all_forms_valid
 
     def save(self):

+ 21 - 7
misago/threads/views/generic/posting.py

@@ -6,6 +6,7 @@ from django.shortcuts import redirect, render
 from django.utils.translation import ugettext_lazy, ugettext as _
 from django.views.generic import View
 
+from misago.core.exceptions import AjaxError
 from misago.forums.lists import get_forum_path
 
 from misago.threads.posting import (PostingInterrupt, EditorFormset,
@@ -86,12 +87,26 @@ class EditorView(ViewBase):
                                 quote=quote)
 
         if request.method == 'POST':
-            if 'submit' in request.POST and formset.is_valid():
-                try:
-                    formset.save()
-                    return redirect(thread.get_absolute_url())
-                except PostingInterrupt as e:
-                    messages.error(request, e.message)
+            if 'submit' in request.POST:
+                if formset.is_valid():
+                    try:
+                        formset.save()
+                        messages.success(request, _("New thread was posted."))
+                        if request.is_ajax():
+                            return JsonResponse({
+                                'thread_url': thread.get_absolute_url()
+                            })
+                        else:
+                            return redirect(thread.get_absolute_url())
+                    except PostingInterrupt as e:
+                        if request.is_ajax():
+                            raise AjaxError(e.message)
+                        else:
+                            messages.error(request, e.message)
+                elif request.is_ajax():
+                    return JsonResponse({
+                        'errors': formset.errors
+                    })
 
             if request.is_ajax():
                 if 'form' in request.POST:
@@ -103,7 +118,6 @@ class EditorView(ViewBase):
                         'preview': formset.post.parsed
                     })
 
-
         return self.render(request, {
             'mode': mode,
             'formset': formset,