// new accident pint begin var addMap = null; var editMap = null; var excelDatepickerFirstTable = {}; var posterDatepickerFirstTable = {}; var isSetMarkerAdd = false; var isSetMarkerEdit = false; var markerAdd; var markerEdit; var PERMISSIONS = []; var validation_role_for_enabled_vehicle = []; var add_accident_date; var add_accident_time; var edit_accident_date; var edit_accident_time; var mapShow; var showMapMarker; $("[data-mask]").inputmask(); var mapUrl = "https://rmsmap.rmto.ir/141map/"; var divIcon = L.divIcon({ html: `
مکان
`, iconSize: [55, 75], iconAnchor: [33, 64], }); var divIconEdit = L.divIcon({ html: `
مکان
`, iconSize: [55, 75], iconAnchor: [33, 64], }); 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(); L.tileLayer(`${mapUrl}/{z}/{x}/{y}.png`, {}).addTo(mapShow); showMapMarker = L.marker(position, { icon: divIcon }).addTo(mapShow); resolve(); }, 200) }); } function changePositionMarkerInMapShow(position) { return new Promise(function(resolve) { setTimeout(() => { mapShow.setView(position, 7); mapShow.invalidateSize(); showMapMarker.setLatLng(position) resolve(); }, 200) }); } $(document).on("change", ".collision_type", function() { var input = $(this).val(); const modal = $(this).parents('.modal') modal.find(".accident-participant-input").val(""); modal.find(".accident-participant-input").prop('disabled', true); validation_role_for_enabled_vehicle[input].forEach(function(item) { modal.find(`#${item}`).prop('disabled', false); modal.find(`#${item}`).val(""); }); }); $(document).on("change", ".accident_type", function() { var input = $(this).val(); const modal = $(this).parents('.modal') if (input == '0') { modal.find(".number_of_injured").prop('disabled', true).val(""); modal.find(".number_of_died").prop('disabled', true).val(""); } else if (input == '1') { modal.find(".number_of_injured").prop('disabled', true).val(""); modal.find(".number_of_died").prop('disabled', true).val(""); } else if (input == '2') { modal.find(".number_of_injured").prop('disabled', false).val(""); modal.find(".number_of_died").prop('disabled', true).val(""); } else { modal.find(".number_of_injured").prop('disabled', false).val(""); modal.find(".number_of_died").prop('disabled', false).val(""); } }); $(document).on('change', '.accident-reasons', function() { const modal = $(this).parents('.modal') if (modal.find('.accident-reasons:checked').length == modal.find('.accident-reasons').length) { modal.find('.select_all_accident_reasons').prop('checked', true) } else { modal.find('.select_all_accident_reasons').prop('checked', false) } }) $(document).on('change', '.increase-damage-reasons', function() { const modal = $(this).parents('.modal') if (modal.find('.increase-damage-reasons:checked').length == modal.find('.increase-damage-reasons').length) { modal.find('.select_all_increase_damage_reasons').prop('checked', true) } else { modal.find('.select_all_increase_damage_reasons').prop('checked', false) } }) // image upload begin $(document).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]); } }); $(".btn-delete-img").on("click", 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 $('.select_all_accident_reasons').on('click', function() { const modal = $(this).parents('.modal') if ($(this).prop('checked')) { modal.find('.accident-reasons').prop('checked', true) } else { modal.find('.accident-reasons').prop('checked', false) } }) $('.select_all_increase_damage_reasons').on('click', function() { const modal = $(this).parents('.modal') if ($(this).prop('checked')) { modal.find('.increase-damage-reasons').prop('checked', true) } else { modal.find('.increase-damage-reasons').prop('checked', false) } }) // map setting $("#accident_add").on("click", function() { const modal = $('#add_accident_modal') showLoaderScreen() modal.find('.required-text-inputs').val('') modal.find('.accident-participant-input').val('').prop('disabled', true) modal.find('.number_of_injured').prop('disabled', true) modal.find('.number_of_died').prop('disabled', true) modal.find('.select-inputs').val(0) modal.find('.accident-reasons').prop('checked', false) modal.find('.increase-damage-reasons').prop('checked', false) modal.find('.validity-checker').removeClass('validity-checker') modal.find(".img-input").val(""); modal.find(".img-preview").removeAttr("src"); modal.find(".img-preview").css("display", "none"); modal.find(".img-title").css("display", ""); modal.find('.btn-delete-img').attr("disabled", "disabled"); modal.find("#add_project_start_map").val(""); createAddMap(modal).then(() => { hideLoaderScreen() }) modal.modal("show"); //add pin move to thois marker yasi isSetMarkerAdd = false; $("#pin_marker").removeClass("pin-set"); }); function createAddMap(modal) { return new Promise(resolve => { setTimeout(() => { var bounds = [ [42.9130026312, 75.6166317076], [20.5782370061, 35.5092252948], ]; if (addMap != null) { addMap.setView([35.7065, 51.3477], 7) markerAdd.setLatLng(L.latLng([35.7065, 51.3477])); modal.find("#pin_marker").removeClass("pin-move pin-set"); } else { addMap = L.map("add_map", { maxBounds: bounds, minZoom: 6, attributionControl: false }).setView([35.7065, 51.3477], 7); L.tileLayer(`${mapUrl}{z}/{x}/{y}.png`, {}).addTo(addMap); setMarkerDefaultAdd(modal); } resolve() }, 400) }) } function createEditMap(modal, lat, lng) { return new Promise(resolve => { var bounds = [ [42.9130026312, 75.6166317076], [20.5782370061, 35.5092252948], ]; setTimeout(() => { if (editMap != null) { editMap.setView([lat, lng], 7) markerEdit.setLatLng(L.latLng([lat, lng])); } else { editMap = L.map("edit_map", { maxBounds: bounds, minZoom: 6, attributionControl: false }).setView([lat, lng], 7); L.tileLayer(`${mapUrl}{z}/{x}/{y}.png`, {}).addTo(editMap); setMarkerDefaultEdit(modal, lat, lng); } resolve() }, 400) }) } function setMarkerDefaultAdd(modal) { isSetMarkerAdd = false; modal.find("#pin_marker").removeClass("pin-set"); modal.find("#accident_point_map").val(""); modal.find("#add_project_start_map").val(""); markerAdd = new L.marker([35.7065, 51.3477], { icon: divIcon, draggable: true, }).addTo(addMap); addMap.on("move", function() { if (!isSetMarkerAdd) { markerAdd.setLatLng(L.latLng(addMap.getCenter())); modal.find("#pin_marker").removeClass("pin-set").addClass("pin-move"); } }); addMap.on("moveend", function() { if (!isSetMarkerAdd) { markerAdd.setLatLng(L.latLng(addMap.getCenter())); modal.find("#pin_marker").removeClass("pin-move pin-set"); } }); markerAdd.on("click", function() { if (!isSetMarkerAdd) { markerAdd.setLatLng(L.latLng(addMap.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"); $("#add_project_start_map").val( markerAdd.getLatLng().lat.toFixed(6) + markerAdd.getLatLng().lng.toFixed(6) ); } markerAdd.addTo(addMap); $(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_project_start_map").val( markerAdd.getLatLng().lat.toFixed(6) + markerAdd.getLatLng().lng.toFixed(6) ); modal.find("#accident_point_map").removeClass("validity-checker"); } else { addMap.setView(markerAdd.getLatLng()); } }); } function setMarkerDefaultEdit(modal, lat, lng) { isSetMarkerEdit = false; modal.find("#accident_point_map").val(""); markerEdit = new L.marker([lat, lng], { icon: divIcon, draggable: true, }).addTo(editMap); modal.find("#pin_marker").removeClass("pin-move pin-warn").addClass("pin-set"); markerEdit.on("click", function() { if (!isSetMarkerEdit) { markerEdit.setLatLng(L.latLng(editMap.getCenter())); isSetMarkerEdit = true; modal.find("#pin_marker") .removeClass("pin-move pin-warn") .addClass("pin-set"); modal.find("#accident_point_map").val( markerEdit.getLatLng().lat.toFixed(6) + markerEdit.getLatLng().lng.toFixed(6) ); modal.find("#accident_point_map").removeClass("validity-checker"); } markerEdit.addTo(editMap); $(this).hide(); modal.find("#pin_marker").removeClass("pin-move pin-warn").addClass("pin-set"); }); markerEdit.on("drag", function() { modal.find("#pin_marker").addClass("pin-move"); }); markerEdit.on("dragend", function() { modal.find("#pin_marker").removeClass("pin-move"); if (modal.find("#pin_marker").hasClass("pin-set") || isSetMarkerEdit) { modal.find("#pin_marker").addClass("pin-set"); modal.find("#accident_point_map").val( markerEdit.getLatLng().lat.toFixed(6) + markerEdit.getLatLng().lng.toFixed(6) ); $("#edit_project_start_map").val( markerEdit.getLatLng().lat.toFixed(6) + markerEdit.getLatLng().lng.toFixed(6) ); modal.find("#accident_point_map").removeClass("validity-checker"); } else { editMap.setView(markerEdit.getLatLng()); modal.find("#pin_marker").addClass("pin-set"); $("#edit_project_start_map").val( markerEdit.getLatLng().lat.toFixed(6) + markerEdit.getLatLng().lng.toFixed(6) ); } }); } // map setting end function showLoaderScreen() { $(".divloader").css("display", "flex").hide().fadeIn(); } function hideLoaderScreen() { $(".divloader").fadeOut(); } $(document).ready(function() { appendYearFilter(); const modalAdd = $('#add_accident_modal') const modalEdit = $('#edit_accident_modal') add_accident_date = modalAdd.find('#add_accident_date').persianDatepicker({ format: "YYYY/MM/DD", minDate: new Date(2022, 02, 21), // it will set minDate from first of 1401 autoClose: true, // initialValue: false, onSelect: function(unix) { modalAdd.find('#add_day_of_the_week').val(new persianDate([add_accident_date.getState().selected.year, add_accident_date.getState().selected.month, add_accident_date.getState().selected.date]).format('dddd')) } }); add_accident_time = modalAdd.find('#add_accident_time').persianDatepicker({ format: "HH:mm", autoClose: true, initialValue: false, onlyTimePicker: true, timePicker: { second: { enabled: false, } } }); edit_accident_date = modalEdit.find('#edit_accident_date').persianDatepicker({ format: "YYYY/MM/DD", minDate: new Date(2022, 02, 21), // it will set minDate from first of 1401 autoClose: true, initialValue: false, onSelect: function(unix) { modalEdit.find('#edit_day_of_the_week').val(new persianDate([edit_accident_date.getState().selected.year, edit_accident_date.getState().selected.month, edit_accident_date.getState().selected.date]).format('dddd')) } }); edit_accident_time = modalEdit.find('#edit_accident_time').persianDatepicker({ format: "HH:mm", autoClose: true, initialValue: false, onlyTimePicker: true, timePicker: { second: { enabled: false, } } }); 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; }, }); posterDatepickerFirstTable.from = $( "#datapicker-from-poster-table" ).persianDatepicker({ format: "YYYY/MM/DD", autoClose: true, onSelect: function(unix) { posterDatepickerFirstTable.from.touched = true; $("#datapicker-to-poster-table").prop("disabled", ""); if ( posterDatepickerFirstTable.from.getState().selected.unixDate >= posterDatepickerFirstTable.to.getState().selected.unixDate ) { posterDatepickerFirstTable.to.setDate( posterDatepickerFirstTable.from.getState().selected.unixDate ); } if ( posterDatepickerFirstTable.to && posterDatepickerFirstTable.to.options && posterDatepickerFirstTable.to.options.minDate != unix ) { let cachedValue = posterDatepickerFirstTable.to.getState().selected.unixDate; posterDatepickerFirstTable.to.options = { minDate: unix }; if (posterDatepickerFirstTable.from.touched) { posterDatepickerFirstTable.to.setDate(cachedValue); } } }, }); posterDatepickerFirstTable.to = $( "#datapicker-to-poster-table" ).persianDatepicker({ format: "YYYY/MM/DD", autoClose: true, onSelect: function(unix) { posterDatepickerFirstTable.to.touched = true; }, }); // fetch accident reasons begin $.ajax({ url: "https://rms.rmto.ir/daily_accident/accident_reasons", type: "GET", cache: false, async: false, contentType: false, processData: false, success: function(results) { results.forEach(function(result) { modalAdd.find("#accident_reasons").append(`
`); modalEdit.find("#accident_reasons").append(`
`); $("#expert_confirmation_modal").find(".accident-reasons").append(`
${result.value}
`); }); }, error: function() { Swal.fire({ icon: "error", title: "خطا", text: "مشکل در دریافت سطح دسترسی", confirmButtonText: "بروزرسانی صفحه", showLoaderOnConfirm: true, preConfirm: () => { location.reload(true); }, }); }, }); // fetch accident reasons end // fetch accident increase damage reasons begin $.ajax({ url: "https://rms.rmto.ir/daily_accident/accident_increase_damage_reasons", type: "GET", cache: false, async: false, contentType: false, processData: false, success: function(results) { results.forEach(function(result) { modalAdd.find("#increase_damage_reasons").append(`
`); modalEdit.find("#increase_damage_reasons").append(`
`); $("#expert_confirmation_modal").find(".increase-damage-reasons").append(`
${result.value}
`); }); }, error: function() { Swal.fire({ icon: "error", title: "خطا", text: "مشکل در دریافت سطح دسترسی", confirmButtonText: "بروزرسانی صفحه", showLoaderOnConfirm: true, preConfirm: () => { location.reload(true); }, }); }, }); // fetch accident increase damage reasons end // fetch accident participants begin $.ajax({ url: "https://rms.rmto.ir/daily_accident/get_participants", type: "GET", cache: false, async: false, contentType: false, processData: false, success: function(results) { results.forEach(function(result) { //yasi modalAdd.find("#accident_participant").append(`
`); modalEdit.find("#accident_participant").append(`
`); }); }, error: function() { Swal.fire({ icon: "error", title: "خطا", text: "مشکل در دریافت سطح دسترسی", confirmButtonText: "بروزرسانی صفحه", showLoaderOnConfirm: true, preConfirm: () => { location.reload(true); }, }); }, }); // fetch accident participants end // fetch accident type begin $.ajax({ url: "https://rms.rmto.ir/daily_accident/accident_types", type: "GET", cache: false, async: false, contentType: false, processData: false, success: function(results) { results.forEach(function(result) { modalAdd.find("#add_accident_type").append(``); modalEdit.find("#edit_accident_type").append(``); }); }, error: function() { Swal.fire({ icon: "error", title: "خطا", text: "مشکل در دریافت سطح دسترسی", confirmButtonText: "بروزرسانی صفحه", showLoaderOnConfirm: true, preConfirm: () => { location.reload(true); }, }); }, }); // fetch accident type end // fetch accident collision type begin $.ajax({ url: "https://rms.rmto.ir/daily_accident/get_accident_collision_type", type: "GET", cache: false, async: false, contentType: false, processData: false, success: function(results) { results.forEach(function(result) { validation_role_for_enabled_vehicle[result.key] = JSON.parse(result.validation).enabled_list; modalAdd.find("#add_collision_type").append(``); modalEdit.find("#edit_collision_type").append(``); $(".parent-filter").find("#filter_collision_type").append(``); }); }, error: function() { Swal.fire({ icon: "error", title: "خطا", text: "مشکل در دریافت سطح دسترسی", confirmButtonText: "بروزرسانی صفحه", showLoaderOnConfirm: true, preConfirm: () => { location.reload(true); }, }); }, }); // fetch accident collision type end // permissins begin $.ajax({ url: "https://rms.rmto.ir/webapi/user/get-permission", 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); }, }); }, }); /// [start] add accident permissions if (!( $.inArray("add-accident", PERMISSIONS) != -1 || $.inArray("add-accident-province", PERMISSIONS) != -1 )) $("#accident_add").remove(); // ) { $.ajax({ url: `https://rms.rmto.ir/webapi/getuser/province-perm?type=all`, type: "GET", beforeSend: function() { showLoaderScreen(); }, success: function(result) { const provinces = result.data; $("#add_province_id").empty(); $("#edit_province_id").empty(); $("#select-province").empty(); $("#add_province_id").append( '' ); $("#edit_province_id").append( '' ); $("#select-province-excel").append(''); $("#select-province-poster").append(''); $("#select-province").append( '' ); for (let index = 0; index < provinces.length; index++) { $("#add_province_id").append( "\ \ " ); $("#edit_province_id").append( "\ \ " ); $("#select-province").append( "\ \ " ); $("#select-province-excel").append(""); $("#select-province-poster").append(""); } hideLoaderScreen(); }, error: function(error) { hideLoaderScreen(); Swal.fire({ icon: "error", title: "خطا", text: "مشکل در دریافت استان ها", confirmButtonText: "بروزرسانی صفحه", showLoaderOnConfirm: true, preConfirm: () => { location.reload(true); }, }); }, }); // } /// [end] add accident permissions // permissins end table = $("#main-table-points").DataTable({ serverSide: true, dom: "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: "https://rms.rmto.ir/daily_accident/show", type: "GET", dataSrc: function(json) { if (json.can_submit == 0) { $('#point-add').prop('disabled', true) } canSubmit = json.can_submit return json.data; }, }, columns: [{ className: "text-center", data: "id", name: { name: 'id', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: "province_fa", name: { name: 'province_fa', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: "axis_name", name: { name: 'axis_name', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: "axis_type_fa", name: { name: 'axis_type_fa', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: "distance_axis_start", name: { name: 'distance_axis_start', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: "local_name", name: { name: 'local_name', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: null, name: { name: 'option', type: 'option' }, render: function(data, type, row) { return `
`; }, orderable: false, searchable: false, }, { className: "text-center", data: "number_of_injured", name: { name: 'number_of_injured', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: "number_of_died", name: { name: 'number_of_died', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: "collision_type_fa", name: { name: 'collision_type_fa', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: "way_geometri_fa", name: { name: 'way_geometri_fa', type: 'select' }, searchable: true, orderable: true, }, { className: "text-center", data: "weather_condition_fa", name: { name: 'weather_condition_fa', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: "day_of_the_week", name: { name: 'day_of_the_week', type: 'text' }, searchable: true, orderable: true, }, { className: "text-center", data: "accident_time", name: { name: 'accident_time', type: 'between_time' }, searchable: true, orderable: true, }, { className: "text-center", data: null, name: { name: 'accident_date', type: 'between' }, render: function(data, type, row) { return moment(data.accident_date).format('jYYYY/jMM/jDD') }, searchable: true, orderable: true, }, { className: "text-center", data: null, name: { name: 'created_at', type: 'text' }, render: function(data, type, row) { return moment(data.created_at).format('HH:mm:ss jYYYY/jMM/jDD') }, searchable: true, orderable: true, }, { className: "text-center", data: null, name: { name: 'option', type: 'option' }, render: function(data, type, row) { let content = `
` if (data.state == 2 || data.state == 0) { if (data.state == 0) { content += `` } if (( $.inArray("edit-accident", PERMISSIONS) != -1 || $.inArray("edit-accident-province", PERMISSIONS) != -1 )) { content += `` } if (( $.inArray("delete-accident", PERMISSIONS) != -1 || $.inArray("delete-accident-province", PERMISSIONS) != -1 )) { content += `` } } else { content += `
موارد تایید شده امکان تغییر و یا حذف را ندارند.
` } content += `
` return content; }, orderable: false, searchable: false, }, { className: "text-center", data: null, name: { name: 'state', type: 'text' }, render: function(data, type, row) { let content = `
` if (data.state == 2) { if (!( $.inArray("accident-investigation", PERMISSIONS) != -1 || $.inArray("provincial-accident-investigation", PERMISSIONS) != -1 )) content += `
${data.state_fa}
`; else content += `` } else if (data.state == 1) content += `
تایید شده
` else if (data.state == 0) content += `عدم تایید` content += `
` return content; }, orderable: false, searchable: false, }, ], buttons: [{ className: "static-btn-cta", text: '
گزارش تصادفات
', action: function(e, dt, node, config) { $(".parent-poster").css("display", "block"); }, }, { className: "static-btn-cta", text: '
نمایش روی نقشه
', action: function(e, dt, node, config) { window.open("https://rms.rmto.ir/daily_accident_map", "_blank"); }, }, { text: '
فیلترینگ پیشرفته
', action: function(e, dt, node, config) { $(".parent-filter").css("display", "block"); }, }, { className: "static-btn-cta", text: '
گزارش آماری
', action: function(e, dt, node, config) { $(".parent-excel").css("display", "block"); }, }, ], }); }); // add part begin $(document).on("click", "#add_accident", function() { const modal = $(this).parents('.modal') $("#add_accident").prop("disabled", true); if (validateForm(modal)) { //yasi if (validateReasons(modal.find("#add_accident_type").val())) { if (validateAddAccidentParticipant($("#add_collision_type").val(), modal)) { let formData = new FormData(); formData.append("province_id", modal.find("#add_province_id").val()); formData.append("axis_name", modal.find("#add_axis_name").val()); formData.append("axis_type", modal.find("#add_axis_type").val()); formData.append("axis_start", modal.find("#add_axis_start").val()); formData.append("axis_end", modal.find("#add_axis_end").val()); formData.append("distance_axis_start", modal.find("#add_distance_axis_start").val()); formData.append("local_name", modal.find("#add_local_name").val()); formData.append("lat", markerAdd.getLatLng().lat.toFixed(6)); formData.append("lng", markerAdd.getLatLng().lng.toFixed(6)); formData.append("way_geometri", modal.find("#add_way_geometri").val()); formData.append("police_serial", modal.find("#add_police_serial").val()); formData.append("avarage_speed", modal.find("#add_avarage_speed").val()); formData.append("legal_speed", modal.find("#add_legal_speed").val()); formData.append("accident_date", moment(add_accident_date.getState().selected.unixDate).format('YYYY-MM-DD')); formData.append("accident_time", moment(add_accident_time.getState().selected.unixDate).format('HH:mm')); formData.append("day_of_the_week", modal.find("#add_day_of_the_week").val()); formData.append("direction", modal.find("#add_direction").val()); formData.append("number_of_injured", modal.find("#add_number_of_injured").val()); formData.append("number_of_died", modal.find("#add_number_of_died").val()); formData.append("weather_condition", modal.find("#add_weather_condition").val()); formData.append("collision_type", modal.find("#add_collision_type").val()); formData.append("accident_type", modal.find("#add_accident_type").val()); formData.append("participants_heavy_vehicle", modal.find("#heavy_vehicle").val()); formData.append("participants_light_vehicle", modal.find("#light_vehicle").val()); formData.append("participants_bicycle", modal.find("#bicycle").val()); const first_image = modal.find("#adddeviceImg1").get(0).files[0] if (typeof first_image !== "undefined") formData.append("first_image", first_image); const second_image = modal.find("#adddeviceImg2").get(0).files[0] if (typeof second_image !== "undefined") formData.append("second_image", second_image); const police_file = modal.find("#adddeviceImg3").get(0).files[0] if (typeof police_file !== "undefined") formData.append("police_file", police_file); modal.find(".increase-damage-reasons").each(function(index, item) { modal.find(item).is(":checked") ? formData.append(modal.find(item).prop("name"), 1) : formData.append($(item).prop("name"), 0) }); modal.find(".accident-reasons").each(function(index, item) { modal.find(item).is(":checked") ? formData.append(modal.find(item).prop("name"), 1) : formData.append($(item).prop("name"), 0) }); for (var pair of formData.entries()) {} showLoaderScreen(); $.ajax({ url: "https://rms.rmto.ir/daily_accident/store", type: "POST", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, data: formData, cache: false, contentType: false, processData: false, success: function(result) { hideLoaderScreen(); $("#add_accident").prop("disabled", false); modal.modal("hide"); Swal.fire({ icon: "success", text: " تصادف با موفقیت ثبت شد", confirmButtonText: "بستن", }); table.ajax.reload(null, false); }, error: function(error) { hideLoaderScreen(); $("#add_accident").prop("disabled", false); Swal.fire({ icon: "error", title: "خطا", text: "مشکل در ارتباط با سرور", confirmButtonText: "بستن", }); }, }); } else { $("#add_accident").prop("disabled", false); } } else { $("#add_accident").prop("disabled", false); } } else { Swal.fire({ icon: "error", title: "خطا", text: "لطفا مقادیر را به درستی وارد نمایید.", confirmButtonText: "بستن ", }); $("#add_accident").prop("disabled", false); } }); // add part end $(document).on('input', '.text-number', function() { $(this).val($(this).val().replace(/[^0-9]/gi, '')); }); function validateForm(modal) { var validation_status = true; modal.find(".select-inputs").each(function(index, item) { if (modal.find(item).val() == 0) { modal.find(item).addClass('validity-checker'); validation_status = false; } else { modal.find(item).removeClass('validity-checker'); } }); if (modal.find("#add_project_start_map").val() == "") { validation_status = false; modal.find("#add_project_start_map").addClass('validity-checker'); } else { // validation_status = true; modal.find("#add_project_start_map").removeClass('validity-checker'); } if (modal.find("#edit_project_start_map").val() == "") { validation_status = false; modal.find("#edit_project_start_map").addClass('validity-checker'); } else { // validation_status = true; modal.find("#edit_project_start_map").removeClass('validity-checker'); } modal.find(".required-text-inputs:enabled").each(function(index, item) { if (modal.find(item).val().trim() == '') { modal.find(item).addClass('validity-checker'); validation_status = false; } else { modal.find(item).removeClass('validity-checker'); } }); return validation_status; } function validateReasons(accident_type) { var validation_status = true; if ($('.accident-reasons:checked').length == 0) { validation_status = false; $('.accident-reasons').addClass('validity-checker'); Swal.fire({ icon: "error", title: "خطا", text: "لطفا یکی از عوامل شکل گیری تصادف را وارد کنید.", confirmButtonText: "بستن ", }); } else { $('.accident-reasons').removeClass('validity-checker'); } if (accident_type == '3') { if ($('.increase-damage-reasons:checked').length == 0) { validation_status = false; $('.increase-damage-reasons').addClass('validity-checker'); Swal.fire({ icon: "error", title: "خطا", text: "لطفا یکی از عوامل شدت تصادف را وارد کنید.", confirmButtonText: "بستن ", }); } else { $('.increase-damage-reasons').removeClass('validity-checker'); } } else { $('.increase-damage-reasons').removeClass('validity-checker'); } return validation_status; } function validateAddAccidentParticipant(collision_type, modal) { var validation_status = true; $('.accident-participant-input').removeClass('validity-checker'); var sumAccidentParticipant = 0 modal.find('.accident-participant-input:not(:disabled)').each(function(index, item) { sumAccidentParticipant += parseInt($(item).val()) }) switch (collision_type) { case '1': if (sumAccidentParticipant < 2) { validation_status = false; $('.accident-participant-input:not(:disabled)').addClass('validity-checker'); Swal.fire({ icon: "error", title: "خطا", text: "حداقل دو عامل درگیر در تصادف باید ثبت شود.", confirmButtonText: "بستن ", }); } break; case '2': if (sumAccidentParticipant != 1) { validation_status = false; $('.accident-participant-input:not(:disabled)').addClass('validity-checker'); Swal.fire({ icon: "error", title: "خطا", text: "فقط یک عامل باید در تصادف دخیل باشد.", confirmButtonText: "بستن ", }); } break; case '3': if (sumAccidentParticipant < 2) { validation_status = false; $('.accident-participant-input:not(:disabled)').addClass('validity-checker'); Swal.fire({ icon: "error", title: "خطا", text: "حداقل دو عامل درگیر در تصادف باید ثبت شود.", confirmButtonText: "بستن ", }); } break; case '4': if (sumAccidentParticipant < 2) { validation_status = false; $('.accident-participant-input:not(:disabled)').addClass('validity-checker'); Swal.fire({ icon: "error", title: "خطا", text: "حداقل دو عامل درگیر در تصادف باید ثبت شود.", confirmButtonText: "بستن ", }); } break; case '5': if (sumAccidentParticipant != 1) { validation_status = false; $('.accident-participant-input:not(:disabled)').addClass('validity-checker'); Swal.fire({ icon: "error", title: "خطا", text: "فقط یک عامل باید در تصادف دخیل باشد.", confirmButtonText: "بستن ", }); } break; case '6': if (sumAccidentParticipant != 1) { validation_status = false; $('.accident-participant-input:not(:disabled)').addClass('validity-checker'); Swal.fire({ icon: "error", title: "خطا", text: "فقط یک عامل باید در تصادف دخیل باشد.", confirmButtonText: "بستن ", }); } break; case '7': if (sumAccidentParticipant != 1) { validation_status = false; $('.accident-participant-input:not(:disabled)').addClass('validity-checker'); Swal.fire({ icon: "error", title: "خطا", text: "فقط یک عامل باید در تصادف دخیل باشد.", confirmButtonText: "بستن ", }); } break; } return validation_status; } function restrictInputOtherThanArabic($field) { var arabicCharUnicodeRange = /[\u0600-\u06FF-0-9-45]/; $field.bind("keypress", function(event) { var key = event.which; if (key == 8 || key == 0 || key === 32) { return true; } var str = String.fromCharCode(key); if (arabicCharUnicodeRange.test(str)) { return true; } return false; }); } $(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"); } if ( clicked.closest(".btn-table-excel").length == 0 && clicked.closest(".parent-excel").length == 0 && $(".parent-excel").css("display") != "none" ) { $(".parent-excel").css("display", "none"); } if ( clicked.closest(".btn-table-poster").length == 0 && clicked.closest(".parent-poster").length == 0 && $(".parent-poster").css("display") != "none" ) { $(".parent-poster").css("display", "none"); } }); restrictInputOtherThanArabic($(".arabic-text")); function checkCountAccidentType(modal, input) { if (input == '0') { modal.find(".number_of_injured").prop('disabled', true).val(""); modal.find(".number_of_died").prop('disabled', true).val(""); } else if (input == '1') { modal.find(".number_of_injured").prop('disabled', true).val(""); modal.find(".number_of_died").prop('disabled', true).val(""); } else if (input == '2') { modal.find(".number_of_injured").prop('disabled', false).val(""); modal.find(".number_of_died").prop('disabled', true).val(""); } else { modal.find(".number_of_injured").prop('disabled', false).val(""); modal.find(".number_of_died").prop('disabled', false).val(""); } } function checkAccidentParticipant(modal, value) { validation_role_for_enabled_vehicle[value].forEach(function(item) { modal.find(`#${item}`).prop('disabled', false); modal.find(`#${item}`).val(""); }); } $(document).on('click', '.btn-show-expert-message', function() { // xxx const modal = $("#show_expert_message_modal"); let tr = $(this).closest("tr"); let row = table.row(tr); let message = row.data().message; $("#show_expert_message").val(message); modal.modal("show"); }); $(document).on('click', '.btn-edit-accident', function() { const modal = $('#edit_accident_modal') const tr = $(this).closest("tr"); const row = table.row(tr); const id = row.data().id showLoaderScreen() $.ajax({ url: `https://rms.rmto.ir/daily_accident/${id}`, type: "GET", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, cache: false, contentType: false, processData: false, success: function(result) { modal.find('#edit_accident').data('rowId', id) modal.find('.required-text-inputs').val('') modal.find('.accident-participant-input').val('').prop('disabled', true) modal.find('.number_of_injured').prop('disabled', true) modal.find('.number_of_died').prop('disabled', true) modal.find('.select-inputs').val(0) modal.find('.accident-reasons').prop('checked', false) modal.find('.increase-damage-reasons').prop('checked', false) modal.find('.validity-checker').removeClass('validity-checker') modal.find(".img-input").val(""); modal.find(".img-preview").removeAttr("src"); modal.find(".img-preview").css("display", "none"); modal.find(".img-title").css("display", ""); modal.find('.btn-delete-img').attr("disabled", "disabled"); modal.find('.btn-delete-img').data('isDelete', false) modal.find('#edit_province_id').val(result.province_id) modal.find('#edit_axis_name').val(result.axis_name) modal.find('#edit_axis_type').val(result.axis_type) modal.find('#edit_axis_start').val(result.axis_start) modal.find('#edit_axis_end').val(result.axis_end) modal.find('#edit_distance_axis_start').val(result.distance_axis_start) modal.find('#edit_local_name').val(result.local_name) modal.find('#edit_police_serial').val(result.police_serial) modal.find('#edit_accident_type').val(result.accident_type) checkCountAccidentType(modal, result.accident_type) modal.find('#edit_number_of_injured').val(result.number_of_injured) modal.find('#edit_number_of_died').val(result.number_of_died) const accident_date = `${moment(result.accident_date).unix()}000` edit_accident_date.setDate(+accident_date) // console.log(new persianDate([moment(result.accident_date).locale('fa').format('YYYY'), moment(result.accident_date).locale('fa').format('MM'), moment(result.accident_date).locale('fa').format('DD')]).format('dddd')); // console.log("fukc"); // console.log([moment(result.accident_date).locale('fa').format('YYYY'), moment(result.accident_date).locale('fa').format('MM'), moment(result.accident_date).locale('fa').format('DD')]); modal.find('#edit_day_of_the_week').val(new persianDate([edit_accident_date.getState().selected.year, edit_accident_date.getState().selected.month, edit_accident_date.getState().selected.date]).format('dddd')) const accident_time = `${moment(`2020-10-20 ${result.accident_time}`).unix()}000` edit_accident_time.setDate(+accident_time) modal.find('#edit_weather_condition').val(result.weather_condition) modal.find('#edit_direction').val(result.direction) console.log(result.way_geometri); modal.find('#edit_way_geometri').val(result.way_geometri) modal.find('#edit_collision_type').val(result.collision_type) checkAccidentParticipant(modal, result.collision_type) modal.find('#bicycle').val(result.participants_bicycle) modal.find('#heavy_vehicle').val(result.participants_heavy_vehicle) modal.find('#light_vehicle').val(result.participants_light_vehicle) if (result.first_image != null) { modal.find('#deviceImg1Title').css('display', 'none') modal.find('#deviceImg1Preview').css('display', '') modal.find('#deviceImg1Preview').attr('src', `https://rms.rmto.ir/storage/${result.first_image}`) modal.find('#deleteDeviceImg1').prop('disabled', false) } if (result.second_image != null) { modal.find('#deviceImg2Title').css('display', 'none') modal.find('#deviceImg2Preview').css('display', '') modal.find('#deviceImg2Preview').attr('src', `https://rms.rmto.ir/storage/${result.second_image}`) modal.find('#deleteDeviceImg2').prop('disabled', false) } if (result.police_file != null) { modal.find('#deviceImg3Title').css('display', 'none') modal.find('#deviceImg3Preview').css('display', '') modal.find('#deviceImg3Preview').attr('src', `https://rms.rmto.ir/storage/${result.police_file}`) modal.find('#deleteDeviceImg3').prop('disabled', false) } modal.find('#edit_legal_speed').val(result.legal_speed) modal.find('#edit_avarage_speed').val(result.avarage_speed) result.accident_reason_adam_rayat_fasele_tooli == 1 ? modal.find('#edit_adam_rayat_fasele_tooli').prop('checked', true) : modal.find('#edit_adam_rayat_fasele_tooli').prop('checked', false) result.accident_reason_adam_rayat_obor == 1 ? modal.find('#edit_adam_rayat_obor').prop('checked', true) : modal.find('#edit_adam_rayat_obor').prop('checked', false) result.accident_reason_adam_rayat_sebghat_mojaz == 1 ? modal.find('#edit_adam_rayat_sebghat_mojaz').prop('checked', true) : modal.find('#edit_adam_rayat_sebghat_mojaz').prop('checked', false) result.accident_reason_adam_rayat_sorat_mojaz == 1 ? modal.find('#edit_adam_rayat_sorat_mojaz').prop('checked', true) : modal.find('#edit_adam_rayat_sorat_mojaz').prop('checked', false) result.accident_reason_adam_roshanaye_zarori_dar_noqte == 1 ? modal.find('#edit_adam_roshanaye_zarori_dar_noqte').prop('checked', true) : modal.find('#edit_adam_roshanaye_zarori_dar_noqte').prop('checked', false) result.accident_reason_arze_kam_savare_ro == 1 ? modal.find('#edit_arze_kam_savare_ro').prop('checked', true) : modal.find('#edit_arze_kam_savare_ro').prop('checked', false) result.accident_reason_did_na_kafi == 1 ? modal.find('#edit_did_na_kafi').prop('checked', true) : modal.find('#edit_did_na_kafi').prop('checked', false) result.accident_reason_dor_monaseb_dar_qus == 1 ? modal.find('#edit_dor_monaseb_dar_qus').prop('checked', true) : modal.find('#edit_dor_monaseb_dar_qus').prop('checked', false) result.accident_reason_ebham_dar_masir == 1 ? modal.find('#edit_ebham_dar_masir').prop('checked', true) : modal.find('#edit_ebham_dar_masir').prop('checked', false) result.accident_reason_hendese_na_monaseb_vorodi_va_khoroji == 1 ? modal.find('#edit_hendese_na_monaseb_vorodi_va_khoroji').prop('checked', true) : modal.find('#edit_hendese_na_monaseb_vorodi_va_khoroji').prop('checked', false) result.accident_reason_kahesh_na_monaseb_tedad == 1 ? modal.find('#edit_kahesh_na_monaseb_tedad').prop('checked', true) : modal.find('#edit_kahesh_na_monaseb_tedad').prop('checked', false) result.accident_reason_mahal_na_monaseb_dastrasi == 1 ? modal.find('#edit_mahal_na_monaseb_dastrasi').prop('checked', true) : modal.find('#edit_mahal_na_monaseb_dastrasi').prop('checked', false) result.accident_reason_mantaqe_ba_afzayesh_nagahani == 1 ? modal.find('#edit_mantaqe_ba_afzayesh_nagahani').prop('checked', true) : modal.find('#edit_mantaqe_ba_afzayesh_nagahani').prop('checked', false) result.accident_reason_mantaqe_ba_obor_heyvanat_ahli == 1 ? modal.find('#edit_mantaqe_ba_obor_heyvanat_ahli').prop('checked', true) : modal.find('#edit_mantaqe_ba_obor_heyvanat_ahli').prop('checked', false) result.accident_reason_mantaqe_ba_rizesh_az_divar == 1 ? modal.find('#edit_mantaqe_ba_rizesh_az_divar').prop('checked', true) : modal.find('#edit_mantaqe_ba_rizesh_az_divar').prop('checked', false) result.accident_reason_mantaqe_ba_tadakhol_terafiki == 1 ? modal.find('#edit_mantaqe_ba_tadakhol_terafiki').prop('checked', true) : modal.find('#edit_mantaqe_ba_tadakhol_terafiki').prop('checked', false) result.accident_reason_mantaqe_meh_gir == 1 ? modal.find('#edit_mantaqe_meh_gir').prop('checked', true) : modal.find('#edit_mantaqe_meh_gir').prop('checked', false) result.accident_reason_nabod_dar_khat_sebqat_dar_sarbalaye == 1 ? modal.find('#edit_nabod_dar_khat_sebqat_dar_sarbalaye').prop('checked', true) : modal.find('#edit_nabod_dar_khat_sebqat_dar_sarbalaye').prop('checked', false) result.accident_reason_naqs_dar_alayem_ekhtari_va_entezami == 1 ? modal.find('#edit_naqs_dar_alayem_ekhtari_va_entezami').prop('checked', true) : modal.find('#edit_naqs_dar_alayem_ekhtari_va_entezami').prop('checked', false) result.accident_reason_naqs_dar_alayem_pish_agahi == 1 ? modal.find('#edit_naqs_dar_alayem_pish_agahi').prop('checked', true) : modal.find('#edit_naqs_dar_alayem_pish_agahi').prop('checked', false) result.accident_reason_naqs_dar_ashkar_sazi_shrayet_khas == 1 ? modal.find('#edit_naqs_dar_ashkar_sazi_shrayet_khas').prop('checked', true) : modal.find('#edit_naqs_dar_ashkar_sazi_shrayet_khas').prop('checked', false) result.accident_reason_naqs_dar_ashkarsazi_navahi == 1 ? modal.find('#edit_naqs_dar_ashkarsazi_navahi').prop('checked', true) : modal.find('#edit_naqs_dar_ashkarsazi_navahi').prop('checked', false) result.accident_reason_oftadegi_dar_labe_asphalt == 1 ? modal.find('#edit_oftadegi_dar_labe_asphalt').prop('checked', true) : modal.find('#edit_oftadegi_dar_labe_asphalt').prop('checked', false) result.accident_reason_qarar_gire_qus_ofoqi == 1 ? modal.find('#edit_qarar_gire_qus_ofoqi').prop('checked', true) : modal.find('#edit_qarar_gire_qus_ofoqi').prop('checked', false) result.accident_reason_qus_ofoqi_dar_saraziri_tond == 1 ? modal.find('#edit_qus_ofoqi_dar_saraziri_tond').prop('checked', true) : modal.find('#edit_qus_ofoqi_dar_saraziri_tond').prop('checked', false) result.accident_reason_qus_tond_ofoghi == 1 ? modal.find('#edit_qus_tond_ofoghi').prop('checked', true) : modal.find('#edit_qus_tond_ofoghi').prop('checked', false) result.accident_reason_qus_tond_qaem == 1 ? modal.find('#edit_qus_tond_qaem').prop('checked', true) : modal.find('#edit_qus_tond_qaem').prop('checked', false) result.accident_reason_roye_na_monaseb == 1 ? modal.find('#edit_roye_na_monaseb').prop('checked', true) : modal.find('#edit_roye_na_monaseb').prop('checked', false) result.accident_reason_saraziri_tond == 1 ? modal.find('#edit_saraziri_tond').prop('checked', true) : modal.find('#edit_saraziri_tond').prop('checked', false) result.accident_reason_tabdil_na_monaseb_noe_rah == 1 ? modal.find('#edit_tabdil_na_monaseb_noe_rah').prop('checked', true) : modal.find('#edit_tabdil_na_monaseb_noe_rah').prop('checked', false) result.increase_damage_reasons_feqdan_jodakonnande_dar_miyane_rah == 1 ? modal.find('#edit_feqdan_jodakonnande_dar_miyane_rah').prop('checked', true) : modal.find('#edit_feqdan_jodakonnande_dar_miyane_rah').prop('checked', false) result.increase_damage_reasons_mane_solb_bedone_hefaz == 1 ? modal.find('#edit_mane_solb_bedone_hefaz').prop('checked', true) : modal.find('#edit_mane_solb_bedone_hefaz').prop('checked', false) result.increase_damage_reasons_naqs_dar_naheye_enteqali == 1 ? modal.find('#edit_naqs_dar_naheye_enteqali').prop('checked', true) : modal.find('#edit_naqs_dar_naheye_enteqali').prop('checked', false) result.increase_damage_reasons_naqs_ya_adam_kefayat == 1 ? modal.find('#edit_naqs_ya_adam_kefayat').prop('checked', true) : modal.find('#edit_naqs_ya_adam_kefayat').prop('checked', false) result.increase_damage_reasons_naqs_ya_adam_kefayat_hefaze_miyani == 1 ? modal.find('#edit_naqs_ya_adam_kefayat_hefaze_miyani').prop('checked', true) : modal.find('#edit_naqs_ya_adam_kefayat_hefaze_miyani').prop('checked', false) result.increase_damage_reasons_naqs_ya_adam_kefayat_narde_pol == 1 ? modal.find('#edit_naqs_ya_adam_kefayat_narde_pol').prop('checked', true) : modal.find('#edit_naqs_ya_adam_kefayat_narde_pol').prop('checked', false) result.increase_damage_reasons_sar_azad_hefaz == 1 ? modal.find('#edit_sar_azad_hefaz').prop('checked', true) : modal.find('#edit_sar_azad_hefaz').prop('checked', false) result.increase_damage_reasons_shirvani_tond_ya_partgah == 1 ? modal.find('#edit_shirvani_tond_ya_partgah').prop('checked', true) : modal.find('#edit_shirvani_tond_ya_partgah').prop('checked', false) if (modal.find('.accident-reasons:checked').length == modal.find('.accident-reasons').length) { modal.find('.select_all_accident_reasons').prop('checked', true) } else { modal.find('.select_all_accident_reasons').prop('checked', false) } if (modal.find('.increase-damage-reasons:checked').length == modal.find('.increase-damage-reasons').length) { modal.find('.select_all_increase_damage_reasons').prop('checked', true) } else { modal.find('.select_all_increase-damage_reasons').prop('checked', false) } createEditMap(modal, result.lat, result.lng).then(() => { editMap.setView([result.lat, result.lng], 7) isSetMarkerEdit = true; markerEdit.setLatLng(L.latLng([result.lat, result.lng])); modal.find("#edit_project_start_map").val( markerEdit.getLatLng().lat.toFixed(6) + markerEdit.getLatLng().lng.toFixed(6) ); //yasi modal.find("#pin_marker").removeClass("pin-move pin-warn").addClass("pin-set"); hideLoaderScreen() }) modal.modal('show') }, error: function (error) { hideLoaderScreen(); $("#add_accident").prop("disabled", false); Swal.fire({ icon: "error", title: "خطا", text: "مشکل در ارتباط با سرور", confirmButtonText: "بستن", }); }, }); }) $(document).on("click", "#edit_accident", function () { const modal = $(this).parents('.modal') $("#edit_accident").prop("disabled", true); if (validateForm(modal)) { if (validateReasons(modal.find("#edit_accident_type").val())) { if (validateAddAccidentParticipant($("#edit_collision_type").val(), modal)) { let formData = new FormData(); formData.append("province_id", modal.find("#edit_province_id").val()); formData.append("axis_name", modal.find("#edit_axis_name").val()); formData.append("axis_type", modal.find("#edit_axis_type").val()); formData.append("axis_start", modal.find("#edit_axis_start").val()); formData.append("axis_end", modal.find("#edit_axis_end").val()); formData.append("distance_axis_start", modal.find("#edit_distance_axis_start").val()); formData.append("local_name", modal.find("#edit_local_name").val()); formData.append("lat", markerEdit.getLatLng().lat.toFixed(6)); formData.append("lng", markerEdit.getLatLng().lng.toFixed(6)); formData.append("way_geometri", modal.find("#edit_way_geometri").val()); formData.append("police_serial", modal.find("#edit_police_serial").val()); formData.append("avarage_speed", modal.find("#edit_avarage_speed").val()); formData.append("legal_speed", modal.find("#edit_legal_speed").val()); formData.append("accident_date", moment(edit_accident_date.getState().selected.unixDate).format('YYYY-MM-DD')); formData.append("accident_time", moment(edit_accident_time.getState().selected.unixDate).format('HH:mm')); formData.append("day_of_the_week", modal.find("#edit_day_of_the_week").val()); formData.append("direction", modal.find("#edit_direction").val()); formData.append("number_of_injured", modal.find("#edit_number_of_injured").val()); formData.append("number_of_died", modal.find("#edit_number_of_died").val()); formData.append("weather_condition", modal.find("#edit_weather_condition").val()); formData.append("collision_type", modal.find("#edit_collision_type").val()); formData.append("accident_type", modal.find("#edit_accident_type").val()); formData.append("participants_heavy_vehicle", modal.find("#heavy_vehicle").val()); formData.append("participants_light_vehicle", modal.find("#light_vehicle").val()); formData.append("participants_bicycle", modal.find("#bicycle").val()); const first_image = modal.find("#editdeviceImg1").get(0).files[0] if (typeof first_image !== "undefined") formData.append("first_image", first_image); if (modal.find('#deleteDeviceImg1').data('isDelete')) formData.append("first_image_is_deleted", 1) const second_image = modal.find("#editdeviceImg2").get(0).files[0] if (typeof second_image !== "undefined") formData.append("second_image", second_image); if (modal.find('#deleteDeviceImg2').data('isDelete')) formData.append("second_image_is_deleted", 1) const police_file = modal.find("#editdeviceImg3").get(0).files[0] if (typeof police_file !== "undefined") formData.append("police_file", police_file); if (modal.find('#deleteDeviceImg3').data('isDelete')) formData.append("police_file_is_deleted", 1) modal.find(".increase-damage-reasons").each(function (index, item) { modal.find(item).is(":checked") ? formData.append(modal.find(item).prop("name"), 1) : formData.append($(item).prop("name"), 0) }); modal.find(".accident-reasons").each(function (index, item) { modal.find(item).is(":checked") ? formData.append(modal.find(item).prop("name"), 1) : formData.append($(item).prop("name"), 0) }); showLoaderScreen(); $.ajax({ url: "https://rms.rmto.ir/daily_accident/update/" + modal.find('#edit_accident').data('rowId'), type: "POST", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, data: formData, cache: false, contentType: false, processData: false, success: function (result) { hideLoaderScreen(); $("#edit_accident").prop("disabled", false); modal.modal("hide"); Swal.fire({ icon: "success", text: " تصادف با موفقیت ویرایش شد", confirmButtonText: "بستن", }); table.ajax.reload(null, false); }, error: function (error) { hideLoaderScreen(); $("#edit_accident").prop("disabled", false); Swal.fire({ icon: "error", title: "خطا", text: "مشکل در ارتباط با سرور", confirmButtonText: "بستن", }); }, }); } else { $("#edit_accident").prop("disabled", false); } } else { $("#edit_accident").prop("disabled", false); } } else { Swal.fire({ icon: "error", title: "خطا", text: "لطفا مقادیر را به درستی وارد نمایید.", confirmButtonText: "بستن ", }); $("#edit_accident").prop("disabled", false); } }); $(document).on('click', '.btn-delete-accident', function () { let tr = $(this).closest("tr"); let row = table.row(tr); let row_id = row.data().id; let formData = new FormData(); Swal.fire({ icon: "warning", title: "آیا برای حذف مطمئن هستید؟", showCancelButton: true, confirmButtonColor: "#3085d6", cancelButtonColor: "#d33", confirmButtonText: "بله، حذف می‌شود", cancelButtonText: "منصرف شدم!", showLoaderOnConfirm: true, preConfirm: () => { showLoaderScreen(); $.ajax({ url: "https://rms.rmto.ir/daily_accident/delete/" + row_id, type: "POST", headers: { "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"), }, cache: false, contentType: false, processData: false, beforeSend: function () { showLoaderScreen(); }, success: function (result) { table.ajax.reload(null, false); hideLoaderScreen(); }, error: function (error) { hideLoaderScreen(); Swal.fire({ icon: "error", title: "خطا", text: "مشکل در برقراری ارتباط با سرور", confirmButtonText: "بستن", }); }, }); }, }); }) $("input[name=add_project_start_map]").on("keyup", function () { checkMarkerValidation(); }); $("input[name=edit_project_start_map]").on("keyup", function () { checkMarkerAddValidation(); }); $(document).on("change", "#add_province_id", function () { let center_lat = $(this).find("option:selected").data("centerLat"); let center_lng = $(this).find("option:selected").data("centerLng"); addMap.panTo(new L.LatLng(center_lat, center_lng)); if (isSetMarkerAdd) { markerAdd.setLatLng(L.latLng([center_lat, center_lng])); } }); function checkMarkerValidation(forSaveData = false, pageOnLoad = false) { const modal = $('#add_accident_modal') let reg = /^([0-9]){2}\.([0-9])+$/; let startLatLngVal = $( "input[name=add_project_start_map]" ) .val() .split(" - "); let startLatLng = startLatLngVal.map(function (e) { e = e.replace(/_/g, ""); return parseFloat(e.slice(1, -1)); }); if (isNaN(startLatLng[0])) { if (!forSaveData) { $("input[name=add_project_start_map]").removeClass( "is-invalid-input" ); } else { $("input[name=add_project_start_map]").addClass( "is-invalid-input" ); } modal.find("#pin_marker").removeClass("pin-move pin-set"); $("input[name=add_project_start_map]").val(""); $("input[name=add_project_start_map]").attr( "placeholder", "(شروع) => (عرض جغرافیایی) - (طول جغرافیایی)" ); return false; } else if ( !startLatLng == 2 || !reg.test(startLatLng[0]) || !reg.test(startLatLng[1]) ) { $("input[name=add_project_start_map]").addClass( "is-invalid-input" ); modal.find("#pin_marker").removeClass("pin-move pin-set"); return false; } else { if (!forSaveData) { $("input[name=add_project_start_map]").removeClass( "is-invalid-input" ); markerAdd.setLatLng(startLatLng); if (pageOnLoad) { setTimeout(() => { modal.find("#pin_marker").removeClass("pin-move").addClass("pin-set"); markerAdd.setLatLng(startLatLng); }, 10); } else { modal.find("#pin_marker").removeClass("pin-move").addClass("pin-set"); } } addMap.panTo(new L.LatLng(startLatLng[0], startLatLng[1])); if (isSetMarkerAdd) { markerAdd.setLatLng(L.latLng([startLatLng[0], startLatLng[1]])); } isSetMarkerAdd = true; return true; } } function checkMarkerAddValidation(forSaveData = false, pageOnLoad = false) { const modal = $('#edit_accident_modal') let reg = /^([0-9]){2}\.([0-9])+$/; let startLatLngVal = $( "input[name=edit_project_start_map]" ) .val() .split(" - "); let startLatLng = startLatLngVal.map(function (e) { e = e.replace(/_/g, ""); return parseFloat(e.slice(1, -1)); }); if (isNaN(startLatLng[0])) { if (!forSaveData) { $("input[name=edit_project_start_map]").removeClass( "is-invalid-input" ); } else { $("input[name=edit_project_start_map]").addClass( "is-invalid-input" ); } modal.find("#pin_marker").removeClass("pin-move pin-set"); $("input[name=edit_project_start_map]").val(""); $("input[name=edit_project_start_map]").attr( "placeholder", "(شروع) => (عرض جغرافیایی) - (طول جغرافیایی)" ); return false; } else if ( !startLatLng == 2 || !reg.test(startLatLng[0]) || !reg.test(startLatLng[1]) ) { $("input[name=edit_project_start_map]").addClass( "is-invalid-input" ); modal.find("#pin_marker").removeClass("pin-move pin-set"); return false; } else { if (!forSaveData) { $("input[name=edit_project_start_map]").removeClass( "is-invalid-input" ); markerEdit.setLatLng(startLatLng); if (pageOnLoad) { setTimeout(() => { modal.find("#pin_marker").removeClass("pin-move").addClass("pin-set"); markerEdit.setLatLng(startLatLng); }, 10); } else { modal.find("#pin_marker").removeClass("pin-move").addClass("pin-set"); } } editMap.panTo(new L.LatLng(startLatLng[0], startLatLng[1])); if (isSetMarkerEdit) { markerEdit.setLatLng(L.latLng([startLatLng[0], startLatLng[1]])); } isSetMarkerEdit = true; return true; } } $(document).on("change", "#edit_province_id", function () { let center_lat = $(this).find("option:selected").data("centerLat"); let center_lng = $(this).find("option:selected").data("centerLng"); editMap.panTo(new L.LatLng(center_lat, center_lng)); if (isSetMarkerEdit) { markerEdit.setLatLng(L.latLng([center_lat, center_lng])); } }); $(document).on("click", ".expert_confirmation", function () { const modal = $("#expert_confirmation_modal"); modal.modal("show"); const all_sub_items = modal.find(".item-ex-conf"); all_sub_items.find("h6").css("color", "#000") const tr = $(this).closest("tr"); const row = table.row(tr); const id = row.data().id; modal.find("button[type='unconfirm']").data("rowId", id); modal.find("button[type='confirm']").data("rowId", id); $.ajax({ url: `https://rms.rmto.ir/daily_accident/${id}`, type: "GET", cache: false, async: false, contentType: false, processData: false, success: function (results) { $("#accident_time").text(results.accident_time); $("#day_of_the_week").text(results.day_of_the_week); $("#province_fa").text(results.province_fa); $("#legal_speed").text(results.legal_speed); $("#avarage_speed").text(results.avarage_speed); $("#collision_type_fa").text(results.collision_type_fa); $("#accident_type_fa").text(results.accident_type_fa); $("#axis_name").text(results.axis_name); $("#axis_start").text(results.axis_start); $("#axis_end").text(results.axis_end); $("#axis_type_fa").text(results.axis_type_fa); $("#direction_fa").text(results.direction_fa); $("#lat").text(results.lat); $("#lng").text(results.lng); $("#way_geometri_fa").text(results.way_geometri_fa); $("#local_name").text(results.local_name); $("#weather_condition_fa").text(results.weather_condition_fa); $("#accident_date").text(results.accident_date); results.accident_reason_adam_rayat_fasele_tooli == 1 ? modal.find('#adam_rayat_fasele_tooli').prop('checked', true) && modal.find("#adam_rayat_fasele_tooli").parents("h6").css("color", "#ff5c0f") : modal.find('#adam_rayat_fasele_tooli').prop('checked', false) results.accident_reason_adam_rayat_obor == 1 ? modal.find('#adam_rayat_obor').prop('checked', true) && modal.find("#adam_rayat_obor").parents("h6").css("color", "#ff5c0f") : modal.find('#adam_rayat_obor').prop('checked', false) results.accident_reason_adam_rayat_sebghat_mojaz == 1 ? modal.find('#adam_rayat_sebghat_mojaz').prop('checked', true) && modal.find("#adam_rayat_sebghat_mojaz").parents("h6").css("color", "#ff5c0f") : modal.find('#adam_rayat_sebghat_mojaz').prop('checked', false) results.accident_reason_adam_rayat_sorat_mojaz == 1 ? modal.find('#adam_rayat_sorat_mojaz').prop('checked', true) && modal.find("#adam_rayat_sorat_mojaz").parents("h6").css("color", "#ff5c0f") : modal.find('#adam_rayat_sorat_mojaz').prop('checked', false) results.accident_reason_adam_roshanaye_zarori_dar_noqte == 1 ? modal.find('#adam_roshanaye_zarori_dar_noqte').prop('checked', true) && modal.find("#adam_roshanaye_zarori_dar_noqte").parents("h6").css("color", "#ff5c0f") : modal.find('#adam_roshanaye_zarori_dar_noqte').prop('checked', false) results.accident_reason_arze_kam_savare_ro == 1 ? modal.find('#arze_kam_savare_ro').prop('checked', true) && modal.find("#arze_kam_savare_ro").parents("h6").css("color", "#ff5c0f") : modal.find('#arze_kam_savare_ro').prop('checked', false) results.accident_reason_did_na_kafi == 1 ? modal.find('#did_na_kafi').prop('checked', true) && modal.find("#did_na_kafi").parents("h6").css("color", "#ff5c0f") : modal.find('#did_na_kafi').prop('checked', false) results.accident_reason_dor_monaseb_dar_qus == 1 ? modal.find('#dor_monaseb_dar_qus').prop('checked', true) && modal.find("#dor_monaseb_dar_qus").parents("h6").css("color", "#ff5c0f") : modal.find('#dor_monaseb_dar_qus').prop('checked', false) results.accident_reason_ebham_dar_masir == 1 ? modal.find('#ebham_dar_masir').prop('checked', true) && modal.find("#ebham_dar_masir").parents("h6").css("color", "#ff5c0f") : modal.find('#ebham_dar_masir').prop('checked', false) results.accident_reason_hendese_na_monaseb_vorodi_va_khoroji == 1 ? modal.find('#hendese_na_monaseb_vorodi_va_khoroji').prop('checked', true) && modal.find("#hendese_na_monaseb_vorodi_va_khoroji").parents("h6").css("color", "#ff5c0f") : modal.find('#hendese_na_monaseb_vorodi_va_khoroji').prop('checked', false) results.accident_reason_kahesh_na_monaseb_tedad == 1 ? modal.find('#kahesh_na_monaseb_tedad').prop('checked', true) && modal.find("#kahesh_na_monaseb_tedad").parents("h6").css("color", "#ff5c0f") : modal.find('#kahesh_na_monaseb_tedad').prop('checked', false) results.accident_reason_mahal_na_monaseb_dastrasi == 1 ? modal.find('#mahal_na_monaseb_dastrasi').prop('checked', true) && modal.find("#mahal_na_monaseb_dastrasi").parents("h6").css("color", "#ff5c0f") : modal.find('#mahal_na_monaseb_dastrasi').prop('checked', false) results.accident_reason_mantaqe_ba_afzayesh_nagahani == 1 ? modal.find('#mantaqe_ba_afzayesh_nagahani').prop('checked', true) && modal.find("#mantaqe_ba_afzayesh_nagahani").parents("h6").css("color", "#ff5c0f") : modal.find('#mantaqe_ba_afzayesh_nagahani').prop('checked', false) results.accident_reason_mantaqe_ba_obor_heyvanat_ahli == 1 ? modal.find('#mantaqe_ba_obor_heyvanat_ahli').prop('checked', true) && modal.find("#mantaqe_ba_obor_heyvanat_ahli").parents("h6").css("color", "#ff5c0f") : modal.find('#mantaqe_ba_obor_heyvanat_ahli').prop('checked', false) results.accident_reason_mantaqe_ba_rizesh_az_divar == 1 ? modal.find('#mantaqe_ba_rizesh_az_divar').prop('checked', true) && modal.find("#mantaqe_ba_rizesh_az_divar").parents("h6").css("color", "#ff5c0f") : modal.find('#mantaqe_ba_rizesh_az_divar').prop('checked', false) results.accident_reason_mantaqe_ba_tadakhol_terafiki == 1 ? modal.find('#mantaqe_ba_tadakhol_terafiki').prop('checked', true) && modal.find("#mantaqe_ba_tadakhol_terafiki").parents("h6").css("color", "#ff5c0f") : modal.find('#mantaqe_ba_tadakhol_terafiki').prop('checked', false) results.accident_reason_mantaqe_meh_gir == 1 ? modal.find('#mantaqe_meh_gir').prop('checked', true) && modal.find("#mantaqe_meh_gir").parents("h6").css("color", "#ff5c0f") : modal.find('#mantaqe_meh_gir').prop('checked', false) results.accident_reason_nabod_dar_khat_sebqat_dar_sarbalaye == 1 ? modal.find('#nabod_dar_khat_sebqat_dar_sarbalaye').prop('checked', true) && modal.find("#nabod_dar_khat_sebqat_dar_sarbalaye").parents("h6").css("color", "#ff5c0f") : modal.find('#nabod_dar_khat_sebqat_dar_sarbalaye').prop('checked', false) results.accident_reason_naqs_dar_alayem_ekhtari_va_entezami == 1 ? modal.find('#naqs_dar_alayem_ekhtari_va_entezami').prop('checked', true) && modal.find("#naqs_dar_alayem_ekhtari_va_entezami").parents("h6").css("color", "#ff5c0f") : modal.find('#naqs_dar_alayem_ekhtari_va_entezami').prop('checked', false) results.accident_reason_naqs_dar_alayem_pish_agahi == 1 ? modal.find('#naqs_dar_alayem_pish_agahi').prop('checked', true) && modal.find("#naqs_dar_alayem_pish_agahi").parents("h6").css("color", "#ff5c0f") : modal.find('#naqs_dar_alayem_pish_agahi').prop('checked', false) results.accident_reason_naqs_dar_ashkar_sazi_shrayet_khas == 1 ? modal.find('#naqs_dar_ashkar_sazi_shrayet_khas').prop('checked', true) && modal.find("#naqs_dar_ashkar_sazi_shrayet_khas").parents("h6").css("color", "#ff5c0f") : modal.find('#naqs_dar_ashkar_sazi_shrayet_khas').prop('checked', false) results.accident_reason_naqs_dar_ashkarsazi_navahi == 1 ? modal.find('#naqs_dar_ashkarsazi_navahi').prop('checked', true) && modal.find("#naqs_dar_ashkarsazi_navahi").parents("h6").css("color", "#ff5c0f") : modal.find('#naqs_dar_ashkarsazi_navahi').prop('checked', false) results.accident_reason_oftadegi_dar_labe_asphalt == 1 ? modal.find('#oftadegi_dar_labe_asphalt').prop('checked', true) && modal.find("#oftadegi_dar_labe_asphalt").parents("h6").css("color", "#ff5c0f") : modal.find('#oftadegi_dar_labe_asphalt').prop('checked', false) results.accident_reason_qarar_gire_qus_ofoqi == 1 ? modal.find('#qarar_gire_qus_ofoqi').prop('checked', true) && modal.find("#qarar_gire_qus_ofoqi").parents("h6").css("color", "#ff5c0f") : modal.find('#qarar_gire_qus_ofoqi').prop('checked', false) results.accident_reason_qus_ofoqi_dar_saraziri_tond == 1 ? modal.find('#qus_ofoqi_dar_saraziri_tond').prop('checked', true) && modal.find("#qus_ofoqi_dar_saraziri_tond").parents("h6").css("color", "#ff5c0f") : modal.find('#qus_ofoqi_dar_saraziri_tond').prop('checked', false) results.accident_reason_qus_tond_ofoghi == 1 ? modal.find('#qus_tond_ofoghi').prop('checked', true) && modal.find("#qus_tond_ofoghi").parents("h6").css("color", "#ff5c0f") : modal.find('#qus_tond_ofoghi').prop('checked', false) results.accident_reason_qus_tond_qaem == 1 ? modal.find('#qus_tond_qaem').prop('checked', true) && modal.find("#qus_tond_qaem").parents("h6").css("color", "#ff5c0f") : modal.find('#qus_tond_qaem').prop('checked', false) results.accident_reason_roye_na_monaseb == 1 ? modal.find('#roye_na_monaseb').prop('checked', true) && modal.find("#roye_na_monaseb").parents("h6").css("color", "#ff5c0f") : modal.find('#roye_na_monaseb').prop('checked', false) results.accident_reason_saraziri_tond == 1 ? modal.find('#saraziri_tond').prop('checked', true) && modal.find("#saraziri_tond").parents("h6").css("color", "#ff5c0f") : modal.find('#saraziri_tond').prop('checked', false) results.accident_reason_tabdil_na_monaseb_noe_rah == 1 ? modal.find('#tabdil_na_monaseb_noe_rah').prop('checked', true) && modal.find("#tabdil_na_monaseb_noe_rah").parents("h6").css("color", "#ff5c0f") : modal.find('#tabdil_na_monaseb_noe_rah').prop('checked', false) results.increase_damage_reasons_feqdan_jodakonnande_dar_miyane_rah == 1 ? modal.find('#feqdan_jodakonnande_dar_miyane_rah').prop('checked', true) && modal.find("#feqdan_jodakonnande_dar_miyane_rah").parents("h6").css("color", "#ff5c0f") : modal.find('#feqdan_jodakonnande_dar_miyane_rah').prop('checked', false) results.increase_damage_reasons_mane_solb_bedone_hefaz == 1 ? modal.find('#mane_solb_bedone_hefaz').prop('checked', true) && modal.find("#mane_solb_bedone_hefaz").parents("h6").css("color", "#ff5c0f") : modal.find('#mane_solb_bedone_hefaz').prop('checked', false) results.increase_damage_reasons_naqs_dar_naheye_enteqali == 1 ? modal.find('#naqs_dar_naheye_enteqali').prop('checked', true) && modal.find("#naqs_dar_naheye_enteqali").parents("h6").css("color", "#ff5c0f") : modal.find('#naqs_dar_naheye_enteqali').prop('checked', false) results.increase_damage_reasons_naqs_ya_adam_kefayat == 1 ? modal.find('#naqs_ya_adam_kefayat').prop('checked', true) && modal.find("#naqs_ya_adam_kefayat").parents("h6").css("color", "#ff5c0f") : modal.find('#naqs_ya_adam_kefayat').prop('checked', false) results.increase_damage_reasons_naqs_ya_adam_kefayat_hefaze_miyani == 1 ? modal.find('#naqs_ya_adam_kefayat_hefaze_miyani').prop('checked', true) && modal.find("#naqs_ya_adam_kefayat_hefaze_miyani").parents("h6").css("color", "#ff5c0f") : modal.find('#naqs_ya_adam_kefayat_hefaze_miyani').prop('checked', false) results.increase_damage_reasons_naqs_ya_adam_kefayat_narde_pol == 1 ? modal.find('#naqs_ya_adam_kefayat_narde_pol').prop('checked', true) && modal.find("#naqs_ya_adam_kefayat_narde_pol").parents("h6").css("color", "#ff5c0f") : modal.find('#naqs_ya_adam_kefayat_narde_pol').prop('checked', false) results.increase_damage_reasons_sar_azad_hefaz == 1 ? modal.find('#sar_azad_hefaz').prop('checked', true) && modal.find("#sar_azad_hefaz").parents("h6").css("color", "#ff5c0f") : modal.find('#sar_azad_hefaz').prop('checked', false) results.increase_damage_reasons_shirvani_tond_ya_partgah == 1 ? modal.find('#shirvani_tond_ya_partgah').prop('checked', true) && modal.find("#shirvani_tond_ya_partgah").parents("h6").css("color", "#ff5c0f") : modal.find('#shirvani_tond_ya_partgah').prop('checked', false) }, error: function () { Swal.fire({ icon: "error", title: "خطا", text: "مشکل در دریافت سطح دسترسی", confirmButtonText: "بروزرسانی صفحه", showLoaderOnConfirm: true, preConfirm: () => { location.reload(true); }, }); }, }); }); // unconfirm accident [modal oppening] $(document).on('click', '#unconfirm', function () { const modal = $("#expert_message"); modal.find("button[type='submit']").data("rowId", $(this).data("rowId")); modal.modal("show"); modal.find(".make-clean-textarea").val(""); }); // end unconfirm accident // confirm [submmit] $(document).on('click', '#confirm', function () { const modal = $(this).parents(".modal"); Swal.fire({ icon: "warning", title: "آیا برای تایید مطمئن هستید؟", showCancelButton: true, confirmButtonColor: "#3085d6", cancelButtonColor: "#d33", confirmButtonText: "بله، تایید می‌شود", cancelButtonText: "منصرف شدم!", showLoaderOnConfirm: true, preConfirm: () => { let formData = new FormData(); formData.append("state", 1); $.ajax({ url: `https://rms.rmto.ir/daily_accident/set_state/${modal.find("button[type='confirm']").data("rowId")}`, 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("button[type='confirm']").prop("disabled", true); }, success: function (result) { modal.modal("hide"); Swal.fire({ icon: "success", title: `انجام شد`, text: `پیام شما با موفقیت ثبت شد`, heightAuto: false, showConfirmButton: false, timer: 1500, }); table.ajax.reload(); }, error: function (request) { Swal.fire({ icon: "error", title: "خطا", text: "مشکل در تایید", confirmButtonText: "بستن", showLoaderOnConfirm: true, }); modal.find("button[type='confirm']").prop("disabled", false); }, complete: function (data) { hideLoaderScreen(); modal.find("button[type='confirm']").prop("disabled", false); }, }); }, }); }); // end confirm $(document).on("click", "#record_message", function () { const modal = $(this).parents(".modal"); if ($("#create_expert_message").val() == "") { $("#create_expert_message").css("border-color", "crimson"); Swal.fire({ icon: "error", title: "خطا", text: "لطفا فیلد مشخص شده را پر کنید", confirmButtonText: "بستن", showLoaderOnConfirm: true, }); } else { const state = 0; const message = modal.find("#create_expert_message").val(); let formData = new FormData(); formData.append("state", state); formData.append("message", message); $.ajax({ url: `https://rms.rmto.ir/daily_accident/set_state/${modal.find("#record_message").data("rowId")}`, 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("#record_message").prop("disabled", true); }, success: function (result) { modal.modal("hide"); $("#expert_confirmation_modal").modal("hide"); Swal.fire({ icon: "success", title: `انجام شد`, text: `پیام شما با موفقیت ثبت شد`, heightAuto: false, showConfirmButton: false, timer: 1500, }); table.ajax.reload(); }, error: function (request) { modal.find("#record_message").prop("disabled", false); }, complete: function (data) { hideLoaderScreen(); modal.find("#record_message").prop("disabled", false); }, }); } }); $("#main-table-points").on("click", ".btn-showOnMap-dailyAccident", function () { showLoaderScreen(); const modal = $("#show_dailyAccident_modal"); const tr = $(this).closest("tr"); const row = table.row(tr); const row_lat = row.data().lat; const 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(); }); } else { changePositionMarkerInMapShow(markerPosition).then(() => { hideLoaderScreen(); }); } modal.modal("show"); }); function appendYearFilter() { var current_year; $(".yearfilter").append(``); current_year = new persianDate().year(); for (let i = 1398; i <= current_year; i++) { $(".yearfilter").append( "\ \ " ); } } $(document).on("click", "#btn_filter_show", function () { _table = table; var currentFilterQueryto = ""; var currentFilterQueryfrom = ""; var currentDate = {}; const province_value = $("#select-province option:selected"); const collision_type = $("#filter_collision_type option:selected"); const axis_value = $("#filter_axis_type option:selected"); const way_geometry = $("#filter_way_geometri option:selected"); const timePicker = $("#timePicker"); currentFilterYear = $('select[name="yearfilter"]').val(); if (currentFilterYear != 0) { currentDate.from = moment(currentFilterYear, "jYYYY"); currentFilterQueryfrom = currentDate.from.locale("en").format("YYYY-MM-DD"); currentDate.to = moment(currentFilterYear, "jYYYY"); currentDate.to.add(1, "year"); currentFilterQueryto = currentDate.to.locale("en").format("YYYY-MM-DD"); } console.log(currentFilterQueryfrom); console.log(currentFilterQueryto); if (province_value.val() != 0) { _table = _table.column(1).search(province_value.text()) } else { _table = _table.column(1).search('') } if (collision_type.val() != 0) { _table = _table.column(9).search(collision_type.text()) } else { _table = _table.column(9).search('') } if (axis_value.val() != 0) { _table = _table.column(3).search(axis_value.text()) } else { _table = _table.column(3).search('') } if (way_geometry.val() != 0) { _table = _table.column(10).search(way_geometry.text()) } else { _table = _table.column(10).search('') } if (currentFilterYear != 0) { _table = _table.column(14).search(currentFilterQueryfrom + "&" + currentFilterQueryto) } else { _table = _table.column(14).search('') } if (timePicker.val() != 0) { if (timePicker.val() == 1) { _table = _table.column(13).search("06:00:00&18:00:00"); }else { _table = _table.column(13).search("18:00:01&23:59:59_00:00:00&05:59:59"); } }else { _table = _table.column(13).search(''); } _table.draw(); }); $("#btn_excel-download").on("click", function () { let currentDate = {}; let queryParems = []; const province = $('select[name="select-province-excel"]').val(); if (!( $("#datapicker-from-excel-table").is(":disabled") && $("#datapicker-to-excel-table").is(":disabled") )) { if ( excelDatepickerFirstTable.from != "" && excelDatepickerFirstTable.to != "" ) { currentDate.from = moment( excelDatepickerFirstTable.from.getState().selected.year + "/" + excelDatepickerFirstTable.from.getState().selected.month + "/" + excelDatepickerFirstTable.from.getState().selected.date, "jYYYY/jM/jD" ).format("YYYY-MM-DD"); currentDate.to = moment( excelDatepickerFirstTable.to.getState().selected.year + "/" + excelDatepickerFirstTable.to.getState().selected.month + "/" + excelDatepickerFirstTable.to.getState().selected.date, "jYYYY/jM/jD" ).format("YYYY-MM-DD"); queryParems.push(`fromDate=${currentDate.from}`); queryParems.push(`toDate=${currentDate.to}`); } } if (province != 0) queryParems.push(`province=${province}`); const url = `https://rms.rmto.ir/reports/daily-accident${queryParems.length != 0 ? `?${queryParems.join("&")}` : ""}`; window.open(url, "_blank"); }); $("#btn_poster-download").on("click", function () { let currentDate = {}; let queryParems = []; const province = $('select[name="select-province-poster"]').val(); if (province != 0) queryParems.push(`province_id=${province}`); if (!( $("#datapicker-from-poster-table").is(":disabled") && $("#datapicker-to-poster-table").is(":disabled") )) { if ( posterDatepickerFirstTable.from != "" && posterDatepickerFirstTable.to != "" ) { currentDate.from = moment( posterDatepickerFirstTable.from.getState().selected.year + "/" + posterDatepickerFirstTable.from.getState().selected.month + "/" + posterDatepickerFirstTable.from.getState().selected.date, "jYYYY/jM/jD" ).format("YYYY-MM-DD"); currentDate.to = moment( posterDatepickerFirstTable.to.getState().selected.year + "/" + posterDatepickerFirstTable.to.getState().selected.month + "/" + posterDatepickerFirstTable.to.getState().selected.date, "jYYYY/jM/jD" ).format("YYYY-MM-DD"); queryParems.push(`from_date=${currentDate.from}`); queryParems.push(`to_date=${currentDate.to}`); } } const url = `https://rms.rmto.ir/daily_accident_poster${queryParems.length != 0 ? `?${queryParems.join("&")}` : ""}`; window.open(url, "_blank"); });