1
0

ticket_detail.html 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 }}"?
  152. <br>
  153. From "{{ ticket.get_status_display }}" to "<span id="selectedStatusOption">12312</span>"
  154. </div>
  155. <div class="modal-footer">
  156. <button type="button" class="btn btn-primary" data-bs-dismiss="modal">
  157. <i class="fa-solid fa-xmark pe-1"></i>
  158. Close
  159. </button>
  160. <button form="ticket-change-status-form" class="btn btn-outline-primary" type="submit">
  161. <i class="fa-solid fa-check pe-1"></i>
  162. Confirm
  163. </button>
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. {% endif %}
  169. </div>
  170. </div>
  171. <!--Attachments block-->
  172. <h4 class="mt-4">Attachments</h4>
  173. {% if ticket.attachment_set.count %}
  174. <div class="table-responsive">
  175. <table class="table mb-3">
  176. <thead>
  177. <tr>
  178. <th>File</th>
  179. <th>Uploaded</th>
  180. <th>By</th>
  181. <th>Remove</th>
  182. </tr>
  183. </thead>
  184. <tbody>
  185. {% for attachment in attachments %}
  186. <tr>
  187. <td><a href="{{ attachment.file.url }}">{{ attachment.filename }}</a></td>
  188. <td>{{ attachment.timestamp }}</td>
  189. <td>{{ attachment.added_by.username }}</td>
  190. <td>
  191. {% if attachment.added_by == user or ticket.created_by == user %}
  192. <form action="{% url "tickets:remove_attachment" attachment.id %}" method="POST">
  193. {% csrf_token %}
  194. <button type="submit" class="btn btn-danger btn-sm">
  195. <i class="fa-solid fa-xmark"></i>
  196. </button>
  197. </form>
  198. {% endif %}
  199. </td>
  200. </tr>
  201. {% endfor %}
  202. </tbody>
  203. </table>
  204. </div>
  205. {% endif %}
  206. <form method="post" enctype="multipart/form-data">
  207. {% csrf_token %}
  208. <div class="input-group">
  209. <input type="file" class="form-control" id="attachment_file_input" name="attachment_file_input">
  210. <button class="btn btn-primary">
  211. <i class="fa-solid fa-upload pe-1"></i>
  212. Upload
  213. </button>
  214. </div>
  215. </form>
  216. <!--Discussion block-->
  217. <h4 class="mt-4">Discussion</h4>
  218. <form class="mb-3" method="post">
  219. {% csrf_token %}
  220. <textarea class="form-control" name="comment-body" rows="2" placeholder="Write your comment here" required></textarea>
  221. <div class="d-flex justify-content-end">
  222. <button class="btn btn-primary mt-2" type="submit">
  223. <i class="fa-solid fa-paper-plane pe-1"></i>
  224. Post
  225. </button>
  226. </div>
  227. </form>
  228. {% if comment_list %}
  229. {% for comment in comment_list %}
  230. <div class="card mb-2 bg-body-secondary">
  231. <div class="card-body">
  232. <h5>{{ comment.author_username }}</h5>
  233. {{ comment.body|safe|urlize|linebreaks }}
  234. <div class="text-body-secondary d-flex justify-content-between">
  235. <small>{{ comment.author_email }}</small>
  236. <small>{{ comment.date }}</small>
  237. </div>
  238. </div>
  239. </div>
  240. {% endfor %}
  241. {% endif %}
  242. {% endblock %}
  243. {% block extra_js %}
  244. <script>
  245. // Support file attachment uploader
  246. $('#attachment_file_input').on('change',function(){
  247. // Get the file name and remove browser-added "fakepath."
  248. // Then replace the "Choose a file" label.
  249. var fileName = $(this).val().replace('C:\\fakepath\\', " ");
  250. $(this).next('.custom-file-label').html(fileName);
  251. })
  252. </script>
  253. <script>
  254. $('#ticket-change-status-btn').on('click', (e) => {
  255. e.preventDefault();
  256. const selectValue = $('#select-ticket-status')[0].selectedOptions[0].textContent;
  257. $('#selectedStatusOption')[0].textContent = selectValue;
  258. })
  259. </script>
  260. {% endblock extra_js %}