resq/templates/ticket/form.html.twig
2023-11-07 04:02:33 +08:00

418 lines
22 KiB
Twig

{% extends 'base.html.twig' %}
{% block body %}
<!-- BEGIN: Subheader -->
<div class="m-subheader">
<div class="d-flex align-items-center">
<div class="mr-auto">
<h3 class="m-subheader__title">Tickets</h3>
</div>
</div>
</div>
<!-- END: Subheader -->
<div class="m-content">
<!--Begin::Section-->
<div class="row">
<div class="col-xl-10">
<div class="m-portlet m-portlet--mobile">
<div class="m-portlet__head">
<div class="m-portlet__head-caption">
<div class="m-portlet__head-title">
<span class="m-portlet__head-icon">
<i class="fa fa-ticket"></i>
</span>
<h3 class="m-portlet__head-text">
{% if mode == 'update' %}
Edit Ticket
<small>{{ obj.getID }}</small>
{% else %}
New Ticket
{% if customer %}
<small>for {{ customer.getFirstName ~ " " ~ customer.getLastName }}</small>
{% endif %}
{% endif %}
</h3>
</div>
</div>
</div>
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('ticket_update_submit', {'id': obj.getId}) : url('ticket_create_submit', {'customer_id': customer ? customer.getID : false, 'job_order_id': job_order ? job_order.getID : false}) }}">
<div class="m-portlet__body">
<div class="m-form__section m-form__section--first{{ mode == 'create' ? ' m-form__section--last' }}">
{% if (mode == 'update') and (obj.getTicketType != null) %}
<div class="form-group m-form__group row no-border">
<div class="col-lg-4">
<label data-field="status">Legacy Ticket Type</label>
<select class="form-control m-input" id="ticket-type" name="ticket_type" disabled>
<option value=""></option>
{% for key, ticket_type in ticket_types %}
<option value="{{ key }}"{{ key == obj.getTicketType ? ' selected' }}>{{ ticket_type }}</option>
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="ticket_type"></div>
</div>
<div class="col-lg-4">
<label data-field="other_ticket_type">Legacy Other Ticket Type <small>(please specify)</small></label>
<input type="text" name="other_ticket_type" id="other-ticket-type" class="form-control m-input" value="{{ obj.getOtherTicketType }}" disabled>
<div class="form-control-feedback hide" data-field="other_ticket_type"></div>
</div>
</div>
{% endif %}
<div class="form-group m-form__group row no-border">
<div class="col-lg-4">
<label data-field="status">Ticket Type</label>
<select class="form-control m-input" id="new-ticket-type" name="new_ticket_type">
<option value="">Select a ticket type</option>
{% for id, label in sets.new_ticket_types %}
{% if obj.getNewTicketType %}
<option value="{{ id }}"{{ id == obj.getNewTicketType.getID ? ' selected' }}>{{ label }}</option>
{% else %}
<option value="{{ id }}">{{ label }}</option>
{% endif %}
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="new_ticket_type"></div>
</div>
<div class="col-lg-4">
<label data-field="sub_ticket_type">Sub Ticket Type</label>
<select class="form-control m-input" id="sub-ticket-type" name="sub_ticket_type">
{% if obj.getSubTicketType == null %}
<option value="0">Select a ticket type first</option>
{% else %}
<option value="0">Select a sub-ticket type</option>
{% for sub_ttype in sets.sub_ticket_types %}
{% if sub_ttype.ticket_type_id == obj.getNewTicketType.getID %}
{% if sub_ttype.id == obj.getSubTicketType.getID|default(0) %}
<option value="{{ sub_ttype.id }}" selected>{{ sub_ttype.name }}</option>
{% else %}
<option value="{{ sub_ttype.id }}">{{ sub_ttype.name }}</option>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
</select>
<div class="form-control-feedback hide" data-field="sub_ticket_type"></div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-12">
<label for="other_desc" data-field="remarks"> Description </label>
<textarea class="form-control m-input" id="other-desc" rows="4" name="other_desc">{{ obj.getOtherDescription }}</textarea>
<div class="form-control-feedback hide" data-field="other_desc"></div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-4">
<label data-field="first_name">First Name</label>
<input type="text" name="first_name" class="form-control m-input" value="{{ customer and mode == 'create' ? customer.getFirstName : obj.getFirstName }}"{{ customer ? ' disabled' }}>
<div class="form-control-feedback hide" data-field="first_name"></div>
</div>
<div class="col-lg-4">
<label data-field="last_name">Last Name</label>
<input type="text" name="last_name" class="form-control m-input" value="{{ customer and mode == 'create' ? customer.getLastName : obj.getLastName }}"{{ customer ? ' disabled' }}>
<div class="form-control-feedback hide" data-field="last_name"></div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-4">
<label data-field="contact_num">Contact Number</label>
<div class="input-group m-input-group">
<span class="input-group-addon">{% trans %}country_code_prefix{% endtrans %}</span>
<input type="text" name="contact_num" class="form-control m-input" value="{{ customer and mode == 'create' and customer.getPhoneMobile is not empty ? customer.getPhoneMobile : obj.getContactNumber }}"{{ customer ? ' disabled' }}>
<div class="form-control-feedback hide" data-field="contact_num"></div>
</div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-4">
<label data-field="plate_number">Vehicle Plate Number</label>
<input type="text" name="plate_number" class="form-control m-input" value="{{ obj.getPlateNumber }}">
<div class="form-control-feedback hide" data-field="plate_number"></div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-4">
<label data-field="status">Source of Awareness</label>
<select class="form-control m-input" id="source-of-awareness" name="source_of_awareness">
<option value=""></option>
{% for key, soa in soa_types %}
<option value="{{ key }}"{{ key == obj.getSourceOfAwareness ? ' selected' }}>{{ soa }}</option>
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="source_of_awareness"></div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-12">
<label for="remarks" data-field="remarks"> Remarks </label>
<textarea class="form-control m-input" id="remarks" rows="6" name="remarks">{{ obj.getRemarks }}</textarea>
<div class="form-control-feedback hide" data-field="remarks"></div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-4">
<label data-field="status">Status</label>
<select class="form-control m-input" id="status" name="status">
{% for key, status in statuses %}
<option value="{{ key }}"{{ key == obj.getStatus ? ' selected' }}>{{ status }}</option>
{% endfor %}
</select>
<div class="form-control-feedback hide" data-field="status"></div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-12">
<label for="details" data-field="details">
Details
</label>
<textarea class="form-control m-input" id="details" rows="6" name="details">{{ obj.getDetails }}</textarea>
<div class="form-control-feedback hide" data-field="details"></div>
</div>
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-4">
<label data-field="job_order_id">Linked Job Order</label>
<input type="text" name="job_order_id" class="form-control m-input" value="{{ job_order.getID|default('None') }}" disabled>
<div class="form-control-feedback hide" data-field="job_order_id"></div>
</div>
{% if job_order %}
<div class="col-lg-4">
<label>&nbsp;</label>
<div>
<a href="{{ url('jo_all_form', {'id': job_order.getID }) }}" class="btn btn-info">View Job Order</a>
</div>
</div>
{% endif %}
</div>
<div class="form-group m-form__group row no-border">
<div class="col-lg-4">
<span class="m-switch m-switch--icon block-switch">
<label>
<input type="checkbox" name="flag_late_doc" id="flag_late_doc" value="1"{{ obj.isLateDoc ? ' checked' }}>
<label class="switch-label" for="flag_late_doc">This is a late documentation</label>
<span></span>
</label>
</span>
</div>
</div>
<div class="form-group m-form__group row no-border{{ obj.isLateDoc ? '' : ' hide' }}" id="late_doc_reason_box">
<div class="col-lg-12">
<label for="details" data-field="late_doc_reason">
Reason for Late Documentation
</label>
<textarea class="form-control m-input" id="late_doc_reason" rows="6" name="late_doc_reason">{{ obj.getLateDocReason }}</textarea>
<div class="form-control-feedback hide" data-field="late_doc_reason"></div>
</div>
</div>
</div>
{% if mode == 'update' %}
<div class="m-form__seperator m-form__seperator--dashed"></div>
<div class="m-form__section m-form__section--last">
<div class="m-form__heading">
<h3 class="m-form__heading-title">
Related Tickets
</h3>
</div>
<div class="form-group m-form__group row">
<div class="col-lg-12">
<div class="m_datatable" id="data-related-tickets"></div>
</div>
</div>
</div>
{% endif %}
</div>
<div class="m-portlet__foot m-portlet__foot--fit">
<div class="m-form__actions m-form__actions--solid m-form__actions--right">
<div class="row">
<div class="col-lg-12">
<button type="submit" class="btn btn-success">Submit</button>
<a href="{{ redirect_url }}" class="btn btn-secondary">Back</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script>
$(function() {
$("#row-form").submit(function(e) {
var form = $(this);
e.preventDefault();
$.ajax({
method: "POST",
url: form.prop('action'),
data: form.serialize()
}).done(function(response) {
// remove all error classes
removeErrors();
swal({
title: 'Done!',
text: 'Your changes have been saved!',
type: 'success',
onClose: function() {
window.location.href = "{{ redirect_url }}";
}
});
}).fail(function(response) {
if (response.status == 422) {
var errors = response.responseJSON.errors;
var firstfield = false;
// remove all error classes first
removeErrors();
// display errors contextually
$.each(errors, function(field, msg) {
var formfield = $("[name='" + field + "']");
var label = $("label[data-field='" + field + "']");
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
// add error classes to bad fields
formfield.addClass('form-control-danger');
label.addClass('has-danger');
msgbox.html(msg).addClass('has-danger').removeClass('hide');
// check if this field comes first in DOM
var domfield = formfield.get(0);
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
firstfield = domfield;
}
});
// focus on first bad field
firstfield.focus();
// scroll to above that field to make it visible
$('html, body').animate({
scrollTop: $(firstfield).offset().top - 200
}, 100);
}
});
});
// remove all error classes
function removeErrors() {
$(".form-control-danger").removeClass('form-control-danger');
$("[data-field]").removeClass('has-danger');
$(".form-control-feedback[data-field]").addClass('hide');
}
// toggle other ticket type field
$("#ticket-type").change(function() {
var field = $("#other-ticket-type");
if ($(this).val() == '{{ other_ticket_type }}') {
field.prop('disabled', false);
} else {
field.prop('disabled', true).val("");
}
}).change();
{% if mode == 'update' %}
// related tickets
var ticketRows = [];
{% for ticket in related_tickets %}
trow = {
id: "{{ ticket.getID }}",
date_create: "{{ ticket.getDateCreate|date('d M Y - h:i A') }}",
ticket_type: "{{ ticket.getTicketTypeText }}",
status: "{{ ticket.getStatusText }}",
edit_url: "{{ url('ticket_update', {'id': ticket.getID}) }}"
};
ticketRows.push(trow);
{% endfor %}
// tickets data table
var ticketOptions = {
data: {
type: 'local',
source: ticketRows,
saveState: {
cookie: false,
webstorage: false
}
},
layout: {
scroll: true
},
columns: [
{
field: 'id',
title: 'ID',
width: 30
},
{
field: 'date_create',
title: 'Date Created',
width: 200
},
{
field: 'ticket_type',
title: 'Ticket Type'
},
{
field: 'status',
title: 'Status'
},
{
field: 'Actions',
width: 70,
title: 'Actions',
sortable: false,
overflow: 'visible',
template: function (row, index, datatable) {
return '<a href="' + row.edit_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-accent m-btn--icon m-btn--icon-only m-btn--pill btn-edit-ticket" title="Edit"><i class="la la-edit"></i></a>';
},
}
],
pagination: false
};
var ticketTable = $("#data-related-tickets").mDatatable(ticketOptions);
{% endif %}
});
var subticket_type_list = {{ sets.sub_ticket_types|json_encode|raw }};
// populate sub ticket type field
$('form').on('change', '#new-ticket-type', function() {
console.log('ticket type change');
var ticket_type_id = $(this).val();
// build options for sub ticket type based on selected ticket type
var options = '<option value="0">Select sub ticket type</option>';
for (var i in subticket_type_list) {
if (subticket_type_list[i].ticket_type_id == ticket_type_id) {
options += '<option value="' + subticket_type_list[i].id + '">' + subticket_type_list[i].name + '</option>'
}
}
$('#sub-ticket-type').html(options);
});
$('form').on('change', '#flag_late_doc', (e) => {
const reasonBox = document.getElementById("late_doc_reason_box");
if (e.target.checked) {
reasonBox.classList.remove('hide');
reasonBox.querySelector('textarea').focus();
} else {
reasonBox.classList.add('hide');
}
});
</script>
{% endblock %}