Просмотр исходного кода

Change thread title on its edit

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

+ 7 - 0
misago/static/misago/js/misago-posts.js

@@ -41,6 +41,13 @@ $(function() {
           on_post: function(data) {
             Misago.Alerts.success(data.message);
             _this.change_post(data.parsed);
+
+            if (Misago.Posting.$form.find('.thread-title').length == 1) {
+              var old_title = $.trim($('#thread-title').html());
+              $('#thread-title').html(data.title_escaped);
+              document.title = document.title.replace(old_title, data.title_escaped)
+            }
+
             Misago.Posting.cancel();
             Misago.Scroll.scrollTo(_this.$e);
             return false;

+ 1 - 1
misago/templates/misago/thread/replies.html

@@ -27,7 +27,7 @@
       </ol>
       {% endif %}
 
-      <h1>{{ thread }}</h1>
+      <h1 id="thread-title">{{ thread }}</h1>
 
       <ul class="list-inline page-details">
         <li class="tooltip-bottom" title="{% trans "Thread author" %}">

+ 2 - 1
misago/threads/posting/reply.py

@@ -11,7 +11,8 @@ class ReplyFormMiddleware(PostingMiddleware):
         initial_data = {'title': self.thread.title, 'post': self.post.original}
 
         if self.mode == EDIT:
-            if can_edit_thread(self.user, self.thread):
+            is_first_post = self.post.id == self.thread.first_post_id
+            if is_first_post and can_edit_thread(self.user, self.thread):
                 FormType = ThreadForm
             else:
                 FormType = ReplyForm

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

@@ -2,6 +2,7 @@ from django.contrib import messages
 from django.db.transaction import atomic
 from django.http import JsonResponse
 from django.shortcuts import redirect, render
+from django.utils import html
 from django.utils.translation import ugettext as _
 from django.views.generic import View
 
@@ -128,6 +129,7 @@ class PostingView(ViewBase):
                             'parsed': post.parsed,
                             'original': post.original,
                             'title': thread.title,
+                            'title_escaped': html.escape(thread.title),
                         })
                     except PostingInterrupt as e:
                         return JsonResponse({'interrupt': e.message})