419 lines
17 KiB
Twig
419 lines
17 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">Hubs</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 Hub
|
|
<small>{{ obj.getName() }}</small>
|
|
{% else %}
|
|
New Hub
|
|
{% endif %}
|
|
</h3>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<form id="row-form" class="m-form m-form--label-align-right" method="post" action="{{ mode == 'update' ? url('hub_update_submit', {'id': obj.getId()}) : url('hub_create_submit') }}">
|
|
|
|
<div class="m-portlet__body">
|
|
<ul id="customer-tabs" class="nav nav-tabs" role="tablist">
|
|
<li class="nav-item">
|
|
<a class="nav-link active" data-toggle="tab" href="#hub-info">Hub Info</a>
|
|
</li>
|
|
{% if mode == 'update' %}
|
|
<li class="nav-item">
|
|
<a class="nav-link" data-toggle="tab" href="#outlets">Outlets</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" data-toggle="tab" href="#riders">Assigned Riders</a>
|
|
</li>
|
|
{% endif %}
|
|
</ul>
|
|
<div class="tab-content">
|
|
<div class="tab-pane active" id="hub-info" role="tabpanel">
|
|
<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() }}">
|
|
<div class="form-control-feedback hide" data-field="name"></div>
|
|
</div>
|
|
<div class="col-lg-6">
|
|
<label for="branch" data-field="branch">
|
|
Branch
|
|
</label>
|
|
<input type="text" name="branch" class="form-control m-input" value="{{ obj.getBranch() }}">
|
|
<div class="form-control-feedback hide" data-field="branch"></div>
|
|
</div>
|
|
</div>
|
|
<div class="form-group m-form__group row no-border">
|
|
<div class="col-lg-6">
|
|
<label for="address" data-field="address">
|
|
Address
|
|
</label>
|
|
<textarea class="form-control m-input" id="address" rows="4" name="address">{{ obj.getAddress }}</textarea>
|
|
<div class="form-control-feedback hide" data-field="address"></div>
|
|
</div>
|
|
<div class="col-lg-6">
|
|
<label for="contact_nums" data-field="contact_nums">
|
|
Contact Numbers
|
|
</label>
|
|
<textarea class="form-control m-input" id="contact_nums" rows="4" name="contact_nums">{{ obj.getContactNumbers }}</textarea>
|
|
<div class="form-control-feedback hide" data-field="contact_nums"></div>
|
|
</div>
|
|
</div>
|
|
<div class="form-group m-form__group row no-border">
|
|
<div class="col-lg-3">
|
|
<label for="time_open">
|
|
Time Open
|
|
</label>
|
|
<div class="input-group timepicker">
|
|
<input id="timepicker_open" type="text" name="time_open" class="form-control m-input" readonly placeholder="Select time" type="text" value="{{ obj.getTimeOpen.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="time_open"></div>
|
|
</div>
|
|
<div class="col-lg-3">
|
|
<label for="time_close">
|
|
Time Close
|
|
</label>
|
|
<div class="input-group timepicker">
|
|
<input id="timepicker_close" type="text" name="time_close" class="form-control m-input" readonly placeholder="Select time" type="text" value="{{ obj.getTimeClose.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="time_close"></div>
|
|
</div>
|
|
</div>
|
|
<div class="form-group m-form__group row">
|
|
<div class="col-lg-12">
|
|
<label>
|
|
Map Coordinates
|
|
</label>
|
|
<input type="hidden" id="map_lat" name="coord_lat" value="">
|
|
<input type="hidden" id="map_lng" name="coord_lng" value="">
|
|
<div class="input-group">
|
|
<input type="text" class="form-control" id="m_gmap_address" placeholder="Search">
|
|
<span class="input-group-btn">
|
|
<button class="btn btn-primary" id="m_gmap_btn">
|
|
<i class="fa fa-search"></i>
|
|
</button>
|
|
</span>
|
|
</div>
|
|
<div id="m_gmap" style="height:600px;"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% if mode == 'update' %}
|
|
<div class="tab-pane" id="outlets" role="tabpanel">
|
|
<div class="form-group m-form__group row form-group-inner row">
|
|
<div class="col-lg-12">
|
|
<div id="data-outlets"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="tab-pane" id="riders" role="tabpanel">
|
|
<div class="form-group m-form__group row form-group-inner row">
|
|
<div class="col-lg-12">
|
|
<div id="data-riders"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
</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('hub_list') }}" class="btn btn-secondary">Back</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
|
|
{% block scripts %}
|
|
<script src="//maps.google.com/maps/api/js?key={{ gmaps_api_key }}" type="text/javascript"></script>
|
|
<script src="/assets/vendors/custom/gmaps/gmaps.js" type="text/javascript"></script>
|
|
|
|
<script>
|
|
|
|
// BEGIN google maps stuff
|
|
function selectPoint(map, latlng) {
|
|
var lat = latlng.lat();
|
|
var lng = latlng.lng();
|
|
|
|
// show it in map
|
|
map.removeMarkers();
|
|
map.setCenter(lat, lng);
|
|
map.addMarker({
|
|
lat: lat,
|
|
lng: lng
|
|
});
|
|
|
|
// set value in hidden input
|
|
$('#map_lat').val(lat);
|
|
$('#map_lng').val(lng);
|
|
}
|
|
|
|
var map = new GMaps({
|
|
div: '#m_gmap',
|
|
lat: 14.6091,
|
|
lng: 121.0223,
|
|
click: function(e) {
|
|
// handle click in map
|
|
selectPoint(map, e.latLng);
|
|
e.stop();
|
|
}
|
|
});
|
|
var handleAction = function() {
|
|
var text = $.trim($('#m_gmap_address').val());
|
|
GMaps.geocode({
|
|
address: text,
|
|
callback: function(results, status) {
|
|
map.removeMarkers();
|
|
if (status == 'OK') {
|
|
selectPoint(map, results[0].geometry.location);
|
|
}
|
|
},
|
|
region: 'ph'
|
|
});
|
|
}
|
|
|
|
$('#m_gmap_btn').click(function(e) {
|
|
e.preventDefault();
|
|
handleAction();
|
|
});
|
|
|
|
$("#m_gmap_address").keypress(function(e) {
|
|
var keycode = (e.keyCode ? e.keyCode : e.which);
|
|
if (keycode == '13') {
|
|
e.preventDefault();
|
|
handleAction();
|
|
}
|
|
});
|
|
|
|
// END google maps stuff
|
|
|
|
$(document).ready(function() {
|
|
// timepickers
|
|
$('#timepicker_open, #timepicker_close').timepicker({
|
|
format: "HH:ii P",
|
|
minuteStep: 1,
|
|
showMeridian: true,
|
|
snapToStep: true,
|
|
bootcssVer: 3,
|
|
todayHighlight: true,
|
|
autoclose: true
|
|
});
|
|
|
|
// check if we need to set map
|
|
{% if mode == 'update' %}
|
|
var latlng = new google.maps.LatLng({{ obj.getCoordinates.getLatitude }}, {{ obj.getCoordinates.getLongitude }});
|
|
selectPoint(map, latlng);
|
|
{% endif %}
|
|
|
|
});
|
|
|
|
|
|
$(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('hub_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');
|
|
}
|
|
|
|
// initialize arrays
|
|
var outletRows = [];
|
|
var riderRows = [];
|
|
|
|
{% for outlet in obj.getOutlets() %}
|
|
orow = {
|
|
name: "{{ outlet.getName() }}",
|
|
branch: "{{ outlet.getBranch() }}",
|
|
address: "{{ outlet.getAddress() }}",
|
|
contact_nums: '{{ outlet.getContactNumbers()|replace({"\r\n": "<br>"})|raw }}',
|
|
time_open: "{{ outlet.getTimeOpen()|date('g:i A') }}",
|
|
time_close: "{{ outlet.getTimeClose()|date('g:i A') }}"
|
|
};
|
|
|
|
outletRows.push(orow);
|
|
{% endfor %}
|
|
|
|
{% for rider in obj.getRiders() %}
|
|
rrow = {
|
|
first_name: "{{ rider.getFirstName() }}",
|
|
last_name: "{{ rider.getLastName() }}",
|
|
contact_num: "{{ rider.getContactNumber() }}",
|
|
plate_number: "{{ rider.getPlateNumber() }}"
|
|
};
|
|
|
|
riderRows.push(rrow);
|
|
{% endfor %}
|
|
|
|
// outlets data table
|
|
var outletOptions = {
|
|
data: {
|
|
type: 'local',
|
|
source: outletRows,
|
|
saveState: {
|
|
cookie: false,
|
|
webstorage: false
|
|
}
|
|
},
|
|
columns: [
|
|
{
|
|
field: 'name',
|
|
title: 'Outlet'
|
|
},
|
|
{
|
|
field: 'branch',
|
|
title: 'Branch'
|
|
},
|
|
{
|
|
field: 'address',
|
|
title: 'Address'
|
|
},
|
|
{
|
|
field: 'contact_nums',
|
|
title: 'Contact Nos.'
|
|
},
|
|
{
|
|
field: 'time_open',
|
|
title: 'Time Open'
|
|
},
|
|
{
|
|
field: 'time_close',
|
|
title: 'Time Close'
|
|
}
|
|
],
|
|
pagination: false
|
|
};
|
|
|
|
var outletTable = $("#data-outlets").mDatatable(outletOptions);
|
|
|
|
// riders data table
|
|
var riderOptions = {
|
|
data: {
|
|
type: 'local',
|
|
source: riderRows,
|
|
saveState: {
|
|
cookie: false,
|
|
webstorage: false
|
|
}
|
|
},
|
|
columns: [
|
|
{
|
|
field: 'first_name',
|
|
title: 'First Name'
|
|
},
|
|
{
|
|
field: 'last_name',
|
|
title: 'Last Name'
|
|
},
|
|
{
|
|
field: 'contact_num',
|
|
title: 'Contact No.'
|
|
},
|
|
{
|
|
field: 'plate_number',
|
|
title: 'Plate Number'
|
|
}
|
|
],
|
|
pagination: false
|
|
};
|
|
|
|
var riderTable = $("#data-riders").mDatatable(riderOptions);
|
|
});
|
|
</script>
|
|
{% endblock %}
|