879 lines
36 KiB
JavaScript
879 lines
36 KiB
JavaScript
var isValidProvider = false;
|
||
var isValidCity = false;
|
||
var isNationalCode = false;
|
||
var isSend = false;
|
||
var url = '/';
|
||
let id;
|
||
|
||
$(function () {
|
||
// create toast
|
||
const Toast = Swal.mixin({
|
||
toast: true,
|
||
position: 'top-end',
|
||
showConfirmButton: false,
|
||
timer: 3000,
|
||
timerProgressBar: true,
|
||
didOpen: (toast) => {
|
||
toast.addEventListener('mouseenter', Swal.stopTimer)
|
||
toast.addEventListener('mouseleave', Swal.resumeTimer)
|
||
}
|
||
})
|
||
|
||
//get data by id
|
||
id = $('#form_id').val();
|
||
|
||
$.ajax({
|
||
async: false,
|
||
url: url + "webapi/cmms/provinces/all",
|
||
type: "GET",
|
||
headers: {
|
||
accept: "application/json",
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (res) {
|
||
$("#province").empty();
|
||
$("#province").append('<option value="0">انتخاب استان</option>');
|
||
$.each(res.data, function (key, value) {
|
||
$("#province").append(
|
||
"<option value=" +
|
||
value.province_id +
|
||
">" +
|
||
value.province_fa +
|
||
"</option>"
|
||
);
|
||
});
|
||
$.ajax({
|
||
async: false,
|
||
url: url + "api/cmms/" + id + "/show",
|
||
type: "GET",
|
||
headers: {
|
||
accept: "application/json",
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (res) {
|
||
buildForm(res.data.car_type).then(
|
||
() => {
|
||
fillCities(res.data.province_id).then(
|
||
(onResolved) => {
|
||
$('#form_number').val(res.data.form_number)
|
||
$('#form-date').val(moment(res.data.updated_at).format('jYYYY/jMM/jDD'))
|
||
|
||
$('#personal_num').val(res.data.dedicated_number)
|
||
$('#dedicated_number').val(res.data.dedicated_number)
|
||
$('#shasi_num').val(res.data.chassis_number)
|
||
|
||
$('#province').val(res.data.province_id)
|
||
$('#city').val(res.data.city_id)
|
||
isValidCity = true;
|
||
|
||
$('#device_name').val(res.data.device_name)
|
||
$('#gps_code').val(res.data.gps_code)
|
||
$('#operator_name').val(res.data.operator_name)
|
||
$('#national_code').val(res.data.operator_nationalcode)
|
||
$('#operator_phone').val(res.data.operator_phone)
|
||
$('#operator_phone').val(res.data.operator_phone)
|
||
|
||
$('#deviceImg1Preview').attr('src', url + res.data.image1)
|
||
$('#deviceImg2Preview').attr('src', url + res.data.image2)
|
||
$('#deviceImg3Preview').attr('src', url + res.data.image3)
|
||
|
||
$('input[name="motor"][value="' + res.data.motor + '"]').prop('checked', true)
|
||
$('input[name="power"][value="' + res.data.power + '"]').prop('checked', true)
|
||
$('input[name="hydraulic"][value="' + res.data.hydraulic + '"]').prop('checked', true)
|
||
$('input[name="ripper"][value="' + res.data.ripper + '"]').prop('checked', true)
|
||
$('input[name="zirbandi"][value="' + res.data.zirbandi + '"]').prop('checked', true)
|
||
$('input[name="jolobandi"][value="' + res.data.jolobandi + '"]').prop('checked', true)
|
||
$('input[name="bucket"][value="' + res.data.bucket + '"]').prop('checked', true)
|
||
$('input[name="chassis"][value="' + res.data.chassis + '"]').prop('checked', true)
|
||
$('input[name="electrical"][value="' + res.data.electrical + '"]').prop('checked', true)
|
||
$('input[name="safety"][value="' + res.data.safety + '"]').prop('checked', true)
|
||
$('input[name="gps"][value="' + res.data.gps + '"]').prop('checked', true)
|
||
$('input[name="color"][value="' + res.data.color + '"]').prop('checked', true)
|
||
|
||
$('input[name="motor_description"]').val(res.data.motor_description)
|
||
$('input[name="power_description"]').val(res.data.power_description)
|
||
$('input[name="hydraulic_description"]').val(res.data.hydraulic_description)
|
||
$('input[name="ripper_description"]').val(res.data.ripper_description)
|
||
$('input[name="zirbandi_description"]').val(res.data.zirbandi_description)
|
||
$('input[name="jolobandi_description"]').val(res.data.jolobandi_description)
|
||
$('input[name="bucket_description"]').val(res.data.bucket_description)
|
||
$('input[name="chassis_description"]').val(res.data.chassis_description)
|
||
$('input[name="electrical_description"]').val(res.data.electrical_description)
|
||
$('input[name="safety_description"]').val(res.data.safety_description)
|
||
$('input[name="gps_description"]').val(res.data.gps_description)
|
||
$('input[name="color_description"]').val(res.data.color_description)
|
||
$('input[name="service_description"]').val(res.data.service_description)
|
||
$('input[name="fuel_description"]').val(res.data.fuel_description)
|
||
|
||
$('input[name="motor_score"]').val(res.data.motor_score)
|
||
$('input[name="power_score"]').val(res.data.power_score)
|
||
$('input[name="hydraulic_score"]').val(res.data.hydraulic_score)
|
||
$('input[name="ripper_score"]').val(res.data.ripper_score)
|
||
$('input[name="zirbandi_score"]').val(res.data.zirbandi_score)
|
||
$('input[name="jolobandi_score"]').val(res.data.jolobandi_score)
|
||
$('input[name="bucket_score"]').val(res.data.bucket_score)
|
||
$('input[name="chassis_score"]').val(res.data.chassis_score)
|
||
$('input[name="electrical_score"]').val(res.data.electrical_score)
|
||
$('input[name="safety_score"]').val(res.data.safety_score)
|
||
$('input[name="gps_score"]').val(res.data.gps_score)
|
||
$('input[name="color_score"]').val(res.data.color_score)
|
||
$('input[name="service_status"]').val(res.data.service_status)
|
||
$('input[name="fuel_form"]').val(res.data.fuel_form)
|
||
$('input[name="total_points"]').val(res.data.total_points)
|
||
|
||
$('input[name="question1"][value="' + res.data.question1 + '"]').prop('checked', true)
|
||
$('input[name="question2"][value="' + res.data.question2 + '"]').prop('checked', true)
|
||
$('input[name="question3"][value="' + res.data.question3 + '"]').prop('checked', true)
|
||
$('input[name="question4"][value="' + res.data.question4 + '"]').prop('checked', true)
|
||
$('input[name="question5"][value="' + res.data.question5 + '"]').prop('checked', true)
|
||
|
||
$('#proceedingsFilePreview').attr('src', url + res.data.file1)
|
||
|
||
$('#auditor_name').val(res.data.auditor_name)
|
||
$('#member1_name').val(res.data.member1_name)
|
||
$('#member2_name').val(res.data.member2_name)
|
||
$('#member3_name').val(res.data.member3_name)
|
||
|
||
$('#auditor_position').val(res.data.auditor_position)
|
||
$('#member1_position').val(res.data.member1_position)
|
||
$('#member2_position').val(res.data.member2_position)
|
||
$('#member3_position').val(res.data.member3_position)
|
||
|
||
isNationalCode = (checkNationalCode(res.data.operator_nationalcode)) ? true : false
|
||
|
||
formValid()
|
||
}
|
||
);
|
||
}
|
||
);
|
||
},
|
||
error: function () {
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا سرور",
|
||
text: "مشکل در دریافت اطلاعات",
|
||
confirmButtonText: "بروزرسانی صفحه",
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
location.reload(true);
|
||
return true;
|
||
}
|
||
});
|
||
}
|
||
});
|
||
},
|
||
error: function () {
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا سرور",
|
||
text: "مشکل در دریافت استان ها",
|
||
confirmButtonText: "بروزرسانی صفحه",
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
location.reload(true);
|
||
return true;
|
||
}
|
||
});
|
||
}
|
||
});
|
||
|
||
// get cities by provicens_id and validation
|
||
$("#province").change(function () {
|
||
fillCities($(this).val())
|
||
|
||
formValid();
|
||
});
|
||
|
||
|
||
// validation city
|
||
$("#city").change(function () {
|
||
isValidCity = false;
|
||
var cityId = $(this).val();
|
||
if (cityId != 0) {
|
||
isValidCity = true;
|
||
} else {
|
||
isValidCity = false;
|
||
}
|
||
|
||
formValid();
|
||
});
|
||
|
||
|
||
$(".ott").click(function (event) {
|
||
if (event.target.type !== "radio") {
|
||
$(":radio", this).trigger("click");
|
||
}
|
||
});
|
||
|
||
// print
|
||
$('#print').on('click', function () {
|
||
window.print();
|
||
});
|
||
|
||
// send all data
|
||
$("#send").on("click", function () {
|
||
$('#send').attr('disabled', 'disabled');
|
||
$('#send').text('در حال ویرایش');
|
||
|
||
var isRequire = true;
|
||
var car_type = $("#car_type").val()
|
||
var data = new FormData();
|
||
|
||
// append Moshakhasat
|
||
if ($("#dedicated_number").val() != '')
|
||
data.append("dedicated_number", $("#dedicated_number").val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($("#shasi_num").val() != '')
|
||
data.append("chassis_number", $("#shasi_num").val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($("#province").val() != '')
|
||
data.append("province_id", $("#province").val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($("#city").val() != '')
|
||
data.append("city_id", $("#city").val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($("#device_name").val() != '')
|
||
data.append("device_name", $("#device_name").val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($("#gps_code").val() != '')
|
||
data.append("gps_code", $("#gps_code").val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($("#operator_name").val() != '')
|
||
data.append("operator_name", $("#operator_name").val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($("#national_code").val() != '')
|
||
data.append("operator_nationalcode", $("#national_code").val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($("#operator_phone").val() != '')
|
||
data.append("operator_phone", $("#operator_phone").val());
|
||
else
|
||
isRequire = false
|
||
|
||
|
||
// check values undefined before append
|
||
if (typeof $('input[name="motor"]:checked').val() !== "undefined")
|
||
data.append("motor", $('input[name="motor"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="power"]:checked').val() !== "undefined")
|
||
data.append("power", $('input[name="power"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="hydraulic"]:checked').val() !== "undefined")
|
||
data.append("hydraulic", $('input[name="hydraulic"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (car_type == "B") {
|
||
if (typeof $('input[name="ripper"]:checked').val() !== "undefined")
|
||
data.append("ripper", $('input[name="ripper"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
}
|
||
|
||
if (typeof $('input[name="zirbandi"]:checked').val() !== "undefined")
|
||
data.append("zirbandi", $('input[name="zirbandi"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (car_type == "G") {
|
||
if (typeof $('input[name="jolobandi"]:checked').val() !== "undefined")
|
||
data.append("jolobandi", $('input[name="jolobandi"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
}
|
||
|
||
if (car_type == "Ex") {
|
||
if (typeof $('input[name="bucket"]:checked').val() !== "undefined")
|
||
data.append("bucket", $('input[name="bucket"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
}
|
||
|
||
if (typeof $('input[name="chassis"]:checked').val() !== "undefined")
|
||
data.append("chassis", $('input[name="chassis"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="electrical"]:checked').val() !== "undefined")
|
||
data.append("electrical", $('input[name="electrical"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="safety"]:checked').val() !== "undefined")
|
||
data.append("safety", $('input[name="safety"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="gps"]:checked').val() !== "undefined")
|
||
data.append("gps", $('input[name="gps"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="color"]:checked').val() !== "undefined")
|
||
data.append("color", $('input[name="color"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
|
||
|
||
data.append("motor_description", $('input[name="motor_description"]').val());
|
||
|
||
data.append("power_description", $('input[name="power_description"]').val());
|
||
|
||
data.append("hydraulic_description", $('input[name="hydraulic_description"]').val());
|
||
|
||
if (car_type == "B")
|
||
data.append("ripper_description", $('input[name="ripper_description"]').val());
|
||
|
||
data.append("zirbandi_description", $('input[name="zirbandi_description"]').val());
|
||
|
||
if (car_type == "G")
|
||
data.append("jolobandi_description", $('input[name="jolobandi_description"]').val());
|
||
|
||
if (car_type == "Ex")
|
||
data.append("bucket_description", $('input[name="bucket_description"]').val());
|
||
|
||
data.append("chassis_description", $('input[name="chassis_description"]').val());
|
||
|
||
data.append("electrical_description", $('input[name="electrical_description"]').val());
|
||
|
||
data.append("safety_description", $('input[name="safety_description"]').val());
|
||
|
||
data.append("gps_description", $('input[name="gps_description"]').val());
|
||
|
||
data.append("color_description", $('input[name="color_description"]').val());
|
||
|
||
data.append("service_description", $('input[name="service_description"]').val());
|
||
|
||
data.append("fuel_description", $('input[name="fuel_description"]').val());
|
||
|
||
|
||
if ($('input[name="motor_score"]').val() != '')
|
||
data.append("motor_score", $('input[name="motor_score"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($('input[name="power_score"]').val() != '')
|
||
data.append("power_score", $('input[name="power_score"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($('input[name="hydraulic_score"]').val() != '')
|
||
data.append("hydraulic_score", $('input[name="hydraulic_score"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (car_type == "B") {
|
||
if ($('input[name="ripper_score"]').val() != '')
|
||
data.append("ripper_score", $('input[name="ripper_score"]').val());
|
||
else
|
||
isRequire = false
|
||
}
|
||
|
||
if ($('input[name="zirbandi_score"]').val() != '')
|
||
data.append("zirbandi_score", $('input[name="zirbandi_score"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (car_type == "G") {
|
||
if ($('input[name="jolobandi_score"]').val() != '')
|
||
data.append("jolobandi_score", $('input[name="jolobandi_score"]').val());
|
||
else
|
||
isRequire = false
|
||
}
|
||
|
||
if (car_type == "Ex") {
|
||
if ($('input[name="bucket_score"]').val() != '')
|
||
data.append("bucket_score", $('input[name="bucket_score"]').val());
|
||
else
|
||
isRequire = false
|
||
}
|
||
|
||
if ($('input[name="chassis_score"]').val() != '')
|
||
data.append("chassis_score", $('input[name="chassis_score"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($('input[name="electrical_score"]').val() != '')
|
||
data.append("electrical_score", $('input[name="electrical_score"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($('input[name="safety_score"]').val() != '')
|
||
data.append("safety_score", $('input[name="safety_score"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($('input[name="gps_score"]').val() != '')
|
||
data.append("gps_score", $('input[name="gps_score"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($('input[name="color_score"]').val() != '')
|
||
data.append("color_score", $('input[name="color_score"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($('input[name="service_status"]').val() != '')
|
||
data.append("service_status", $('input[name="service_status"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if ($('input[name="fuel_form"]').val() != '')
|
||
data.append("fuel_form", $('input[name="fuel_form"]').val());
|
||
else
|
||
isRequire = false
|
||
|
||
|
||
// append total points
|
||
data.append("total_points", $('input[name="total_points"]').val());
|
||
|
||
|
||
// check questions undefined before append
|
||
if (typeof $('input[name="question1"]:checked').val() !== "undefined")
|
||
data.append("question1", $('input[name="question1"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="question2"]:checked').val() !== "undefined")
|
||
data.append("question2", $('input[name="question2"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="question3"]:checked').val() !== "undefined")
|
||
data.append("question3", $('input[name="question3"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="question4"]:checked').val() !== "undefined")
|
||
data.append("question4", $('input[name="question4"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="question5"]:checked').val() !== "undefined")
|
||
data.append("question5", $('input[name="question5"]:checked').val());
|
||
else
|
||
isRequire = false
|
||
|
||
// append auditor and members
|
||
data.append("auditor_name", $("#auditor_name").val());
|
||
data.append("member1_name", $("#member1_name").val());
|
||
data.append("member2_name", $("#member2_name").val());
|
||
data.append("member3_name", $("#member3_name").val());
|
||
|
||
data.append("auditor_position", $("#auditor_position").val());
|
||
data.append("member1_position", $("#member1_position").val());
|
||
data.append("member2_position", $("#member2_position").val());
|
||
data.append("member3_position", $("#member3_position").val());
|
||
|
||
// append auditor_name
|
||
data.append("car_type", $("#car_type").val());
|
||
|
||
// append device images
|
||
if ((typeof $('#deviceImg1').get(0).files[0] === "undefined") && (!document.getElementById("deviceImg1Preview").hasAttribute('src')))
|
||
isRequire = false
|
||
else if (typeof $('#deviceImg1').get(0).files[0] !== "undefined")
|
||
data.append("image1", $('#deviceImg1').get(0).files[0]);
|
||
|
||
if ((typeof $('#deviceImg2').get(0).files[0] === "undefined") && (!document.getElementById("deviceImg2Preview").hasAttribute('src')))
|
||
isRequire = false
|
||
else if (typeof $('#deviceImg2').get(0).files[0] !== "undefined")
|
||
data.append("image2", $('#deviceImg2').get(0).files[0]);
|
||
|
||
if ((typeof $('#deviceImg3').get(0).files[0] === "undefined") && (!document.getElementById("deviceImg3Preview").hasAttribute('src')))
|
||
isRequire = false
|
||
else if (typeof $('#deviceImg3').get(0).files[0] !== "undefined")
|
||
data.append("image3", $('#deviceImg3').get(0).files[0]);
|
||
|
||
|
||
// append proceedings file
|
||
if ((typeof $('#proceedingsFile').get(0).files[0] === "undefined") && (!document.getElementById("proceedingsFilePreview").hasAttribute('src')))
|
||
isRequire = false
|
||
else if (typeof $('#proceedingsFile').get(0).files[0] !== "undefined")
|
||
data.append("file1", $('#proceedingsFile').get(0).files[0]);
|
||
|
||
|
||
if (isRequire) {
|
||
$.ajax({
|
||
url: url + "cmms/" + id + "/edit",
|
||
type: "POST",
|
||
headers: {
|
||
accept: "application/json",
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
data: data,
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (res) {
|
||
$('#print').removeAttr('disabled');
|
||
$('#reset').removeAttr('disabled');
|
||
$('#form_number').val(res.data.form_number);
|
||
$('#form-date').val(moment().format('jYYYY/jMM/jDD'))
|
||
$('#send').text('ویرایش شد');
|
||
$('#send').removeClass('btn-primary');
|
||
$('#send').addClass('btn-success');
|
||
Toast.fire({
|
||
icon: 'success',
|
||
title: 'ویرایش اطلاعات با موفقیت انجام شد'
|
||
})
|
||
isSend = true;
|
||
},
|
||
error: function (xhr) {
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا سرور",
|
||
text: "مشکل در ثبت اطلاعات",
|
||
showCancelButton: true,
|
||
showConfirmButton: false,
|
||
cancelButtonText: "بستن",
|
||
})
|
||
$('#send').removeAttr('disabled');
|
||
$('#send').text('ویرایش');
|
||
},
|
||
});
|
||
} else {
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "لطفا اطلاعات صحیح وارد نمایید",
|
||
showConfirmButton: false,
|
||
cancelButtonText: "بستن",
|
||
})
|
||
|
||
$('#send').removeAttr('disabled');
|
||
$('#send').text('ویرایش');
|
||
}
|
||
});
|
||
|
||
// check scores between 1 and 5 before sum scores
|
||
$(".shakhes_input").keyup(function () {
|
||
var total = 0;
|
||
var inputs = $(".shakhes_input");
|
||
for (var i = 0; i < inputs.length; i++) {
|
||
if (inputs[i].value != "") {
|
||
total += parseInt(inputs[i].value);
|
||
}
|
||
}
|
||
$("#total_points").val(total);
|
||
});
|
||
|
||
$(".shakhes_input").bind('keypress', function (event) {
|
||
var key = event.which;
|
||
var str = String.fromCharCode(key);
|
||
|
||
if (key == 0 || key === 32) {
|
||
return true;
|
||
}
|
||
|
||
var re = ($(this).hasClass('zero')) ? /^[0-5]$/ : /^[1-5]$/
|
||
if (re.test(str)) {
|
||
return true
|
||
}
|
||
|
||
return false
|
||
});
|
||
|
||
//upload files
|
||
$('.img-input').on('change', function () {
|
||
var input = this;
|
||
var parent = $(this).parents('.img-file');
|
||
if (input.files && input.files[0]) {
|
||
var reader = new FileReader();
|
||
|
||
reader.onload = function (e) {
|
||
parent.find('.img-title').css('display', 'none')
|
||
parent.find('.btn-delete-img').removeAttr('disabled');
|
||
parent.find('.img-preview')
|
||
.attr('src', e.target.result);
|
||
|
||
};
|
||
|
||
reader.readAsDataURL(input.files[0]);
|
||
}
|
||
})
|
||
|
||
//clear files
|
||
$('.btn-delete-img').on('click', function () {
|
||
var parent = $(this).parents('.img-file');
|
||
|
||
parent.find('.img-input').val('');
|
||
parent.find('.img-preview').removeAttr('src');
|
||
parent.find('.img-title').css('display', '');
|
||
$(this).attr('disabled', 'disabled')
|
||
formValid()
|
||
})
|
||
|
||
$('#national_code').keyup(function () {
|
||
if (checkNationalCode($(this).val())) {
|
||
$('#national_code_err').css('display', 'none');
|
||
isNationalCode = true;
|
||
formValid()
|
||
return true;
|
||
} else {
|
||
$('#national_code_err').css('display', 'block');
|
||
isNationalCode = false;
|
||
formValid()
|
||
return false;
|
||
}
|
||
})
|
||
|
||
//build form by car_type
|
||
function buildForm(car_type) {
|
||
|
||
//build form
|
||
sortTable($('#table-car-form'), car_type)
|
||
|
||
// update car_type form
|
||
$("#car_type").val(car_type);
|
||
|
||
return Promise.resolve("Success");
|
||
}
|
||
|
||
//realtime validation inputs
|
||
$('input').on('change', function () {
|
||
formValid()
|
||
})
|
||
|
||
//realtime validation selects
|
||
$('select').on('change', function () {
|
||
formValid()
|
||
})
|
||
|
||
// validation
|
||
function formValid() {
|
||
if (!isSend) {
|
||
var isRequire = true;
|
||
if ($("#dedicated_number").val() == '')
|
||
isRequire = false
|
||
else if ($("#shasi_num").val() == '')
|
||
isRequire = false
|
||
else if ($("#province").val() == '')
|
||
isRequire = false
|
||
else if ($("#city").val() == '')
|
||
isRequire = false
|
||
else if ($("#device_name").val() == '')
|
||
isRequire = false
|
||
else if ($("#gps_code").val() == '')
|
||
isRequire = false
|
||
else if ($("#operator_name").val() == '')
|
||
isRequire = false
|
||
else if ($("#national_code").val() == '')
|
||
isRequire = false
|
||
else if ($("#operator_phone").val() == '')
|
||
isRequire = false
|
||
|
||
|
||
if (typeof $('input[name="motor"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
if (typeof $('input[name="power"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
if (typeof $('input[name="hydraulic"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
if (car_type == "B") {
|
||
if (typeof $('input[name="ripper"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
}
|
||
if (typeof $('input[name="zirbandi"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
if (car_type == "G") {
|
||
if (typeof $('input[name="jolobandi"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
}
|
||
if (car_type == "Ex") {
|
||
if (typeof $('input[name="bucket"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
}
|
||
if (typeof $('input[name="chassis"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
if (typeof $('input[name="electrical"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
if (typeof $('input[name="safety"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
if (typeof $('input[name="gps"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
if (typeof $('input[name="color"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
|
||
|
||
if ($('input[name="motor_score"]').val() == '')
|
||
isRequire = false
|
||
if ($('input[name="power_score"]').val() == '')
|
||
isRequire = false
|
||
if ($('input[name="hydraulic_score"]').val() == '')
|
||
isRequire = false
|
||
if (car_type == "B") {
|
||
if ($('input[name="ripper_score"]').val() == '')
|
||
isRequire = false
|
||
}
|
||
if ($('input[name="zirbandi_score"]').val() == '')
|
||
isRequire = false
|
||
if (car_type == "G") {
|
||
if ($('input[name="jolobandi_score"]').val() == '')
|
||
isRequire = false
|
||
}
|
||
if (car_type == "Ex") {
|
||
if ($('input[name="bucket_score"]').val() == '')
|
||
isRequire = false
|
||
}
|
||
if ($('input[name="chassis_score"]').val() == '')
|
||
isRequire = false
|
||
if ($('input[name="electrical_score"]').val() == '')
|
||
isRequire = false
|
||
if ($('input[name="safety_score"]').val() == '')
|
||
isRequire = false
|
||
if ($('input[name="gps_score"]').val() == '')
|
||
isRequire = false
|
||
if ($('input[name="color_score"]').val() == '')
|
||
isRequire = false
|
||
if ($('input[name="service_status"]').val() == '')
|
||
isRequire = false
|
||
if ($('input[name="fuel_form"]').val() == '')
|
||
isRequire = false
|
||
|
||
|
||
if (typeof $('input[name="question1"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="question2"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="question3"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="question4"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
|
||
if (typeof $('input[name="question5"]:checked').val() === "undefined")
|
||
isRequire = false
|
||
|
||
|
||
if ((typeof $('#deviceImg1').get(0).files[0] === "undefined") && (!document.getElementById("deviceImg1Preview").hasAttribute('src')))
|
||
isRequire = false
|
||
|
||
if ((typeof $('#deviceImg2').get(0).files[0] === "undefined") && (!document.getElementById("deviceImg2Preview").hasAttribute('src')))
|
||
isRequire = false
|
||
|
||
if ((typeof $('#deviceImg3').get(0).files[0] === "undefined") && (!document.getElementById("deviceImg3Preview").hasAttribute('src')))
|
||
isRequire = false
|
||
|
||
// append proceedings file
|
||
if ((typeof $('#proceedingsFile').get(0).files[0] === "undefined") && (!document.getElementById("proceedingsFilePreview").hasAttribute('src')))
|
||
isRequire = false
|
||
|
||
if (isValidProvider && isValidCity && isNationalCode && isRequire) {
|
||
$('#send').removeAttr('disabled');
|
||
$('#send').text('ویرایش')
|
||
$('#send').removeClass('btn-warning');
|
||
$('#send').addClass('btn-primary');
|
||
$('#print').removeAttr('disabled');
|
||
} else {
|
||
$('#send').attr('disabled', 'disabled');
|
||
$('#send').text('فرم را پر کنید')
|
||
$('#send').addClass('btn-warning');
|
||
$('#send').removeClass('btn-primary');
|
||
$('#print').attr('disabled', 'disabled');
|
||
}
|
||
}
|
||
}
|
||
|
||
function checkNationalCode(code) {
|
||
|
||
if (code == "1111111111" || code == "2222222222" || code == "3333333333" || code == "4444444444" || code == "5555555555" || code == "6666666666" || code == "7777777777" || code == "8888888888" || code == "9999999999") return false
|
||
|
||
var L = code.length;
|
||
|
||
if (L < 8 || parseInt(code, 10) == 0) return false;
|
||
code = ('0000' + code).substr(L + 4 - 10);
|
||
if (parseInt(code.substr(3, 6), 10) == 0) return false;
|
||
var c = parseInt(code.substr(9, 1), 10);
|
||
var s = 0;
|
||
for (var i = 0; i < 9; i++)
|
||
s += parseInt(code.substr(i, 1), 10) * (10 - i);
|
||
s = s % 11;
|
||
return (s < 2 && c == s) || (s >= 2 && c == (11 - s));
|
||
}
|
||
|
||
//fill cities by province_id
|
||
function fillCities(province_id) {
|
||
isValidProvider = false;
|
||
if (province_id != 0) {
|
||
$.ajax({
|
||
async: false,
|
||
url: url + "api/cmms/cities?id=" + province_id,
|
||
type: "GET",
|
||
headers: {
|
||
accept: "application/json",
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (res) {
|
||
$("#city").empty();
|
||
$("#city").append('<option value="0">انتخاب شهرستان</option>');
|
||
$.each(res.data, function (key, value) {
|
||
$("#city").append(
|
||
"<option value=" + value.id + ">" + value.name_fa + "</option>"
|
||
);
|
||
});
|
||
isValidProvider = true;
|
||
},
|
||
error: function () {
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا سرور",
|
||
text: "مشکل در دریافت شهر ها",
|
||
confirmButtonText: "بروزرسانی صفحه",
|
||
}).then((result) => {
|
||
if (result.isConfirmed) {
|
||
location.reload(true);
|
||
return true;
|
||
}
|
||
});
|
||
}
|
||
});
|
||
} else {
|
||
$("#city").empty();
|
||
$("#city").append('<option value="0">انتخاب شهرستان</option>');
|
||
isValidProvider = false;
|
||
}
|
||
return Promise.resolve();
|
||
}
|
||
|
||
//sort table
|
||
function sortTable(table, car_type) {
|
||
tbody = table.find('tbody');
|
||
tbody.find('th[' + car_type + '="none"]').closest('tr').addClass('d-none')
|
||
|
||
|
||
tbody.find('tr').sort(function (a, b) {
|
||
return $('th:first', a).attr(car_type).localeCompare($('th:first', b).attr(car_type));
|
||
}).appendTo(tbody);
|
||
}
|
||
}) |