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

quote/reply (redirect) & quick-quote (javascript) functionalities

Casper Van Gheluwe 11 лет назад
Родитель
Сommit
c409975b76

+ 29 - 0
flaskbb/forum/views.py

@@ -335,6 +335,35 @@ def new_post(topic_id, slug=None):
     return render_template("forum/new_post.html", topic=topic, form=form)
 
 
+@forum.route("/topic/<int:topic_id>/post/<int:post_id>/reply", methods=["POST", "GET"])
+@login_required
+def reply_post(topic_id, post_id):
+    topic = Topic.query.filter_by(id=topic_id).first_or_404()
+    post = Post.query.filter_by(id=post_id).first_or_404()
+
+    if post.topic.forum.locked:
+        flash("This forum is locked; you cannot submit new topics or posts.",
+              "danger")
+        return redirect(post.topic.forum.url)
+
+    if post.topic.locked:
+        flash("The topic is locked.", "danger")
+        return redirect(post.topic.forum.url)
+
+    if not can_post_reply(user=current_user, forum=topic.forum):
+        flash("You do not have the permissions to post in this topic", "danger")
+        return redirect(topic.forum.url)
+
+    form = ReplyForm()
+    if form.validate_on_submit():
+        form.save(current_user, topic)
+        return redirect(post.topic.url)
+    else:
+        form.content.data = '[quote]{}[/quote]'.format(post.content)
+
+    return render_template("forum/new_post.html", topic=post.topic, form=form)
+
+
 @forum.route("/post/<int:post_id>/edit", methods=["POST", "GET"])
 @login_required
 def edit_post(post_id):

+ 23 - 0
flaskbb/static/js/topic.js

@@ -0,0 +1,23 @@
+/**
+ * Topic.js
+ */
+$(document).ready(function () {
+    console.log("document ready")
+        $(".quote_btn").click(function (event) {
+            event.preventDefault();
+
+            // QuickReply Textarea
+            var $contents = $(".reply-content textarea#content");
+            // Original Post
+            var $original = $(".post_body#" + $(this).attr('data-post-id'));
+            // Content of the Post, in plaintext (strips tags) and without the signature
+            var content = $original.clone().find('.signature').remove().end().text().trim();
+
+            // Add quote to the Quickreply Textarea
+            if ($contents.val().length > 0) {
+                $contents.val($contents.val() + "\n[quote]" + content + "[/quote]");
+            } else {
+        $contents.val("[quote]" + content + "[/quote]");
+        }
+    });
+});

+ 22 - 13
flaskbb/templates/forum/topic.html

@@ -1,7 +1,7 @@
+{% extends theme("layout.html") %}
 {% set page_title = topic.title ~ " - Topic" %}
 {% set active_forum_nav=True %}
 
-{% extends theme("layout.html") %}
 {% block content %}
 {% from theme('macros.html') import render_pagination, form_field %}
 
@@ -130,12 +130,14 @@
                 <div class="post_body" id="pid{{ post.id }}">
                 {% autoescape false %}
                     {{ post.content|markup }}
-                    <!-- Signaure Begin -->
+                    <!-- Signature Begin -->
                     {% if post.user_id and post.user.signature %}
-                    <hr>
-                    {{ post.user.signature|markup }}
+                    <div class="signature">
+                        <hr>
+                        {{ post.user.signature|markup }}
+                    </div>
                     {% endif %}
-                    <!-- Signaure End -->
+                    <!-- Signature End -->
                 {% endautoescape %}
                 </div>
             </td>
@@ -167,25 +169,32 @@
                         <a href="{{ url_for('forum.delete_post', post_id=post.id) }}">Delete</a> |
                         {% endif %}
                     {% endif %}
-
-                    <a href="#">Quote</a>
+                    {% if current_user|post_reply(topic.forum) and not (topic.locked or topic.forum.locked) %}
+                        <!-- Quick quote -->
+                        <a href="#" class="quote_btn" data-post-id="pid{{ post.id }}">Quote</a> |
+                        <!-- Full quote/reply -->
+                        <a href="{{ url_for('forum.reply_post', topic_id=topic.id, post_id=post.id) }}">Reply</a>
+                    {% endif %}
                 </span>
             </td>
         </tr>
         {% endfor %}
-
     </tbody>
 </table>
 
 {% if form %}
     {% from "macros.html" import render_field %}
-<form class="form" action="#" method="post">
-    {{ form.hidden_tag() }}
+    <form class="form" action="#" method="post">
+        {{ form.hidden_tag() }}
 
-    {{ render_field(form.content, div_class="col-sm-12", rows=5) }}
+        {{ render_field(form.content, div_class="col-sm-12 reply-content", rows=5) }}
 
-    <button type="submit" class="btn btn-success">Reply!</button>
-</form>
+        <button type="submit" class="btn btn-success">Reply!</button>
+    </form>
 {% endif %}
 
 {% endblock %}
+
+{% block scripts %}
+<script type="text/javascript" src="{{ url_for('static', filename='js/topic.js') }}"></script>
+{% endblock %}

+ 3 - 0
flaskbb/templates/layout.html

@@ -123,5 +123,8 @@
         <script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
         <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
         {% endblock %}
+
+        {% block scripts %}
+        {% endblock %}
     </body>
 </html>

+ 3 - 0
flaskbb/themes/bootstrap2/templates/layout.html

@@ -124,5 +124,8 @@
         <script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
         <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
         {% endblock %}
+
+        {% block scripts %}
+        {% endblock %}
     </body>
 </html>

+ 3 - 0
flaskbb/themes/bootstrap3/templates/layout.html

@@ -123,5 +123,8 @@
         <script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
         <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
         {% endblock %}
+
+        {% block scripts %}
+        {% endblock %}
     </body>
 </html>