2013-08-05 09:29:54 +00:00
|
|
|
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
|
|
|
// License: GNU General Public License v3. See license.txt
|
2012-02-23 07:05:32 +00:00
|
|
|
|
2012-01-27 10:27:17 +00:00
|
|
|
// js inside blog page
|
2012-07-12 13:11:12 +00:00
|
|
|
|
2012-12-17 07:22:43 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
var n_comments = $(".comment-row").length;
|
2012-07-09 14:32:52 +00:00
|
|
|
|
2012-12-17 07:22:43 +00:00
|
|
|
if(n_comments) {
|
|
|
|
$(".no_comment").toggle(false);
|
2012-07-11 13:10:57 +00:00
|
|
|
}
|
2012-12-17 07:22:43 +00:00
|
|
|
if(n_comments > 50) {
|
|
|
|
$(".add-comment").toggle(false)
|
2013-08-21 12:18:08 +00:00
|
|
|
.parent().append("<div class='alert alert-warning'>Comments are closed.</div>")
|
2012-07-11 13:10:57 +00:00
|
|
|
}
|
2012-12-17 07:22:43 +00:00
|
|
|
$(".add-comment").click(function() {
|
|
|
|
$("#comment-form").toggle();
|
|
|
|
$("#comment-form input, #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(),
|
|
|
|
cmd: "website.helpers.blog.add_comment",
|
2013-03-12 14:34:30 +00:00
|
|
|
comment_doctype: "Blog Post",
|
2012-12-17 07:22:43 +00:00
|
|
|
comment_docname: "{{ name }}",
|
2013-02-21 14:36:57 +00:00
|
|
|
page_name: "{{ page_name }}",
|
|
|
|
_type: "POST"
|
2012-07-11 13:10:57 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 07:22:43 +00:00
|
|
|
$("#comment-form .alert").toggle(false);
|
|
|
|
|
|
|
|
if(!args.comment_by_fullname || !args.comment_by || !args.comment) {
|
|
|
|
$("#comment-form .alert")
|
|
|
|
.html("All fields are necessary to submit the comment.")
|
|
|
|
.toggle(true);
|
|
|
|
return false;
|
2012-07-11 13:10:57 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 07:22:43 +00:00
|
|
|
|
|
|
|
$.ajax({
|
2013-02-10 07:40:53 +00:00
|
|
|
type: "POST",
|
2012-12-17 07:22:43 +00:00
|
|
|
url: "server.py",
|
|
|
|
data: args,
|
|
|
|
dataType: "json",
|
|
|
|
success: function(data) {
|
|
|
|
if(data.exc) {
|
|
|
|
$("#comment-form .alert")
|
|
|
|
.html(data.exc)
|
|
|
|
.toggle(true)
|
|
|
|
} else {
|
|
|
|
$(data.message).appendTo(".blog-comments");
|
|
|
|
$(".no_comment").toggle(false);
|
|
|
|
$(".add-comment").toggle(false);
|
|
|
|
$("#comment-form")
|
2013-08-21 12:18:08 +00:00
|
|
|
.replaceWith("<div class='alert alert-success'>Thank you for your comment!</div>")
|
2012-12-17 07:22:43 +00:00
|
|
|
}
|
2012-07-11 13:10:57 +00:00
|
|
|
}
|
2012-12-17 07:22:43 +00:00
|
|
|
})
|
2012-07-12 13:11:12 +00:00
|
|
|
|
2012-12-17 07:22:43 +00:00
|
|
|
return false;
|
|
|
|
})
|
|
|
|
})
|