1327 lines
37 KiB
JavaScript
1327 lines
37 KiB
JavaScript
var map = null;
|
||
var table
|
||
var startAbrarMarker = null;
|
||
var isSetStartAbrarMarker = false;
|
||
var endAbrarMarker = null;
|
||
var isSetEndAbrarMarker = false;
|
||
var routeControls = [];
|
||
var routeControlsPath = [];
|
||
var popupArrays = [];
|
||
var popupArraysPath = [];
|
||
var polylinePath = null;
|
||
|
||
var mapCenterLat = null;
|
||
var mapCenterLng = null;
|
||
var tablesecond
|
||
var hasError = false;
|
||
var province,
|
||
town,
|
||
axisName,
|
||
axisType,
|
||
projectTitle,
|
||
contractor,
|
||
consultant,
|
||
contractDate,
|
||
contractPrice,
|
||
contractDatePicker;
|
||
var provinces = [];
|
||
var towns = [];
|
||
var projectDistance = {};
|
||
var editProjectDistance = null;
|
||
var project_distance_edit = {};
|
||
|
||
|
||
|
||
var startAbrarDivIcon = L.divIcon({
|
||
html: `
|
||
<div id="pin-marker-start" class="pin-marker">
|
||
<div class="map-pin-marker">
|
||
<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: [33, 64],
|
||
});
|
||
|
||
var endAbrarDivIcon = L.divIcon({
|
||
html: `
|
||
<div id="pin-marker-end" class="pin-marker">
|
||
<div class="map-pin-marker">
|
||
<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: [33, 64],
|
||
});
|
||
|
||
var projectEditId = null;
|
||
var projectEditData = [];
|
||
var abrarProjectSlider = null;
|
||
|
||
function showLoaderScreen() {
|
||
$(".starter-loader-container").css("display", "flex").hide().fadeIn();
|
||
}
|
||
|
||
function hideLoaderScreen() {
|
||
$(".starter-loader-container").fadeOut();
|
||
}
|
||
|
||
$(document).ready(function () {
|
||
|
||
getProvinces();
|
||
|
||
table = $("#example").DataTable({
|
||
dom: "lBfrtip",
|
||
pagingType: "simple_numbers",
|
||
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, "asc"][(1, "asc")], [2, "desc"], [3, "desc"], [4, "desc"]],
|
||
order: [[0, "asc"]],
|
||
processing: true,
|
||
select: true,
|
||
ajax: {
|
||
url: "/road-maintenance-project/getlist",
|
||
type: "GET",
|
||
dataSrc: function (json) {
|
||
return json.data;
|
||
},
|
||
},
|
||
columns: [
|
||
{
|
||
className: "text-center",
|
||
data: null,
|
||
render: function (data, type, row, meta) {
|
||
// console.log(meta.row);
|
||
return meta.row + 1;
|
||
},
|
||
},
|
||
{ data: "province.name" },
|
||
{ data: "city.name" },
|
||
{ data: "axis_name" },
|
||
{ data: "axis_type" },
|
||
{ data: "project_name" },
|
||
{ data: "contractor_name" },
|
||
{ data: "consultant_name" },
|
||
{ data: "contract_date" },
|
||
{ data: "contract_credit" },
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
return "-";
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
return "-";
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
return (
|
||
`<button id="editButton${data.id}" onclick="showModal(`+ data.id +`)" class="btn btn-danger btn-sm editor details-control" title="ویرایش"><i class="fa fa-edit"></i><div></div></button>
|
||
<button class="btn btn-primary btn-sm projectdistance" title="طول پروژه"><i class=" fa fa-spinner"></i></button>
|
||
<button class="btn btn-sm btn-success finalsubmit" title=" ثبت نهایی " ><i class="fa fa-check"></i></button>
|
||
<button class="btn btn-sm btn-danger deletsubmit" title=" حذف " style="width: 28px"><i class="fa fa-trash"></i></button>
|
||
<button class="btn btn-sm btn-success update" title=" بروزرسانی" style="width:28px"><i class="fa fa-tasks"></i></button>`
|
||
)
|
||
},
|
||
},
|
||
],
|
||
buttons: [
|
||
{
|
||
extend: "excelHtml5",
|
||
title: "Excel",
|
||
text: "خروجی به اکسل",
|
||
//yasi change start
|
||
messageTop: " فهرست پروژه نگهداری راه ها ",
|
||
exportOptions: {
|
||
columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
|
||
//yasi change end
|
||
},
|
||
},
|
||
],
|
||
});
|
||
//yasi change end
|
||
|
||
});
|
||
|
||
function createLeafletMap() {
|
||
let bounds = [
|
||
[42.9130026312, 75.6166317076],
|
||
[20.5782370061, 35.5092252948]
|
||
];
|
||
|
||
map = new L.map('abrar-map', {
|
||
maxBounds: bounds,
|
||
minZoom: 6
|
||
}).setView([32.4279, 53.6880], 9);
|
||
|
||
L.tileLayer('https://testmap.141.ir/141map/{z}/{x}/{y}.png', {}).addTo(map);
|
||
|
||
startAbrarMarker = new L.marker(L.latLng(map.getCenter()), {
|
||
icon: startAbrarDivIcon,
|
||
draggable: true
|
||
}).addTo(map);
|
||
|
||
endAbrarMarker = new L.marker(L.latLng(map.getCenter()), {
|
||
icon: endAbrarDivIcon,
|
||
draggable: true
|
||
});
|
||
|
||
// map.on('move', function () {
|
||
// if (!isSetStartAbrarMarker) {
|
||
// startAbrarMarker.setLatLng(L.latLng(map.getCenter()));
|
||
// $('#pin-marker-start').removeClass('pin-set pin-warn').addClass('pin-move');
|
||
// }
|
||
|
||
|
||
// });
|
||
|
||
map.on("move", function () {
|
||
if (!isSetStartAbrarMarker && !isSetEndAbrarMarker) {
|
||
startAbrarMarker.setLatLng(L.latLng(map.getCenter()));
|
||
$("#pin-marker-start").removeClass("pin-set").addClass("pin-move");
|
||
}
|
||
|
||
if (isSetStartAbrarMarker && !isSetEndAbrarMarker) {
|
||
endAbrarMarker.setLatLng(L.latLng(map.getCenter()));
|
||
$("#pin-marker-end").removeClass("pin-set").addClass("pin-move");
|
||
}
|
||
});
|
||
|
||
map.on("moveend", function () {
|
||
if (!isSetStartAbrarMarker && !isSetEndAbrarMarker) {
|
||
startAbrarMarker.setLatLng(L.latLng(map.getCenter()));
|
||
$("#pin-marker-start").removeClass("pin-move pin-set");
|
||
}
|
||
|
||
if (isSetStartAbrarMarker && !isSetEndAbrarMarker) {
|
||
endAbrarMarker.setLatLng(L.latLng(map.getCenter()));
|
||
$("#pin-marker-end").removeClass("pin-move pin-set");
|
||
}
|
||
});
|
||
|
||
startAbrarMarker.on('click', function () {
|
||
console.log("clickstart")
|
||
if (!isSetStartAbrarMarker) {
|
||
startAbrarMarker.setLatLng(L.latLng(map.getCenter()));
|
||
isSetStartAbrarMarker = true;
|
||
|
||
$('#pin-marker-start').removeClass('pin-move pin-warn').addClass('pin-set');
|
||
|
||
$('#stepModalmaintenance input[name=abrar-project-latlng-start]').val(
|
||
startAbrarMarker.getLatLng().lat.toFixed(10) +
|
||
startAbrarMarker.getLatLng().lng.toFixed(10)
|
||
);
|
||
$('#stepModalmaintenance input[name=abrar-project-latlng-start]').removeClass('is-invalid-input');
|
||
|
||
|
||
|
||
let markerLatLng = [
|
||
startAbrarMarker.getLatLng().lat,
|
||
startAbrarMarker.getLatLng().lng + 0.0008
|
||
];
|
||
|
||
map.setView(markerLatLng);
|
||
endAbrarMarker.setLatLng(markerLatLng);
|
||
endAbrarMarker.addTo(map);
|
||
}
|
||
});
|
||
|
||
endAbrarMarker.on('click', function () {
|
||
console.log("clickend")
|
||
if (!isSetEndAbrarMarker) {
|
||
endAbrarMarker.setLatLng(L.latLng(map.getCenter()));
|
||
isSetEndAbrarMarker = true;
|
||
|
||
$('#pin-marker-end').removeClass('pin-move').addClass('pin-set');
|
||
|
||
$('#stepModalmaintenance input[name=abrar-project-latlng-end]').val(
|
||
endAbrarMarker.getLatLng().lat.toFixed(10) +
|
||
endAbrarMarker.getLatLng().lng.toFixed(10)
|
||
);
|
||
$('#stepModalmaintenance input[name=abrar-project-latlng-end]').removeClass('is-invalid-input');
|
||
|
||
checkMarkersAndDrawPath();
|
||
}
|
||
});
|
||
|
||
startAbrarMarker.on('drag', function () {
|
||
$('#pin-marker-start').addClass('pin-move');
|
||
checkMarkersAndDrawPath();
|
||
});
|
||
|
||
endAbrarMarker.on('drag', function () {
|
||
$('#pin-marker-end').addClass('pin-move');
|
||
checkMarkersAndDrawPath();
|
||
});
|
||
|
||
startAbrarMarker.on('dragend', function () {
|
||
$('#pin-marker-start').removeClass('pin-move');
|
||
|
||
if ($('#pin-marker-start').hasClass('pin-set') || isSetStartAbrarMarker) {
|
||
|
||
$('#stepModalmaintenance input[name=abrar-project-latlng-start]').val(
|
||
startAbrarMarker.getLatLng().lat.toFixed(10) +
|
||
startAbrarMarker.getLatLng().lng.toFixed(10)
|
||
);
|
||
$('#stepModalmaintenance input[name=abrar-project-latlng-start]').removeClass('is-invalid-input');
|
||
$('#pin-marker-start').addClass('pin-set');
|
||
checkMarkersAndDrawPath();
|
||
} else {
|
||
map.setView(startAbrarMarker.getLatLng());
|
||
}
|
||
});
|
||
|
||
endAbrarMarker.on('dragend', function () {
|
||
$('#pin-marker-end').removeClass('pin-move');
|
||
|
||
if ($('#pin-marker-end').hasClass('pin-set') || isSetEndAbrarMarker) {
|
||
$('#stepModalmaintenance input[name=abrar-project-latlng-end]').val(
|
||
endAbrarMarker.getLatLng().lat.toFixed(10) +
|
||
endAbrarMarker.getLatLng().lng.toFixed(10)
|
||
);
|
||
$('#stepModalmaintenance input[name=abrar-project-latlng-end]').removeClass('is-invalid-input');
|
||
$('#pin-marker-end').addClass('pin-set');
|
||
checkMarkersAndDrawPath();
|
||
} else {
|
||
map.setView(endAbrarMarker.getLatLng());
|
||
}
|
||
});
|
||
}
|
||
|
||
function initialField(){
|
||
$("#axis-name-id").val("")
|
||
$("#axis-type-id").val("0")
|
||
$("#project-title-id").val("")
|
||
$("#contractor-id").val("")
|
||
$("#consultant-id").val("")
|
||
$("#contract-date-id").val("")
|
||
$("#contract-price-id").val("")
|
||
}
|
||
|
||
function initialMarkerMapValue() {
|
||
if(isSetStartAbrarMarker){
|
||
endAbrarMarker.remove();
|
||
}
|
||
|
||
isSetEndAbrarMarker = false;
|
||
map.setView([32.4279, 53.6880], 9);
|
||
startAbrarMarker.setLatLng(L.latLng(map.getCenter()));
|
||
isSetStartAbrarMarker = false;
|
||
|
||
removeStartToEndPath();
|
||
|
||
$("#pin-marker-start").removeClass("pin-move pin-set");
|
||
$("#pin-marker-end").removeClass("pin-move pin-set");
|
||
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-start]").val("");
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-end]").val("");
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-start]").removeClass(
|
||
"is-invalid-input"
|
||
);
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-end]").removeClass(
|
||
"is-invalid-input"
|
||
);
|
||
}
|
||
|
||
$("#add-project-button").on("click", function () {
|
||
showModal();
|
||
initialField();
|
||
|
||
if (map == null) {
|
||
setTimeout(() => {
|
||
createLeafletMap();
|
||
|
||
}, 200);
|
||
}else{
|
||
initialMarkerMapValue();
|
||
}
|
||
|
||
|
||
$("#province-id").empty();
|
||
$("#province-id").append('<option value="0">انتخاب اداره کل</option>');
|
||
|
||
console.log(provinces);
|
||
|
||
for (let index = 0; index < provinces.length; index++) {
|
||
$("#province-id").append(
|
||
"\
|
||
<option value=" +
|
||
provinces[index].id +
|
||
">" +
|
||
provinces[index].name_fa +
|
||
"</option>\
|
||
"
|
||
);
|
||
}
|
||
|
||
$("#province-id").change(function () {
|
||
|
||
if ((value = $(this).val())) {
|
||
console.log(value)
|
||
getTowns(value);
|
||
}
|
||
});
|
||
|
||
contractDatePicker = $("input[name=contract-date]").persianDatepicker({
|
||
format: "YYYY/MM/DD",
|
||
initialValue: false,
|
||
autoClose: true,
|
||
});
|
||
|
||
|
||
|
||
})
|
||
|
||
//yasi change start
|
||
$("#example").on("click", "tbody tr", function () {
|
||
if ($(this).hasClass("selected")) {
|
||
// console.log("selected")
|
||
$(this).removeClass("selected");
|
||
} else {
|
||
// console.log("deselect")
|
||
table.$("tr.selected").removeClass("selected");
|
||
$(this).addClass("selected");
|
||
}
|
||
});
|
||
function scrolldown() {
|
||
$("html, body").animate(
|
||
{
|
||
scrollTop: $(".up").offset().top,
|
||
},
|
||
50
|
||
);
|
||
}
|
||
$("#example").on("click", "button.projectdistance", function () {
|
||
$("#tool-main").css("display", "block");
|
||
scrolldown()
|
||
var tr = $(this).closest("tr");
|
||
var row = table.row(tr);
|
||
console.log(row.data())
|
||
tablesecond = $("#exampletool").DataTable({
|
||
dom: "lBfrtip",
|
||
destroy: true,
|
||
// "pagingType": "full_numbers",
|
||
pagingType: "simple_numbers",
|
||
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, "asc"][(1, "asc")], [2, "desc"], [3, "desc"], [4, "desc"]],
|
||
order: [[0, "desc"]],
|
||
processing: true,
|
||
ajax: {
|
||
url:
|
||
"http://localhost:3000/data",
|
||
type: "GET",
|
||
dataSrc: function (json) {
|
||
console.log(json)
|
||
return json;
|
||
},
|
||
},
|
||
columns: [
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return 0;
|
||
},
|
||
},
|
||
{
|
||
className: "text-center",
|
||
orderable: false,
|
||
data: null,
|
||
render: function (data, type, row) {
|
||
// console.log(meta.row);
|
||
return (
|
||
`<button id="edittool${data.id}" class="btn btn-danger btn-sm edittool" title="ویرایش"><i class="fa fa-edit"></i><div></div></button>
|
||
<button class="btn btn-sm btn-success submittool" title=" ثبت " ><i class="fa fa-check"></i></button>
|
||
`
|
||
)
|
||
},
|
||
},
|
||
],
|
||
|
||
buttons: [
|
||
{
|
||
extend: "excelHtml5",
|
||
title: "Excel",
|
||
text: "خروجی به اکسل",
|
||
messageTop: " طول پروژه به کیلومتر ",
|
||
exportOptions: {
|
||
columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
||
},
|
||
},
|
||
],
|
||
});
|
||
});
|
||
$("#exampletool").on("click", "button.edittool", function () {
|
||
// console.log("hi")
|
||
var tr = $(this).closest("tr");
|
||
var row = table.row(0);
|
||
console.log("hi", row.data())
|
||
$("#show-projecttool").modal('show')
|
||
})
|
||
$("#exampletool").on("click", "button.submittool", function () {
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: "آیا برای ثبت مطمئن هستید؟",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#3085d6",
|
||
cancelButtonColor: "#d33",
|
||
confirmButtonText: "بله، تایید میشود",
|
||
cancelButtonText: "منصرف شدم!",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
$.ajax({
|
||
url: "",
|
||
type: "POST",
|
||
headers: {
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
data: formData,
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (result) {
|
||
|
||
},
|
||
error: function (error) {
|
||
console.log(error);
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "پر کردن تمامی عناوین خواسته شده الزامی است",
|
||
confirmButtonText: "بستن",
|
||
});
|
||
},
|
||
});
|
||
},
|
||
});
|
||
})
|
||
$("#example").on("click", "button.finalsubmit", function () {
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: "آیا برای ثبت مطمئن هستید؟",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#3085d6",
|
||
cancelButtonColor: "#d33",
|
||
confirmButtonText: "بله، تایید میشود",
|
||
cancelButtonText: "منصرف شدم!",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
window.open("/dashboarderoad/form%20upload/pages/road-mapshow.html")
|
||
},
|
||
});
|
||
})
|
||
$("#example").on("click", "button.deletsubmit", function () {
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: "آیا برای ثبت مطمئن هستید؟",
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#3085d6",
|
||
cancelButtonColor: "#d33",
|
||
confirmButtonText: "بله، تایید میشود",
|
||
cancelButtonText: "منصرف شدم!",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
window.open("https://datatables.net/reference/api/row().data()");
|
||
// $.ajax({
|
||
// url: "",
|
||
// type: "POST",
|
||
// headers: {
|
||
// "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
// },
|
||
// data: formData,
|
||
// cache: false,
|
||
// contentType: false,
|
||
// processData: false,
|
||
// success: function (result) {
|
||
|
||
// },
|
||
// error: function (error) {
|
||
// console.log(error);
|
||
// Swal.fire({
|
||
// icon: "error",
|
||
// title: "خطا",
|
||
// text: "پر کردن تمامی عناوین خواسته شده الزامی است",
|
||
// confirmButtonText: "بستن",
|
||
// });
|
||
// },
|
||
// });
|
||
},
|
||
});
|
||
})
|
||
|
||
function getProvinces() {
|
||
let reqUrl = "/contents/provinces";
|
||
// showLoaderScreen();
|
||
$.ajax({
|
||
url: reqUrl,
|
||
type: "GET",
|
||
success: function (result) {
|
||
hideLoaderScreen();
|
||
//console.log(result);
|
||
provinces = result.data;
|
||
},
|
||
error: function (error) {
|
||
// hideLoaderScreen();
|
||
//console.log(error);
|
||
},
|
||
});
|
||
}
|
||
|
||
function getTowns(id) {
|
||
let reqUrl = "/contents/provinces/" + id;
|
||
showLoaderScreen();
|
||
$.ajax({
|
||
url: reqUrl,
|
||
type: "GET",
|
||
success: function (result) {
|
||
hideLoaderScreen();
|
||
//console.log(result);
|
||
towns = result.data;
|
||
|
||
console.log(towns)
|
||
setTownSelect("");
|
||
},
|
||
error: function (error) {
|
||
hideLoaderScreen();
|
||
//console.log(error);
|
||
},
|
||
});
|
||
}
|
||
|
||
|
||
|
||
function setTownSelect(box) {
|
||
|
||
|
||
|
||
$("#town-id"+box).empty();
|
||
$("#town-id"+box).append('<option value="0">انتخاب شهرستان</option>');
|
||
|
||
for (let index = 0; index < towns.length; index++) {
|
||
$("#town-id"+box).append(
|
||
"\
|
||
<option value=" +
|
||
towns[index].id +
|
||
">" +
|
||
towns[index].name_fa +
|
||
"</option>\
|
||
"
|
||
);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
function showModal(id) {
|
||
|
||
$("#stepModalmaintenance").modal("show");
|
||
|
||
$("[data-mask]").inputmask();
|
||
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-start]").on(
|
||
"keyup",
|
||
function () {
|
||
console.log("he deals a card")
|
||
checkStartMarkerValidation();
|
||
}
|
||
);
|
||
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-end]").on(
|
||
"keyup",
|
||
function () {
|
||
checkEndMarkerValidation();
|
||
}
|
||
);
|
||
|
||
function checkStartMarkerValidation(forSaveData = false, pageOnLoad = false) {
|
||
let reg = /^([0-9]){2}\.([0-9])+$/;
|
||
let startLatLngVal = $(
|
||
"#stepModalmaintenance input[name=abrar-project-latlng-start]"
|
||
)
|
||
.val()
|
||
.split(" - ");
|
||
let startLatLng = startLatLngVal.map(function (e) {
|
||
e = e.replace(/_/g, "");
|
||
return parseFloat(e.slice(1, -1));
|
||
});
|
||
|
||
if (isNaN(startLatLng[0])) {
|
||
if (!forSaveData) {
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-start]").removeClass(
|
||
"is-invalid-input"
|
||
);
|
||
} else {
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-start]").addClass(
|
||
"is-invalid-input"
|
||
);
|
||
}
|
||
$("#pin-marker-start").removeClass("pin-move pin-set");
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-start]").val("");
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-start]").attr(
|
||
"placeholder",
|
||
"(شروع) => (طول جغرافیایی) - (عرض جغرافیایی)"
|
||
);
|
||
return false;
|
||
} else if (
|
||
!startLatLng == 2 ||
|
||
!reg.test(startLatLng[0]) ||
|
||
!reg.test(startLatLng[1])
|
||
) {
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-start]").addClass(
|
||
"is-invalid-input"
|
||
);
|
||
$("#pin-marker-start").removeClass("pin-move pin-set");
|
||
return false;
|
||
} else {
|
||
if (!forSaveData) {
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-start]").removeClass(
|
||
"is-invalid-input"
|
||
);
|
||
|
||
startAbrarMarker.setLatLng(startLatLng);
|
||
|
||
if (pageOnLoad) {
|
||
setTimeout(() => {
|
||
$("#pin-marker-start").removeClass("pin-move").addClass("pin-set");
|
||
startAbrarMarker.setLatLng(startLatLng);
|
||
}, 10);
|
||
} else {
|
||
$("#pin-marker-start").removeClass("pin-move").addClass("pin-set");
|
||
}
|
||
|
||
if (!isSetEndAbrarMarker) {
|
||
let markerLatLng = [
|
||
startAbrarMarker.getLatLng().lat,
|
||
startAbrarMarker.getLatLng().lng + 0.0008,
|
||
];
|
||
|
||
map.setView(markerLatLng);
|
||
endAbrarMarker.setLatLng(markerLatLng);
|
||
|
||
if (!isSetStartAbrarMarker) {
|
||
endAbrarMarker.addTo(map);
|
||
}
|
||
}
|
||
|
||
isSetStartAbrarMarker = true;
|
||
} else {
|
||
projectEditData["project-start-latlng"] = [
|
||
startAbrarMarker.getLatLng().lat.toFixed(10),
|
||
startAbrarMarker.getLatLng().lng.toFixed(10),
|
||
];
|
||
}
|
||
|
||
checkMarkersAndDrawPath();
|
||
|
||
return true;
|
||
}
|
||
}
|
||
|
||
function checkEndMarkerValidation(forSaveData = false, pageOnLoad = false) {
|
||
let reg = /^([0-9]){2}\.([0-9])+$/;
|
||
let endLatLngVal = $("#stepModalmaintenance input[name=abrar-project-latlng-end]")
|
||
.val()
|
||
.split(" - ");
|
||
let endLatLng = endLatLngVal.map(function (e) {
|
||
e = e.replace(/_/g, "");
|
||
return parseFloat(e.slice(1, -1));
|
||
});
|
||
|
||
if (isNaN(endLatLng[0])) {
|
||
if (!forSaveData) {
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-end]").removeClass(
|
||
"is-invalid-input"
|
||
);
|
||
} else {
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-end]").addClass(
|
||
"is-invalid-input"
|
||
);
|
||
}
|
||
$("#pin-marker-end").removeClass("pin-move pin-set");
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-end]").val("");
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-end]").attr(
|
||
"placeholder",
|
||
"(پایان) => (طول جغرافیایی) - (عرض جغرافیایی)"
|
||
);
|
||
return false;
|
||
} else if (
|
||
!endLatLng == 2 ||
|
||
!reg.test(endLatLng[0]) ||
|
||
!reg.test(endLatLng[1])
|
||
) {
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-end]").addClass(
|
||
"is-invalid-input"
|
||
);
|
||
$("#pin-marker-end").removeClass("pin-move pin-set");
|
||
return false;
|
||
} else {
|
||
if (!forSaveData) {
|
||
$("#stepModalmaintenance input[name=abrar-project-latlng-end]").removeClass(
|
||
"is-invalid-input"
|
||
);
|
||
|
||
endAbrarMarker.setLatLng(endLatLng);
|
||
isSetEndAbrarMarker = true;
|
||
|
||
if (pageOnLoad) {
|
||
setTimeout(() => {
|
||
$("#pin-marker-end").removeClass("pin-move").addClass("pin-set");
|
||
endAbrarMarker.setLatLng(endLatLng);
|
||
}, 10);
|
||
} else {
|
||
$("#pin-marker-end").removeClass("pin-move").addClass("pin-set");
|
||
}
|
||
} else {
|
||
projectEditData["project-end-latlng"] = [
|
||
endAbrarMarker.getLatLng().lat.toFixed(10),
|
||
endAbrarMarker.getLatLng().lng.toFixed(10),
|
||
];
|
||
}
|
||
|
||
checkMarkersAndDrawPath();
|
||
|
||
return true;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
$("#subTown").empty();
|
||
$("#subTown").append(`<div class="form-group col-md-4">
|
||
<label>
|
||
شهرستان
|
||
</label>
|
||
<select
|
||
class="form-control"
|
||
style="font-size:12px"
|
||
name="town"
|
||
id="town-id"
|
||
>
|
||
<option value="0">انتخاب شهرستان</option>
|
||
</select>
|
||
|
||
</div>`)
|
||
|
||
|
||
|
||
$(".cancel").on("click",function() {
|
||
$("#stepModalmaintenance").modal("hide");
|
||
|
||
})
|
||
|
||
restrictInputOtherThanArabic($("#axis-name-id"));
|
||
restrictInputOtherThanArabic($("#project-title-id"));
|
||
restrictInputOtherThanArabic($("#contractor-id"));
|
||
restrictInputOtherThanArabic($("#consultant-id"));
|
||
|
||
|
||
}
|
||
|
||
|
||
function submitRoadMaintenance(id) {
|
||
|
||
formData = new FormData();
|
||
|
||
|
||
formData.append('rms-status', $('#cBox' + (id)).prop('checked') ? "1" : "0");
|
||
|
||
if ($("#parentButton" + id).children("p").length) {
|
||
formData.append('rms-start-latlng', $("#parentButton" + id).children("p").html().slice(1, $("#parentButton" + id).children("p").html().length - 1))
|
||
}
|
||
|
||
|
||
if ($('#uploadBefore' + (id))[0].files.length > 0) {
|
||
formData.append('files_' + fileIndex, $('#uploadBefore' + (id))[0].files[0]);
|
||
fileIndex++
|
||
}
|
||
if ($('#uploadAfter' + (id))[0].files.length > 0) {
|
||
formData.append('files_' + fileIndex, $('#uploadAfter' + (id))[0].files[0]);
|
||
}
|
||
if ($('#desBox' + id).val() != undefined) {
|
||
formData.append('rms-description', $('#desBox' + id).val());
|
||
}
|
||
|
||
Swal.fire({
|
||
icon: "warning",
|
||
title: "آیا مطمئن هستید؟",
|
||
|
||
showCancelButton: true,
|
||
confirmButtonColor: "#3085d6",
|
||
cancelButtonColor: "#d33",
|
||
confirmButtonText: "بله، تایید میشود",
|
||
cancelButtonText: "منصرف شدم!",
|
||
showLoaderOnConfirm: true,
|
||
preConfirm: () => {
|
||
// showLoaderScreen()
|
||
$.ajax({
|
||
url: "/road-observation-problems/" + id + "/edit",
|
||
type: 'POST',
|
||
data: formData,
|
||
headers: {
|
||
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
|
||
},
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (result) {
|
||
//console.log(result);
|
||
ajaxcalltablefastReaction();
|
||
setTimeout(() => {
|
||
// hideLoaderScreen();
|
||
// window.open("/rmto?newAbrarProjectId=" + projectEditId, '_self');
|
||
}, 200);
|
||
},
|
||
error: function (error) {
|
||
console.log(error);
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "خطایی رخ داده است",
|
||
confirmButtonText: "بستن",
|
||
});
|
||
},
|
||
});
|
||
},
|
||
});
|
||
// }
|
||
}
|
||
|
||
function restrictInputOtherThanArabic($field) {
|
||
// Arabic characters fall in the Unicode range 0600 - 06FF
|
||
var arabicCharUnicodeRange = /[\u0600-\u06FF]/;
|
||
|
||
$field.bind("keypress", function (event) {
|
||
var key = event.which;
|
||
// 0 = numpad
|
||
// 8 = backspace
|
||
// 32 = space
|
||
if (key == 8 || key == 0 || key === 32) {
|
||
return true;
|
||
}
|
||
|
||
var str = String.fromCharCode(key);
|
||
if (arabicCharUnicodeRange.test(str)) {
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
});
|
||
}
|
||
|
||
function addTownBox(){
|
||
|
||
let childNum = $("#subTown").children().length;
|
||
|
||
console.log($("#town-id").val())
|
||
|
||
if(childNum == 1 && $("#town-id").val() != 0 ){
|
||
|
||
$("#subTown div").append(`<input type ="number" class="form-control" min="0" max="100" style="margin-top: 5px;"></input>`)
|
||
|
||
$("#subTown").append(`<div class="form-group col-md-4">
|
||
<label>
|
||
شهرستان
|
||
</label>
|
||
<select
|
||
class="form-control"
|
||
style="font-size:12px"
|
||
name="town"
|
||
id="town-id${childNum}"
|
||
>
|
||
<option value="0" style="font-size:10px">انتخاب شهرستان</option>
|
||
</select>
|
||
<input type ="number" class="form-control" min="0" max="100" style="margin-top: 5px;"></input>
|
||
</div>`)
|
||
setTownSelect(childNum)
|
||
}
|
||
else if(childNum == 2 && $("#town-id1").val() != 0 ){
|
||
$("#subTown").append(`<div class="form-group col-md-4">
|
||
<label>
|
||
شهرستان
|
||
</label>
|
||
<select
|
||
class="form-control"
|
||
style="font-size:12px"
|
||
name="town"
|
||
id="town-id${childNum}"
|
||
>
|
||
<option value="0" style="font-size:10px">انتخاب شهرستان</option>
|
||
</select>
|
||
<input type ="number" class="form-control" min="0" max="100" style="margin-top: 5px;"></input>
|
||
</div>`)
|
||
setTownSelect(childNum)
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
function checkMarkersAndDrawPath() {
|
||
if (
|
||
$("#pin-marker-start").hasClass("pin-set") &&
|
||
!$("#pin-marker-start").hasClass("pin-move") &&
|
||
$("#pin-marker-end").hasClass("pin-set") &&
|
||
!$("#pin-marker-end").hasClass("pin-move")
|
||
) {
|
||
drawPath()
|
||
} else {
|
||
setTimeout(() => {
|
||
if (
|
||
$("#pin-marker-start").hasClass("pin-set") &&
|
||
!$("#pin-marker-start").hasClass("pin-move") &&
|
||
$("#pin-marker-end").hasClass("pin-set") &&
|
||
!$("#pin-marker-end").hasClass("pin-move")
|
||
) {
|
||
drawPath()
|
||
} else {
|
||
if (routeControlsPath.length) {
|
||
$(routeControlsPath).each(function (index, control) {
|
||
map.removeControl(control);
|
||
routeControlsPath.splice(routeControlsPath.indexOf(index), 1);
|
||
});
|
||
}
|
||
if (polylinePath != null) {
|
||
map.removeLayer(polylinePath);
|
||
}
|
||
}
|
||
}, 20);
|
||
}
|
||
}
|
||
|
||
function removeStartToEndPath() {
|
||
if (routeControlsPath.length) {
|
||
$(routeControlsPath).each(function (index, control) {
|
||
map.removeControl(control);
|
||
routeControlsPath.splice(routeControlsPath.indexOf(index), 1);
|
||
});
|
||
}
|
||
if (polylinePath != null) {
|
||
map.removeLayer(polylinePath);
|
||
}
|
||
}
|
||
|
||
// function drawStartToEndPath(pathType, source, dest) {
|
||
// if (routeControlsPath.length) {
|
||
// $(routeControlsPath).each(function (index, control) {
|
||
// map.removeControl(control);
|
||
// routeControlsPath.splice(routeControlsPath.indexOf(index), 1);
|
||
// });
|
||
// }
|
||
// if (polylinePath != null) {
|
||
// map.removeLayer(polylinePath);
|
||
// }
|
||
// switch (pathType) {
|
||
// case "line": {
|
||
// polylinePath = L.polyline(
|
||
// [
|
||
// [source[0], source[1]],
|
||
// [dest[0], dest[1]],
|
||
// ],
|
||
// {
|
||
// color: "#0073e6",
|
||
// opacity: 0.6,
|
||
// weight: 5,
|
||
// }
|
||
// ).addTo(map);
|
||
// break;
|
||
// }
|
||
// case "axis": {
|
||
// $.get(
|
||
// `https://testmap.141.ir/route/v1/driving/${source[1]},${source[0]};${dest[1]},${dest[0]}?overview=false&alternatives=true&steps=true`,
|
||
// function (data) {
|
||
// routeControlsPath.push(
|
||
// L.Routing.control({
|
||
// waypoints: [
|
||
// L.latLng(parseFloat(source[0]), parseFloat(source[1])),
|
||
// L.latLng(parseFloat(dest[0]), parseFloat(dest[1])),
|
||
// ],
|
||
// fitSelectedRoutes: false,
|
||
// draggableWaypoints: true,
|
||
// createMarker: function () {
|
||
// return null;
|
||
// },
|
||
// lineOptions: {
|
||
// addWaypoints: false,
|
||
// styles: [
|
||
// {
|
||
// color: "#0073e6",
|
||
// opacity: 0.6,
|
||
// weight: 5,
|
||
// },
|
||
// ],
|
||
// },
|
||
// })
|
||
// .on("routesfound", function (e) {
|
||
// for (let index = 0; index < popupArraysPath.length; index++) {
|
||
// if (popupArraysPath[index] !== null) {
|
||
// map.removeLayer(popupArraysPath[index]);
|
||
// }
|
||
// }
|
||
|
||
// /*let popup = new L.Popup({
|
||
// 'maxWidth': '300',
|
||
// 'maxHeight': '150',
|
||
// 'className': 'customRouteEstimate'
|
||
// });
|
||
|
||
// let popupLocation = new L.LatLng(e.routes[0].coordinates[parseInt(e.routes[0]
|
||
// .coordinates
|
||
// .length /
|
||
// 2)].lat,
|
||
// e.routes[0].coordinates[parseInt(e.routes[0].coordinates.length / 2)]
|
||
// .lng);
|
||
// let popupContent = "<span style=\"color:#FF5630 ; font-size:11px\">مسافت : </span>" + parseFloat(e.routes[0].summary.totalDistance / 1000.0).toFixed(2) + " کیلومتر";
|
||
// popup.setLatLng(popupLocation);
|
||
// popup.setContent(popupContent);
|
||
// popupArraysPath.push(popup);
|
||
// map.addLayer(popup);*/
|
||
// })
|
||
// .addTo(map)
|
||
// );
|
||
// }
|
||
// );
|
||
|
||
// $(".leaflet-control-container").css("display", "none");
|
||
// $(".leaflet-routing-container-hide").css("display", "none");
|
||
// break;
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
function drawPath() {
|
||
if (routeControls.length) {
|
||
$(routeControls).each(function (index, control) {
|
||
map.removeControl(control);
|
||
routeControls.splice(routeControls.indexOf(index), 1);
|
||
});
|
||
}
|
||
// $.get(`https://testmap.141.ir/route/v1/driving/${sourceLng},${sourceLat};${destLng},${destLat}?overview=false&alternatives=true&steps=true`,
|
||
// function (data) {
|
||
routeControls.push(
|
||
L.Routing.control({
|
||
waypoints: [
|
||
L.latLng(parseFloat(startAbrarMarker.getLatLng().lat), parseFloat(startAbrarMarker.getLatLng().lng)),
|
||
L.latLng(parseFloat(endAbrarMarker.getLatLng().lat), parseFloat(endAbrarMarker.getLatLng().lng)),
|
||
],
|
||
fitSelectedRoutes: false,
|
||
draggableWaypoints: true,
|
||
createMarker: function () {
|
||
return null;
|
||
},
|
||
lineOptions: {
|
||
addWaypoints: false,
|
||
styles: [
|
||
{
|
||
color: "#28a745",
|
||
opacity: 0.8,
|
||
weight: 5,
|
||
},
|
||
],
|
||
},
|
||
})
|
||
.on("routesfound", function (e) {
|
||
var divideBy = 2;
|
||
|
||
for (let index = 0; index < popupArrays.length; index++) {
|
||
map.removeLayer(popupArrays[index]);
|
||
}
|
||
|
||
var customOptions = {
|
||
maxWidth: "300",
|
||
maxHeight: "150",
|
||
className: "customRouteEstimate",
|
||
};
|
||
var popup = new L.Popup(customOptions);
|
||
|
||
var popupLocation = new L.LatLng(
|
||
e.routes[0].coordinates[
|
||
parseInt(e.routes[0].coordinates.length / divideBy)
|
||
].lat,
|
||
e.routes[0].coordinates[
|
||
parseInt(e.routes[0].coordinates.length / divideBy)
|
||
].lng
|
||
);
|
||
|
||
var popupContent =
|
||
'<span style="color:#FF5630; font-size:11px; font-family: IRANSansFaNum;">مسافت: </span>' +
|
||
parseFloat(e.routes[0].summary.totalDistance / 1000.0).toFixed(2) +
|
||
" کیلومتر";
|
||
|
||
saveTotalDistance = parseFloat(
|
||
parseFloat(e.routes[0].summary.totalDistance / 1000.0).toFixed(2)
|
||
);
|
||
|
||
popup.setLatLng(popupLocation);
|
||
popup.setContent(popupContent);
|
||
|
||
popupArrays.push(popup);
|
||
map.addLayer(popup);
|
||
|
||
// showItemSelectionModal();
|
||
})
|
||
.addTo(map)
|
||
);
|
||
// });
|
||
|
||
$(".leaflet-control-container").css("display", "none");
|
||
$(".leaflet-routing-container-hide").css("display", "none");
|
||
}
|
||
$("#rejectoolfinal").on('click', function () {
|
||
$("#show-projecttool").modal('hide')
|
||
})
|
||
|