Files

1606 lines
62 KiB
JavaScript

var pendingComplaintTable;
var pendingComplaint_api = `/v2/road_observations/pending`;
var mapUrl = `https://rmsmap.rmto.ir/141map/`;
var refrence_api = `/v2/road_observations/refer/`;
var addPendingComplaint_api = `/v2/road_observations/handle/`;
var send_to_pending_api = "/v2/road_observations/restore/";
var province_api = "/webapi/getuser/province-perm";
var refrence_office_api = "/v2/road_observations/refer/list/";
var refrence_list_api = "/v2/road_observations/refer/report/";
var mapAdd = null;
var markerAdd;
var mapShow;
var showMapMarker;
var isSetMarkerAdd = false;
// p datepicker
var excelDatepickerFirstTable = {};
var filter_date_from;
// p datepicker
// icon for map
var divIcon = L.divIcon({
html: `
<div id="pin_marker" 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],
});
// end icon for map
// about maps
//// create add map
function createMapAdd(modal) {
return new Promise(resolve => {
setTimeout(() => {
const bounds = [
[42.9130026312, 75.6166317076],
[20.5782370061, 35.5092252948],
];
if (mapAdd != null) {
mapAdd.setView([35.7065, 51.3477], 7)
markerAdd.setLatLng(L.latLng([35.7065, 51.3477]));
modal.find("#pin_marker").removeClass("pin-move pin-set");
} else {
mapAdd = L.map("add_map", {
maxBounds: bounds,
minZoom: 6,
attributionControl: false
}).setView([35.7065, 51.3477], 7);
L.tileLayer(`${mapUrl}{z}/{x}/{y}.png`, {}).addTo(mapAdd);
setMarkerDefaultAdd(modal);
}
resolve()
}, 400)
})
}
//// set marker [add]
function setMarkerDefaultAdd(modal) {
isSetMarkerAdd = false;
modal.find("#pin_marker").removeClass("pin-set");
modal.find("#accident_point_map").val("");
modal.find("#add_register_pos").val("");
markerAdd = new L.marker([35.7065, 51.3477], {
icon: divIcon,
draggable: true,
}).addTo(mapAdd);
mapAdd.on("move", function () {
if (!isSetMarkerAdd) {
markerAdd.setLatLng(L.latLng(mapAdd.getCenter()));
modal.find("#pin_marker").removeClass("pin-set").addClass("pin-move");
}
});
mapAdd.on("moveend", function () {
if (!isSetMarkerAdd) {
markerAdd.setLatLng(L.latLng(mapAdd.getCenter()));
modal.find("#pin_marker").removeClass("pin-move pin-set");
}
});
markerAdd.on("click", function () {
if (!isSetMarkerAdd) {
markerAdd.setLatLng(L.latLng(mapAdd.getCenter()));
isSetMarkerAdd = true;
modal.find("#pin_marker")
.removeClass("pin-move pin-warn")
.addClass("pin-set");
modal.find("#accident_point_map").val(
markerAdd.getLatLng().lat.toFixed(6) +
markerAdd.getLatLng().lng.toFixed(6)
);
modal.find("#accident_point_map").removeClass("validity-checker");
console.log("yop");
$("#add_register_pos").val(
markerAdd.getLatLng().lat.toFixed(6) +
markerAdd.getLatLng().lng.toFixed(6)
);
}
markerAdd.addTo(mapAdd);
$(this).hide();
modal.find("#pin_marker").removeClass("pin-move pin-warn").addClass("pin-set");
});
markerAdd.on("drag", function () {
modal.find("#pin_marker").addClass("pin-move");
});
markerAdd.on("dragend", function () {
modal.find("#pin_marker").removeClass("pin-move");
if (modal.find("#pin_marker").hasClass("pin-set") || isSetMarkerAdd) {
modal.find("#pin_marker").addClass("pin-set");
modal.find("#accident_point_map").val(
markerAdd.getLatLng().lat.toFixed(6) +
markerAdd.getLatLng().lng.toFixed(6)
);
$("#add_register_pos").val(
markerAdd.getLatLng().lat.toFixed(6) +
markerAdd.getLatLng().lng.toFixed(6)
);
modal.find("#accident_point_map").removeClass("validity-checker");
} else {
mapAdd.setView(markerAdd.getLatLng());
}
});
}
//// end set marker
//// end create add map
//// build show map
function buildMapShowAndMarker(position) {
return new Promise(function (resolve) {
setTimeout(() => {
const bounds = [
[42.9130026312, 75.6166317076],
[20.5782370061, 35.5092252948],
];
mapShow = L.map("map_show", {
maxBounds: bounds,
minZoom: 6,
zoomControl: false,
attributionControl: false
}).setView(position, 7);
mapShow.invalidateSize();
mapShow.addLayer(L.tileLayer(`${mapUrl}{z}/{x}/{y}.png`, {
attributionControl: false,
}));
showMapMarker = L.marker(position, { icon: divIcon }).addTo(mapShow);
resolve();
}, 200);
});
}
//// end build show map
//// relocate show map
function changePositionMarkerInMapShow(position) {
return new Promise(function (resolve) {
setTimeout(() => {
mapShow.setView(position, 7);
mapShow.invalidateSize();
showMapMarker.setLatLng(position)
resolve();
}, 200)
});
}
//// end relocate show map
//// regex for map
function checkStartMarkerValidation(forSaveData = false, pageOnLoad = false) {
let reg = /^([0-9]){2}\.([0-9])+$/;
let endLatLngVal = $("#add_register_pos").val().split(" - ");
let endLatLng = endLatLngVal.map(function (e) {
e = e.replace(/_/g, "");
return parseFloat(e.slice(1, -1));
});
if (isNaN(endLatLng[0])) {
if (!forSaveData) {
$("#add_register_pos").removeClass("is-invalid-input");
} else {
$("#add_register_pos").addClass("is-invalid-input");
}
$("#pin_marker").removeClass("pin-move pin-set");
$("#add_register_pos").val("");
$("#add_register_pos").attr("placeholder", "(پایان) => (عرض جغرافیایی) - (طول جغرافیایی)");
return false;
} else if (!endLatLng == 2 || !reg.test(endLatLng[0]) || !reg.test(endLatLng[1])) {
$("#add_register_pos").addClass(
"is-invalid-input"
);
$("#pin_marker").removeClass("pin-move pin-set");
return false;
} else {
if (!forSaveData) {
$("#add_register_pos").removeClass("is-invalid-input");
markerAdd.setLatLng(endLatLng);
isSetMarkerAdd = true;
if (pageOnLoad) {
setTimeout(() => {
$("#pin_marker").removeClass("pin-move").addClass("pin-set");
markerAdd.setLatLng(endLatLng);
}, 10);
} else {
$("#pin_marker").removeClass("pin-move").addClass("pin-set");
}
let markerLatLng = [markerAdd.getLatLng().lat, markerAdd.getLatLng().lng + 0.0008,];
mapAdd.setView(markerLatLng);
isSetMarkerAdd = true;
}
return true;
}
}
//// regex for map
// end about maps
// bind func
$(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(".btn-table-filter").length == 0 &&
clicked.closest(".parent-filter").length == 0 &&
$(".parent-filter").css("display") != "none"
) {
$(".parent-filter").css("display", "none");
}
});
// end bind func
// province permission
// if ($.inArray("------", PERMISSIONS) != -1 || $.inArray("------", PERMISSIONS) != -1) {
$.ajax({
url: province_api + "?type=all", //+ (($.inArray("------", PERMISSIONS) != -1 ? "?type=all" : ""))
type: "GET",
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
const provinces = result.data;
$("#filter_province").empty();
$("#select-province-excel").empty();
$("#filter_province").append('<option value="0">انتخاب استان</option>');
$("#select-province-excel").append('<option value="0">انتخاب استان</option>');
for (let index = 0; index < provinces.length; index++) {
$("#filter_province").append(`<option value="${provinces[index].id}">${provinces[index].name_fa}</option>`);
$("#select-province-excel").append("<option value=" + provinces[index].id + ">" + provinces[index].name_fa + "</option>");
}
hideLoaderScreen();
},
error: function (error) {
ajax_error(request.responseJSON, request.status);
hideLoaderScreen();
},
});
// }
// end province permission
// city resiver
function refrence_office(province_id) {
showLoaderScreen();
$("#refrence_office").empty();
$("#refrence_office").append(`<option value="0" disabled selected>انتخاب اداره</option>`);
$.ajax({
url: refrence_office_api + province_id,
type: "GET",
success: function (data) {
office_refrence = data.data;
for (let i = 0; i < office_refrence.length; i++) {
$("#refrence_office").append(`<option value="${office_refrence[i].id}">${office_refrence[i].name_fa}</option>`);
}
},
error: function (error) {
ajax_error(error.responseJSON, error.status);
hideLoaderScreen();
},
complete: function (data) {
$("#refrence_road_observation_modal").modal("show");
hideLoaderScreen();
},
});
}
// city resiver
// refrence list resiver
function refrence_list(id) {
showLoaderScreen();
$('#refrence_show_list').find('tbody').empty()
$.ajax({
url: refrence_list_api + id,
type: "GET",
success: function ({ data }) {
for (const item of data) {
const context = `<tr>
<td>${item.user}</td>
<td>${item.from_edareh}</td>
<td>${item.to_edareh}</td>
<td style="direction:ltr">${moment(item.created_at).locale('fa').format('YYYY/MM/DD || HH:mm')}</td>
<td>${item.description}</td>
</tr>`
$('#refrence_show_list').find('tbody').append(context)
}
},
error: function (error) {
ajax_error(error.responseJSON, error.status);
hideLoaderScreen();
},
complete: function (data) {
$("#refrence_show_road_observation_modal").modal("show");
hideLoaderScreen();
},
});
}
// refrence list resiver
// scroll to downTable
function scrolldowntable() { $("html, body").animate({ scrollTop: $(".scrollMagic").offset().top + 1000, }, 50); }
// scroll to downTable
// excel datepicker
excelDatepickerFirstTable.from = $("#datapicker-from-excel-table").persianDatepicker({
format: "YYYY/MM/DD",
autoClose: true,
onSelect: function (unix) {
excelDatepickerFirstTable.from.touched = true;
$("#datapicker-to-excel-table").prop("disabled", "");
if (
excelDatepickerFirstTable.from.getState().selected.unixDate >=
excelDatepickerFirstTable.to.getState().selected.unixDate
) {
excelDatepickerFirstTable.to.setDate(
excelDatepickerFirstTable.from.getState().selected.unixDate
);
}
if (
excelDatepickerFirstTable.to &&
excelDatepickerFirstTable.to.options &&
excelDatepickerFirstTable.to.options.minDate != unix
) {
let cachedValue =
excelDatepickerFirstTable.to.getState().selected.unixDate;
excelDatepickerFirstTable.to.options = { minDate: unix };
if (excelDatepickerFirstTable.from.touched) {
excelDatepickerFirstTable.to.setDate(cachedValue);
}
}
},
});
excelDatepickerFirstTable.to = $("#datapicker-to-excel-table").persianDatepicker({
format: "YYYY/MM/DD",
autoClose: true,
onSelect: function (unix) {
excelDatepickerFirstTable.to.touched = true;
},
});
// end excel datepicker
// image upload
$("#pending_complaint").on("change", ".img-input", function () {
var input = this;
var parent = $(input).parents(".img-box");
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
parent.find(".img-title").css("display", "none");
parent.find(".img-preview").css("display", "");
parent.find(".btn-delete-img").removeAttr("disabled");
parent.find(".btn-delete-img").data('isDelete', false)
parent.find(".img-preview").attr("src", e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
});
$("#pending_complaint").on("click", ".btn-delete-img", function () {
var parent = $(this).parents(".img-box");
$(this).data('isDelete', true)
parent.find(".img-input").val("");
parent.find(".img-preview").removeAttr("src");
parent.find(".img-preview").css("display", "none");
parent.find(".img-title").css("display", "");
$(this).attr("disabled", "disabled");
});
// image upload end
$(document).ready(function () {
$.fn.dataTable.ext.errMode = 'none';
filter_date_from = $(".parent-filter").find('#filter_date_from').persianDatepicker({
format: "YYYY/MM/DD",
initialValue: false,
autoClose: true,
initialValueType: "persian",
});
$('[data-toggle="tooltip"]').tooltip();
$("[data-mask]").inputmask();
pendingTableFunc();
});
// show on map
$(".table").on("click", ".btn-showOnMap-road-observation", function () {
showLoaderScreen();
const choosen_table = $(this).parents(".table-box");
const modal = $("#show_road_observation_modal");
let row_lat;
let row_lng;
const tr = $(this).closest("tr");
const row = choosen_table.hasClass("pending-table") ? pendingComplaintTable.row(tr) : doneComplaintTable.row(tr);
if (choosen_table.hasClass("done-table") && $(this).hasClass("solver-position")) {
row_lat = row.data().rms_start_latlng[0];
row_lng = row.data().rms_start_latlng[1];
} else {
row_lat = row.data().lat;
row_lng = row.data().lng;
}
const markerPosition = [row_lat, row_lng];
modal.find("#show_on_map_lat").text(row_lat);
modal.find("#show_on_map_lng").text(row_lng);
if (mapShow == null) {
buildMapShowAndMarker(markerPosition).then(() => {
hideLoaderScreen();
modal.find("#pin_marker").addClass("pin-set");
});
} else {
changePositionMarkerInMapShow(markerPosition).then(() => {
hideLoaderScreen();
modal.find("#pin_marker").addClass("pin-set");
});
}
modal.modal("show");
});
// end show on map
// show description
$(".table").on("click", ".btn-show-description", function () {
const choosen_table = $(this).parents(".table-box");
const modal = $("#description_road_observation_modal");
let description;
const tr = $(this).closest("tr");
const row = choosen_table.hasClass("pending-table") ? pendingComplaintTable.row(tr) : doneComplaintTable.row(tr);
if (choosen_table.hasClass("done-table") && $(this).hasClass("solver-description")) {
description = row.data().rms_description;
} else {
description = row.data().Description;
}
modal.find(".description-text").text(description);
modal.modal("show");
});
// end show description
// filling map input [add]
$("#add_register_pos").on("keyup", function () {
checkStartMarkerValidation();
if ($(this).val() == "") {
markerAdd.setLatLng(L.latLng([35.7065, 51.3477]));
mapAdd.setView(L.latLng([35.7065, 51.3477]));
}
});
// end filling map input
// register position
$(".table").on("click", ".btn-register-position", function () {
isSetMarkerAdd = false;
const choosen_table = $(this).parents(".table-box");
const modal = $("#show_register_position_modal");
const selectedId = $(this).data("id");
let tr = $(this).closest("tr");
let row = choosen_table.hasClass("pending-table") ? pendingComplaintTable.row(tr) : doneComplaintTable.row(tr);
let latLngPro = L.latLng(+row.data().lat, +row.data().lng);
$(".input-add-register-pos").val("");
$(".input-add-register-pos").attr("placeholder", "(پایان) => (عرض جغرافیایی) - (طول جغرافیایی)");
modal.find(".input-add-register-pos").removeClass("validity-checker");
modal.find(".row-id").data("rowId", selectedId);
modal.find(".row-id").text(selectedId);
createMapAdd(modal).then(() => {
mapAdd.setView(latLngPro);
markerAdd.setLatLng(latLngPro);
hideLoaderScreen();
});
modal.modal("show");
});
$(document).on("click", "#choose_position", function () {
const modal = $(this).parents(".modal");
modal.find(".input-add-register-pos").val() == "" ? modal.find(".input-add-register-pos").addClass("validity-checker") : modal.find(".input-add-register-pos").removeClass("validity-checker");
if (modal.find(".validity-checker").length != 0) {
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا تمامی مقادیر را تکمیل کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
thisBtn.prop("disabled", false);
} else {
const add_lat = markerAdd.getLatLng().lat.toFixed(6);
const add_lng = markerAdd.getLatLng().lng.toFixed(6);
const selectedId = modal.find(".row-id").data("rowId");
$("#pending_complaint").find(`.btn-register-position[data-id="${selectedId}"]`).data("latValue", add_lat);
$("#pending_complaint").find(`.btn-register-position[data-id="${selectedId}"]`).data("lngValue", add_lng);
modal.modal("hide");
}
});
// end register position
// description
$("#pending_complaint").on("click", ".btn-add-desc", function () {
const modal = $("#add_description_road_observation_modal");
const selectedId = $(this).data("id");
modal.find(".input-add-desc").val("");
modal.find(".input-add-desc").removeClass("validity-checker");
modal.find(".row-id").data("rowId", selectedId);
modal.find(".row-id").text(selectedId);
modal.modal("show");
});
$(document).on("click", "#add_description_cta", function () {
const modal = $(this).parents(".modal");
modal.find(".input-add-desc").val() == "" ? modal.find(".input-add-desc").addClass("validity-checker") : modal.find(".input-add-desc").removeClass("validity-checker");
if (modal.find(".validity-checker").length != 0) {
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا تمامی مقادیر را تکمیل کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
} else {
const add_description = modal.find("#add_description").val();
const selectedId = modal.find(".row-id").data("rowId");
$("#pending_complaint").find(`.btn-add-desc[data-id="${selectedId}"]`).data("descValue", add_description);
modal.modal("hide");
}
});
// end description
// action radio button
$("#pending_complaint").on("change", ".action-radio", function () {
const tr = $(this).closest("tr");
const imgParent = tr.find(".image-btn").parents(".img-box");
if ($(this).val() == 1) {
tr.find(".btn-add-desc").prop("disabled", false);
tr.find(".img-input").prop("disabled", false);
tr.find(".btn-register-position").prop("disabled", false);
tr.find(".btn-register-position img").attr("src", "/dist/images/new-design/iranTempOrange.svg");
tr.find(".btn-add-pending-complaint").prop("disabled", false);
} else if ($(this).val() == 2) {
tr.find(".btn-add-desc").prop("disabled", false);
tr.find(".img-input").prop("disabled", true);
tr.find(".btn-register-position").prop("disabled", true);
tr.find(".btn-register-position img").attr("src", "/dist/images/new-design/iranTemp3.svg");
tr.find(".btn-add-pending-complaint").prop("disabled", false);
}
});
// action radio button
// refrence show
$("#pending_complaint").on("click", ".btn-refrence-show", function () {
const modal = $("#refrence_show_road_observation_modal");
let tr = $(this).closest("tr");
let row = pendingComplaintTable.row(tr);
refrence_list(row.data().road_observeds_id);
});
// end refrence show
// refrence
$("#pending_complaint").on("click", ".btn-refrence", function () {
const modal = $("#refrence_road_observation_modal");
let tr = $(this).closest("tr");
let row = pendingComplaintTable.row(tr);
const province_id = row.data().province_id;
modal.find("#refrence_cta").data("rowId", row.data().road_observeds_id);
modal.find(".select-refrence").removeClass("validity-checker");
modal.find(".textarea-refrence").removeClass("validity-checker");
modal.find(".textarea-refrence").val("");
refrence_office(province_id);
});
$(document).on("click", "#refrence_cta", function () {
const modal = $(this).parents(".modal");
const row_id = $(this).data("rowId");
modal.find(".select-refrence").removeClass("validity-checker");
modal.find(".textarea-refrence").removeClass("validity-checker");
modal.find("#refrence_cta").prop("disabled", true);
const edarate_shahri_id = modal.find("#refrence_office").children("option:selected").val();
const refer_description = modal.find("#refrence_description").val();
if (refer_description == "") modal.find(".textarea-refrence").addClass("validity-checker");
if (edarate_shahri_id == 0) modal.find(".select-refrence").addClass("validity-checker");
if (modal.find(".validity-checker").length != 0) {
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا تمامی مقادیر را تکمیل کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
modal.find("#refrence_cta").prop("disabled", false);
} else {
modal.find(".select-refrence").removeClass("validity-checker");
formData = new FormData();
formData.append("edarate_shahri_id", edarate_shahri_id);
formData.append("refer_description", refer_description);
$.ajax({
url: refrence_api + row_id,
type: "POST",
cache: false,
data: formData,
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
Accept: "application/json",
},
beforeSend: function () {
showLoaderScreen();
modal.find("#refrence_cta").prop("disabled", true);
},
success: function (result) {
modal.modal("hide");
Swal.fire({
icon: "success",
title: `انجام شد`,
text: `با موفقیت ارجاع داده شد`,
heightAuto: false,
showConfirmButton: false,
timer: 1500,
});
pendingComplaintTable.ajax.reload(null, false);
},
error: function (error) {
console.log(error);
modal.find("#refrence_cta").prop("disabled", false);
ajax_error(request.responseJSON, request.status);
},
complete: function (data) {
hideLoaderScreen();
modal.find("#refrence_cta").prop("disabled", false);
},
});
}
});
// end refrence
// table functions
//// pending complaint table
function pendingTableFunc() {
pendingComplaintTable = $("#pending_complaint").DataTable({
serverSide: true,
dom: "<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: [
[9, "desc"]
],
processing: true,
select: true,
ajax: {
url: pendingComplaint_api,
type: "GET",
dataSrc: function (json) {
$(".pending-counter").text(json.recordsFiltered)
$('.pending-counter').each(function () {
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: 2500,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
$(this).text($(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
}
});
});
return json.data;
},
error: function (error) {
hideLoaderScreen();
ajax_error(request.responseJSON, request.status);
},
},
columns: [
{
className: "text-center align-middle",
data: "road_observeds_id",
// render: function(data, type, row, meta) {
// return (meta.settings._iDisplayStart + meta.row) + 1
// },
name: {
name: 'road_observeds.id',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting align-middle",
data: "fk_RegisteredEventMessage",
name: {
name: 'fk_RegisteredEventMessage',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting align-middle",
data: "province_fa",
name: {
name: 'province_fa',
type: 'text'
},
searchable: true,
orderable: true,
},
// {
// className: "text-center sorting align-middle",
// data: "city_fa",
// name: {
// name: 'city_fa',
// type: 'text'
// },
// searchable: true,
// orderable: true,
// },
{
className: "text-center sorting align-middle",
data: "edarate_shahri_name_fa",
name: {
name: 'edarate_shahri.name_fa',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting align-middle",
data: "Title",
name: {
name: 'Title',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting align-middle",
data: "FeatureTypeTitle",
name: {
name: 'FeatureTypeTitle',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'Description',
type: 'option'
},
render: function (data, type, row) {
return `<div class="text-center">
<button class="btn-dataTable btn-show-description" title="نمایش توضیحات">
<i class="fa fa-comment icon-btnTable"></i>
</button>
</div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="text-center">
<button class="btn-dataTable btn-showOnMap-road-observation" title="نمایش مختصات">
<img src="/dist/images/new-design/iranTempGreen.svg" />
</button>
</div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center sorting align-middle",
data: "MobileForSendEventSms",
name: {
name: 'MobileForSendEventSms',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center align-middle date-direction",
data: null,
name: {
name: 'road_observeds.StartTime_DateTime',
type: 'between'
},
render: function (data, type, row) {
return moment(data.road_observeds_nikarayan_created_at).locale('fa').format('YYYY/MM/DD || HH:mm');
},
orderable: true,
searchable: true,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="d-flex flex-column align-items-start">
<div class="d-flex align-items-start mb-2">
<input class="action-radio" id="action_accept${data.road_observeds_id}" data-id="${data.road_observeds_id}" type="radio" name="actions${data.road_observeds_id}" value="1">
<label for="action_accept${data.road_observeds_id}" class="mb-0 mr-2 text-nowrap">انجام شد</label>
</div>
<div class="d-flex align-items-start">
<input class="action-radio" id="action_reject${data.road_observeds_id}" data-id="${data.road_observeds_id}" type="radio" name="actions${data.road_observeds_id}" value="2">
<label for="action_reject${data.road_observeds_id}" class="mb-0 mr-2 text-nowrap">انجام نشد</label>
</div>
</div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="text-center">
<button class="btn-dataTable btn-register-position" data-id="${data.road_observeds_id}" data-lat-value="" data-lng-value="" disabled title="ثبت مختصات">
<img src="/dist/images/new-design/iranTemp3.svg" />
</button>
</div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="img-box img-box-1 col d-flex justify-content-center">
<div class="d-flex flex-column">
<label class="imgbox d-flex align-items-center justify-content-center" for="action_before_image${data.road_observeds_id}">
<span class="img-title text-nowrap" id="action_before_imageTitle${data.road_observeds_id}">تصویر قبل</span>
<img class="img-preview" id="action_before_imagePreview${data.road_observeds_id}" src="" />
</label>
<button class="btn-delete-img btn btn-danger btn-sm" id="deleteaction_before_image${data.road_observeds_id}" disabled><i class="fa fa-trash" style="color: #fff;"></i></button>
</div>
<input type="file" name="action_before_image" id="action_before_image${data.road_observeds_id}" class="img-input d-none img-before" accept=".jpg, .png" disabled>
</div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="img-box img-box-2 col d-flex justify-content-center">
<div class="d-flex flex-column">
<label class="imgbox d-flex align-items-center justify-content-center" for="action_after_image${data.road_observeds_id}">
<span class="img-title text-nowrap" id="action_after_imageTitle${data.road_observeds_id}">تصویر بعد</span>
<img class="img-preview" id="action_after_imagePreview${data.road_observeds_id}" src="" />
</label>
<button class="btn-delete-img btn btn-danger btn-sm" id="deleteaction_after_image${data.road_observeds_id}" disabled><i class="fa fa-trash" style="color: #fff;"></i></button>
</div>
<input type="file" name="action_after_image" id="action_after_image${data.road_observeds_id}" class="img-input d-none img-after" accept=".jpg, .png" disabled>
</div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="text-center">
<button class="btn-dataTable btn-add-desc" data-id="${data.road_observeds_id}" data-desc-value="" disabled title="ثبت توضیحات">
<i class="fa fa-envelope"></i>
</button>
</div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="text-center d-flex align-items-center justify-content-center">
<button class="btn-dataTable btn-refrence d-flex flex-column align-items-center" title="ارجاع">
<i class="fa fa-share"></i><span>ارجاع</span>
</button>
<div class="pipeline mx-2"></div>
<button class="btn-dataTable btn-refrence-show d-flex flex-column align-items-center" title="لیست ارجاعات" style="width:72px">
<i class="fa fa-list"></i><span>لیست ارجاعات</span>
</button>
<div class="pipeline mx-2"></div>
<button class="btn-dataTable btn-add-pending-complaint d-flex flex-column align-items-center" disabled title="ثبت">
<i class="fa fa-check-square"></i><span>ثبت</span>
</button>
</div>`;
},
orderable: false,
searchable: false,
},
],
buttons: [
{
className: "mx-2",
text: '<div class="btn-table-filter"><div class="d-flex flex-column"><i class="fa mb-2 fa-filter icon-color"></i>فیلترینگ پیشرفته</div></div>',
action: function (e, dt, node, config) {
topPosition = $(e.target).parents('.btn-table-filter').offset().top + $(e.target).parents('.btn-table-filter').height() + 5
$(".parent-filter").css('top', topPosition);
$(".parent-filter").css("display", "block");
},
},
{
className: "static-btn-cta",
text: '<div class="btn-table-excel"><div class="d-flex flex-column"><i class="fa mb-2 fa-book icon-color"></i>گزارش اکسل</div></div>',
action: function (e, dt, node, config) {
let currentDate = {};
let queryParems = [];
const province = $("#filter_province option:selected").val();
if ($("#filter_date_from").val() != "") {
const filter_date_from_value = moment(filter_date_from.getState().selected.unixDate).format("YYYY-MM-DD");
currentDate.from = filter_date_from_value;
currentDate.to = moment().format("YYYY-MM-DD");
queryParems.push(`fromDate=${currentDate.from}`);
queryParems.push(`toDate=${currentDate.to}`);
}
if (province != 0) queryParems.push(`province_id=${province}`);
const url = `/v2/road_observations/report/pending${queryParems.length != 0 ? `?${queryParems.join("&")}` : ""}`;
window.open(url, "_blank");
},
},
// {
{
className: "d-md-none mx-2",
text: '<div class="btn-table-filter"><div class="d-flex flex-column"><i class="fa mb-2 fa-reply icon-color"></i>بازگشت</div></div>',
action: function (e, dt, node, config) {
window.location = '/v2'
},
},
// className: "done-table-btn mx-2",
// text: '<div class="d-flex flex-column"><i class="fa mb-2 fa-check-circle icon-color"></i>شکایات رسیدگی شده</div>',
// },
],
initComplete: function () {
$('[data-toggle="tooltip"]').tooltip();
},
});
}
//// end pending complaint table
//// done complaint table
function doneTableFunc() {
doneComplaintTable = $("#done_complaint").DataTable({
serverSide: true,
dom: "<lB<t>p>",
pagingType: "simple_numbers",
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, "asc"][(1, "asc")],
[2, "desc"],
[3, "desc"],
[4, "desc"]
],
order: [
[0, "desc"]
],
processing: true,
select: true,
ajax: {
url: doneComplaint_api,
type: "GET",
dataSrc: function (json) {
$(".done-counter").text(json.recordsTotal)
$('.done-counter').each(function () {
$(this).prop('Counter', 0).animate({
Counter: $(this).text()
}, {
duration: 2500,
easing: 'swing',
step: function (now) {
$(this).text(Math.ceil(now));
$(this).text($(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
}
});
});
return json.data;
},
error: function (error) {
ajax_error(request.responseJSON, request.status);
}
},
columns: [
{
className: "text-center align-middle",
data: null,
render: function (data, type, row, meta) {
return (meta.settings._iDisplayStart + meta.row) + 1
},
name: {
name: 'road_observeds.id',
type: 'option'
},
searchable: false,
orderable: false,
},
{
className: "text-center sorting align-middle",
data: "fk_RegisteredEventMessage",
name: {
name: 'fk_RegisteredEventMessage',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting align-middle",
data: "province_fa",
name: {
name: 'province_fa',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting align-middle",
data: "city_fa",
name: {
name: 'city_fa',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting align-middle",
data: "edarate_shahri_name_fa",
name: {
name: 'edarate_shahri.name_fa',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting align-middle",
data: "Title",
name: {
name: 'Title',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center sorting align-middle",
data: "FeatureTypeTitle",
name: {
name: 'FeatureTypeTitle',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'Description',
type: 'option'
},
render: function (data, type, row) {
return `<div class="text-center">
<button class="btn-dataTable btn-show-description" title="نمایش توضیحات">
<i class="fa fa-comment icon-btnTable"></i>
</button>
</div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="text-center">
<button class="btn-dataTable btn-showOnMap-road-observation" title="نمایش مختصات">
<img src="/dist/images/new-design/iranTempGreen.svg" />
</button>
</div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center sorting align-middle",
data: "MobileForSendEventSms",
name: {
name: 'MobileForSendEventSms',
type: 'text'
},
searchable: true,
orderable: true,
},
{
className: "text-center align-middle date-direction",
data: null,
name: {
name: 'road_observeds.created_at',
type: 'between'
},
render: function (data, type, row) {
return moment(data.road_observeds_created_at).locale('fa').format('YYYY/MM/DD || hh:mm');
},
orderable: true,
searchable: true,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'rms_status',
type: 'option'
},
render: function (data, type, row) {
return data.rms_status == 1 ? "انجام شده" : "انجام نشده";
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
if (data.rms_status == 1) {
return `<div class="text-center">
<button class="btn-dataTable btn-showOnMap-road-observation solver-position" title="نمایش مختصات">
<img src="/dist/images/new-design/iranTempGreen.svg" />
</button>
</div>`;
} else {
return `---`;
}
},
orderable: false,
searchable: false,
},
{
className: "text-center",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
let content = `<div class="d-flex justify-content-around">`;
if (data.image_before != null) {
content += `<img class="table-image" width="20px" height="20px" src="${data.image_before}" />`
} else {
content += `---`;
}
content += `</div>`;
return content;
},
orderable: false,
searchable: false,
},
{
className: "text-center",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
let content = `<div class="d-flex justify-content-around">`;
if (data.image_after != null) {
content += `<img class="table-image" width="20px" height="20px" src="${data.image_after}" />`
} else {
content += `---`;
}
content += `</div>`;
return content;
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle date-direction",
data: null,
name: {
name: 'rms_last_activity_fa',
type: 'option'
},
render: function (data, type, row) {
return moment(data.rms_last_activity_fa).format('YYYY/MM/DD || hh:mm');
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'rms_description',
type: 'option'
},
render: function (data, type, row) {
if (data.rms_description == null) {
return `---`;
} else {
return `<div class="text-center">
<button class="btn-dataTable btn-show-description solver-description" title="نمایش توضیحات">
<i class="fa fa-comment icon-btnTable"></i>
</button>
</div>`;
}
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="text-center">
<button class="btn-dataTable send-to-pending" title="بازگردانی به روند بررسی">
<i class="fa fa-share-square"></i>
</button>
</div>`;
},
orderable: false,
searchable: false,
},
{
className: "text-center align-middle",
data: null,
name: {
name: 'option',
type: 'option'
},
render: function (data, type, row) {
return `<div class="text-center">
<button class="btn-dataTable download-pdf" title="خروجی" onclick="window.open('/webapi/fast-reaction/${data.road_observeds_id}/preview/print')">
<i class="fa fa-file-pdf"></i>
</button>
</div>`;
},
orderable: false,
searchable: false,
},
],
buttons: [],
initComplete: function () {
$('[data-toggle="tooltip"]').tooltip();
},
});
}
//// end done complaint table
// end table functions
// add pending complaint table
$("#pending_complaint").on("click", ".btn-add-pending-complaint", function () {
const thisBtn = $(this);
thisBtn.prop("disabled", true);
let tr = $(this).closest("tr");
let row = pendingComplaintTable.row(tr);
const row_id = row.data().road_observeds_id;
const rms_status = tr.find('.action-radio:checked').val();
const rms_start_latlng = tr.find('.btn-register-position').data("latValue") == "" ? "" : [tr.find('.btn-register-position').data("latValue"), tr.find('.btn-register-position').data("lngValue")]
const image_before = tr.find('.img-before').get(0).files[0];
const image_after = tr.find('.img-after').get(0).files[0];
const rms_description = tr.find('.btn-add-desc').data("descValue");
let formData = new FormData();
formData.append("rms-status", rms_status);
if (rms_description != "") { formData.append("description", rms_description) }
if (rms_status == 1) {
if (rms_start_latlng != "") {
formData.append("rms-start-latlng", rms_start_latlng);
tr.find(".btn-register-position").parents("td").removeClass("validity-checker-table");
} else {
tr.find(".btn-register-position").parents("td").addClass("validity-checker-table");
}
if (image_before != undefined) {
formData.append("image-before-1", image_before);
tr.find(".img-box-1").parents("td").removeClass("validity-checker-table");
} else {
tr.find(".img-box-1").parents("td").addClass("validity-checker-table");
}
if (image_after != undefined) {
formData.append("image-after-1", image_after);
tr.find(".img-box-2").parents("td").removeClass("validity-checker-table");
} else {
tr.find(".img-box-2").parents("td").addClass("validity-checker-table");
}
} else {
tr.find(".btn-register-position").parents("td").removeClass("validity-checker-table");
tr.find(".img-box-1").parents("td").removeClass("validity-checker-table");
tr.find(".img-box-2").parents("td").removeClass("validity-checker-table");
}
if (tr.find("td").hasClass("validity-checker-table")) {
Swal.fire({
icon: "error",
title: "خطا",
text: "لطفا تمامی مقادیر را تکمیل کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
thisBtn.prop("disabled", false);
} else {
$.ajax({
url: addPendingComplaint_api + row_id,
type: "POST",
data: formData,
cache: false,
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
},
beforeSend: function () {
showLoaderScreen();
},
success: function (result) {
thisBtn.prop('disabled', false);
hideLoaderScreen();
Swal.fire({
icon: "success",
title: "ثبت موفق",
text: "اطلاعات شکایت با موفقیت ثبت شد",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
}).then(result => {
pendingComplaintTable.ajax.reload(null, false);
})
},
error: function (error) {
thisBtn.prop('disabled', false)
ajax_error(request.responseJSON, request.status);
hideLoaderScreen();
},
});
}
});
// add pending complaint table
// run done table
// $(document).on("click", ".done-table-btn", function() {
// $(document).find(".done-table").removeClass("d-none");
// if (doneComplaintTable == null) {
// doneTableFunc();
// }
// setTimeout(() => {scrolldowntable()}, 200);
// });
// end run done table
// show image
$(document).on("click", ".table-image", function () {
const modal = $("#show_image_road_observation_modal");
modal.modal("show");
$("#show_image").attr("src", $(this).attr("src"));
});
// end show image
// paginate loading
$(document).on("click", ".paginate_button", function () {
setTimeout(() => { $('[data-toggle="tooltip"]').tooltip() }, 400);
});
// end paginate loading
// send to pending
$(document).on("click", ".send-to-pending", function () {
const modal = $("#send_to_pending_road_observation_modal");
let tr = $(this).closest("tr");
let row = doneComplaintTable.row(tr);
modal.find("#send_to_pending_description_cta").data("rowId", row.data().road_observeds_id);
modal.find(".textarea-send-to-pending").val("");
modal.modal("show");
});
// new changes should be checked
$(document).on("click", "#send_to_pending_description_cta", function () {
const modal = $(this).parents(".modal");
const row_id = $(this).data("rowId");
const description = modal.find("#send_to_pending_description").val();
if (description == "") {
modal.find(".textarea-send-to-pending").addClass("validity-checker");
Swal.fire({
icon: "error",
title: "خطا",
text: "توضیحات مربوطه را وارد کنید",
cancelButtonText: "بستن",
showConfirmButton: false,
showCancelButton: true,
});
} else {
modal.find(".textarea-send-to-pending").removeClass("validity-checker");
formData = new FormData();
formData.append("restore_description", description);
$.ajax({
url: send_to_pending_api + row_id,
type: "POST",
cache: false,
data: formData,
processData: false,
contentType: false,
headers: {
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
Accept: "application/json",
},
beforeSend: function () {
showLoaderScreen();
modal.find("#send_to_pending_description_cta").prop("disabled", true);
},
success: function (result) {
modal.modal("hide");
Swal.fire({
icon: "success",
title: `انجام شد`,
text: `با موفقیت بازگردانی شد`,
heightAuto: false,
showConfirmButton: false,
timer: 1500,
});
pendingComplaintTable.ajax.reload();
doneComplaintTable.ajax.reload();
},
error: function (error) {
modal.find("#send_to_pending_description_cta").prop("disabled", false);
ajax_error(request.responseJSON, request.status);
},
complete: function (data) {
hideLoaderScreen();
modal.find("#send_to_pending_description_cta").prop("disabled", false);
},
});
}
});
// end send to pending
// filter [pendingComplaintTable]
$(document).on("click", "#btn_filter", function () {
_table = pendingComplaintTable
const province_value = $("#filter_province option:selected");
// const subject_progress = $("#select-subject-progress option:selected");
const filter_status = $("#filter_status");
const filter_date_from_value = moment(filter_date_from.getState().selected.unixDate).format("YYYY-MM-DD");
if (province_value.val() != 0) {
_table = _table.column(2).search(province_value.text());
} else {
_table = _table.column(2).search('');
}
// if (subject_progress.val() != 0) {
// _table = _table.column(6).search(subject_progress.text());
// } else {
// _table = _table.column(6).search('');
// }
if ($("#filter_date_from").val() != "") {
_table = _table.column(9).search(filter_date_from_value + "&" + moment().format("YYYY-MM-DD"));
} else {
_table = _table.column(9).search('');
}
_table.draw();
});
// end filter
// excel [pendingComplaintTable]
$("#btn_excel-download").on("click", function () {
});
// end excel