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(
widget=forms.TextInput(attrs={'class': 'form-control'}),
widget=forms.TextInput(attrs={'class': 'form-control', 'autocomplete': 'off'}),
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'),
)
@ -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.'),
)
class Media:
js = ('helpdesk/js/init_due_date.js',)
def __init__(self, kbcategory=None, *args, **kwargs):
super().__init__(*args, **kwargs)
if kbcategory:

View File

@ -61,8 +61,12 @@ table.table caption {
table.ticket-stats caption {color: #fbff00; font-style: italic;}
table.ticket-stats tbody th, table.ticket-stats tbody tr {padding-left: 20px}
.errorlist {list-style: none;}
.errorlist {padding: 0;}
.errorlist {
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}
#helpdesk-nav-collapse #searchform {

View File

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

View File

@ -13,20 +13,32 @@
{% endblock %}
{% block helpdesk_body %}
<div class="container">
<div class="card card-register mx-auto mt-5">
<div class="card-header">{% trans "Submit a Ticket" %}</div>
<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>
<form method='post' action='./' enctype='multipart/form-data'>
<p>
{% trans "Unless otherwise stated, all fields are required." %}
{% trans "Please provide as descriptive a title and description as possible." %}
</p>
{% if form.errors %}
{% include 'helpdesk/include/alert_form_errors.html' %}
{% endif %}
<form method='post' enctype='multipart/form-data'>
{% csrf_token %}
{% for field in form %}
{% if field.is_hidden %}
{{ field }}
{% else %}
<div class="form-group">
<!--<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required="required">-->
<label for='id_{{ field.name }}'>{% trans field.label %}{% if not field.field.required %}&nbsp;({% trans "Optional" %}){% endif %}</label>
<label for='id_{{ field.name }}'>
{% trans field.label %}
{% if not field.field.required %}
({% trans "Optional" %})
{% endif %}
</label>
{{ field }}
{% if field.errors %}
<small class='error'>{{ field.errors }}</small>
@ -37,8 +49,10 @@
</div>
{% endif %}
{% endfor %}
<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>
<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>
@ -46,22 +60,17 @@
{% endblock %}
{% block helpdesk_js %}
<script type='text/javascript' language='javascript'>
{{ form.media.js }}
<script>
// this function listens for changes on any file input, and
// emits the appropriate event to update the input's text.
// Needed to have properly styled file input buttons! (this really shouldn't be this hard...)
$(document).on('change', ':file', function () {
var input = $(this),
const input = $(this),
inputWidgetNum = $(this).attr('id').split("file")[1],
numFiles = input.get(0).files ? input.get(0).files.length : 1,
label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
input.trigger('fileselect', [numFiles, label, inputWidgetNum]);
});
</script>
<script>
$( function() {
$( "#id_due_date" ).datepicker();
} );
</script>
{% 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

@ -19,5 +19,8 @@
</div>
</div>
</div>
{% endblock %}
{% block helpdesk_js %}
{{ form.media.js }}
{% endblock %}

View File

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

View File

@ -11,66 +11,37 @@
{% endblock %}
{% 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">
<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>
<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>
{% endif %}
{% endfor %}
{% endcomment %}
<div class='buttons form-group'>
<input type='submit' class="btn btn-primary" value='{% trans "Submit Ticket" %}' />
</div>
</fieldset>
{% csrf_token %}</form>
<h2>{% trans "Submit a Ticket" %}</h2>
{% include 'helpdesk/public_create_ticket_base.html' %}
</div>
</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>
@ -81,24 +52,33 @@
<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 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' /></div>
<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>
{% csrf_token %}</form>
</div></div>
</form>
</div>
</div>
</div>
{% endif %}
</div>
</div>
{% endblock %}
{% block helpdesk_js %}
{{ form.media.js }}
{% endblock %}

View File

@ -15,6 +15,13 @@
<td>{{ ticket.created|date:"r" }} ({{ ticket.created|naturaltime }})</td>
</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>
<th>{% trans "Submitter E-Mail" %}</th>
<td>{{ ticket.submitter_email }}</td>
@ -28,8 +35,9 @@
{% for customfield in ticket.ticketcustomfieldvalue_set.all %}
<tr>
<th>{{ customfield.field.label }}</th>
<td>{{ customfield.value }}</td>
</tr>{% endfor %}
<td>{{ customfield.value|default:"" }}</td>
</tr>
{% endfor %}
{% if tags_enabled %}
<tr>

View File

@ -137,6 +137,12 @@ class SuccessIframeView(TemplateView):
class CreateTicketView(BaseCreateTicketView):
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):
template_name = 'helpdesk/public_homepage.html'