blob: efdd6bca8afa87497d9925049fd068b60b0c82f8 [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301// ERPNext - web based ERP (http://erpnext.com)
2// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
Rushabh Mehtac8d2e732012-01-27 15:57:17 +053017// js inside blog page
Anand Doshi51146c02012-07-12 18:41:12 +053018
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053019$(document).ready(function() {
20 var n_comments = $(".comment-row").length;
Anand Doshi40fce892012-07-09 20:02:52 +053021
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053022 if(n_comments) {
23 $(".no_comment").toggle(false);
Anand Doshi40fce892012-07-09 20:02:52 +053024 }
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053025 if(n_comments > 50) {
26 $(".add-comment").toggle(false)
27 .parent().append("<div class='alert'>Comments are closed.</div>")
Anand Doshi8c7e76b2012-07-11 18:40:57 +053028 }
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053029 $(".add-comment").click(function() {
30 $("#comment-form").toggle();
31 $("#comment-form input, #comment-form, textarea").val("");
32 })
33 $("#submit-comment").click(function() {
34 var args = {
35 comment_by_fullname: $("[name='comment_by_fullname']").val(),
36 comment_by: $("[name='comment_by']").val(),
37 comment: $("[name='comment']").val(),
38 cmd: "website.helpers.blog.add_comment",
Anand Doshi2e6806e2013-03-12 20:04:30 +053039 comment_doctype: "Blog Post",
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053040 comment_docname: "{{ name }}",
Anand Doshi5acd0822013-02-21 20:06:57 +053041 page_name: "{{ page_name }}",
42 _type: "POST"
Anand Doshi8c7e76b2012-07-11 18:40:57 +053043 }
44
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053045 $("#comment-form .alert").toggle(false);
46
47 if(!args.comment_by_fullname || !args.comment_by || !args.comment) {
48 $("#comment-form .alert")
49 .html("All fields are necessary to submit the comment.")
50 .toggle(true);
51 return false;
Anand Doshi8c7e76b2012-07-11 18:40:57 +053052 }
53
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053054
55 $.ajax({
Anand Doshi18a0c582013-02-10 13:10:53 +053056 type: "POST",
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053057 url: "server.py",
58 data: args,
59 dataType: "json",
60 success: function(data) {
61 if(data.exc) {
62 $("#comment-form .alert")
63 .html(data.exc)
64 .toggle(true)
65 } else {
66 $(data.message).appendTo(".blog-comments");
67 $(".no_comment").toggle(false);
68 $(".add-comment").toggle(false);
69 $("#comment-form")
70 .replaceWith("<div class='alert'>Thank you for your comment!</div>")
71 }
Anand Doshi8c7e76b2012-07-11 18:40:57 +053072 }
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053073 })
Anand Doshi51146c02012-07-12 18:41:12 +053074
Rushabh Mehtafd6ad192012-12-17 12:52:43 +053075 return false;
76 })
77})