No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

comments.html 2.4 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. {% if not comment_list %}
  2. <div class="no-comment">
  3. <div class="alert alert-info">Start a new discussion.</div>
  4. </div>
  5. {% endif %}
  6. <div itemscope itemtype="http://schema.org/UserComments" id="comment-list">
  7. {% for comment in comment_list %}
  8. {% include "templates/includes/comment.html" %}
  9. {% endfor %}
  10. </div>
  11. <div><button class="btn btn-default add-comment">Add Comment</button></div>
  12. <div style="display: none; margin-top: 10px; max-width: 400px;"
  13. id="comment-form">
  14. <div class="alert" style="display:none;"></div>
  15. <form>
  16. <fieldset>
  17. <input class="form-control" name="comment_by_fullname" placeholder="Your Name" type="text"/><br>
  18. <input class="form-control" name="comment_by"
  19. placeholder="Your Email Id" type="text"/><br>
  20. <textarea class="form-control" name="comment" rows=10
  21. placeholder="Comment"/>
  22. </textarea><br>
  23. <button class="btn btn-info" id="submit-comment">Submit</button>
  24. </fieldset>
  25. </form>
  26. </div>
  27. <script>
  28. $(document).ready(function() {
  29. var n_comments = $(".comment-row").length;
  30. if(n_comments) {
  31. $(".no_comment").toggle(false);
  32. }
  33. if(n_comments > 50) {
  34. $(".add-comment").toggle(false)
  35. .parent().append("<div class='alert alert-warning'>Comments are closed.</div>")
  36. }
  37. $(".add-comment").click(function() {
  38. $(this).toggle(false);
  39. $("#comment-form").toggle();
  40. $("[name='comment_by']").val(getCookie("user_id") || "");
  41. $("[name='comment_by_fullname']").val(getCookie("full_name") || "");
  42. $("#comment-form textarea").val("");
  43. })
  44. $("#submit-comment").click(function() {
  45. var args = {
  46. comment_by_fullname: $("[name='comment_by_fullname']").val(),
  47. comment_by: $("[name='comment_by']").val(),
  48. comment: $("[name='comment']").val(),
  49. comment_doctype: "{{ doctype }}",
  50. comment_docname: "{{ name }}",
  51. page_name: "{{ page_name }}",
  52. }
  53. if(!args.comment_by_fullname || !args.comment_by || !args.comment) {
  54. wn.msgprint("All fields are necessary to submit the comment.")
  55. return false;
  56. }
  57. wn.call({
  58. btn: this,
  59. type: "POST",
  60. method: "webnotes.templates.includes.comments.add_comment",
  61. args: args,
  62. callback: function(r) {
  63. if(r.exc) {
  64. if(r._server_messages)
  65. wn.msgprint(r._server_messages);
  66. } else {
  67. $(r.message).appendTo("#comment-list");
  68. $(".no-comment, .add-comment").toggle(false);
  69. $("#comment-form")
  70. .replaceWith("<div class='alert alert-success'>Thank you for your comment!</div>")
  71. }
  72. }
  73. })
  74. return false;
  75. })
  76. })
  77. </script>