You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

123 lines
3.7 KiB

  1. <div class="comment-view">
  2. <div class="comment-header">{{ comment_text or "" }}</div>
  3. {% if not comment_list %}
  4. <div class="no-comment">
  5. <p class="text-muted">{{ _("Start a new discussion.") }}</p>
  6. <br>
  7. </div>
  8. {% endif %}
  9. <div itemscope itemtype="http://schema.org/UserComments" id="comment-list">
  10. {% for comment in comment_list %}
  11. {% include "templates/includes/comments/comment.html" %}
  12. {% endfor %}
  13. </div>
  14. </div>
  15. <div class="add-comment-section">
  16. <div class="text-muted hidden login-required">
  17. <a href="/login?redirect-to={{ pathname }}">{{ _("Login to comment") }}</a>
  18. </div>
  19. <div class="comment-form-wrapper">
  20. <a class="add-comment btn btn-default btn-sm">{{ _("Add Comment") }}</a>
  21. <div style="display: none;" id="comment-form">
  22. <p>{{ _("Leave a Comment") }}</p>
  23. <div class="alert" style="display:none;"></div>
  24. <form>
  25. <fieldset>
  26. <div class="row {% if login_required %}hide{% endif %}">
  27. <div class="col-sm-6">
  28. <p><input class="form-control" name="comment_by_fullname" placeholder="{{ _("Your Name") }}"
  29. type="text"></p>
  30. </div>
  31. <div class="col-sm-6">
  32. <p><input class="form-control" name="comment_by"
  33. placeholder="{{ _("Your Email Id") }}" type="email"></p>
  34. </div>
  35. </div>
  36. <p><textarea class="form-control" name="comment" rows=10
  37. placeholder="{{ _("Comment") }}"></textarea></p>
  38. <button class="btn btn-primary btn-sm" id="submit-comment" style="margin-top:10px">
  39. {{ _("Submit") }}</button>
  40. </fieldset>
  41. </form>
  42. </div>
  43. </div>
  44. </div>
  45. <script>
  46. frappe.ready(function() {
  47. var login_required = {{ login_required and 1 or 0 }};
  48. if (login_required && !frappe.is_user_logged_in()) {
  49. $(".login-required, .comment-form-wrapper").toggleClass("hidden");
  50. }
  51. var n_comments = $(".comment-row").length;
  52. if(n_comments) {
  53. $(".no_comment").toggle(false);
  54. }
  55. if(n_comments > 50) {
  56. $(".add-comment").toggle(false)
  57. .parent().append("<div class='text-muted'>Comments are closed.</div>")
  58. }
  59. $(".add-comment").click(function() {
  60. $(this).toggle(false);
  61. $("#comment-form").toggle();
  62. var full_name = "", user_id = "";
  63. if(frappe.is_user_logged_in()) {
  64. full_name = getCookie("full_name");
  65. user_id = getCookie("user_id");
  66. if(user_id != "Guest") {
  67. $("[name='comment_by']").val(user_id);
  68. $("[name='comment_by_fullname']").val(full_name);
  69. }
  70. }
  71. $("#comment-form textarea").val("");
  72. })
  73. $("#submit-comment").click(function() {
  74. var args = {
  75. comment_by_fullname: $("[name='comment_by_fullname']").val(),
  76. comment_by: $("[name='comment_by']").val(),
  77. comment: $("[name='comment']").val(),
  78. reference_doctype: "{{ reference_doctype or doctype }}",
  79. reference_name: "{{ reference_name or name }}",
  80. comment_type: "Comment",
  81. route: "{{ pathname }}",
  82. }
  83. if(!args.comment_by_fullname || !args.comment_by || !args.comment) {
  84. frappe.msgprint("All fields are necessary to submit the comment.")
  85. return false;
  86. }
  87. if (!valid_email(args.comment_by)) {
  88. frappe.msgprint("Please enter a valid email address.");
  89. return false;
  90. }
  91. frappe.call({
  92. btn: this,
  93. type: "POST",
  94. method: "frappe.templates.includes.comments.comments.add_comment",
  95. args: args,
  96. callback: function(r) {
  97. if(r.exc) {
  98. if(r._server_messages)
  99. frappe.msgprint(r._server_messages);
  100. } else {
  101. $(r.message).appendTo("#comment-list");
  102. $(".no-comment, .add-comment").toggle(false);
  103. $("#comment-form")
  104. .replaceWith('<div class="text-muted">Thank you for your comment!</div>')
  105. }
  106. }
  107. })
  108. return false;
  109. })
  110. });
  111. </script>