diff --git a/pillar/web/nodes/custom/comments.py b/pillar/web/nodes/custom/comments.py index c2c2861b..40194c6c 100644 --- a/pillar/web/nodes/custom/comments.py +++ b/pillar/web/nodes/custom/comments.py @@ -207,6 +207,26 @@ def comments_for_node(node_id): node_id=node_id, comments=comments, nr_of_comments=nr_of_comments, + show_comments=True, + can_post_comments=can_post_comments) + + +@blueprint.route('//commentform') +def commentform_for_node(node_id): + """Shows only the comment for for comments attached to the given node. + + i.e. does not show the comments themselves, just the form to post a new comment. + """ + + api = system_util.pillar_api() + + node = Node.find(node_id, api=api) + project = Project({'_id': node.project}) + can_post_comments = project.node_type_has_method('comment', 'POST', api=api) + + return render_template('nodes/custom/comment/list_embed.html', + node_id=node_id, + show_comments=False, can_post_comments=can_post_comments) diff --git a/src/templates/nodes/custom/comment/list_embed.jade b/src/templates/nodes/custom/comment/list_embed.jade index f968fdde..83f1e9f2 100644 --- a/src/templates/nodes/custom/comment/list_embed.jade +++ b/src/templates/nodes/custom/comment/list_embed.jade @@ -69,6 +69,7 @@ | {% endif %} + | {% if show_comments %} section#comments-list-header #comments-list-title | {% if nr_of_comments == 0 %}No{% else %}{{ nr_of_comments }}{% endif %} comment{{ nr_of_comments|pluralize }} @@ -76,6 +77,7 @@ | {% for comment in comments['_items'] %} | {{ macros.render_comment(comment, False) }} | {% endfor %} + | {% endif %} | {% block comment_scripts %} script. @@ -99,11 +101,16 @@ script. } }) .done(function(comment_node_id) { + {% if show_comments %} var commentsUrl = "{{ url_for('nodes.comments_for_node', node_id=node_id) }}"; loadComments(commentsUrl) .done(function() { $('#' + comment_node_id).scrollHere(); }); + {% else %} + // TODO: implement something here + console.log('Comment posted succesfully, reload the page to see it.'); + {% endif %} }); });