2016-10-19 09:57:43 +02:00
|
|
|
| {% import 'nodes/custom/comment/_macros.html' as macros %}
|
2017-09-21 01:14:53 +02:00
|
|
|
#comments.comments-container
|
|
|
|
section#comments-list.comments-list
|
2016-10-19 09:57:43 +02:00
|
|
|
.comment-reply-container
|
|
|
|
| {% if can_post_comments %}
|
|
|
|
.comment-reply-avatar
|
2016-11-03 15:34:50 +01:00
|
|
|
img(
|
2017-10-27 00:04:38 +02:00
|
|
|
title="{{ _('Commenting as') }} {{ current_user.full_name }}",
|
2016-11-03 15:34:50 +01:00
|
|
|
src="{{ current_user.gravatar }}")
|
2016-10-19 09:57:43 +02:00
|
|
|
|
|
|
|
.comment-reply-form
|
|
|
|
|
|
|
|
.comment-reply-field
|
|
|
|
textarea(
|
|
|
|
id="comment_field",
|
|
|
|
data-parent-id="{{ node_id }}",
|
2017-10-27 00:04:38 +02:00
|
|
|
placeholder="{{ _('Join the conversation...') }}")
|
2016-10-19 09:57:43 +02:00
|
|
|
|
|
|
|
.comment-reply-meta
|
2017-09-25 00:39:34 +02:00
|
|
|
|
|
|
|
button.comment-action-submit(
|
2016-10-19 09:57:43 +02:00
|
|
|
id="comment_submit",
|
|
|
|
type="button",
|
2016-11-03 15:34:50 +01:00
|
|
|
title="Post Comment (Ctrl+Enter)")
|
2017-09-25 00:39:34 +02:00
|
|
|
span
|
|
|
|
i.pi-paper-plane
|
2017-10-27 00:04:38 +02:00
|
|
|
| {{ _('Send') }}
|
2017-09-25 00:39:34 +02:00
|
|
|
span.hotkey Ctrl + Enter
|
|
|
|
|
|
|
|
.comment-reply-preview
|
|
|
|
.comment-reply-preview-md
|
|
|
|
.comment-reply-info
|
|
|
|
.comment-action-cancel(
|
|
|
|
type="button",
|
2017-10-27 00:04:38 +02:00
|
|
|
title="{{ _('cancel') }}")
|
|
|
|
span {{ _('cancel') }}
|
2016-10-19 09:57:43 +02:00
|
|
|
|
2017-09-25 00:39:34 +02:00
|
|
|
a(
|
2017-10-27 00:04:38 +02:00
|
|
|
title="{{ _('Handy guide of Markdown syntax') }}",
|
2017-09-25 00:39:34 +02:00
|
|
|
target="_blank",
|
|
|
|
href="https://guides.github.com/features/mastering-markdown/")
|
2017-10-27 00:04:38 +02:00
|
|
|
span {{ _('markdown cheatsheet') }}
|
2016-10-19 09:57:43 +02:00
|
|
|
|
|
|
|
| {% elif current_user.is_authenticated %}
|
|
|
|
|
2016-11-08 14:19:17 +01:00
|
|
|
| {# * User is authenticated, but has no subscription or 'POST' permission #}
|
2016-10-19 09:57:43 +02:00
|
|
|
.comment-reply-form
|
|
|
|
.comment-reply-field.sign-in
|
2017-08-18 14:47:42 +02:00
|
|
|
| {% if current_user.has_cap('subscriber') %}
|
2016-11-09 18:15:34 +01:00
|
|
|
i.pi-lock
|
|
|
|
| Only project members can comment.
|
2017-12-06 14:39:30 +01:00
|
|
|
| {% elif current_user.has_cap('can-renew-subscription') %}
|
|
|
|
i.pi-heart
|
|
|
|
a(href='/renew', target='_blank') Renew your subscription to join the conversation!
|
2016-11-09 18:15:34 +01:00
|
|
|
| {% else %}
|
|
|
|
| Join the conversation! <a href="https://store.blender.org/product/membership/">Subscribe to Blender Cloud</a> now.
|
|
|
|
| {% endif %}
|
2016-10-19 09:57:43 +02:00
|
|
|
|
|
|
|
| {% else %}
|
|
|
|
| {# * User is not autenticated #}
|
|
|
|
.comment-reply-form
|
|
|
|
.comment-reply-field.sign-in
|
2017-10-27 00:04:38 +02:00
|
|
|
a(href="{{ url_for('users.login') }}") {{ _('Log in to comment') }}
|
2016-10-19 09:57:43 +02:00
|
|
|
| {% endif %}
|
|
|
|
|
2017-09-16 20:11:16 +02:00
|
|
|
| {% if show_comments and (nr_of_comments > 0) %}
|
2017-09-21 01:14:53 +02:00
|
|
|
section.comments-list-header
|
|
|
|
.comments-list-title
|
2017-10-27 00:04:38 +02:00
|
|
|
| {{ nr_of_comments }} {{ _('comment') }}{{ nr_of_comments|pluralize }}
|
2017-09-30 23:21:54 +02:00
|
|
|
.comments-list-items
|
2016-10-19 09:57:43 +02:00
|
|
|
| {% for comment in comments['_items'] %}
|
|
|
|
| {{ macros.render_comment(comment, False) }}
|
|
|
|
| {% endfor %}
|
2016-11-02 15:40:26 +01:00
|
|
|
| {% endif %}
|
2016-10-19 09:57:43 +02:00
|
|
|
|
2016-11-03 15:34:50 +01:00
|
|
|
| {% block comment_scripts %}
|
2016-10-19 09:57:43 +02:00
|
|
|
script.
|
2017-09-25 00:35:35 +02:00
|
|
|
|
2017-11-23 16:40:58 +01:00
|
|
|
{% if show_comments %}
|
|
|
|
$('body')
|
|
|
|
.off('pillar:comment-posted')
|
|
|
|
.on('pillar:comment-posted', function(e, comment_node_id) {
|
|
|
|
|
|
|
|
var commentsUrl = "{{ url_for('nodes.comments_for_node', node_id=node_id) }}";
|
|
|
|
|
|
|
|
loadComments(commentsUrl)
|
|
|
|
.done(function() {
|
|
|
|
$('#' + comment_node_id).scrollHere();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-25 00:35:35 +02:00
|
|
|
// If there's a comment link in the URL, scroll there
|
2017-09-13 14:05:18 +02:00
|
|
|
function scrollToLinkedComment() {
|
|
|
|
var scrollToId = location.hash;
|
|
|
|
if (scrollToId.length <= 1) return;
|
|
|
|
|
|
|
|
$(scrollToId)
|
|
|
|
.addClass('comment-linked')
|
|
|
|
.scrollHere();
|
|
|
|
}
|
|
|
|
$(scrollToLinkedComment);
|
2016-11-03 15:34:50 +01:00
|
|
|
|
2017-11-23 16:40:58 +01:00
|
|
|
{% endif %}
|
2017-11-04 01:58:05 +01:00
|
|
|
|
2017-11-23 16:40:58 +01:00
|
|
|
|
|
|
|
{% if can_post_comments %}
|
|
|
|
|
|
|
|
// If we can actually comment, load the tools to do it
|
2017-11-04 01:58:05 +01:00
|
|
|
|
2017-09-25 00:35:35 +02:00
|
|
|
// Initialize Markdown to later convert comment as we type
|
2016-11-03 15:34:50 +01:00
|
|
|
var convert = new Markdown.getSanitizingConverter();
|
|
|
|
Markdown.Extra.init(convert);
|
|
|
|
convert = convert.makeHtml;
|
|
|
|
|
2017-09-25 00:35:35 +02:00
|
|
|
// Submit new comment
|
|
|
|
$(document)
|
|
|
|
.off('click','body .comment-action-submit')
|
|
|
|
.on( 'click','body .comment-action-submit', function(e){
|
2017-09-22 19:12:13 +02:00
|
|
|
post_comment($(this));
|
2016-10-19 09:57:43 +02:00
|
|
|
});
|
|
|
|
|
2017-09-25 00:35:35 +02:00
|
|
|
// Writing comment
|
2016-10-19 09:57:43 +02:00
|
|
|
// Markdown convert as we type in the textarea
|
2017-09-25 00:35:35 +02:00
|
|
|
$(document)
|
|
|
|
.off('keyup','body .comment-reply-field textarea')
|
|
|
|
.on( 'keyup','body .comment-reply-field textarea',function(e){
|
2016-10-19 09:57:43 +02:00
|
|
|
var $textarea = $(this);
|
|
|
|
var $container = $(this).parent();
|
2017-09-25 00:39:34 +02:00
|
|
|
var $preview = $container.parent().find('.comment-reply-preview-md');
|
2016-10-19 09:57:43 +02:00
|
|
|
|
|
|
|
// TODO: communicate with back-end to do the conversion,
|
|
|
|
// rather than relying on our JS-converted Markdown.
|
|
|
|
$preview.html(convert($textarea.val()));
|
|
|
|
|
|
|
|
// While we are at it, style if empty
|
2016-11-03 15:34:50 +01:00
|
|
|
if ($textarea.val()) {
|
|
|
|
$container.addClass('filled');
|
2016-10-19 09:57:43 +02:00
|
|
|
} else {
|
2016-11-03 15:34:50 +01:00
|
|
|
$container.removeClass('filled');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send on ctrl+enter
|
|
|
|
if ($textarea.is(":focus")) {
|
|
|
|
if ((e.keyCode == 10 || e.keyCode == 13) && e.ctrlKey){
|
2017-09-22 19:12:13 +02:00
|
|
|
post_comment($container.find('.comment-action-submit'));
|
2016-11-03 15:34:50 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-19 09:57:43 +02:00
|
|
|
});
|
|
|
|
|
2017-11-23 16:40:58 +01:00
|
|
|
// Autoresize the textarea as we type
|
|
|
|
$('#comment_field').autoResize();
|
|
|
|
|
2016-10-19 09:57:43 +02:00
|
|
|
|
2017-09-25 00:35:35 +02:00
|
|
|
// Edit comment
|
|
|
|
// Enter edit mode
|
|
|
|
$(document)
|
|
|
|
.off('click','body .comment-action-edit span.edit_mode')
|
|
|
|
.on( 'click','body .comment-action-edit span.edit_mode',function(){
|
|
|
|
|
2016-10-19 09:57:43 +02:00
|
|
|
comment_mode(this, 'edit');
|
|
|
|
|
2017-09-25 00:39:34 +02:00
|
|
|
var $parent_div = $(this).closest('.comment-container');
|
|
|
|
var comment_id = $parent_div.data('node-id');
|
2016-10-19 09:57:43 +02:00
|
|
|
|
2017-11-08 22:01:34 +01:00
|
|
|
var comment_content = $parent_div.find('.comment-body span');
|
2016-10-19 09:57:43 +02:00
|
|
|
var height = comment_content.height();
|
|
|
|
|
|
|
|
loadComment(comment_id, {'properties.content': 1})
|
2017-09-25 00:39:34 +02:00
|
|
|
|
2016-10-19 09:57:43 +02:00
|
|
|
.done(function(data) {
|
|
|
|
var comment_raw = data['properties']['content'];
|
|
|
|
comment_content.html($('<textarea>').text(comment_raw));
|
|
|
|
comment_content
|
|
|
|
.addClass('editing')
|
|
|
|
.find('textarea')
|
2017-11-08 22:49:56 +01:00
|
|
|
.autoResize()
|
2016-10-19 09:57:43 +02:00
|
|
|
.focus()
|
|
|
|
.trigger('keyup');
|
|
|
|
})
|
|
|
|
.fail(function(xhr) {
|
|
|
|
if (console) console.log('Error fetching comment: ', xhr);
|
2017-09-25 00:37:03 +02:00
|
|
|
toastr.error('Error ' + xhr.status + ' entering edit mode.');
|
2016-10-19 09:57:43 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-09-25 00:35:35 +02:00
|
|
|
// Abort, abort
|
|
|
|
$(document)
|
|
|
|
.off('click','body .comment-action-edit span.edit_cancel')
|
|
|
|
.on( 'click','body .comment-action-edit span.edit_cancel',function(e){
|
2016-10-20 16:47:04 +02:00
|
|
|
commentEditCancel(this, true);
|
2016-10-19 09:57:43 +02:00
|
|
|
});
|
|
|
|
|
2017-09-25 00:35:35 +02:00
|
|
|
// Save edited comment
|
|
|
|
$(document)
|
|
|
|
.off('click','body .comment-action-edit span.edit_save')
|
|
|
|
.on( 'click','body .comment-action-edit span.edit_save',function(e){
|
2016-10-19 09:57:43 +02:00
|
|
|
var $button = $(this);
|
|
|
|
var $container = $button.closest('.comment-container');
|
|
|
|
|
|
|
|
save_comment(false, $container)
|
|
|
|
.progress(function() {
|
|
|
|
$button
|
|
|
|
.addClass('submitting')
|
|
|
|
.html('<i class="pi-spin spin"></i> Posting...');
|
|
|
|
})
|
|
|
|
.fail(function(xhr) {
|
|
|
|
if (typeof xhr === 'string') {
|
|
|
|
show_comment_edit_button_error($button, xhr);
|
|
|
|
} else {
|
|
|
|
// If it's not a string, we assume it's a jQuery XHR object.
|
|
|
|
if (console) console.log('Error saving comment:', xhr.responseText);
|
|
|
|
show_comment_edit_button_error($button, "Houston! Try again?");
|
|
|
|
}
|
|
|
|
})
|
2016-10-20 16:47:04 +02:00
|
|
|
.done(function(comment_id, comment_html) {
|
|
|
|
commentEditCancel($button, false)
|
|
|
|
|
2017-11-08 22:01:34 +01:00
|
|
|
$container.find('.comment-body span')
|
2016-10-20 16:47:04 +02:00
|
|
|
.html(comment_html)
|
2017-11-08 22:49:56 +01:00
|
|
|
.removeClass('editing')
|
2016-10-20 16:47:04 +02:00
|
|
|
.flashOnce();
|
2016-10-19 09:57:43 +02:00
|
|
|
|
|
|
|
$button
|
|
|
|
.html('<i class="pi-check"></i> save changes')
|
|
|
|
.removeClass('saving');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-23 16:40:58 +01:00
|
|
|
{% endif %}
|
|
|
|
|
2016-10-19 09:57:43 +02:00
|
|
|
| {% endblock %}
|