Update ticketCC views and also reformat HTML files along with some improvements in form errors.

This commit is contained in:
bbe 2020-10-31 18:33:41 +01:00
parent 7564c5739b
commit 1788f2fb84
3 changed files with 187 additions and 122 deletions

View File

@ -1,4 +1,6 @@
{% extends "helpdesk/base.html" %}{% load i18n %}
{% extends "helpdesk/base.html" %}
{% load i18n %}
{% block helpdesk_title %}{% trans "Add Ticket CC" %}{% endblock %}
@ -26,47 +28,77 @@
<div class="card-body">
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<li class="active"><a href="#EmailCC" data-toggle="tab">{% trans 'Email' %}</a>
<li class="nav-item">
<a class="nav-link{% if not form.errors.user %} active{% endif %}" href="#EmailCC" data-toggle="tab">
{% trans 'Email' %}
</a>
</li>
<li><a href="#UserCC" data-toggle="tab">{% trans 'User' %}</a>
<li class="divider"></li>
<li class="nav-item">
<a class="nav-link{% if form.errors.user %} active{% endif %}" href="#UserCC" data-toggle="tab">
{% trans 'User' %}
</a>
</li>
</ul>
{% if form.errors %}
{% include 'helpdesk/include/alert_form_errors.html' %}
<ul>{{ form.non_field_errors }}</ul>
{% endif %}
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane in active" id="EmailCC">
<div class="tab-pane{% if not form.errors.user %} in active{% endif %}" id="EmailCC">
<h4>{% trans 'Add Email' %}</h4>
<form method='post' action='./'>
<form method='post'>
{% csrf_token %}
<fieldset>
<dl>{% for field in form_email %}
<dt><label for='id_{{ field.name }}'>{{ field.label }}</label></dt>
<dl>
{% for field in form_email %}
<dt>{{ field.label_tag }}</dt>
<dd>{{ field }}</dd>
{% if field.errors %}<dd class='error'>{{ field.errors }}</dd>{% endif %}
{% if field.help_text %}<dd class='form_help_text'>{{ field.help_text }}</dd>{% endif %}
{% endfor %}</dl>
{% if field.name == 'email' and form.errors.email %}
<dd class='error'>{{ form.errors.email }}</dd>
{% endif %}
{% if field.help_text %}
<dd class='form_help_text'>{{ field.help_text }}</dd>
{% endif %}
{% endfor %}
</dl>
</fieldset>
<button class="btn btn-primary" type='submit'>{% trans "Save Ticket CC" %}</button>
{% csrf_token %}</form>
<a href="{% url 'helpdesk:ticket_cc' ticket.id %}" class="btn btn-secondary">
{% trans "Cancel" %}
</a>
</form>
</div>
<div class="tab-pane fade" id="UserCC">
<div class="tab-pane{% if form.errors.user %} in active{% endif %}" id="UserCC">
<h4>{% trans 'Add User' %}</h4>
<form method='post' action='./'>
<form method='post'>
{% csrf_token %}
<fieldset>
<dl>{% for field in form_user %}
<dt><label for='id_{{ field.name }}'>{{ field.label }}</label></dt>
<dl>
{% for field in form_user %}
<dt>{{ field.label_tag }}</dt>
<dd>{{ field }}</dd>
{% if field.errors %}<dd class='error'>{{ field.errors }}</dd>{% endif %}
{% if field.help_text %}<dd class='form_help_text'>{{ field.help_text }}</dd>{% endif %}
{% endfor %}</dl>
{% if field.name == 'user' and form.errors.user %}
<dd class='error'>{{ form.errors.user }}</dd>
{% endif %}
{% if field.help_text %}
<dd class='form_help_text'>{{ field.help_text }}</dd>
{% endif %}
{% endfor %}
</dl>
</fieldset>
<button class="btn btn-primary" type='submit'>{% trans "Save Ticket CC" %}</button>
{% csrf_token %}</form>
<a href="{% url 'helpdesk:ticket_cc' ticket.id %}" class="btn btn-secondary">
{% trans "Cancel" %}
</a>
</form>
</div>
</div>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
{% endblock %}

View File

@ -1,4 +1,6 @@
{% extends "helpdesk/base.html" %}{% load i18n %}
{% extends "helpdesk/base.html" %}
{% load i18n %}
{% block helpdesk_title %}{% trans "Ticket CC Settings" %}{% endblock %}
@ -33,18 +35,36 @@
<thead>
<tr>
<th>{% trans "E-Mail Address or Helpdesk User" %}</th>
<th>{% trans "View?" %}</th>
<th>{% trans "Update?" %}</th>
<th>{% trans "Delete" %}</th>
<th class="text-center">{% trans "View?" %}</th>
<th class="text-center">{% trans "Update?" %}</th>
<th class="text-center">{% trans "Delete" %}</th>
</tr>
</thead>
<tbody>
{% for person in copies_to %}
<tr class='row_{% cycle 'odd' 'even' %}'>
<td>{{ person.display }}</td>
<td>{{ person.can_view }}</td>
<td>{{ person.can_update }}</td>
<td><a href='{% url 'helpdesk:ticket_cc_del' ticket.id person.id %}'><button class="btn btn-danger btn-xs">{% trans "Delete" %}</button></a></td>
<td class="text-center">
{% if person.can_view %}
<i class="fa fa-2x fa-check text-success"></i>
{% else %}
<i class="fa fa-2x fa-times text-danger"></i>
{% endif %}
</td>
<td class="text-center">
{% if person.can_update %}
<i class="fa fa-2x fa-check text-success"></i>
{% else %}
<i class="fa fa-2x fa-times text-danger"></i>
{% endif %}
</td>
<td class="text-center">
<a href='{% url 'helpdesk:ticket_cc_del' ticket.id person.id %}'>
<button class="btn btn-danger btn-xs">
{% trans "Delete" %}
</button>
</a>
</td>
</tr>
{% endfor %}
</tbody>
@ -60,6 +80,12 @@
</div>
<!-- /.row -->
<p><a href='{% url 'helpdesk:view' ticket.id %}'><button class="btn btn-primary btn-lg">{% blocktrans with ticket.title as ticket_title %}Return to <em>{{ ticket_title }}</em>{% endblocktrans %}</button></a></p>
<p>
<a href='{% url 'helpdesk:view' ticket.id %}'>
<button class="btn btn-primary btn-lg">
{% blocktrans with ticket.title as ticket_title %}Return to <em>{{ ticket_title }}</em>{% endblocktrans %}
</button>
</a>
</p>
{% endblock %}

View File

@ -1508,21 +1508,27 @@ def ticket_cc_add(request, ticket_id):
ticket = get_object_or_404(Ticket, id=ticket_id)
ticket_perm_check(request, ticket)
form = None
if request.method == 'POST':
form = TicketCCForm(request.POST)
if form.is_valid():
user = form.cleaned_data.get('user')
email = form.cleaned_data.get('email')
if user and ticket.ticketcc_set.filter(user=user).exists():
form.add_error('user', _('Impossible to add twice the same user'))
elif email and ticket.ticketcc_set.filter(email=email).exists():
form.add_error('email', _('Impossible to add twice the same email address'))
else:
ticketcc = form.save(commit=False)
ticketcc.ticket = ticket
ticketcc.save()
return HttpResponseRedirect(reverse('helpdesk:ticket_cc',
kwargs={'ticket_id': ticket.id}))
else:
form_email = TicketCCEmailForm()
form_user = TicketCCUserForm()
return HttpResponseRedirect(reverse('helpdesk:ticket_cc', kwargs={'ticket_id': ticket.id}))
return render(request, 'helpdesk/ticket_cc_add.html', {
'ticket': ticket,
'form_email': form_email,
'form_user': form_user,
'form': form,
'form_email': TicketCCEmailForm(),
'form_user': TicketCCUserForm(),
})
@ -1531,13 +1537,14 @@ ticket_cc_add = staff_member_required(ticket_cc_add)
@helpdesk_staff_member_required
def ticket_cc_del(request, ticket_id, cc_id):
ticket = get_object_or_404(Ticket, id=ticket_id)
cc = get_object_or_404(TicketCC, ticket__id=ticket_id, id=cc_id)
if request.method == 'POST':
cc.delete()
return HttpResponseRedirect(reverse('helpdesk:ticket_cc',
kwargs={'ticket_id': cc.ticket.id}))
return render(request, 'helpdesk/ticket_cc_del.html', {'cc': cc})
return HttpResponseRedirect(reverse('helpdesk:ticket_cc', kwargs={'ticket_id': cc.ticket.id}))
return render(request, 'helpdesk/ticket_cc_del.html', {'ticket': ticket, 'cc': cc})
ticket_cc_del = staff_member_required(ticket_cc_del)