254 lines
12 KiB
Twig
254 lines
12 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">Shift Schedules</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- END: Subheader -->
|
|
<div class="m-content">
|
|
<!--Begin::Section-->
|
|
<div class="row">
|
|
<div class="col-xl-12">
|
|
<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-building"></i>
|
|
</span>
|
|
<h3 class="m-portlet__head-text">
|
|
{% if mode == 'update' %}
|
|
Edit Shift Schedule
|
|
<small>{{ obj.getName() }}</small>
|
|
{% else %}
|
|
New Shift Schedule
|
|
{% endif %}
|
|
</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<form id="row-form" class="m-form m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('shift_schedule_update_submit', {'id': obj.getId()}) : url('shift_schedule_create_submit') }}">
|
|
<div class="m-portlet__body">
|
|
<div class="form-group m-form__group row no-border">
|
|
<div class="col-lg-6">
|
|
<label for="name" data-field="name">
|
|
Name
|
|
</label>
|
|
<input type="text" name="name" class="form-control m-input" value="{{ obj.getName()|default('') }}">
|
|
<div class="form-control-feedback hide" data-field="name"></div>
|
|
</div>
|
|
</div>
|
|
<div class="form-group m-form__group row no-border">
|
|
<div class="col-lg-3">
|
|
<label for="start_time">
|
|
Start Time
|
|
</label>
|
|
<div class="input-group timepicker">
|
|
<input id="timepicker_start" type="text" name="start_time" class="form-control m-input tp-start" readonly placeholder="Select time" type="text" value="{{ obj.getStartTime.format('g:i A') }}" />
|
|
<span class="input-group-addon">
|
|
<i class="la la-clock-o"></i>
|
|
</span>
|
|
</div>
|
|
<div class="form-control-feedback hide" data-field="start_time"></div>
|
|
</div>
|
|
<div class="col-lg-3">
|
|
<label for="end_time">
|
|
End Time
|
|
</label>
|
|
<div class="input-group timepicker">
|
|
<input id="timepicker_end" type="text" name="end_time" class="form-control m-input tp-end" readonly placeholder="Select time" type="text" value="{{ obj.getEndTime.format('g:i A') }}" />
|
|
<span class="input-group-addon">
|
|
<i class="la la-clock-o"></i>
|
|
</span>
|
|
</div>
|
|
<div class="form-control-feedback hide" data-field="end_time"></div>
|
|
</div>
|
|
</div>
|
|
<div class="m-form__seperator m-form__seperator--dashed"></div>
|
|
<div class="m-form__section" id="shift-entry-section">
|
|
<div class="m-form__heading">
|
|
<h3 class="m-form__heading-title">
|
|
Breakdown of Shift Schedule
|
|
</h3>
|
|
</div>
|
|
<div class="form-group m-form__group row">
|
|
<button type="button" class="btn btn-primary" id="btn-add-shift-entry">Add Shift Entry</button>
|
|
</div>
|
|
<!-- loop through the existing shift entries -->
|
|
{% for shift_entry in shift_entries %}
|
|
<div class="form-group m-form__group row">
|
|
<div class="col-lg-3">
|
|
<div class="input-group timepicker">
|
|
<input id="timepicker_start_entry" type="text" name="shift_start_time[]" class="form-control m-input tp-start-shift-entry" readonly placeholder="Select time" type="text" value="{{ shift_entry.start.format('g:i A') }}" />
|
|
<span class="input-group-addon">
|
|
<i class="la la-clock-o"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-3">
|
|
<div class="input-group timepicker">
|
|
<input id="timepicker_end_entry" type="text" name="shift_end_time[]" class="form-control m-input tp-end-shift-entry" readonly placeholder="Select time" type="text" value="{{ shift_entry.end.format('g:i A') }}" />
|
|
<span class="input-group-addon">
|
|
<i class="la la-clock-o"></i>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-1">
|
|
<button class="btn btn-danger btn-shift-entry-remove">X</button>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</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="{{ url('shift_schedule_list') }}" class="btn btn-secondary">Back</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
|
|
{% block scripts %}
|
|
<script>
|
|
|
|
var timepicker_options = {
|
|
format: "HH:ii P",
|
|
minuteStep: 1,
|
|
showMeridian: true,
|
|
snapToStep: true,
|
|
bootcssVer: 3,
|
|
todayHighlight: true,
|
|
autoclose: true
|
|
};
|
|
|
|
$(document).ready(function() {
|
|
// timepickers
|
|
$(".tp-start, .tp-end, .tp-start-shift-entry, .tp-end-shift-entry").timepicker(timepicker_options);
|
|
});
|
|
|
|
|
|
// add shift entry
|
|
$("#btn-add-shift-entry").click(function() {
|
|
console.log('adding shift entry');
|
|
|
|
var html = '<div class="form-group m-form__group row">';
|
|
html += '<div class="col-lg-3">';
|
|
html += '<div class="input-group timepicker">';
|
|
html += '<input id="timepicker_start_entry" type="text" name="shift_start_time[]" class="form-control m-input tp-start-shift-entry" readonly placeholder="Select time" type="text" value="{{ obj.getStartTime.format('g:i A') }}" />';
|
|
html += '<span class="input-group-addon">';
|
|
html += '<i class="la la-clock-o"></i>';
|
|
html += '</span></div></div>';
|
|
|
|
html += '<div class="col-lg-3">';
|
|
html += '<div class="input-group timepicker">';
|
|
html += '<input id="timepicker_end_entry" type="text" name="shift_end_time[]" class="form-control m-input tp-end-shift-entry" readonly placeholder="Select time" type="text" value="{{ obj.getEndTime.format('g:i A') }}" />';
|
|
html += '<span class="input-group-addon">';
|
|
html += '<i class="la la-clock-o"></i>';
|
|
html += '</span></div></div>';
|
|
|
|
html += '<div class="col-lg-1">';
|
|
html += '<button class="btn btn-danger btn-shift-entry-remove">X</button>';
|
|
html += '</div>';
|
|
|
|
$('#shift-entry-section').append(html);
|
|
|
|
// add timepicker functionality to just added timepickers
|
|
$(".tp-start-shift-entry, .tp-end-shift-entry").timepicker(timepicker_options);
|
|
|
|
return false;
|
|
});
|
|
|
|
// remove shift entry
|
|
$('body').on('click', '.btn-shift-entry-remove', function(e) {
|
|
console.log('removing service charge');
|
|
|
|
$(this).closest('.row').remove();
|
|
|
|
return false;
|
|
});
|
|
|
|
$(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 = "{{ url('shift_schedule_list') }}";
|
|
}
|
|
});
|
|
}).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');
|
|
}
|
|
|
|
});
|
|
</script>
|
|
{% endblock %}
|