comment_update.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. {% if not is_js %}
  2. {% extends "repo_master.html" %}
  3. {% endif %}
  4. {% block repo %}
  5. <section class="edit_comment">
  6. <form action="{{ request.base_url }}" method="post" class="pr_comment_form">
  7. <fieldset class="form-group">
  8. <label for="comment"><strong>Edit comment</strong></label>
  9. <small class="text-muted pull-xs-right">
  10. <span class="btn btn-sm btn-secondary inactive"
  11. aria-pressed="false" id="edit_previewinmarkdown">Preview
  12. </span>
  13. </small>
  14. <div id="edit">
  15. <textarea class="form-control width-100per" id="update_comment" name="update_comment">
  16. {{- comment.comment -}}
  17. </textarea>
  18. </div>
  19. <div id="preview" class="p-1">
  20. </div>
  21. </fieldset>
  22. {{ form.csrf_token }}
  23. <div>
  24. <input type="hidden" name="edit_comment" value="{{ comment.id }}" />
  25. <input type="submit" class="btn btn-primary" value="Update" />
  26. <input type="button" id="comment_update_cancel" class="btn btn-secondary cancel cancel_btn" value="Cancel" />
  27. </div>
  28. </form>
  29. </section>
  30. <script type="text/javascript" nonce="{{ g.nonce }}">
  31. $("#preview").hide();
  32. $("#edit_previewinmarkdown").click(
  33. function(event, ui) {
  34. if ($("#edit_previewinmarkdown").hasClass("inactive")){
  35. var _text = $("#update_comment").val();
  36. var _url = "{{ url_for('ui_ns.markdown_preview',
  37. repo=repo.name,
  38. user=repo.user.user if repo.is_fork,
  39. namespace=repo.namespace) | safe}}";
  40. $.ajax({
  41. url: _url ,
  42. type: 'POST',
  43. data: {
  44. content: _text,
  45. csrf_token: "{{ g.confirmationform.csrf_token.current_token }}",
  46. },
  47. dataType: 'html',
  48. success: function(res) {
  49. var preview = emojione.toImage(res);
  50. $("#preview").html(preview);
  51. $("#edit_previewinmarkdown").toggleClass("inactive active");
  52. $("#update_comment").hide();
  53. $("#preview" ).show();
  54. },
  55. error: function() {
  56. alert('Unable to generate preview!');
  57. }
  58. });
  59. return false;
  60. } else if ($("#edit_previewinmarkdown").hasClass("active")){
  61. $("#edit_previewinmarkdown").toggleClass("active inactive");
  62. $("#update_comment").show();
  63. $("#preview").hide();
  64. }
  65. }
  66. );
  67. $.get("{{ url_for('api_ns.api_users') }}", {
  68. pattern: '*'
  69. }).done(function(resp) {
  70. var userConfig = {
  71. at: '@',
  72. data: resp['mention'],
  73. insertTpl: '@${username}',
  74. displayTpl: "<li><img src=\"${image}\"> ${username} <small>${name}</small></li>",
  75. searchKey: "username"
  76. }
  77. $("#update_comment").atwho(userConfig);
  78. });
  79. $.when(
  80. {% if g.issues_enabled %}
  81. $.get("{{ url_for('api_ns.api_view_issues', namespace=repo.namespace, repo=repo.name, username=username, status='all') }}"),
  82. {% endif %}
  83. $.get("{{ url_for('api_ns.api_pull_request_views', namespace=repo.namespace, repo=repo.name, username=username, status='all') }}")
  84. ).done(function(issuesResp, prResp) {
  85. // 0 is the api response
  86. var issuesAndPrs = issuesResp[0]['issues'].concat(prResp[0]['requests']);
  87. var data = $.map(issuesAndPrs, function(ticket, idx) {
  88. return {
  89. name: ticket.id.toString(),
  90. title: $('<div>').text(ticket.title).html()
  91. }
  92. });
  93. var issueAndPrConfig = {
  94. at: '#',
  95. data: data,
  96. insertTpl: '#${name}',
  97. displayTpl: "<li>#${name}<small> ${title}</small></li>",
  98. }
  99. $("#update_comment").atwho(issueAndPrConfig);
  100. })
  101. </script>
  102. {% endblock %}