Created
May 9, 2020 05:46
-
-
Save polodev/adadb5292977fc39ffc0598f038abb58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
// Start ready block | |
// if ($.fn.datetimepicker) { | |
// $('#incident_date_time').datetimepicker({ | |
// format: 'Y-m-d H:i', | |
// step: 5 | |
// }); | |
// } | |
if ($.fn.flatpickr) { | |
console.log('flatpickr') | |
$("#date_of_accident").flatpickr({ | |
dateFormat: "Y-m-d", | |
maxDate: 'today', | |
}); | |
$("#hospital_admission_date").flatpickr({ | |
dateFormat: "Y-m-d", | |
maxDate: 'today', | |
}); | |
$("#hospital_discharge_date").flatpickr({ | |
dateFormat: "Y-m-d", | |
maxDate: 'today', | |
}); | |
} | |
// if ($.fn.datepicker) { | |
// console.log('datepicker found') | |
// $('#date_of_accident').datepicker(); | |
// $('#hospital_admission_date').datepicker(); | |
// $('#hospital_discharge_date').datepicker(); | |
// } | |
function close_all_conditional_id () { | |
$('#accidental_injury').hide(); | |
$('#general_hospitalization').hide(); | |
$('#opd_services').hide(); | |
$('#accidental_injury_document').hide(); | |
$('#general_hospitalization_document').hide(); | |
$('#opd_services_document').hide(); | |
} | |
function open_accidental_injury() { | |
close_all_conditional_id(); | |
$('#accidental_injury').show(); | |
$('#accidental_injury_document').show(); | |
} | |
function open_general_hospitalization() { | |
close_all_conditional_id(); | |
$('#general_hospitalization').show(); | |
$('#general_hospitalization_document').show(); | |
} | |
function open_opd_services() { | |
close_all_conditional_id(); | |
$('#opd_services').show(); | |
$('#opd_services_document').show(); | |
} | |
function hide_show_type_of_claim() { | |
// smart way | |
var claim_types_functions = { | |
"accidental_injury": open_accidental_injury, | |
"general_hospitalization": open_general_hospitalization, | |
"opd_services": open_opd_services, | |
} | |
var type_of_claim_value =$("#type_of_claim").val() ; | |
var executable_function = claim_types_functions[type_of_claim_value] | |
executable_function(); | |
// general way | |
// if($("#type_of_claim").val() == 'accidental_injury'){ | |
// open_accidental_injury(); | |
// }else if($("#type_of_claim").val() == 'general_hospitalization'){ | |
// open_general_hospitalization(); | |
// }else if($("#type_of_claim").val() == 'opd_services'){ | |
// open_opd_services(); | |
// } | |
} | |
function hide_and_show_opd_services_doctor_diagnostic() { | |
if($(".type_of_opd_claim:checked").val() == 'doctor_visit_only'){ | |
$('#opd_services_document_only_doctor').show(); | |
$('#opd_services_document_doctor_with_diagnostic').hide(); | |
} else { | |
$('#opd_services_document_only_doctor').hide(); | |
$('#opd_services_document_doctor_with_diagnostic').show(); | |
} | |
} | |
function hide_show_payment_type() { | |
if($(".payment_type:checked").val() == 'payment_bank'){ | |
$('#payment_bank').show(); | |
$('#payment_mobile').hide(); | |
}else{ | |
$('#payment_bank').hide(); | |
$('#payment_mobile').show(); | |
} | |
} | |
hide_show_type_of_claim(); | |
hide_show_payment_type(); | |
hide_and_show_opd_services_doctor_diagnostic(); | |
// hide and show block | |
$("#type_of_claim").change(function() { | |
hide_show_type_of_claim(); | |
}); | |
$(".payment_type" ).click(function() { | |
hide_show_payment_type(); | |
}); | |
$(".type_of_opd_claim" ).click(function() { | |
hide_and_show_opd_services_doctor_diagnostic(); | |
}); | |
if ($.fn.validate) { | |
$.validator.addMethod('filesize', function(value, element, param) { | |
return this.optional(element) || (element.files[0].size <= param) | |
}, function(params, element) { | |
return 'File size must be less than 512 KB' | |
}); | |
$.validator.addMethod('fileextension', function(value, element) { | |
if($(element).val() != ''){ | |
var fname = element.files[0].name.toLowerCase(); | |
var re = /(\.pdf|\.jpg|\.jpeg|\.png|\.docx|\.doc)$/i; | |
var mime_types = "application/pdf,image/jpeg,image/png,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/msword"; | |
if(re.exec(fname) && (mime_types.indexOf(element.files[0].type) >= 0)){ | |
return true; | |
}else{ | |
return false; | |
} | |
}else{ | |
return true; | |
} | |
}, function(params, element) { | |
return 'Invalid file format.' | |
}); | |
} | |
var rules = { | |
area_manager_name: { | |
required: true, | |
}, | |
area_manager_designation: { | |
required: true, | |
}, | |
area_manager_area_name: { | |
required: true, | |
}, | |
area_manager_mobile_number: { | |
required: true, | |
}, | |
area_manager_email: { | |
required: true, | |
email: true, | |
}, | |
rider_name: { | |
required: true | |
}, | |
rider_id: { | |
required: true | |
}, | |
rider_mobile_number: { | |
required: true | |
}, | |
rider_nid: { | |
required: true | |
}, | |
rider_gender: { | |
required: true | |
}, | |
type_of_claim: { | |
required: true | |
}, | |
date_of_accident: { | |
required: function() { | |
if($("#type_of_claim").val() == 'accidental_injury') { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
}, | |
place_of_accident: { | |
required: function() { | |
if($("#type_of_claim").val() == 'accidental_injury') { | |
return true; | |
}else { | |
return false; | |
} | |
} | |
}, | |
hospital_admission_date: { | |
required: function() { | |
if($("#type_of_claim").val() == 'general_hospitalization') { | |
return true; | |
}else { | |
return false; | |
} | |
} | |
}, | |
hospital_discharge_date: { | |
required: function() { | |
if($("#type_of_claim").val() == 'general_hospitalization') { | |
return true; | |
}else { | |
return false; | |
} | |
} | |
}, | |
type_of_opd_claim: { | |
required: function() { | |
if($("#type_of_claim").val() == 'opd_services') { | |
return true; | |
}else { | |
return false; | |
} | |
} | |
}, | |
// Accidental | |
"accidental_injury_incident_report_from_law_enforcement": { | |
required: false, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"accidental_injury_prescription_from_doctor" : { | |
required: function() { | |
if($("#type_of_claim").val() == 'accidental_injury') { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"accidental_injury_diagnostic_reports[]" : { | |
required: function() { | |
if($("#type_of_claim").val() == 'accidental_injury') { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"accidental_injury_medical_bills[]" : { | |
required: function() { | |
if($("#type_of_claim").val() == 'accidental_injury') { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"accidental_injury_image_of_injured_part_of_body[]" : { | |
required: false, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"general_hospitalization_doctor_advice_for_hospitalization" : { | |
required: function() { | |
if($("#type_of_claim").val() == 'general_hospitalization') { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"general_hospitalization_discharge_certificate" : { | |
required: function() { | |
if($("#type_of_claim").val() == 'general_hospitalization') { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"general_hospitalization_hospital_bill" : { | |
required: function() { | |
if($("#type_of_claim").val() == 'general_hospitalization') { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"general_hospitalization_diagnostic_reports[]" : { | |
required: function() { | |
if($("#type_of_claim").val() == 'general_hospitalization') { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"general_hospitalization_nid" : { | |
required: function() { | |
if($("#type_of_claim").val() == 'general_hospitalization') { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"opd_doctor_visit_prescription" : { | |
required: function() { | |
if( ($(".type_of_opd_claim:checked").val() == 'doctor_visit_only') && ($("#type_of_claim").val() == 'opd_services')) { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"opd_doctor_visit_diagnostic_prescription" : { | |
required: function() { | |
if( ($(".type_of_opd_claim:checked").val() == 'doctor_visit_only') && ($("#type_of_claim").val() == 'opd_services')) { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"opd_doctor_visit_diagnostic_test_bills[]" : { | |
required: function() { | |
if( ($(".type_of_opd_claim:checked").val() == 'doctor_visit_only') && ($("#type_of_claim").val() == 'opd_services')) { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
"opd_doctor_visit_diagnostic_test_reports" : { | |
required: function() { | |
if( ($(".type_of_opd_claim:checked").val() == 'doctor_visit_only') && ($("#type_of_claim").val() == 'opd_services')) { | |
return true; | |
}else { | |
return false; | |
} | |
}, | |
fileextension: true, | |
filesize: 524288, | |
}, | |
// payment validation | |
bank_account_holder_name: { | |
required: function(){ | |
if(($(".payment_type:checked").val() == 'payment_bank') && ($("#type_of_claim").val() == 'accidental')){ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
}, | |
bank_account_number: { | |
required: function(){ | |
if(($(".payment_type:checked").val() == 'payment_bank') && ($("#type_of_claim").val() == 'accidental')){ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
}, | |
bank_name: { | |
required: function(){ | |
if(($(".payment_type:checked").val() == 'payment_bank') && ($("#type_of_claim").val() == 'accidental')){ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
}, | |
bank_branch_name: { | |
required: function(){ | |
if(($(".payment_type:checked").val() == 'payment_bank') && ($("#type_of_claim").val() == 'accidental')){ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
}, | |
mobile_account_number: { | |
required: function(){ | |
if(($(".payment_type:checked").val() == 'payment_mobile') && ($("#type_of_claim").val() == 'accidental')){ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
}, | |
number:true | |
}, | |
mobile_account_type: { | |
required: function(){ | |
if(($(".payment_type:checked").val() == 'payment_mobile') && ($("#type_of_claim").val() == 'accidental')){ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
}, | |
terms_and_condition:{ | |
required : true | |
} | |
} | |
$.ajaxSetup({ | |
headers: { | |
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') | |
} | |
}); | |
function saveClaimInfo() { | |
//start loader | |
$('#claim_preloader').fadeIn(); | |
var $form = $('#food_panda_claim_form'); | |
var formData = new FormData(document.getElementById('food_panda_claim_form')); | |
var action_url = $form.data('action'); | |
var success_url = $form.data('success'); | |
console.log('action_url', action_url) | |
console.log('success_url', success_url) | |
$.ajax({ | |
url: action_url, | |
data: formData, | |
processData: false, | |
contentType: false, | |
type: "POST", | |
success: function (data) { | |
console.log('data', data) | |
// $('#claim_preloader').fadeOut(200); | |
window.location = success_url; | |
// var response = JSON.parse(data); | |
// console.log('response', response) | |
// if(response.status == 1){ | |
// window.location = '/'; | |
// }else{ | |
// $('#claim_preloader').fadeOut(200); | |
// console.log('response status else block', response) | |
// } | |
}, | |
error: function (data) { | |
$('#claim_preloader').fadeOut(200); | |
// showDescModal("ERROR - " + data.responseText); | |
console.log('error data', data) | |
} | |
}); | |
} | |
if ($.fn.validate) { | |
$('#food_panda_claim_form').validate({ // initialize the plugin | |
errorPlacement: function(error, element) { | |
error.insertAfter(element); // <- the default | |
console.log('element', element) | |
console.log('all error', error) | |
// if (element.attr("name") == "mobile_account_type") { | |
// error.insertAfter($("#mobile_account_type_error")); | |
// } else if (element.attr("name") == "relationship_with_deceased") { | |
// error.insertAfter($("#relationship_with_deceased_error")); | |
// } else if (element.attr("name") == "died_under_treatment") { | |
// error.insertAfter($("#died_under_treatment_error")); | |
// } else if (element.attr("name") == "died_at_hospital") { | |
// error.insertAfter($("#died_at_hospital_error")); | |
// } else if (element.attr("name") == "terms_and_condition") { | |
// error.insertAfter($("#terms_and_condition_error")); | |
// } else { | |
// error.insertAfter(element); // <- the default | |
// } | |
}, | |
rules: rules, | |
submitHandler: function () { | |
saveClaimInfo(); | |
return false; | |
} | |
}); | |
} | |
// End ready block | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment