Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | // License: GNU General Public License v3. See license.txt |
Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 3 | |
Rushabh Mehta | c8d2e73 | 2012-01-27 15:57:17 +0530 | [diff] [blame] | 4 | // js inside blog page |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 5 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 6 | $(document).ready(function() { |
| 7 | var n_comments = $(".comment-row").length; |
Anand Doshi | 40fce89 | 2012-07-09 20:02:52 +0530 | [diff] [blame] | 8 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 9 | if(n_comments) { |
| 10 | $(".no_comment").toggle(false); |
Anand Doshi | 40fce89 | 2012-07-09 20:02:52 +0530 | [diff] [blame] | 11 | } |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 12 | if(n_comments > 50) { |
| 13 | $(".add-comment").toggle(false) |
Rushabh Mehta | cce21d1 | 2013-08-21 17:48:08 +0530 | [diff] [blame] | 14 | .parent().append("<div class='alert alert-warning'>Comments are closed.</div>") |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 15 | } |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 16 | $(".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 Doshi | 2e6806e | 2013-03-12 20:04:30 +0530 | [diff] [blame] | 26 | comment_doctype: "Blog Post", |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 27 | comment_docname: "{{ name }}", |
Anand Doshi | 5acd082 | 2013-02-21 20:06:57 +0530 | [diff] [blame] | 28 | page_name: "{{ page_name }}", |
| 29 | _type: "POST" |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 30 | } |
| 31 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 32 | $("#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 Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 39 | } |
| 40 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 41 | |
| 42 | $.ajax({ |
Anand Doshi | 18a0c58 | 2013-02-10 13:10:53 +0530 | [diff] [blame] | 43 | type: "POST", |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 44 | 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") |
Rushabh Mehta | cce21d1 | 2013-08-21 17:48:08 +0530 | [diff] [blame] | 57 | .replaceWith("<div class='alert alert-success'>Thank you for your comment!</div>") |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 58 | } |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 59 | } |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 60 | }) |
Anand Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 61 | |
Rushabh Mehta | fd6ad19 | 2012-12-17 12:52:43 +0530 | [diff] [blame] | 62 | return false; |
| 63 | }) |
| 64 | }) |