blob: 11656c8a64240c988a5756baae556926e3064b02 [file] [log] [blame]
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05301// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
2// License: GNU General Public License v3. See license.txt
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05303
Rushabh Mehtac8d2e732012-01-27 15:57:17 +05304// js inside blog page
Anand Doshi51146c02012-07-12 18:41:12 +05305
Rushabh Mehtafd6ad192012-12-17 12:52:43 +05306$(document).ready(function() {
7 var n_comments = $(".comment-row").length;
Anand Doshi40fce892012-07-09 20:02:52 +05308
Rushabh Mehtafd6ad192012-12-17 12:52:43 +05309 if(n_comments) {
10 $(".no_comment").toggle(false);
Anand Doshi40fce892012-07-09 20:02:52 +053011 }
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053012 if(n_comments > 50) {
13 $(".add-comment").toggle(false)
14 .parent().append("<div class='alert'>Comments are closed.</div>")
Anand Doshi8c7e76b2012-07-11 18:40:57 +053015 }
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053016 $(".add-comment").click(function() {
17 $("#comment-form").toggle();
18 $("#comment-form input, #comment-form, textarea").val("");
19 })
20 $("#submit-comment").click(function() {
21 var args = {
22 comment_by_fullname: $("[name='comment_by_fullname']").val(),
23 comment_by: $("[name='comment_by']").val(),
24 comment: $("[name='comment']").val(),
25 cmd: "website.helpers.blog.add_comment",
Anand Doshi2e6806e2013-03-12 20:04:30 +053026 comment_doctype: "Blog Post",
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053027 comment_docname: "{{ name }}",
Anand Doshi5acd0822013-02-21 20:06:57 +053028 page_name: "{{ page_name }}",
29 _type: "POST"
Anand Doshi8c7e76b2012-07-11 18:40:57 +053030 }
31
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053032 $("#comment-form .alert").toggle(false);
33
34 if(!args.comment_by_fullname || !args.comment_by || !args.comment) {
35 $("#comment-form .alert")
36 .html("All fields are necessary to submit the comment.")
37 .toggle(true);
38 return false;
Anand Doshi8c7e76b2012-07-11 18:40:57 +053039 }
40
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053041
42 $.ajax({
Anand Doshi18a0c582013-02-10 13:10:53 +053043 type: "POST",
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053044 url: "server.py",
45 data: args,
46 dataType: "json",
47 success: function(data) {
48 if(data.exc) {
49 $("#comment-form .alert")
50 .html(data.exc)
51 .toggle(true)
52 } else {
53 $(data.message).appendTo(".blog-comments");
54 $(".no_comment").toggle(false);
55 $(".add-comment").toggle(false);
56 $("#comment-form")
57 .replaceWith("<div class='alert'>Thank you for your comment!</div>")
58 }
Anand Doshi8c7e76b2012-07-11 18:40:57 +053059 }
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053060 })
Anand Doshi51146c02012-07-12 18:41:12 +053061
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053062 return false;
63 })
64})