NDOJ/templates/ticket/list.html

278 lines
8.2 KiB
HTML
Raw Permalink Normal View History

2020-01-21 06:35:58 +00:00
{% extends "base.html" %}
{% block media %}
2023-01-27 23:11:10 +00:00
<style>
#ticket-list .fa-check-circle-o {
color: #00a900;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
#ticket-list .fa-exclamation-circle {
color: darkred;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
@media (min-width: 500px) {
#container {
display: flex;
flex-direction: row-reverse;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
#container > main {
flex: 1;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
#container > aside {
flex: 1;
max-width: 200px;
margin-left: 1em;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
#container > aside > div {
position: sticky;
top: 60px;
}
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
.select2-selection__arrow {
display: none;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
.select2-selection__rendered {
cursor: text;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
.select2-results__option {
position: relative;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
.select2-results__option--highlighted {
background-color: #DEDEDE !important;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
li.select2-results__option--highlighted a.user-redirect {
display: inline-block;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
a.user-redirect {
color: #2980b9;
vertical-align: middle;
font-size: 1.2em;
position: absolute;
right: 0.8em;
display: none;
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
a.user-redirect:hover {
text-shadow: 0 0 2px blue;
}
</style>
2020-01-21 06:35:58 +00:00
{% endblock %}
{% block js_media %}
2023-01-27 23:11:10 +00:00
<script type="text/javascript">
window.filter_user_ids = {{filter_status.user_id}};
window.filter_own_id = {{filter_status.own_id}};
window.filter_assignee_ids = {{filter_status.assignee_id}};
</script>
<script type="text/javascript" src="{{ static('event.js') }}"></script>
<script type="text/javascript">
$(function () {
$('input#own').click(function () {
($('<form>').attr('action', window.location.pathname + '?' + $('form#filter-form').serialize())
.append($('<input>').attr('type', 'hidden').attr('name', 'csrfmiddlewaretoken')
.attr('value', $.cookie('csrftoken')))
.attr('method', 'POST').appendTo($('body')).submit());
});
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
register_notify('ticket', {
$checkbox: $('#desktop-notification'),
change: function (enabled) {
if (!enabled)
for (key in localStorage)
if (key.startsWith('ticket:open:'))
delete localStorage[key];
}
});
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
function main_list_notify(id) {
key = 'ticket:open:' + id;
return !(key in localStorage) || localStorage[key] == '0';
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
var $tbody = $('#ticket-list').find('tbody');
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
function new_ticket(ticket) {
console.log('Fetching data for: ' + ticket.id);
$.ajax({
url: '{{ url('ticket_ajax') }}',
data: {id: ticket.id},
success: function (data) {
console.log('Got data for: ' + ticket.id);
console.log(data);
$tbody.prepend($(data.row));
notify('ticket', data.notification.title, {
body: data.notification.body
});
},
error: function (data) {
if (data.status === 403)
console.log('No right to see: ' + ticket.id);
else {
console.log('Could not load ticket:');
console.log(data.responseText);
2020-01-21 06:35:58 +00:00
}
2023-01-27 23:11:10 +00:00
}
});
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
function ticket_status(ticket) {
if (!main_list_notify(ticket.id)) return;
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
var $row = $('#ticket-' + ticket.id);
console.log('Ticket status change: ' + ticket.id);
if ($row.length) {
var $status = $row.find('td').first().find('i');
if (ticket.open) {
$status.removeClass('fa-check-circle-o').addClass('fa-exclamation-circle');
notify('ticket', '{{ _('Reopened: ') }}' + ticket.title);
} else {
$status.removeClass('fa-exclamation-circle').addClass('fa-check-circle-o');
notify('ticket', '{{ _('Closed: ') }}' + ticket.title);
}
}
}
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
window.load_dynamic_update = function (last_msg) {
var $assignees = $(filter_assignee_ids);
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
return new EventReceiver(
"{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}",
['tickets'], last_msg, function (message) {
console.log(message);
if (filter_own_id != null && message.user != filter_own_id &&
!~message.assignees.indexOf(filter_own_id))
return;
if (filter_user_ids.length && !~filter_user_ids.indexOf(message.user))
return;
if ($assignees.length && !$assignees.filter(message.assignees).length)
return;
switch (message.type) {
case 'new-ticket':
new_ticket(message);
break;
case 'ticket-status':
ticket_status(message);
break;
}
}
);
};
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
var user_select2 = {
escapeMarkup: function (markup) {
return markup;
},
templateResult: function (data, container) {
return $('<span>')
.append($('<img>', {
'class': 'user-search-image', src: data.gravatar_url,
width: 24, height: 24
}))
.append($('<span>', {'class': data.display_rank + ' user-search-name'}).text(data.text));
},
ajax: {
data: function (params) {
return {
term: params.term || '',
page: params.page || 1
}
},
processResults: function (data) {
return {
results: data.results,
pagination: {
more: data.more
}
2020-01-21 06:35:58 +00:00
};
2023-01-27 23:11:10 +00:00
},
},
};
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
$('#filter-user').select2($.extend(true, {}, user_select2,
{ajax: {url: '{{ url('ticket_user_select2_ajax') }}'}}));
$('#filter-assignee').select2($.extend(true, {}, user_select2,
{ajax: {url: '{{ url('ticket_assignee_select2_ajax') }}'}}));
});
</script>
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
{% if last_msg %}
<script type="text/javascript">
$(function () {
load_dynamic_update({{last_msg}});
});
</script>
{% endif %}
2020-01-21 06:35:58 +00:00
{% endblock %}
{% block body %}
2023-01-27 23:11:10 +00:00
<div id="container">
<aside>
<div>
<div id="notification-box">
<input id="desktop-notification" type="checkbox">
<label for="desktop-notification">{{ _('Use desktop notification') }}</label>
</div>
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
<form id="filter-form" name="form" action="" method="get">
<div id="own-box" class="filter-check">
<input id="own" type="checkbox" name="own"{% if filter_status.own %} checked{% endif %} value="1">
<label for="own">{{ _('Show my tickets only') }}</label>
</div>
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
<div id="user-box" class="filter-select2">
<label for="filter-user">{{ _('Filing user') }}</label>
<select id="filter-user" style="width: 100%" multiple name="user">
{% for username in filter_status.user %}
<option value="{{ username }}" selected>{{ username }}</option>
{% endfor %}
</select>
</div>
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
<div id="assignee-box" class="filter-select2">
<label for="filter-user">{{ _('Assignee') }}</label>
<select id="filter-assignee" style="width: 100%" multiple name="assignee">
{% for username in filter_status.assignee %}
<option value="{{ username }}" selected>{{ username }}</option>
{% endfor %}
</select>
</div>
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
<button type="submit" style="margin-left: auto" class="submit">{{ _('Go') }}</button>
</form>
</div>
</aside>
2020-01-21 06:35:58 +00:00
2023-01-27 23:11:10 +00:00
<main>
{% if page_obj.num_pages > 1 %}
<div style="margin-bottom:6px; margin-top:3px">{% include "list-pages.html" %}</div>
{% endif %}
<table id="ticket-list" class="table h-scrollable-table">
<thead>
<tr>
<th></th>
<th>{{ _('ID') }}</th>
<th>{{ _('Title') }}</th>
<th>{{ _('User') }}</th>
<th>{{ _('Assignees') }}</th>
</tr>
</thead>
<tbody>
{% for ticket in tickets %}
{% include "ticket/row.html" %}
{% endfor %}
</tbody>
</table>
{% if page_obj.num_pages > 1 %}
<div style="margin-top:10px">{% include "list-pages.html" %}</div>
{% endif %}
</main>
</div>
2020-01-21 06:35:58 +00:00
{% endblock %}