ticket_detail.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. {% extends "tickets/base.html" %}
  2. {% load static %}
  3. {% block content %}
  4. <h3 class="card-title fw-bold my-3">{{ ticket.title }}</h3>
  5. <div class="row">
  6. <div class="col-12 col-md-8 mb-2 mb-md-0">
  7. <div class="card h-100">
  8. <div class="card-body">
  9. {% if ticket.note %}
  10. <div class="card-text overflow-auto">{{ ticket.note|safe|urlize|linebreaks }}</div>
  11. {% endif %}
  12. </div>
  13. </div>
  14. </div>
  15. <div class="col-12 col-md-4">
  16. <div class="card">
  17. <ul class="list-group list-group-flush">
  18. <li class="list-group-item">
  19. <strong>In list:</strong>
  20. <a href="{% url 'tickets:ticket_list_detail' ticket.ticket_list.pk %}">
  21. {{ ticket.ticket_list }}
  22. </a>
  23. </li>
  24. <li class="list-group-item">
  25. <strong>Created by:</strong>
  26. {{ ticket.created_by.username }}
  27. </li>
  28. <li class="list-group-item">
  29. <strong>Assigned to:</strong>
  30. {% if ticket.assigned_to.username %}{{ ticket.assigned_to.username }}{% else %}Anyone{% endif %}
  31. </li>
  32. <li class="list-group-item">
  33. <strong>Type:</strong>
  34. {{ ticket.get_ticket_type_display }}
  35. </li>
  36. <li class="list-group-item">
  37. <strong>Status:</strong>
  38. {{ ticket.get_status_display }}
  39. </li>
  40. <li class="list-group-item">
  41. <strong>Priority:</strong>
  42. {{ ticket.priority }}
  43. </li>
  44. <li class="list-group-item">
  45. <strong>Created at:</strong>
  46. {{ ticket.created_at }}
  47. </li>
  48. <li class="list-group-item">
  49. <strong>Due date:</strong>
  50. {{ ticket.due_date }}
  51. </li>
  52. <li class="list-group-item">
  53. <strong>Updated at:</strong>
  54. {{ ticket.updated_at }}
  55. </li>
  56. </ul>
  57. </div>
  58. {% if available_statuses %}
  59. <form id="ticket-change-status-form" class="my-3" method="POST">
  60. {% csrf_token %}
  61. <label for="select-ticket-status" class="form-label">Available statuses</label>
  62. <div class="input-group">
  63. <select class="form-select" id="select-ticket-status" name="ticket-status">
  64. {% for status in available_statuses %}
  65. <option {% if forloop.first %}selected{% endif %} value="{{ status.0 }}">{{ status.1 }}</option>
  66. {% endfor %}
  67. </select>
  68. <button id="ticket-change-status-btn" class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#ticket-change-status-modal">Change</button>
  69. </div>
  70. </form>
  71. {% else %}
  72. <p class="my-3">No available statuses</p>
  73. {% endif %}
  74. {% if ticket.created_by == user %}
  75. <div class="d-flex justify-content-between">
  76. <button type="button" data-bs-toggle="modal" data-bs-target="#ticket-edit-modal" class="btn btn-primary">
  77. <i class="fa-solid fa-pen-to-square pe-1"></i>
  78. Edit Ticket
  79. </button>
  80. <button type="button" class="btn btn-outline-danger" data-bs-toggle="modal" data-bs-target="#ticket-delete-modal">
  81. <i class="fa-solid fa-trash-can"></i>
  82. </button>
  83. </div>
  84. <!--Ticket edit modal-->
  85. <div class="modal fade" id="ticket-edit-modal" tabindex="-1">
  86. <div class="modal-dialog modal-dialog-centered">
  87. <div class="modal-content">
  88. <div class="modal-header">
  89. <h1 class="modal-title fs-5">
  90. <i class="fa-solid fa-pen-to-square pe-1"></i>
  91. Edit Ticket
  92. </div>
  93. <div class="modal-body">
  94. <form id="ticket-create-form" action="{% url 'tickets:ticket_edit' ticket.pk %}" method="post">
  95. {% include 'tickets/include/form.html' %}
  96. </form>
  97. </div>
  98. <div class="modal-footer">
  99. <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">
  100. <i class="fa-solid fa-xmark pe-1"></i>
  101. Close
  102. </button>
  103. <button class="btn btn-primary" type="submit" form="ticket-create-form">
  104. <i class="fa-solid fa-check pe-1"></i>
  105. Confirm
  106. </button>
  107. </div>
  108. </div>
  109. </div>
  110. </div>
  111. <!--ticket delete modal-->
  112. <div class="modal fade" id="ticket-delete-modal" tabindex="-1">
  113. <div class="modal-dialog modal-dialog-centered">
  114. <div class="modal-content">
  115. <div class="modal-header">
  116. <h1 class="modal-title fs-5">
  117. <i class="fa-solid fa-trash-can pe-1"></i>
  118. Delete Ticket
  119. </h1>
  120. </div>
  121. <div class="modal-body">
  122. Are you sure you want to delete the ticket "{{ ticket.title }}"?
  123. </div>
  124. <div class="modal-footer">
  125. <button type="button" class="btn btn-primary" data-bs-dismiss="modal">
  126. <i class="fa-solid fa-xmark pe-1"></i>
  127. Close
  128. </button>
  129. <form method="post" action="{% url "tickets:ticket_delete" ticket.pk %}">
  130. {% csrf_token %}
  131. <button class="btn btn-outline-danger" type="submit">
  132. <i class="fa-solid fa-check pe-1"></i>
  133. Confirm
  134. </button>
  135. </form>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. <!--ticket change status-->
  141. <div class="modal fade" id="ticket-change-status-modal" tabindex="-1">
  142. <div class="modal-dialog modal-dialog-centered">
  143. <div class="modal-content">
  144. <div class="modal-header">
  145. <h1 class="modal-title fs-5">
  146. <i class="fa-solid fa-trash-can pe-1"></i>
  147. Change Status
  148. </h1>
  149. </div>
  150. <div class="modal-body">
  151. Are you sure you want to change the status of the ticket "{{ ticket.title }}" from <b>{{ ticket.get_status_display }}</b> to <b id="selectedStatusOption"></b>?
  152. </div>
  153. <div class="modal-footer">
  154. <button type="button" class="btn btn-primary" data-bs-dismiss="modal">
  155. <i class="fa-solid fa-xmark pe-1"></i>
  156. Close
  157. </button>
  158. <button form="ticket-change-status-form" class="btn btn-outline-primary" type="submit">
  159. <i class="fa-solid fa-check pe-1"></i>
  160. Confirm
  161. </button>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. {% endif %}
  167. </div>
  168. </div>
  169. <!--Attachments block-->
  170. <h4 class="mt-4">Attachments</h4>
  171. {% if ticket.attachment_set.count %}
  172. <div class="table-responsive">
  173. <table class="table mb-3">
  174. <thead>
  175. <tr>
  176. <th>File</th>
  177. <th>Uploaded</th>
  178. <th>By</th>
  179. <th>Remove</th>
  180. </tr>
  181. </thead>
  182. <tbody>
  183. {% for attachment in attachments %}
  184. <tr>
  185. <td><a href="{{ attachment.file.url }}">{{ attachment.filename }}</a></td>
  186. <td>{{ attachment.timestamp }}</td>
  187. <td>{{ attachment.added_by.username }}</td>
  188. <td>
  189. {% if attachment.added_by == user or ticket.created_by == user %}
  190. <form action="{% url "tickets:remove_attachment" attachment.id %}" method="POST">
  191. {% csrf_token %}
  192. <button type="submit" class="btn btn-danger btn-sm">
  193. <i class="fa-solid fa-xmark"></i>
  194. </button>
  195. </form>
  196. {% endif %}
  197. </td>
  198. </tr>
  199. {% endfor %}
  200. </tbody>
  201. </table>
  202. </div>
  203. {% endif %}
  204. <form method="post" enctype="multipart/form-data">
  205. {% csrf_token %}
  206. <div class="input-group">
  207. <input type="file" class="form-control" id="attachment_file_input" name="attachment_file_input">
  208. <button class="btn btn-primary">
  209. <i class="fa-solid fa-upload pe-1"></i>
  210. Upload
  211. </button>
  212. </div>
  213. </form>
  214. <!--Discussion block-->
  215. <h4 class="mt-4">Discussion</h4>
  216. <form class="mb-3" method="post">
  217. {% csrf_token %}
  218. <textarea class="form-control" name="comment-body" rows="2" placeholder="Write your comment here" required></textarea>
  219. <div class="d-flex justify-content-end">
  220. <button class="btn btn-primary mt-2" type="submit">
  221. <i class="fa-solid fa-paper-plane pe-1"></i>
  222. Post
  223. </button>
  224. </div>
  225. </form>
  226. {% if comment_list %}
  227. {% for comment in comment_list %}
  228. <div class="card mb-2 bg-body-secondary">
  229. <div class="card-body">
  230. <h5>{{ comment.author_username }}</h5>
  231. {{ comment.body|safe|urlize|linebreaks }}
  232. <div class="text-body-secondary d-flex justify-content-between">
  233. <small>{{ comment.author_email }}</small>
  234. <small>{{ comment.date }}</small>
  235. </div>
  236. </div>
  237. </div>
  238. {% endfor %}
  239. {% endif %}
  240. {% endblock %}
  241. {% block extra_js %}
  242. <script>
  243. // Support file attachment uploader
  244. $('#attachment_file_input').on('change',function(){
  245. // Get the file name and remove browser-added "fakepath."
  246. // Then replace the "Choose a file" label.
  247. var fileName = $(this).val().replace('C:\\fakepath\\', " ");
  248. $(this).next('.custom-file-label').html(fileName);
  249. })
  250. </script>
  251. <script>
  252. $('#ticket-change-status-btn').on('click', (e) => {
  253. e.preventDefault();
  254. const selectValue = $('#select-ticket-status')[0].selectedOptions[0].textContent;
  255. $('#selectedStatusOption')[0].textContent = selectValue;
  256. })
  257. </script>
  258. {% endblock extra_js %}