841 lines
29 KiB
JavaScript
841 lines
29 KiB
JavaScript
var isValidProvider = false;
|
||
var isValidCity = false;
|
||
var isNationalCode = false;
|
||
var isSend = false;
|
||
var url = '/';
|
||
|
||
$(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)
|
||
}
|
||
})
|
||
|
||
//reset form and refresh
|
||
$('#reset').on('click', function () {
|
||
location.reload(true);
|
||
});
|
||
|
||
// select device tupe
|
||
$('.btn-type').on('click', function () {
|
||
buildForm($(this).val()).then(
|
||
(onResolved) => {
|
||
$('#form-type').modal('hide')
|
||
}
|
||
);
|
||
});
|
||
|
||
// get all provinces
|
||
$.ajax({
|
||
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>"
|
||
);
|
||
});
|
||
// show modal form type
|
||
$("#form-type").modal({
|
||
backdrop: "static"
|
||
});
|
||
},
|
||
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");
|
||
}
|
||
});
|
||
|
||
// 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")
|
||
data.append("image1", $('#deviceImg1').get(0).files[0]);
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('#deviceImg2').get(0).files[0] !== "undefined")
|
||
data.append("image2", $('#deviceImg2').get(0).files[0]);
|
||
else
|
||
isRequire = false
|
||
|
||
if (typeof $('#deviceImg3').get(0).files[0] !== "undefined")
|
||
data.append("image3", $('#deviceImg3').get(0).files[0]);
|
||
else
|
||
isRequire = false
|
||
|
||
// append proceedings file
|
||
if (typeof $('#proceedingsFile').get(0).files[0] !== "undefined")
|
||
data.append("file1", $('#proceedingsFile').get(0).files[0]);
|
||
else
|
||
isRequire = false
|
||
|
||
if (isRequire) {
|
||
$.ajax({
|
||
url: url + "webapi/cmms/create",
|
||
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: "مشکل در ثبت اطلاعات",
|
||
confirmButtonText: "بستن",
|
||
})
|
||
$('#send').removeAttr('disabled');
|
||
$('#send').text('ثبت');
|
||
},
|
||
});
|
||
} else {
|
||
Swal.fire({
|
||
icon: "error",
|
||
title: "خطا",
|
||
text: "لطفا اطلاعات صحیح وارد نمایید",
|
||
showConfirmButton: false,
|
||
cancelButtonText: "بستن",
|
||
})
|
||
|
||
$('#send').removeAttr('disabled');
|
||
$('#send').text('ثبت');
|
||
}
|
||
});
|
||
|
||
// print
|
||
$('#print').on('click', function () {
|
||
window.print();
|
||
});
|
||
|
||
// get live dedicated_number by search
|
||
$("#personal_num").autocomplete({
|
||
source: function (request, response) {
|
||
var reqData = new FormData();
|
||
reqData.append("data", request.term);
|
||
$.ajax({
|
||
url: url + "webapi/cmms/search",
|
||
type: "POST",
|
||
headers: {
|
||
accept: "application/json",
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
data: reqData,
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (res) {
|
||
response(res.data);
|
||
},
|
||
});
|
||
},
|
||
select: function (event, ui) {
|
||
var reqData = new FormData();
|
||
reqData.append("dedicated_number", ui.item.label);
|
||
$.ajax({
|
||
url: url + "webapi/cmms/machine",
|
||
type: "POST",
|
||
headers: {
|
||
accept: "application/json",
|
||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||
},
|
||
data: reqData,
|
||
cache: false,
|
||
contentType: false,
|
||
processData: false,
|
||
success: function (res) {
|
||
console.log(res);
|
||
resetMoshakhasat();
|
||
isValidProvider = false;
|
||
isValidCity = false;
|
||
|
||
if (typeof res.data.operator_nationalcode !== "undefined") {
|
||
if (checkNationalCode(res.data.operator_nationalcode))
|
||
isNationalCode = true;
|
||
}
|
||
|
||
formValid();
|
||
|
||
$("#shasi_num").val(res.data.body_number);
|
||
$("#currentProvince").text(res.data.unit_group_fa);
|
||
$("#currentCity").text(res.data.unit_name);
|
||
$("#device_name").val(res.data.car_name);
|
||
$("#oprator_name").val(res.data.driver_name);
|
||
$("#gps_code").val(res.data.gps_code);
|
||
$("#national_code").val(res.data.operator_nationalcode);
|
||
$("#operator_phone").val(res.data.mobile);
|
||
$("#dedicated_number").val(res.data.machine_code);
|
||
},
|
||
});
|
||
},
|
||
minLength: 2,
|
||
});
|
||
|
||
// 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]);
|
||
}
|
||
})
|
||
|
||
$('#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;
|
||
}
|
||
})
|
||
|
||
//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()
|
||
})
|
||
|
||
//reset moshakhasat
|
||
function resetMoshakhasat() {
|
||
$("#shasi_num").val("");
|
||
$("#province").val(0);
|
||
$("#city").val(0);
|
||
$("#device_name").val("");
|
||
$("#currentProvince").text("");
|
||
$("#currentCity").text("");
|
||
$("#oprator_name").val("");
|
||
$("#national_code").val("");
|
||
$("#operator_phone").val("");
|
||
}
|
||
|
||
//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")
|
||
isRequire = false
|
||
|
||
if (typeof $('#deviceImg2').get(0).files[0] === "undefined")
|
||
isRequire = false
|
||
|
||
if (typeof $('#deviceImg3').get(0).files[0] === "undefined")
|
||
isRequire = false
|
||
|
||
// append proceedings file
|
||
if (typeof $('#proceedingsFile').get(0).files[0] === "undefined")
|
||
isRequire = false
|
||
|
||
|
||
if (isValidProvider && isValidCity && isNationalCode && isRequire) {
|
||
$('#send').removeAttr('disabled');
|
||
$('#send').text('ثبت')
|
||
$('#send').removeClass('btn-warning');
|
||
$('#send').addClass('btn-primary');
|
||
} else {
|
||
$('#send').attr('disabled', 'disabled');
|
||
$('#send').text('فرم را پر کنید')
|
||
$('#send').addClass('btn-warning');
|
||
$('#send').removeClass('btn-primary');
|
||
}
|
||
}
|
||
}
|
||
|
||
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({
|
||
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 {
|
||
isValidProvider = false;
|
||
$("#city").empty();
|
||
$("#city").append('<option value="0">انتخاب شهرستان</option>');
|
||
}
|
||
|
||
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);
|
||
}
|
||
}); |