|
|
@@ -14,7 +14,7 @@ |
|
|
|
{% if login_required and frappe.user=="Guest" %} |
|
|
|
<div class="text-muted"><a href="/login?redirect-to={{ pathname }}">{{ _("Login to comment") }}</a></div> |
|
|
|
{% else %} |
|
|
|
<p><a class="add-comment">{{ _("Add Comment") }}</a></p> |
|
|
|
<a class="add-comment">{{ _("Add Comment") }}</a> |
|
|
|
<div style="display: none;" id="comment-form"> |
|
|
|
<p>{{ _("Add Comment") }}</p> |
|
|
|
<div class="alert" style="display:none;"></div> |
|
|
@@ -40,65 +40,64 @@ |
|
|
|
{% endif %} |
|
|
|
</div> |
|
|
|
<script> |
|
|
|
frappe.ready(function() { |
|
|
|
console.log("ready!"); |
|
|
|
var n_comments = $(".comment-row").length; |
|
|
|
frappe.ready(function() { |
|
|
|
var n_comments = $(".comment-row").length; |
|
|
|
|
|
|
|
if(n_comments) { |
|
|
|
$(".no_comment").toggle(false); |
|
|
|
} |
|
|
|
if(n_comments > 50) { |
|
|
|
$(".add-comment").toggle(false) |
|
|
|
.parent().append("<div class='text-muted'>Comments are closed.</div>") |
|
|
|
} |
|
|
|
$(".add-comment").click(function() { |
|
|
|
$(this).toggle(false); |
|
|
|
$("#comment-form").toggle(); |
|
|
|
|
|
|
|
$("[name='comment_by']").val(getCookie("user_id") || ""); |
|
|
|
$("[name='comment_by_fullname']").val(getCookie("full_name") || ""); |
|
|
|
$("#comment-form textarea").val(""); |
|
|
|
}) |
|
|
|
$("#submit-comment").click(function() { |
|
|
|
var args = { |
|
|
|
comment_by_fullname: $("[name='comment_by_fullname']").val(), |
|
|
|
comment_by: $("[name='comment_by']").val(), |
|
|
|
comment: $("[name='comment']").val(), |
|
|
|
comment_doctype: "{{ doctype }}", |
|
|
|
comment_docname: "{{ name }}", |
|
|
|
comment_type: "Comment", |
|
|
|
page_name: "{{ pathname }}", |
|
|
|
if(n_comments) { |
|
|
|
$(".no_comment").toggle(false); |
|
|
|
} |
|
|
|
|
|
|
|
if(!args.comment_by_fullname || !args.comment_by || !args.comment) { |
|
|
|
frappe.msgprint("All fields are necessary to submit the comment.") |
|
|
|
return false; |
|
|
|
if(n_comments > 50) { |
|
|
|
$(".add-comment").toggle(false) |
|
|
|
.parent().append("<div class='text-muted'>Comments are closed.</div>") |
|
|
|
} |
|
|
|
$(".add-comment").click(function() { |
|
|
|
$(this).toggle(false); |
|
|
|
$("#comment-form").toggle(); |
|
|
|
|
|
|
|
if (!valid_email(args.comment_by)) { |
|
|
|
frappe.msgprint("Please enter a valid email address."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
$("[name='comment_by']").val(getCookie("user_id") || ""); |
|
|
|
$("[name='comment_by_fullname']").val(getCookie("full_name") || ""); |
|
|
|
$("#comment-form textarea").val(""); |
|
|
|
}) |
|
|
|
$("#submit-comment").click(function() { |
|
|
|
var args = { |
|
|
|
comment_by_fullname: $("[name='comment_by_fullname']").val(), |
|
|
|
comment_by: $("[name='comment_by']").val(), |
|
|
|
comment: $("[name='comment']").val(), |
|
|
|
comment_doctype: "{{ doctype }}", |
|
|
|
comment_docname: "{{ name }}", |
|
|
|
comment_type: "Comment", |
|
|
|
page_name: "{{ pathname }}", |
|
|
|
} |
|
|
|
|
|
|
|
frappe.call({ |
|
|
|
btn: this, |
|
|
|
type: "POST", |
|
|
|
method: "frappe.templates.includes.comments.comments.add_comment", |
|
|
|
args: args, |
|
|
|
callback: function(r) { |
|
|
|
if(r.exc) { |
|
|
|
if(r._server_messages) |
|
|
|
frappe.msgprint(r._server_messages); |
|
|
|
} else { |
|
|
|
$(r.message).appendTo("#comment-list"); |
|
|
|
$(".no-comment, .add-comment").toggle(false); |
|
|
|
$("#comment-form") |
|
|
|
.replaceWith("<div class='alert alert-success'>Thank you for your comment!</div>") |
|
|
|
} |
|
|
|
if(!args.comment_by_fullname || !args.comment_by || !args.comment) { |
|
|
|
frappe.msgprint("All fields are necessary to submit the comment.") |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (!valid_email(args.comment_by)) { |
|
|
|
frappe.msgprint("Please enter a valid email address."); |
|
|
|
return false; |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
return false; |
|
|
|
}) |
|
|
|
}) |
|
|
|
frappe.call({ |
|
|
|
btn: this, |
|
|
|
type: "POST", |
|
|
|
method: "frappe.templates.includes.comments.comments.add_comment", |
|
|
|
args: args, |
|
|
|
callback: function(r) { |
|
|
|
if(r.exc) { |
|
|
|
if(r._server_messages) |
|
|
|
frappe.msgprint(r._server_messages); |
|
|
|
} else { |
|
|
|
$(r.message).appendTo("#comment-list"); |
|
|
|
$(".no-comment, .add-comment").toggle(false); |
|
|
|
$("#comment-form") |
|
|
|
.replaceWith('<div class="text-muted">Thank you for your comment!</div>') |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
return false; |
|
|
|
}) |
|
|
|
}); |
|
|
|
</script> |