Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | // 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 Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 17 | // js inside blog page |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 18 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 19 | $(document).ready(function() { |
| 20 | var n_comments = $(".comment-row").length; |
Anand Doshi | 40fce89 | 2012-07-09 20:02:52 +0530 | [diff] [blame] | 21 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 22 | if(n_comments) { |
| 23 | $(".no_comment").toggle(false); |
Anand Doshi | 40fce89 | 2012-07-09 20:02:52 +0530 | [diff] [blame] | 24 | } |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 25 | if(n_comments > 50) { |
| 26 | $(".add-comment").toggle(false) |
| 27 | .parent().append("<div class='alert'>Comments are closed.</div>") |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 28 | } |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 29 | $(".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", |
| 39 | comment_doctype: "Blog", |
| 40 | comment_docname: "{{ name }}", |
Anand Doshi | 5acd082 | 2013-02-21 20:06:57 +0530 | [diff] [blame] | 41 | page_name: "{{ page_name }}", |
| 42 | _type: "POST" |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 43 | } |
| 44 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 45 | $("#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 Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 52 | } |
| 53 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 54 | |
| 55 | $.ajax({ |
Anand Doshi | 18a0c58 | 2013-02-10 13:10:53 +0530 | [diff] [blame] | 56 | type: "POST", |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 57 | 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 Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 72 | } |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 73 | }) |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 74 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 75 | return false; |
| 76 | }) |
| 77 | }) |