1014 lines
36 KiB
JavaScript
1014 lines
36 KiB
JavaScript
// variables part
|
||
var supervisorCartable;
|
||
var supervisorCartable_url = "/v2/road_patrols/supervisor/cartable/show";
|
||
var verify_api = "/v2/road_patrols/supervisor/cartable/verify/";
|
||
var items_api = "/v2/items"
|
||
var provinces_api = "/webapi/getuser/province-perm";
|
||
var edarat_api = "/public/contents/edarate_shahri_by_province/";
|
||
var permission_api = "/webapi/user/get-permission";
|
||
var deletePatrol_api = "/v2/road_patrols/supervisor/cartable/delete/";
|
||
var report_api = "/v2/road_patrols/operator/report/";
|
||
var excel_api = "/v2/road_patrols/supervisor/cartable/report";
|
||
const MAP_ENDPOINT = "https://rmsmap.rmto.ir";
|
||
var markers = [];
|
||
var markersLayer;
|
||
var mapZoom = getWidth() < 508 ? 5 : 6;
|
||
var filterDatepicker = {};
|
||
var excelDatepicker = {};
|
||
var PERMISSIONS = [];
|
||
// end variables part
|
||
|
||
// resize func
|
||
function getWidth() {
|
||
return Math.max(
|
||
document.body.scrollWidth,
|
||
document.documentElement.scrollWidth,
|
||
document.body.offsetWidth,
|
||
document.documentElement.offsetWidth,
|
||
document.documentElement.clientWidth
|
||
);
|
||
}
|
||
// end resize func
|
||
|
||
// map
|
||
// icon
|
||
var mapIcon = L.icon({
|
||
iconUrl: '/dist/images/dashboard/pinmarker_dashboard.png',
|
||
iconSize: [32, 32],
|
||
});
|
||
var activeMapIcon = L.icon({
|
||
iconUrl: '/dist/images/dashboard/pinmarker_dashboard_active.png',
|
||
iconSize: [32, 32],
|
||
});
|
||
var mapEndIcon = L.divIcon({
|
||
html: `
|
||
<div id="pin-marker-end" class="pin-marker pin-most-dis">
|
||
<div class="map-pin-marker most-distance">
|
||
<div class="pin-main-circle"></div>
|
||
<div class="pin-white-circle"></div>
|
||
<div class="pin-title-circle">
|
||
<span class="title-circle-text">دور ترین نقطه</span>
|
||
</div>
|
||
<div class="pin-main-line"></div>
|
||
</div>
|
||
<div class="pin-main-shadow">
|
||
<div class="shadow-dot">
|
||
</div>
|
||
</div>
|
||
</div>`,
|
||
iconSize: [55, 75],
|
||
iconAnchor: [28, 75],
|
||
});
|
||
// icon
|
||
|
||
var bounds = [
|
||
[42.9130026312, 75.6166317076],
|
||
[20.5782370061, 30.5092252948],
|
||
];
|
||
var map = L.map("map", {
|
||
maxBounds: bounds,
|
||
minZoom: mapZoom,
|
||
zoomControl: false,
|
||
attributionControl: false
|
||
}).setView([35.5468992, 51.7300532], mapZoom);
|
||
L.tileLayer(MAP_ENDPOINT + "/141map/{z}/{x}/{y}.png", {
|
||
attributionControl: false,
|
||
}).addTo(map);
|
||
// end map
|
||
|
||
(() => {
|
||
//get permission
|
||
showLoaderScreen()
|
||
$.ajax({
|
||
url: permission_api,
|
||
type: "GET",
|
||
cache: false,
|
||
async: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (result) {
|
||
PERMISSIONS = result.data;
|
||
},
|
||
error: function () {
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "مشکل در دریافت سطح دسترسی",
|
||
confirmButtonText: "بروزرسانی صفحه",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
location.reload(true);
|
||
},
|
||
});
|
||
},
|
||
});
|
||
//end get permission
|
||
})()
|
||
|
||
$(document).bind("click", function (e) {
|
||
const clicked = $(e.target);
|
||
if (clicked.parents(".toolbox").length != 0) return false;
|
||
if (clicked.parents(".datepicker-grid-view").length != 0) return false;
|
||
if (clicked.parents(".datepicker-navigator").length != 0) return false;
|
||
if (clicked.parents(".datepicker-container").length != 0) return false;
|
||
if (clicked.parents(".select2-selection__choice").length != 0) return false;
|
||
if (
|
||
clicked.closest(".filtering-btn").length == 0 &&
|
||
clicked.closest("#filter_box").length == 0 &&
|
||
$("filter_box").css("display") != "none"
|
||
) {
|
||
$("#filter_box").css("display", "none");
|
||
}
|
||
if (
|
||
clicked.closest(".reporting-btn").length == 0 &&
|
||
clicked.closest("#excel_box").length == 0 &&
|
||
$("excel_box").css("display") != "none"
|
||
) {
|
||
$("#excel_box").css("display", "none");
|
||
}
|
||
});
|
||
|
||
const FilterBoxInit = () => {
|
||
const top = $('.dt-button')[0].offsetHeight + 5
|
||
return `<div id="filter_box" style="top:${top}px">
|
||
<div class="d-flex">
|
||
<div class="form-group" style="flex: 1">
|
||
<label for="filter_id">کد یکتا</label>
|
||
<input id="filter_id" type="search" class="form-control form-control-sm" autocomplete="off" />
|
||
</div>
|
||
</div>
|
||
<div class="d-flex">
|
||
<div class="form-group ml-2" style="flex: 1">
|
||
<label for="filter_province">استان</label>
|
||
<select class="form-control form-control-sm fill-provinces" id="filter_province">
|
||
<option value="-1" selected>انتخاب استان</option>
|
||
</select>
|
||
</div>
|
||
<div class="form-group mr-2" style="flex: 1">
|
||
<label for="filter_edarat">اداره</label>
|
||
<select class="form-control form-control-sm fill-edarat" id="filter_edarat">
|
||
<option value="-1" selected>یک استان انتخاب کنید</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="d-flex">
|
||
<div class="form-group ml-2" style="flex: 1">
|
||
<label for="filter_from_activity_date_time">از تاریخ فعالیت</label>
|
||
<input class="form-control form-control-sm" type="search" id="filter_from_activity_date_time">
|
||
</div>
|
||
<div class="form-group mr-2" style="flex: 1">
|
||
<label for="filter_to_activity_date_time">تا تاریخ فعالیت</label>
|
||
<input class="form-control form-control-sm" type="search" id="filter_to_activity_date_time">
|
||
</div>
|
||
</div>
|
||
<hr />
|
||
<button class="btn btn-info btn-sm" id="btn_filter">فیلتر</button>
|
||
</div>`
|
||
}
|
||
|
||
|
||
const fillFilterBox = () => {
|
||
//fill datepicker
|
||
filterDatepicker.from = $(
|
||
"#filter_from_activity_date_time"
|
||
).persianDatepicker({
|
||
format: "YYYY/MM/DD",
|
||
autoClose: true,
|
||
initialValue: false,
|
||
onSelect: function (unix) {
|
||
filterDatepicker.from.touched = true;
|
||
|
||
if (
|
||
filterDatepicker.from.getState().selected.unixDate >=
|
||
filterDatepicker.to.getState().selected.unixDate
|
||
) {
|
||
filterDatepicker.to.setDate(
|
||
filterDatepicker.from.getState().selected.unixDate
|
||
);
|
||
}
|
||
|
||
if (
|
||
filterDatepicker.to &&
|
||
filterDatepicker.to.options &&
|
||
filterDatepicker.to.options.minDate != unix
|
||
) {
|
||
let cachedValue =
|
||
filterDatepicker.to.getState().selected.unixDate;
|
||
|
||
filterDatepicker.to.options = { minDate: unix };
|
||
|
||
if (filterDatepicker.from.touched) {
|
||
filterDatepicker.to.setDate(cachedValue);
|
||
}
|
||
}
|
||
},
|
||
});
|
||
|
||
filterDatepicker.to = $(
|
||
"#filter_to_activity_date_time"
|
||
).persianDatepicker({
|
||
format: "YYYY/MM/DD",
|
||
autoClose: true,
|
||
initialValue: false,
|
||
onSelect: function (unix) {
|
||
filterDatepicker.to.touched = true;
|
||
},
|
||
});
|
||
|
||
$(document).on('input', '#filter_from_activity_date_time', function (e) {
|
||
if (e.target.value == '') {
|
||
filterDatepicker.from.setDate(moment().valueOf())
|
||
filterDatepicker.to.setDate(moment().valueOf())
|
||
$("#filter_to_activity_date_time").val('')
|
||
$("#filter_from_activity_date_time").val('')
|
||
}
|
||
})
|
||
|
||
$(document).on('input', '#filter_to_activity_date_time', function (e) {
|
||
if (e.target.value == '') {
|
||
filterDatepicker.from.setDate(moment().valueOf())
|
||
filterDatepicker.to.setDate(moment().valueOf())
|
||
$("#filter_from_activity_date_time").val('')
|
||
$("#filter_to_activity_date_time").val('')
|
||
}
|
||
})
|
||
|
||
//fill provinces
|
||
$.ajax({
|
||
url: `${provinces_api}${$.inArray("show-road-patrol-supervise-cartable", PERMISSIONS) != -1 ? "?type=all" : ""}`,
|
||
type: "get",
|
||
headers: {
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
beforeSend: function () {
|
||
$('.fill-provinces').empty()
|
||
$('.fill-provinces').append(`
|
||
<option value="-1">در حال دریافت استان ها...</option>
|
||
`)
|
||
},
|
||
success: function (result) {
|
||
$('.fill-provinces').empty()
|
||
$('.fill-provinces').append(`
|
||
<option value="-1">انتخاب استان</option>
|
||
`)
|
||
result.data.map(item => {
|
||
$('.fill-provinces').append(`
|
||
<option value="${item.id}">${item.name_fa}</option>
|
||
`)
|
||
})
|
||
},
|
||
error: function (request) {
|
||
},
|
||
complete: function () {
|
||
}
|
||
});
|
||
|
||
//fill edarat
|
||
$(document).on('change', '#filter_province', function (e) {
|
||
const proviceId = e.target.value
|
||
|
||
if (proviceId == "-1") {
|
||
$('#filter_edarat').empty()
|
||
$('#filter_edarat').append(`
|
||
<option value="-1">یک استان انتخاب کنید</option>
|
||
`)
|
||
return
|
||
}
|
||
|
||
$.ajax({
|
||
url: edarat_api + proviceId,
|
||
type: "get",
|
||
headers: {
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
beforeSend: function () {
|
||
$('#filter_edarat').empty()
|
||
$('#filter_edarat').append(`
|
||
<option value="-1">در حال دریافت اداره ها...</option>
|
||
`)
|
||
},
|
||
success: function (result) {
|
||
console.log(result);
|
||
$('#filter_edarat').empty()
|
||
$('#filter_edarat').append(`
|
||
<option value="-1">انتخاب اداره</option>
|
||
`)
|
||
result.data.map(item => {
|
||
$('#filter_edarat').append(`
|
||
<option value="${item.id}">${item.name_fa}</option>
|
||
`)
|
||
})
|
||
},
|
||
error: function (request) {
|
||
},
|
||
complete: function () {
|
||
}
|
||
})
|
||
})
|
||
|
||
//fill items
|
||
$.ajax({
|
||
url: items_api,
|
||
type: "get",
|
||
headers: {
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
beforeSend: function () {
|
||
$('.fill-items').empty()
|
||
$('.fill-items').append(`
|
||
<option value="-1">در حال دریافت آیتم...</option>
|
||
`)
|
||
},
|
||
success: function (result) {
|
||
$('.fill-items').empty()
|
||
$('.fill-items').append(`
|
||
<option value="-1">انتخاب آیتم فعالیت</option>
|
||
`)
|
||
result.data.map(item => {
|
||
$('.fill-items').append(`
|
||
<option value="${item.id}">${item.name}</option>
|
||
`)
|
||
})
|
||
},
|
||
error: function (request) {
|
||
},
|
||
complete: function () {
|
||
}
|
||
});
|
||
|
||
//fill status
|
||
$('.fill-status').empty()
|
||
|
||
$('.fill-status').append(`
|
||
<option value="-1">انتخاب وضعیت</option>
|
||
<option value="0">در حال بررسی</option>
|
||
<option value="1">تایید شده</option>
|
||
<option value="2">عدم تایید</option>
|
||
`)
|
||
}
|
||
|
||
const filterBox = (show) => {
|
||
$('#filter_box').css('display', show ? 'flex' : 'none')
|
||
}
|
||
|
||
$(function () {
|
||
// supervisor cartable table
|
||
showLoaderScreen();
|
||
supervisorCartable = $("#supervisor_cartable").DataTable({
|
||
serverSide: true,
|
||
dom: "<<'d-flex justify-content-between align-items-center'lB><t>p>",
|
||
pagingType: "simple_numbers",
|
||
scrollX: true,
|
||
filter: true,
|
||
language: {
|
||
sEmptyTable: "هیچ دادهای در جدول وجود ندارد",
|
||
sInfo: "نمایش _START_ تا _END_ از _TOTAL_ ردیف",
|
||
sInfoEmpty: "نمایش 0 تا 0 از 0 ردیف",
|
||
sInfoFiltered: "(فیلتر شده از _MAX_ ردیف)",
|
||
sInfoPostFix: "",
|
||
sInfoThousands: ",",
|
||
sLengthMenu: "نمایش _MENU_ ردیف",
|
||
sLoadingRecords: "در حال بارگزاری...",
|
||
sProcessing: "در حال پردازش...",
|
||
sSearch: "جستجو: ",
|
||
sZeroRecords: "رکوردی با این مشخصات پیدا نشد",
|
||
oPaginate: {
|
||
sFirst: "برگهی نخست",
|
||
sLast: "برگهی آخر",
|
||
sNext: "بعدی",
|
||
sPrevious: "قبلی",
|
||
},
|
||
oAria: {
|
||
sSortAscending: ": فعال سازی نمایش به صورت صعودی",
|
||
sSortDescending: ": فعال سازی نمایش به صورت نزولی",
|
||
},
|
||
},
|
||
order: [
|
||
[0, "desc"]
|
||
],
|
||
processing: true,
|
||
select: true,
|
||
ajax: {
|
||
url: supervisorCartable_url,
|
||
type: "GET",
|
||
beforeSend: function () {
|
||
showLoaderScreen();
|
||
if (markers.length != 0) {
|
||
map.removeLayer(markersLayer);
|
||
markers = [];
|
||
markersLayer.clearLayers();
|
||
}
|
||
$("#supervisor_cartable").find("tbody tr").removeClass("activate-row");
|
||
},
|
||
dataSrc: function (json) {
|
||
let data = json.data;
|
||
hideLoaderScreen();
|
||
if (data.length == 0) {
|
||
return data
|
||
}
|
||
const latlonArr = []
|
||
for (let i = 0; i < data.length; i++) {
|
||
let marker = new L.Marker([data[i].start_lat, data[i].start_lon], { icon: mapIcon, id: data[i].id }).on('click', function (e) {
|
||
const id = e.target.options.id
|
||
supervisorCartable.rows().eq(0).map(index => {
|
||
if (supervisorCartable.row(index).data().id == id) {
|
||
const node = supervisorCartable.row(index).node()
|
||
$("html, body").animate({
|
||
scrollTop: $(node).offset().top,
|
||
},
|
||
100
|
||
);
|
||
$("#supervisor_cartable").find("tbody tr").removeClass("activate-row");
|
||
$(node).addClass("activate-row");
|
||
setTimeout(() => {
|
||
markersLayer.eachLayer(layer => {
|
||
if (layer.options.id == id) {
|
||
layer.setIcon(activeMapIcon)
|
||
layer.setZIndexOffset(100)
|
||
return
|
||
}
|
||
layer.setZIndexOffset(0)
|
||
layer.setIcon(mapIcon)
|
||
})
|
||
map.flyTo([supervisorCartable.row(index).data().start_lat, supervisorCartable.row(index).data().start_lon], 16, { duration: .5 });
|
||
}, 500)
|
||
}
|
||
})
|
||
})
|
||
markers.push(marker);
|
||
latlonArr.push([data[i].start_lat, data[i].start_lon])
|
||
}
|
||
markersLayer = new L.LayerGroup(markers);
|
||
map.addLayer(markersLayer);
|
||
$("html, body").animate({
|
||
scrollTop: $('#map').offset().top - 50,
|
||
},
|
||
100
|
||
);
|
||
setTimeout(() => {
|
||
map.flyToBounds(latlonArr, { padding: [60, 60], duration: .5 })
|
||
}, 250);
|
||
hideLoaderScreen();
|
||
return json.data;
|
||
},
|
||
error: function (request) {
|
||
ajax_error(request.responseJSON, request.status);
|
||
hideLoaderScreen();
|
||
},
|
||
},
|
||
columns: [
|
||
// 1
|
||
{
|
||
className: "text-center align-middle",
|
||
data: null,
|
||
name: {
|
||
name: 'id',
|
||
type: 'text'
|
||
},
|
||
render: function (data, type, row) {
|
||
return `<div class="d-flex justify-content-center align-items-center"><span>${data.id}</span></div>`
|
||
},
|
||
searchable: true,
|
||
orderable: true,
|
||
},
|
||
// 2
|
||
{
|
||
className: "text-center align-middle",
|
||
data: "province_fa",
|
||
name: {
|
||
name: 'province_id',
|
||
type: 'select'
|
||
},
|
||
searchable: true,
|
||
orderable: true,
|
||
},
|
||
// 3
|
||
{
|
||
className: "text-center align-middle",
|
||
data: "edare_name",
|
||
name: {
|
||
name: 'edare_id',
|
||
type: 'select'
|
||
},
|
||
searchable: true,
|
||
orderable: true,
|
||
},
|
||
// 4
|
||
{
|
||
className: "text-center align-middle",
|
||
data: "officer_name",
|
||
name: {
|
||
name: 'officer_name',
|
||
type: 'text'
|
||
},
|
||
searchable: true,
|
||
orderable: true,
|
||
},
|
||
// 5
|
||
{
|
||
className: "text-center align-middle",
|
||
data: "officer_phone_number",
|
||
name: {
|
||
name: 'officer_phone_number',
|
||
type: 'text'
|
||
},
|
||
searchable: true,
|
||
orderable: true,
|
||
},
|
||
// 6
|
||
{
|
||
className: "d-flex justify-content-center",
|
||
data: null,
|
||
name: {
|
||
name: 'officer_plaque',
|
||
type: 'text'
|
||
},
|
||
render: function (data, type, row) {
|
||
const plaque = data.officer_plaque.split('-')
|
||
return `<div dir='ltr' style="width: 100px" class='d-flex border rounded justify-content-between align-items-center'>
|
||
<div class="p-1">${plaque[0]}</div>
|
||
<div class="p-1">${plaque[1] == '*' ? '<i class="fa fa-wheelchair"></i>' : plaque[1]}</div>
|
||
<div class="p-1">${plaque[2]}</div>
|
||
<div class="p-1 border-left">${plaque[3]}</div>
|
||
</div>`
|
||
},
|
||
searchable: true,
|
||
orderable: true,
|
||
},
|
||
// 7
|
||
{
|
||
className: "text-center text-nowrap align-middle",
|
||
data: null,
|
||
name: {
|
||
name: 'start_time',
|
||
type: 'between'
|
||
},
|
||
render: function (data, type, row) {
|
||
if (data.start_time == null) return '-'
|
||
return moment(data.start_time).format("HH:mm:ss | jYYYY/jMM/jDD")
|
||
},
|
||
searchable: true,
|
||
orderable: true,
|
||
},
|
||
// 8
|
||
{
|
||
className: "text-center text-nowrap align-middle",
|
||
data: null,
|
||
name: {
|
||
name: 'end_time',
|
||
type: 'between'
|
||
},
|
||
render: function (data, type, row) {
|
||
if (data.end_time == null) return '-'
|
||
return moment(data.end_time).format("HH:mm:ss | jYYYY/jMM/jDD")
|
||
},
|
||
searchable: true,
|
||
orderable: true,
|
||
},
|
||
// 9
|
||
{
|
||
className: "text-center align-middle",
|
||
data: "distance",
|
||
name: {
|
||
name: 'distance',
|
||
type: 'text'
|
||
},
|
||
searchable: true,
|
||
orderable: true,
|
||
},
|
||
// 10
|
||
{
|
||
className: "text-center align-middle",
|
||
data: null,
|
||
name: {
|
||
name: 'description',
|
||
type: 'text'
|
||
},
|
||
render: function (data, type, row) {
|
||
return `<button type="button" class="btn-dataTable show-operator-description-btn" data-toggle="tooltip" data-placement="top" title="نمایش"><i class="fa fa-eye icon-btnTable"></i></button>`
|
||
},
|
||
searchable: true,
|
||
orderable: false,
|
||
},
|
||
// 11
|
||
{
|
||
className: "text-center sorting align-middle",
|
||
data: null,
|
||
name: {
|
||
name: 'option',
|
||
type: 'option'
|
||
},
|
||
render: function (data, type, row) {
|
||
let content = `<div class="d-inline-flex">`
|
||
content += `<button type="button" class="btn-dataTable report" data-toggle="tooltip" data-placement="top" title="گزارش"><i class="fa fa-print icon-btnTable"></i></button>`
|
||
content += '</div>'
|
||
return content
|
||
},
|
||
searchable: false,
|
||
orderable: false,
|
||
},
|
||
// 12
|
||
{
|
||
className: "text-center sorting align-middle",
|
||
data: null,
|
||
name: {
|
||
name: 'option',
|
||
type: 'option'
|
||
},
|
||
render: function (data, type, row) {
|
||
let content = `<div class="d-inline-flex">`
|
||
if ($.inArray("partial-delete-road-patrol", PERMISSIONS) != -1 || $.inArray("complete-delete-road-patrol", PERMISSIONS) != -1) {
|
||
content += `<button type="button" class="btn-dataTable delete" data-toggle="tooltip" data-placement="top" title="حذف"><i class="fa fa-trash icon-btnTable"></i></button>`;
|
||
}
|
||
content += '</div>'
|
||
return content
|
||
},
|
||
searchable: false,
|
||
orderable: false,
|
||
}
|
||
],
|
||
buttons: [
|
||
{
|
||
text: '<i class="fa fa-filter" aria-hidden="true"></i><span class="pr-1">فیلتر پیشرفته<span>',
|
||
className: 'table-btns filtering-btn',
|
||
action: function (e, dt, node, config) {
|
||
filterBox(true)
|
||
}
|
||
},
|
||
{
|
||
text: '<i class="fa fa-file" aria-hidden="true"></i><span class="pr-1">گزارش اکسل<span>',
|
||
className: 'table-btns',
|
||
action: function (e, dt, node, config) {
|
||
let queryParems = [];
|
||
const id = $("#filter_id").val();
|
||
const province = $("#filter_province").val();
|
||
const edarat = $("#filter_edarat").val();
|
||
let activityDate = {}
|
||
if ($("#filter_from_activity_date_time").val() != "" && $("#filter_to_activity_date_time").val() != "") {
|
||
activityDate.from = moment(
|
||
filterDatepicker.from.getState().selected.year +
|
||
"/" +
|
||
filterDatepicker.from.getState().selected.month +
|
||
"/" +
|
||
filterDatepicker.from.getState().selected.date,
|
||
"jYYYY/jM/jD"
|
||
).format("YYYY-MM-DD");
|
||
|
||
activityDate.to = moment(
|
||
filterDatepicker.to.getState().selected.year +
|
||
"/" +
|
||
filterDatepicker.to.getState().selected.month +
|
||
"/" +
|
||
filterDatepicker.to.getState().selected.date,
|
||
"jYYYY/jM/jD"
|
||
).format("YYYY-MM-DD");
|
||
|
||
queryParems.push(`fromDate=${activityDate.from}`);
|
||
queryParems.push(`toDate=${activityDate.to}`);
|
||
}
|
||
|
||
if (id != '') queryParems.push(`id=${id}`);
|
||
if (province != '-1') queryParems.push(`province_id=${province}`);
|
||
if (edarat != '-1') queryParems.push(`edare_id=${edarat}`);
|
||
|
||
const url = `${excel_api}${queryParems.length != 0 ? `?${queryParems.join("&")}` : ""}`;
|
||
window.open(url);
|
||
}
|
||
}
|
||
],
|
||
initComplete: function () {
|
||
$(".dt-buttons").append(FilterBoxInit)
|
||
fillFilterBox();
|
||
}
|
||
});
|
||
// end supervisor cartable table
|
||
});
|
||
// end on load
|
||
|
||
$("#supervisor_cartable").on("click", "tbody tr", function (e) {
|
||
e.preventDefault()
|
||
let tr = $(this).closest("tr");
|
||
let row = supervisorCartable.row(tr);
|
||
let data = row.data();
|
||
dataOnMap(data);
|
||
$("#supervisor_cartable").find("tbody tr").removeClass("activate-row");
|
||
$(this).addClass("activate-row");
|
||
});
|
||
|
||
// show active data on map
|
||
function dataOnMap(data) {
|
||
$("html, body").animate({
|
||
scrollTop: $("#map").offset().top - 50,
|
||
},
|
||
100
|
||
);
|
||
setTimeout(() => {
|
||
$("#pin-marker-end").remove();
|
||
markersLayer.eachLayer(layer => {
|
||
if (layer.options.id == data.id) {
|
||
map.addLayer(new L.Marker([data.end_lat, data.end_lon], { icon: mapEndIcon }));
|
||
layer.setIcon(activeMapIcon)
|
||
layer.setZIndexOffset(100)
|
||
return
|
||
}
|
||
layer.setZIndexOffset(0)
|
||
layer.setIcon(mapIcon)
|
||
})
|
||
var latlonArr = [];
|
||
latlonArr.push([data.start_lat, data.start_lon]);
|
||
latlonArr.push([data.end_lat, data.end_lon]);
|
||
map.flyToBounds(latlonArr, { padding: [60, 60], duration: .5 });
|
||
}, 500)
|
||
}
|
||
// end show active data on map
|
||
|
||
// filtering
|
||
$(document).on('click', '#btn_filter', function () {
|
||
filterBox(false)
|
||
|
||
let _table = supervisorCartable
|
||
|
||
const id = $("#filter_id").val();
|
||
const province = $("#filter_province").val();
|
||
const edarat = $("#filter_edarat").val();
|
||
let activityDate = {}
|
||
if (
|
||
$("#filter_from_activity_date_time").val() != "" &&
|
||
$("#filter_to_activity_date_time").val() != ""
|
||
) {
|
||
activityDate.from = moment(
|
||
filterDatepicker.from.getState().selected.year +
|
||
"/" +
|
||
filterDatepicker.from.getState().selected.month +
|
||
"/" +
|
||
filterDatepicker.from.getState().selected.date,
|
||
"jYYYY/jM/jD"
|
||
).format("YYYY-MM-DD");
|
||
|
||
activityDate.to = moment(
|
||
filterDatepicker.to.getState().selected.year +
|
||
"/" +
|
||
filterDatepicker.to.getState().selected.month +
|
||
"/" +
|
||
filterDatepicker.to.getState().selected.date,
|
||
"jYYYY/jM/jD"
|
||
).format("YYYY-MM-DD");
|
||
}
|
||
|
||
if (id != '') {
|
||
_table = _table.column(0).search(id);
|
||
} else {
|
||
_table = _table.column(0).search('');
|
||
}
|
||
|
||
if (province != '-1') {
|
||
_table = _table.column(1).search(province);
|
||
} else {
|
||
_table = _table.column(1).search('');
|
||
}
|
||
|
||
if (edarat != '-1') {
|
||
_table = _table.column(2).search(edarat);
|
||
} else {
|
||
_table = _table.column(2).search('');
|
||
}
|
||
|
||
if (Object.keys(activityDate).length !== 0) {
|
||
_table = _table.column(6).search(`${activityDate.from}&${activityDate.to}`);
|
||
} else {
|
||
_table = _table.column(6).search('');
|
||
}
|
||
|
||
_table.draw();
|
||
})
|
||
// end filtering
|
||
|
||
// confirmation action
|
||
$("#supervisor_cartable").on("click", ".confirm", function (e) {
|
||
e.stopPropagation()
|
||
const modal = $("#varifyDescription_modal");
|
||
let tr = $(this).closest("tr");
|
||
let row = supervisorCartable.row(tr);
|
||
let data = row.data();
|
||
modal.find(".clean-textarea").val("");
|
||
modal.find("#description").removeClass("invalid").removeClass("valid").removeClass('value-important');
|
||
modal.find("#description").data("id", data.id);
|
||
modal.find("#description").data("acceptDecline", 1);
|
||
modal.modal("show");
|
||
$("#supervisor_cartable").find("tbody tr").removeClass("activate-row");
|
||
$("#vaerify").removeClass("d-none");
|
||
$(tr).addClass("activate-row");
|
||
});
|
||
// end confirmation action
|
||
|
||
// show supervisor description
|
||
$("#supervisor_cartable").on("click", ".show-supervisor-description-btn", function (e) {
|
||
e.stopPropagation()
|
||
const modal = $("#varifyDescription_modal");
|
||
let tr = $(this).closest("tr");
|
||
let row = supervisorCartable.row(tr);
|
||
let data = row.data();
|
||
modal.find(".clean-textarea").val("");
|
||
modal.find(".value-important").removeClass("invalid").removeClass("valid");
|
||
$("#vaerify").addClass("d-none");
|
||
modal.find("#description").val(data.supervisor_description);
|
||
modal.modal("show");
|
||
$("#supervisor_cartable").find("tbody tr").removeClass("activate-row");
|
||
$(tr).addClass("activate-row");
|
||
});
|
||
// end show supervisor description
|
||
|
||
// show operator description
|
||
$("#supervisor_cartable").on("click", ".show-operator-description-btn", function (e) {
|
||
e.stopPropagation()
|
||
const modal = $("#show_operator_description_modal");
|
||
let tr = $(this).closest("tr");
|
||
let row = supervisorCartable.row(tr);
|
||
let data = row.data();
|
||
console.log(data);
|
||
modal.find(".clean-textarea").val("");
|
||
modal.find(".value-important").removeClass("invalid").removeClass("valid");
|
||
modal.find("#operator_description").val(data.description);
|
||
modal.modal("show");
|
||
$("#supervisor_cartable").find("tbody tr").removeClass("activate-row");
|
||
$(tr).addClass("activate-row");
|
||
});
|
||
// end show operator description
|
||
|
||
// disapproval action
|
||
$("#supervisor_cartable").on("click", ".disapproval", function (e) {
|
||
e.stopPropagation()
|
||
const modal = $("#varifyDescription_modal");
|
||
let tr = $(this).closest("tr");
|
||
let row = supervisorCartable.row(tr);
|
||
let data = row.data();
|
||
modal.find(".clean-textarea").val("");
|
||
modal.find("#description").removeClass("invalid").removeClass("valid").addClass('value-important');
|
||
modal.find("#description").data("id", data.id);
|
||
modal.find("#description").data("acceptDecline", 2);
|
||
modal.modal("show");
|
||
$("#supervisor_cartable").find("tbody tr").removeClass("activate-row");
|
||
$("#vaerify").removeClass("d-none");
|
||
$(tr).addClass("activate-row");
|
||
});
|
||
// end disapproval action
|
||
|
||
// accept/decline
|
||
$(document).on("click", "#vaerify", function (e) {
|
||
e.preventDefault()
|
||
const modal = $(this).parents(".modal");
|
||
const verify = modal.find("#description").data("acceptDecline");
|
||
const desc = modal.find("#description").val();
|
||
const dataId = modal.find("#description").data("id");
|
||
modal.find("textarea.value-important").each(function () {
|
||
$(this).val() == "" ? $(this).removeClass("valid").addClass("invalid") : $(this).removeClass("invalid").addClass("valid");
|
||
});
|
||
if (modal.find(".invalid").length != 0) { return } else {
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: `${verify == 1 ? "آیا از تایید فعالیت مربوطه اطمینان دارید؟" : "آیا از عدم تایید فعالیت مربوطه اطمینان دارید؟"}`,
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#2d7c23",
|
||
cancelButtonColor: "#971b1b",
|
||
confirmButtonText: "بله اطمینان دارم",
|
||
cancelButtonText: "خیر!",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
modal.modal("hide");
|
||
verifyFunc(verify, dataId, desc);
|
||
},
|
||
});
|
||
}
|
||
});
|
||
// end accept/decline
|
||
|
||
// verify
|
||
function verifyFunc(verify, dataId, desc) {
|
||
let formData = new FormData();
|
||
formData.append("verify", verify);
|
||
formData.append("description", desc);
|
||
$.ajax({
|
||
url: verify_api + dataId,
|
||
type: "POST",
|
||
headers: {
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
data: formData,
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (result) {
|
||
hideLoaderScreen();
|
||
supervisorCartable.ajax.reload();
|
||
},
|
||
error: function (request) {
|
||
hideLoaderScreen();
|
||
ajax_error(request.responseJSON, request.status);
|
||
},
|
||
complete: function () {
|
||
getSideBarActivity();
|
||
}
|
||
});
|
||
}
|
||
// end verify
|
||
|
||
// delete
|
||
$("#supervisor_cartable").on("click", ".delete", function (e) {
|
||
e.preventDefault()
|
||
let tr = $(this).closest("tr");
|
||
let row = supervisorCartable.row(tr);
|
||
let id = row.data().id;
|
||
$("#delte_modal").find("#partial").hide();
|
||
$("#delte_modal").find("#complete").hide();
|
||
if ($.inArray("partial-delete-road-patrol", PERMISSIONS) != -1) {
|
||
$("#delte_modal").find("#partial").show();
|
||
$("#delte_modal").find("#partial").data("patrolId", id);
|
||
}
|
||
if ($.inArray("complete-delete-road-patrol", PERMISSIONS) != -1) {
|
||
$("#delte_modal").find("#complete").show();
|
||
$("#delte_modal").find("#complete").data("patrolId", id);
|
||
}
|
||
$("#delte_modal").modal("show");
|
||
$("#supervisor_cartable").find("tbody tr").removeClass("activate-row");
|
||
$(tr).addClass("activate-row");
|
||
});
|
||
$("#delte_modal").on("click", "#complete", function () {
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: `آیا از حذف کلی گشت اطمینان دارید؟`,
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#2d7c23",
|
||
cancelButtonColor: "#971b1b",
|
||
confirmButtonText: "بله اطمینان دارم",
|
||
cancelButtonText: "خیر!",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
deletePatrol(2, $(this));
|
||
},
|
||
});
|
||
});
|
||
$("#delte_modal").on("click", "#partial", function () {
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: `آیا از حذف جزئی گشت اطمینان دارید؟`,
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#2d7c23",
|
||
cancelButtonColor: "#971b1b",
|
||
confirmButtonText: "بله اطمینان دارم",
|
||
cancelButtonText: "خیر!",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
deletePatrol(1, $(this));
|
||
},
|
||
});
|
||
});
|
||
function deletePatrol(type, btn) {
|
||
const dataId = btn.data("patrolId");
|
||
let formData = new FormData();
|
||
formData.append("type", type);
|
||
$.ajax({
|
||
url: deletePatrol_api + dataId,
|
||
type: "POST",
|
||
headers: {
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
data: formData,
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (result) {
|
||
btn.parents(".modal").modal("hide");
|
||
hideLoaderScreen();
|
||
supervisorCartable.ajax.reload();
|
||
btn.parents(".modal").modal("hide");
|
||
},
|
||
error: function (request) {
|
||
btn.parents(".modal").modal("hide");
|
||
hideLoaderScreen();
|
||
ajax_error(request.responseJSON, request.status);
|
||
},
|
||
complete: function () {
|
||
getSideBarActivity();
|
||
}
|
||
});
|
||
}
|
||
// end delete
|
||
|
||
// report
|
||
$("#supervisor_cartable").on('click', '.report', function (e) {
|
||
e.stopPropagation()
|
||
let tr = $(this).closest("tr");
|
||
let row = supervisorCartable.row(tr);
|
||
let data = row.data();
|
||
window.open(report_api + data.id, '_blank')
|
||
});
|
||
// end report
|