Merge pull request #894 from Benbb96/master

Improvements in Public part, to address issues with setting due date on a ticket, for #750
This commit is contained in:
Garret Wassermann 2020-10-23 12:56:08 -04:00 committed by GitHub
commit 79d8046694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 200 additions and 168 deletions

View File

@ -173,9 +173,9 @@ class AbstractTicketForm(CustomFieldMixin, forms.Form):
) )
due_date = forms.DateTimeField( due_date = forms.DateTimeField(
widget=forms.TextInput(attrs={'class': 'form-control'}), widget=forms.TextInput(attrs={'class': 'form-control', 'autocomplete': 'off'}),
required=False, required=False,
input_formats=['%d/%m/%Y', '%m/%d/%Y', "%d.%m.%Y", ], input_formats=['%d/%m/%Y', '%m/%d/%Y', "%d.%m.%Y"],
label=_('Due on'), label=_('Due on'),
) )
@ -186,6 +186,9 @@ class AbstractTicketForm(CustomFieldMixin, forms.Form):
help_text=_('You can attach a file such as a document or screenshot to this ticket.'), help_text=_('You can attach a file such as a document or screenshot to this ticket.'),
) )
class Media:
js = ('helpdesk/js/init_due_date.js',)
def __init__(self, kbcategory=None, *args, **kwargs): def __init__(self, kbcategory=None, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if kbcategory: if kbcategory:

View File

@ -61,8 +61,12 @@ table.table caption {
table.ticket-stats caption {color: #fbff00; font-style: italic;} table.ticket-stats caption {color: #fbff00; font-style: italic;}
table.ticket-stats tbody th, table.ticket-stats tbody tr {padding-left: 20px} table.ticket-stats tbody th, table.ticket-stats tbody tr {padding-left: 20px}
.errorlist {list-style: none;} .errorlist {
.errorlist {padding: 0;} list-style: none;
padding: 0;
color: red;
}
.has-error .input-group input, .has-error .input-group select, .has-error .input-group textarea {border-color: #b94a48} .has-error .input-group input, .has-error .input-group select, .has-error .input-group textarea {border-color: #b94a48}
#helpdesk-nav-collapse #searchform { #helpdesk-nav-collapse #searchform {

View File

@ -0,0 +1,3 @@
$(() => {
$("#id_due_date").datepicker();
});

View File

@ -3,65 +3,74 @@
{% block helpdesk_title %}{% trans "Create Ticket" %}{% endblock %} {% block helpdesk_title %}{% trans "Create Ticket" %}{% endblock %}
{% block helpdesk_breadcrumb %} {% block helpdesk_breadcrumb %}
<li class="breadcrumb-item"> <li class="breadcrumb-item">
<a href="#">{% trans "Tickets" %}</a> <a href="#">{% trans "Tickets" %}</a>
</li> </li>
<li class="breadcrumb-item active">{% trans "Create Ticket" %}</li> <li class="breadcrumb-item active">{% trans "Create Ticket" %}</li>
{% endblock %} {% endblock %}
{% block helpdesk_head %} {% block helpdesk_head %}
{% endblock %} {% endblock %}
{% block helpdesk_body %} {% block helpdesk_body %}
<div class="container"> <div class="container">
<div class="card card-register mx-auto mt-5"> <div class="card card-register mx-auto mt-5">
<div class="card-header">{% trans "Submit a Ticket" %}</div> <div class="card-header">{% trans "Submit a Ticket" %}</div>
<div class="card-body"> <div class="card-body">
<p>{% trans "Unless otherwise stated, all fields are required." %} {% trans "Please provide as descriptive a title and description as possible." %}</p> <p>
<form method='post' action='./' enctype='multipart/form-data'> {% trans "Unless otherwise stated, all fields are required." %}
{% for field in form %} {% trans "Please provide as descriptive a title and description as possible." %}
{% if field.is_hidden %} </p>
{{ field }}
{% else %} {% if form.errors %}
<div class="form-group"> {% include 'helpdesk/include/alert_form_errors.html' %}
<!--<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required="required">--> {% endif %}
<label for='id_{{ field.name }}'>{% trans field.label %}{% if not field.field.required %}&nbsp;({% trans "Optional" %}){% endif %}</label>
{{ field }} <form method='post' enctype='multipart/form-data'>
{% if field.errors %} {% csrf_token %}
<small class='error'>{{ field.errors }}</small> {% for field in form %}
{% endif %} {% if field.is_hidden %}
{% if field.help_text %} {{ field }}
<small class='form_help_text help-block'>{% trans field.help_text %}</small> {% else %}
{% endif %} <div class="form-group">
</div> <label for='id_{{ field.name }}'>
{% endif %} {% trans field.label %}
{% endfor %} {% if not field.field.required %}
<button type="submit" class="btn btn-primary btn-lg btn-block"><i class="fa fa-send"></i>&nbsp;{% trans "Submit Ticket" %}</button> ({% trans "Optional" %})
{% csrf_token %}</form> {% endif %}
</label>
{{ field }}
{% if field.errors %}
<small class='error'>{{ field.errors }}</small>
{% endif %}
{% if field.help_text %}
<small class='form_help_text help-block'>{% trans field.help_text %}</small>
{% endif %}
</div>
{% endif %}
{% endfor %}
<button type="submit" class="btn btn-primary btn-lg btn-block">
<i class="fa fa-send"></i> {% trans "Submit Ticket" %}
</button>
</form>
</div>
</div> </div>
</div>
</div> </div>
{% endblock %} {% endblock %}
{% block helpdesk_js %} {% block helpdesk_js %}
<script type='text/javascript' language='javascript'> {{ form.media.js }}
// this function listens for changes on any file input, and <script>
// emits the appropriate event to update the input's text. // this function listens for changes on any file input, and
// Needed to have properly styled file input buttons! (this really shouldn't be this hard...) // emits the appropriate event to update the input's text.
$(document).on('change', ':file', function() { // Needed to have properly styled file input buttons! (this really shouldn't be this hard...)
var input = $(this), $(document).on('change', ':file', function () {
inputWidgetNum = $(this).attr('id').split("file")[1], const input = $(this),
numFiles = input.get(0).files ? input.get(0).files.length : 1, inputWidgetNum = $(this).attr('id').split("file")[1],
label = input.val().replace(/\\/g, '/').replace(/.*\//, ''); numFiles = input.get(0).files ? input.get(0).files.length : 1,
input.trigger('fileselect', [numFiles, label, inputWidgetNum]); label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
}); input.trigger('fileselect', [numFiles, label, inputWidgetNum]);
</script> });
</script>
<script>
$( function() {
$( "#id_due_date" ).datepicker();
} );
</script>
{% endblock %} {% endblock %}

View File

@ -0,0 +1,8 @@
{% load i18n %}
<div class="alert alert-danger alert-dismissible fade show" role="alert">
{% trans "There are errors in the form" %}.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>

View File

@ -4,20 +4,23 @@
{% block helpdesk_title %}{% trans "Create Ticket" %}{% endblock %} {% block helpdesk_title %}{% trans "Create Ticket" %}{% endblock %}
{% block helpdesk_breadcrumb %} {% block helpdesk_breadcrumb %}
<li class="breadcrumb-item"> <li class="breadcrumb-item">
<a href="{% url 'helpdesk:home' %}">Public</a> <a href="{% url 'helpdesk:home' %}">Public</a>
</li> </li>
<li class="breadcrumb-item active">Create Ticket</li> <li class="breadcrumb-item active">Create Ticket</li>
{% endblock %} {% endblock %}
{% block helpdesk_body %} {% block helpdesk_body %}
<div class="container"> <div class="container">
<div class="card card-register mx-auto mt-5"> <div class="card card-register mx-auto mt-5">
<div class="card-header">{% trans "Submit a Ticket" %}</div> <div class="card-header">{% trans "Submit a Ticket" %}</div>
<div class="card-body"> <div class="card-body">
{% include 'helpdesk/public_create_ticket_base.html' %} {% include 'helpdesk/public_create_ticket_base.html' %}
</div>
</div> </div>
</div> </div>
</div> {% endblock %}
{% block helpdesk_js %}
{{ form.media.js }}
{% endblock %} {% endblock %}

View File

@ -1,16 +1,24 @@
{% load i18n bootstrap4form %} {% load i18n bootstrap4form %}
{% load load_helpdesk_settings %} {% load load_helpdesk_settings %}
{% with request|load_helpdesk_settings as helpdesk_settings %}
{% if helpdesk_settings.HELPDESK_SUBMIT_A_TICKET_PUBLIC %} {% with request|load_helpdesk_settings as helpdesk_settings %}
{% block form_header %} {% if helpdesk_settings.HELPDESK_SUBMIT_A_TICKET_PUBLIC %}
<p>{% trans "Unless otherwise stated, all fields are required." %} {% trans "Please provide as descriptive a title and description as possible." %}</p> <p>
{% endblock %} {% trans "Unless otherwise stated, all fields are required." %}
<form method='post' enctype='multipart/form-data'> {% trans "Please provide as descriptive a title and description as possible." %}
{{ form|bootstrap4form }} </p>
<button type="submit" class="btn btn-primary btn-lg btn-block"><i class="fa fa-send"></i>&nbsp;{% trans "Submit Ticket" %}</button>
{% csrf_token %}</form> {% if form.errors %}
{% else %} {% include 'helpdesk/include/alert_form_errors.html' %}
<h2>{% trans "Public ticket submission is disabled. Please contact the administrator for assistance." %}</h2> {% endif %}
{% endif %} <form role="form" method='post' enctype='multipart/form-data'>
{% csrf_token %}
{{ form|bootstrap4form }}
<button type="submit" class="btn btn-primary btn-lg btn-block">
{% trans "Submit Ticket" %} <i class="fa fa-paper-plane"></i>
</button>
</form>
{% else %}
<p>{% trans "Public ticket submission is disabled. Please contact the administrator for assistance." %}</p>
{% endif %}
{% endwith %} {% endwith %}

View File

@ -4,101 +4,81 @@
{% block helpdesk_title %}{% trans "Welcome to Helpdesk" %}{% endblock %} {% block helpdesk_title %}{% trans "Welcome to Helpdesk" %}{% endblock %}
{% block helpdesk_breadcrumb %} {% block helpdesk_breadcrumb %}
<li class="breadcrumb-item"> <li class="breadcrumb-item">
<a href="#">Public</a> <a href="#">Public</a>
</li> </li>
<li class="breadcrumb-item active">Homepage</li> <li class="breadcrumb-item active">Homepage</li>
{% endblock %} {% endblock %}
{% block helpdesk_body %} {% block helpdesk_body %}
<div class="container-fluid">
<div class="row">
{% if kb_categories %}
<div class="col-sm">
<h2>{% trans "Knowledgebase Articles" %}</h2>
{% for category in kb_categories %}
<div class="card" style="margin-top: 15px">
<div class="card-body">
<h5 class="card-title">{{ category.title }}</h5>
<p class="card-text">{{ category.description }}</p>
<p class="card-text">
<small class="text-muted">
<a href='{{ category.get_absolute_url }}'>
{% trans 'View articles' %} <i class="fa fa-arrow-right"></i>
</a>
</small>
</p>
</div>
</div>
{% endfor %}
</div>
{% endif %}
<div class="container-fluid"> <div class="col-sm">
<div class="row"> <div class="panel panel-default">
<div class="panel-body">
{% if kb_categories %} <h2>{% trans "Submit a Ticket" %}</h2>
<div class="col-sm"> {% include 'helpdesk/public_create_ticket_base.html' %}
<h2>{% trans "Knowledgebase Articles" %}</h2> </div>
{% for category in kb_categories %} </div>
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ category.title }}</h5>
<p class="card-text">{{ category.description }}</p>
<p class="card-text"><small class="text-muted"><a href='{{ category.get_absolute_url }}'>{% trans 'View articles' %}<i class="fa fa-arrow-right"></i></a></small></p>
</div>
</div>
{% endfor %}
</div>
{% endif %}
{% if helpdesk_settings.HELPDESK_SUBMIT_A_TICKET_PUBLIC %}
<div class="col-sm">
<div class="panel panel-default">
<div class="panel-body">
<h2 name='submit'>{% trans "Submit a Ticket" %}</h2>
<p>{% trans "Please provide as descriptive a title and description as possible." %}</p>
<form role="form" method='post' action='./#submit' enctype='multipart/form-data'>
<fieldset>
{{ form|bootstrap4form }}
{% comment %}
{% for field in form %}
{% if field.is_hidden %}
{{ field }}
{% else %}
<div class="form-group {% if field.errors %}has-error{% endif %}">
<label class="control-label" for='id_{{ field.name }}'>{{ field.label }}</label>{% if not field.field.required %} <span class='form_optional'>{% trans "(Optional)" %}</span>{% endif %}</dt>
<div class="input-group">{{ field }}</div>
{% if field.errors %}<div class="help-block">{{ field.errors }}</div>{% endif %}
{% if field.help_text %}<span class='fhelp-block'>{{ field.help_text }}</span>{% endif %}
</div> </div>
{% endif %} {% if not helpdesk_settings.HELPDESK_VIEW_A_TICKET_PUBLIC and not helpdesk_settings.HELPDESK_SUBMIT_A_TICKET_PUBLIC %}
<h2>{% trans "Please use button at upper right to login first." %}</h2>
{% endif %}
{% endfor %} {% if helpdesk_settings.HELPDESK_VIEW_A_TICKET_PUBLIC %}
{% endcomment %} <div class="col-sm">
<div class="panel panel-default">
<div class='buttons form-group'> <div class="panel-body">
<input type='submit' class="btn btn-primary" value='{% trans "Submit Ticket" %}' /> <h2>{% trans "View a Ticket" %}</h2>
<form method='get' action="{% url 'helpdesk:public_view' %}">
<fieldset>
<div class="form-group {% if field.errors %}has-error{% endif %}">
<label for='id_ticket'>{% trans "Ticket" %}</label>
<div class="input-group">
<input type='text' name='ticket' class='form-control'/>
</div>
</div>
<div class="form-group {% if field.errors %}has-error{% endif %}">
<label for='id_email'>{% trans "Your E-mail Address" %}</label>
<div class="input-group">
<input type='text' name='email' class='form-control'/>
</div>
</div>
<div class='buttons form-group'>
<input type='submit' class="btn btn-primary" value='{% trans "View Ticket" %}'/>
</div>
</fieldset>
</form>
</div>
</div>
</div>
{% endif %}
</div>
</div> </div>
</fieldset> {% endblock %}
{% csrf_token %}</form> {% block helpdesk_js %}
</div> {{ form.media.js }}
</div>
</div>
{% endif %}
{% if not helpdesk_settings.HELPDESK_VIEW_A_TICKET_PUBLIC and not helpdesk_settings.HELPDESK_SUBMIT_A_TICKET_PUBLIC %}
<h2>{% trans "Please use button at upper right to login first." %}</h2>
{% endif %}
{% if helpdesk_settings.HELPDESK_VIEW_A_TICKET_PUBLIC %}
<div class="col-sm">
<div class="panel panel-default">
<div class="panel-body">
<h2>{% trans "View a Ticket" %}</h2>
<form method='get' action="{% url 'helpdesk:public_view' %}">
<fieldset>
<div class="form-group {% if field.errors %}has-error{% endif %}">
<label for='id_ticket'>{% trans "Ticket" %}</label>
<div class="input-group"><input type='text' name='ticket' /></div>
</div>
<div class="form-group {% if field.errors %}has-error{% endif %}">
<label for='id_email'>{% trans "Your E-mail Address" %}</label>
<div class="input-group"><input type='text' name='email' /></div>
</div>
<div class='buttons form-group'>
<input type='submit' class="btn btn-primary" value='{% trans "View Ticket" %}' />
</div>
</fieldset>
{% csrf_token %}</form>
</div></div>
</div>
{% endif %}
{% endblock %} {% endblock %}

View File

@ -15,6 +15,13 @@
<td>{{ ticket.created|date:"r" }} ({{ ticket.created|naturaltime }})</td> <td>{{ ticket.created|date:"r" }} ({{ ticket.created|naturaltime }})</td>
</tr> </tr>
{% if ticket.due_date %}
<tr>
<th>{% trans "Due On" %}</th>
<td>{{ ticket.due_date|date:"r" }} ({{ ticket.due_date|naturaltime }})</td>
</tr>
{% endif %}
<tr> <tr>
<th>{% trans "Submitter E-Mail" %}</th> <th>{% trans "Submitter E-Mail" %}</th>
<td>{{ ticket.submitter_email }}</td> <td>{{ ticket.submitter_email }}</td>
@ -26,10 +33,11 @@
</tr> </tr>
{% for customfield in ticket.ticketcustomfieldvalue_set.all %} {% for customfield in ticket.ticketcustomfieldvalue_set.all %}
<tr> <tr>
<th>{{ customfield.field.label }}</th> <th>{{ customfield.field.label }}</th>
<td>{{ customfield.value }}</td> <td>{{ customfield.value|default:"" }}</td>
</tr>{% endfor %} </tr>
{% endfor %}
{% if tags_enabled %} {% if tags_enabled %}
<tr> <tr>

View File

@ -137,6 +137,12 @@ class SuccessIframeView(TemplateView):
class CreateTicketView(BaseCreateTicketView): class CreateTicketView(BaseCreateTicketView):
template_name = 'helpdesk/public_create_ticket.html' template_name = 'helpdesk/public_create_ticket.html'
def get_form(self, form_class=None):
form = super().get_form(form_class)
# Add the CSS error class to the form in order to better see them in the page
form.error_css_class = 'text-danger'
return form
class Homepage(CreateTicketView): class Homepage(CreateTicketView):
template_name = 'helpdesk/public_homepage.html' template_name = 'helpdesk/public_homepage.html'