_comment_div.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. {# section commentaire. prends en parametre un objet Story ou Epic #}
  2. {# l'objet en parametre doit avoir une propriete 'comments' et une propriete 'uuid' #}
  3. {% load martortags %}
  4. <div class="comment-section" data-obj-uuid="{{ obj.uuid }}">
  5. <ul class="comment-list">
  6. {% for comment in obj.comments.all %}
  7. <li class="comment flex-col" data-id="{{ comment.id }}">
  8. <div class="flex-row">
  9. <span class="comment-header"><i class="fa fa-comment"></i> {{ comment.author }}, le {{ comment.created }}</span>
  10. <a class="disabled comment-edit-btn" href="" style="margin-left: 20px;"><i class="fa fa-pencil"></i></a>
  11. <a class="disabled comment-del-btn" href="" style="margin-left: 10px;"><i class="fa fa-trash"></i></a>
  12. </div>
  13. <div class="comment-display">
  14. {{ comment.content|safe_markdown }}
  15. </div>
  16. </li>
  17. {% endfor %}
  18. </ul>
  19. <form action="{% url 'comment_post' obj_uuid=obj.uuid %}" method="post" accept-charset="utf-8">
  20. {% csrf_token %}
  21. {{ comment_form.content }}
  22. <div class="flex-row flex-end" style="margin-top: 10px;">
  23. <input type="submit">
  24. </div>
  25. </form>
  26. </div>
  27. <!-- <script>
  28. // Nouveau commentaire
  29. $(".comment-section input[type=submit]").click(function (event) {
  30. event.preventDefault();
  31. var section = $(this).closest(".comment-section");
  32. var form = section.find("form");
  33. var obj_uuid = section.data("obj-uuid");
  34. var csrf_token= form.find("input[name=csrfmiddlewaretoken]").attr('value');
  35. var target = form.attr('action');
  36. var content = form.find("textarea").val();
  37. if (!content) {
  38. return;
  39. }
  40. $.ajax({
  41. type: "POST",
  42. url: target,
  43. headers: {"X-CSRFToken": csrf_token},
  44. data: '{"content": ' + JSON.stringify(content) + '}',
  45. contentType: "application/json; charset=utf-8",
  46. dataType: "json",
  47. success: function (comment) {
  48. form.find("textarea").val("");
  49. location.reload();
  50. },
  51. failure: function (response) {
  52. // restore the default behavior
  53. console.log(response.responseText);
  54. alert("An error occured (see the console for more informations)");
  55. },
  56. error: function (response) {
  57. // restore the default behavior
  58. console.log(response.responseText);
  59. alert("An error occured (see the console for more informations)");
  60. }
  61. });
  62. });
  63. </script> -->