Display supported areas in google map. #220
This commit is contained in:
parent
e574ae966a
commit
9e9c59cd0b
5 changed files with 58 additions and 499 deletions
|
|
@ -172,10 +172,6 @@ access_keys:
|
||||||
label: List
|
label: List
|
||||||
- id: geofence.add
|
- id: geofence.add
|
||||||
label: Add
|
label: Add
|
||||||
- id: geofence.update
|
|
||||||
label: Update
|
|
||||||
- id: geofence.delete
|
|
||||||
label: Delete
|
|
||||||
|
|
||||||
- id: rider
|
- id: rider
|
||||||
label: Rider Access
|
label: Rider Access
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,6 @@ geofence_list:
|
||||||
path: /geofence
|
path: /geofence
|
||||||
controller: App\Controller\GeofenceController::index
|
controller: App\Controller\GeofenceController::index
|
||||||
|
|
||||||
geofence_rows:
|
|
||||||
path: /geofence/rows
|
|
||||||
controller: App\Controller\GeofenceController::rows
|
|
||||||
methods: [POST]
|
|
||||||
|
|
||||||
geofence_create:
|
geofence_create:
|
||||||
path: /geofence/create
|
path: /geofence/create
|
||||||
controller: App\Controller\GeofenceController::addForm
|
controller: App\Controller\GeofenceController::addForm
|
||||||
|
|
@ -18,18 +13,3 @@ geofence_create_submit:
|
||||||
path: /geofence/create
|
path: /geofence/create
|
||||||
controller: App\Controller\GeofenceController::addSubmit
|
controller: App\Controller\GeofenceController::addSubmit
|
||||||
methods: [POST]
|
methods: [POST]
|
||||||
|
|
||||||
geofence_update:
|
|
||||||
path: /geofence/{id}
|
|
||||||
controller: App\Controller\GeofenceController::updateForm
|
|
||||||
methods: [GET]
|
|
||||||
|
|
||||||
geofence_update_submit:
|
|
||||||
path: /geofence/{id}
|
|
||||||
controller: App\Controller\GeofenceController::updateSubmit
|
|
||||||
methods: [POST]
|
|
||||||
|
|
||||||
geofence_delete:
|
|
||||||
path: /geofence/{id}
|
|
||||||
controller: App\Controller\GeofenceController::destroy
|
|
||||||
methods: [DELETE]
|
|
||||||
|
|
|
||||||
|
|
@ -23,88 +23,13 @@ class GeofenceController extends BaseController
|
||||||
|
|
||||||
$params = $this->initParameters('geofence_list');
|
$params = $this->initParameters('geofence_list');
|
||||||
|
|
||||||
return $this->render('geofence/list.html.twig', $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function rows(Request $req)
|
|
||||||
{
|
|
||||||
$this->denyAccessUnlessGranted('geofence.list', null, 'No access.');
|
|
||||||
|
|
||||||
// get query builder
|
// get query builder
|
||||||
$qb = $this->getDoctrine()
|
$params['areas'] = $this->getDoctrine()
|
||||||
->getRepository(SupportedArea::class)
|
->getRepository(SupportedArea::class)
|
||||||
->createQueryBuilder('q');
|
->findAll();
|
||||||
|
|
||||||
// get datatable params
|
|
||||||
$datatable = $req->get('datatable');
|
|
||||||
|
|
||||||
// count total records
|
|
||||||
$tquery = $qb->select('COUNT(q)');
|
|
||||||
$this->setQueryFilters($datatable, $tquery);
|
|
||||||
$total = $tquery->getQuery()
|
|
||||||
->getSingleScalarResult();
|
|
||||||
|
|
||||||
// get current page number
|
|
||||||
$page = $datatable['pagination']['page'] ?? 1;
|
|
||||||
|
|
||||||
$perpage = $datatable['pagination']['perpage'];
|
|
||||||
$offset = ($page - 1) * $perpage;
|
|
||||||
|
|
||||||
// add metadata
|
|
||||||
$meta = [
|
|
||||||
'page' => $page,
|
|
||||||
'perpage' => $perpage,
|
|
||||||
'pages' => ceil($total / $perpage),
|
|
||||||
'total' => $total,
|
|
||||||
'sort' => 'asc',
|
|
||||||
'field' => 'id'
|
|
||||||
];
|
|
||||||
|
|
||||||
// build query
|
|
||||||
$query = $qb->select('q');
|
|
||||||
$this->setQueryFilters($datatable, $query);
|
|
||||||
|
|
||||||
// check if sorting is present, otherwise use default
|
|
||||||
if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) {
|
|
||||||
$order = $datatable['sort']['sort'] ?? 'asc';
|
|
||||||
$query->orderBy('q.' . $datatable['sort']['field'], $order);
|
|
||||||
} else {
|
|
||||||
$query->orderBy('q.id', 'asc');
|
|
||||||
}
|
|
||||||
|
|
||||||
// get rows for this page
|
|
||||||
$obj_rows = $query->setFirstResult($offset)
|
|
||||||
->setMaxResults($perpage)
|
|
||||||
->getQuery()
|
|
||||||
->getResult();
|
|
||||||
|
|
||||||
// process rows
|
|
||||||
$rows = [];
|
|
||||||
foreach ($obj_rows as $orow) {
|
|
||||||
// add row data
|
|
||||||
$row['id'] = $orow->getID();
|
|
||||||
$row['name'] = $orow->getName();
|
|
||||||
|
|
||||||
// add row metadata
|
|
||||||
$row['meta'] = [
|
|
||||||
'update_url' => '',
|
|
||||||
'delete_url' => ''
|
|
||||||
];
|
|
||||||
|
|
||||||
// add crud urls
|
|
||||||
if ($this->isGranted('geofence.update'))
|
|
||||||
$row['meta']['update_url'] = $this->generateUrl('geofence_update', ['id' => $row['id']]);
|
|
||||||
if ($this->isGranted('geofence.delete'))
|
|
||||||
$row['meta']['delete_url'] = $this->generateUrl('geofence_delete', ['id' => $row['id']]);
|
|
||||||
|
|
||||||
$rows[] = $row;
|
|
||||||
}
|
|
||||||
|
|
||||||
// response
|
// response
|
||||||
return $this->json([
|
return $this->render('geofence/list.html.twig', $params);
|
||||||
'meta' => $meta,
|
|
||||||
'data' => $rows
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addForm()
|
public function addForm()
|
||||||
|
|
@ -121,59 +46,4 @@ class GeofenceController extends BaseController
|
||||||
return $this->render('geofence/form.html.twig', $params);
|
return $this->render('geofence/form.html.twig', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateForm($id)
|
|
||||||
{
|
|
||||||
$this->denyAccessUnlessGranted('geofence.update', null, 'No access.');
|
|
||||||
|
|
||||||
$params = $this->initParameters('geofence_list');
|
|
||||||
|
|
||||||
// get row data
|
|
||||||
$em = $this->getDoctrine()->getManager();
|
|
||||||
$obj = $em->getRepository(SupportedArea::class)->find($id);
|
|
||||||
|
|
||||||
// make sure this row exists
|
|
||||||
if (empty($obj))
|
|
||||||
throw $this->createNotFoundException('The item does not exist');
|
|
||||||
|
|
||||||
$params['obj'] = $obj;
|
|
||||||
$params['mode'] = 'update';
|
|
||||||
|
|
||||||
$this->fillFormTags($params);
|
|
||||||
|
|
||||||
// response
|
|
||||||
return $this->render('geofence/form.html.twig', $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function initFormTags(&$params)
|
|
||||||
{
|
|
||||||
// default to editing, as we have more forms editing than creating
|
|
||||||
$params['ftags'] = [
|
|
||||||
'set_map_coordinate' => true,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function fillFormTags(&$params)
|
|
||||||
{
|
|
||||||
$this->initFormTags($params);
|
|
||||||
|
|
||||||
switch ($params['mode'])
|
|
||||||
{
|
|
||||||
case 'create':
|
|
||||||
$params['ftags']['set_map_coordinate'] = false;
|
|
||||||
break;
|
|
||||||
case 'update':
|
|
||||||
$params['ftags']['set_map_coordinate'] = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected function setQueryFilters($datatable, QueryBuilder $query)
|
|
||||||
{
|
|
||||||
if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) {
|
|
||||||
$query->where('q.name LIKE :filter')
|
|
||||||
->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,233 +0,0 @@
|
||||||
{% 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">Geofence</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 Geofence
|
|
||||||
<small>{{ obj.getName }}</small>
|
|
||||||
{% else %}
|
|
||||||
New Geofence
|
|
||||||
{% endif %}
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ mode == 'update' ? url('geofence_update_submit', {'id': obj.getID}) : url('geofence_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 }}">
|
|
||||||
<div class="form-control-feedback hide" data-field="name"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group m-form__group row">
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<label data-field="coordinates">
|
|
||||||
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 class="form-control-feedback hide" data-field="coordinates"></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('outlet_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 polygon = new google.maps.Polygon({
|
|
||||||
map: map,
|
|
||||||
paths: obj.getCoverageArea,
|
|
||||||
fillColor: "#336699",
|
|
||||||
fillOpacity: .5,
|
|
||||||
})
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
{% if ftags.set_map_coordinate %}
|
|
||||||
// check if we need to set map
|
|
||||||
alert('mogol');
|
|
||||||
var latlng = new google.maps.LatLng({{ obj.getCoverageArea.getRing(0).getPoint(0).getLatitude }}, {{ obj.getCoverageArea.getRing(0).getPoint(0).getLongitude }});
|
|
||||||
alert(obj.getCoverageArea.getRing(0).getPoint(0).getLatitude);
|
|
||||||
selectPoint(map, latlng);
|
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
// END google maps stuff
|
|
||||||
|
|
||||||
$(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('geofence_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 %}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -5,9 +5,7 @@
|
||||||
<div class="m-subheader">
|
<div class="m-subheader">
|
||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<div class="mr-auto">
|
<div class="mr-auto">
|
||||||
<h3 class="m-subheader__title">
|
<h3 class="m-subheader__title">Geofence</h3>
|
||||||
Geofence
|
|
||||||
</h3>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -17,36 +15,30 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xl-12">
|
<div class="col-xl-12">
|
||||||
<div class="m-portlet m-portlet--mobile">
|
<div class="m-portlet m-portlet--mobile">
|
||||||
<div class="m-portlet__body">
|
<div class="m-portlet__head">
|
||||||
<div class="m-form m-form--label-align-right m--margin-top-20 m--margin-bottom-30">
|
<div class="m-portlet__head-caption">
|
||||||
<div class="row align-items-center">
|
<div class="m-portlet__head-title">
|
||||||
<div class="col-xl-8 order-2 order-xl-1">
|
<span class="m-portlet__head-icon">
|
||||||
<div class="form-group m-form__group row align-items-center">
|
<i class="fa fa-building"></i>
|
||||||
<div class="col-md-4">
|
</span>
|
||||||
<div class="m-input-icon m-input-icon--left">
|
<h3 class="m-portlet__head-text">
|
||||||
<input type="text" class="form-control m-input m-input--solid" placeholder="Search..." id="data-rows-search">
|
Covered Areas
|
||||||
<span class="m-input-icon__icon m-input-icon__icon--left">
|
</h3>
|
||||||
<span><i class="la la-search"></i></span>
|
</div>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ url('geofence_create_submit') }}">
|
||||||
</div>
|
<div class="m-portlet__body">
|
||||||
</div>
|
<div class="form-group m-form__group row">
|
||||||
<div class="col-xl-4 order-1 order-xl-2 m--align-right">
|
<div class="col-lg-12">
|
||||||
<a href="{{ url('geofence_create') }}" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
|
<label data-field="coordinates">
|
||||||
<span>
|
Map
|
||||||
<i class="fa fa-building"></i>
|
</label>
|
||||||
<span>Add Covered Area</span>
|
<div id="m_gmap" style="height:600px;"></div>
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
<div class="m-separator m-separator--dashed d-xl-none"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--begin: Datatable -->
|
</form>
|
||||||
<div id="data-rows"></div>
|
|
||||||
<!--end: Datatable -->
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -54,91 +46,45 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script src="//maps.google.com/maps/api/js?key={{ gmaps_api_key }}" type="text/javascript"></script>
|
||||||
$(function() {
|
<script src="/assets/vendors/custom/gmaps/gmaps.js" type="text/javascript"></script>
|
||||||
var options = {
|
|
||||||
data: {
|
|
||||||
type: 'remote',
|
|
||||||
source: {
|
|
||||||
read: {
|
|
||||||
url: '{{ url("geofence_rows") }}',
|
|
||||||
method: 'POST',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
saveState: {
|
|
||||||
cookie: false,
|
|
||||||
webstorage: false
|
|
||||||
},
|
|
||||||
pageSize: 10,
|
|
||||||
serverPaging: true,
|
|
||||||
serverFiltering: true,
|
|
||||||
serverSorting: true
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
field: 'id',
|
|
||||||
title: 'ID',
|
|
||||||
width: 30
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'name',
|
|
||||||
title: 'Area Name'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
field: 'Actions',
|
|
||||||
width: 110,
|
|
||||||
title: 'Actions',
|
|
||||||
sortable: false,
|
|
||||||
overflow: 'visible',
|
|
||||||
template: function (row, index, datatable) {
|
|
||||||
var actions = '';
|
|
||||||
if (row.meta.update_url != '') {
|
|
||||||
actions += '<a href="' + row.meta.update_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" data-id="' + row.name + '" title="View"><i class="la la-edit"></i></a>';
|
|
||||||
}
|
|
||||||
if (row.meta.delete_url != '') {
|
|
||||||
actions += '<a href="' + row.meta.delete_url + '" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-delete" data-id="' + row.name + '" title="Delete"><i class="la la-trash"></i></a>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return actions;
|
<script>
|
||||||
},
|
|
||||||
}
|
|
||||||
],
|
|
||||||
search: {
|
|
||||||
onEnter: false,
|
|
||||||
input: $('#data-rows-search'),
|
|
||||||
delay: 400
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var table = $("#data-rows").mDatatable(options);
|
initMap();
|
||||||
|
// BEGIN google maps stuff
|
||||||
|
function initMap() {
|
||||||
|
var map = new google.maps.Map(document.getElementById('m_gmap'),
|
||||||
|
{
|
||||||
|
center: {lat: 14.6091, lng: 121.0223},
|
||||||
|
mapTypeId: 'roadmap',
|
||||||
|
zoom: 13
|
||||||
|
});
|
||||||
|
|
||||||
$(document).on('click', '.btn-delete', function(e) {
|
{% for obj in areas %}
|
||||||
var url = $(this).prop('href');
|
var pointsArray = new Array();
|
||||||
var id = $(this).data('id');
|
|
||||||
var btn = $(this);
|
|
||||||
|
|
||||||
e.preventDefault();
|
{% for point in obj.getCoverageArea.getRing(0).getPoints() %}
|
||||||
|
var polylatlng = new google.maps.LatLng(
|
||||||
|
{{ point.getLatitude }},
|
||||||
|
{{ point.getLongitude }});
|
||||||
|
|
||||||
swal({
|
pointsArray.push(polylatlng);
|
||||||
title: 'Confirmation',
|
{% endfor %}
|
||||||
html: 'Are you sure you want to delete <strong>' + id + '</strong>?',
|
|
||||||
type: 'warning',
|
var coveredarea = new google.maps.Polygon({
|
||||||
showCancelButton: true
|
paths: pointsArray,
|
||||||
}).then((result) => {
|
fillColor: "#FF0000",
|
||||||
if (result.value) {
|
fillOpacity: .5,
|
||||||
$.ajax({
|
mapTypeId: 'roadmap'
|
||||||
method: "DELETE",
|
|
||||||
url: url
|
|
||||||
}).done(function(response) {
|
|
||||||
table.row(btn.parents('tr')).remove();
|
|
||||||
table.reload();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
coveredarea.setMap(map);
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
|
||||||
|
// END google maps stuff
|
||||||
|
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue