Team 3 (Levoswitch Enrollment)
Specific Folder FTP Upload / ftp-deploy (push) Successful in 29s
Details
Specific Folder FTP Upload / ftp-deploy (push) Successful in 29s
Details
This commit is contained in:
parent
288e3f6643
commit
8bc7ad4b2d
|
|
@ -326,367 +326,306 @@
|
||||||
@include('layouts.shared/footer-script')
|
@include('layouts.shared/footer-script')
|
||||||
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
|
||||||
<script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
|
<script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
|
||||||
{{-- <script type="text/javascript">
|
|
||||||
jQuery(document).ready(function($) {
|
|
||||||
|
|
||||||
$('#field-contact_id').on('change',function(){
|
|
||||||
$('#field-msl_code').val($(this).find(":selected").attr("msl_code"));
|
|
||||||
})
|
|
||||||
|
|
||||||
$('#field-contact_id').on('change',function(){
|
{{-- <script>
|
||||||
$('#field-speciality').val($(this).find(":selected").attr("speciality"));
|
jQuery(document).ready(function($) {
|
||||||
})
|
|
||||||
|
|
||||||
$('#field-msl_code,#field-speciality').attr('readonly',true);
|
// Check whether the form is loaded in Edit Mode
|
||||||
|
var isEditMode = @json((bool)$id);
|
||||||
|
|
||||||
function initializeSelect2() {
|
// Auto-fill metadata fields (MSL Code, Pcode, Speciality) dynamically
|
||||||
|
$(document).on('change', 'select[id^="field-contact_id"]', function() {
|
||||||
|
let selectedOption = $(this).find(':selected');
|
||||||
|
let idParts = $(this).attr('id').split('-');
|
||||||
|
let suffix = idParts.length > 2 ? '-' + idParts[2] : '';
|
||||||
|
|
||||||
$('select[id^="field-contact_id"]').select2({
|
$('#field-msl_code' + suffix).val(selectedOption.attr('msl_code') || '');
|
||||||
width: '100%',
|
$('#field-pcode' + suffix).val(selectedOption.attr('pcode') || '');
|
||||||
placeholder: '-- Select Doctor --'
|
$('#field-speciality' + suffix).val(selectedOption.attr('speciality') || '');
|
||||||
});
|
|
||||||
|
|
||||||
$('#field-user_id').select2({
|
// Refresh disabled options across all doctor dropdowns
|
||||||
width: '100%',
|
|
||||||
placeholder: '-- Select User / Territory --'
|
|
||||||
});
|
|
||||||
|
|
||||||
$('select[id^="execution-"]').select2({
|
|
||||||
width: '100%'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeSelect2();
|
|
||||||
preventDuplicateDoctors();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* function preventDuplicateDoctors() {
|
|
||||||
|
|
||||||
let selectedValues = [];
|
|
||||||
|
|
||||||
// Get all selected doctor values
|
|
||||||
$('select[id^="field-contact_id"]').each(function () {
|
|
||||||
|
|
||||||
let value = $(this).val();
|
|
||||||
|
|
||||||
if (value) {
|
|
||||||
selectedValues.push(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// Apply duplicate prevention
|
|
||||||
$('select[id^="field-contact_id"]').each(function () {
|
|
||||||
|
|
||||||
let currentSelect = $(this);
|
|
||||||
let currentValue = currentSelect.val();
|
|
||||||
|
|
||||||
currentSelect.find('option').each(function () {
|
|
||||||
|
|
||||||
let option = $(this);
|
|
||||||
let optionValue = option.val();
|
|
||||||
|
|
||||||
if (!optionValue) return;
|
|
||||||
|
|
||||||
// Remove old text
|
|
||||||
let cleanText = option.text().replace(' (Already Added)', '');
|
|
||||||
|
|
||||||
if (
|
|
||||||
selectedValues.includes(optionValue) &&
|
|
||||||
optionValue !== currentValue
|
|
||||||
) {
|
|
||||||
|
|
||||||
option.prop('disabled', true);
|
|
||||||
option.text(cleanText + ' (Already Added)');
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
option.prop('disabled', false);
|
|
||||||
option.text(cleanText);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// 🔥 IMPORTANT
|
|
||||||
currentSelect.select2('destroy');
|
|
||||||
|
|
||||||
currentSelect.select2({
|
|
||||||
width: '100%',
|
|
||||||
placeholder: '-- Select Doctor --'
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
} */
|
|
||||||
|
|
||||||
function preventDuplicateDoctors() {
|
|
||||||
|
|
||||||
let selectedValues = [];
|
|
||||||
|
|
||||||
// Collect selected values
|
|
||||||
$('select[id^="field-contact_id"]').each(function () {
|
|
||||||
|
|
||||||
let value = $(this).val();
|
|
||||||
|
|
||||||
if (value) {
|
|
||||||
selectedValues.push(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$('select[id^="field-contact_id"]').each(function () {
|
|
||||||
|
|
||||||
let currentSelect = $(this);
|
|
||||||
let currentValue = currentSelect.val();
|
|
||||||
|
|
||||||
currentSelect.find('option').each(function () {
|
|
||||||
|
|
||||||
let option = $(this);
|
|
||||||
let optionValue = option.val();
|
|
||||||
|
|
||||||
if (!optionValue) return;
|
|
||||||
|
|
||||||
// remove previous label
|
|
||||||
let cleanText = option.text().replace(' (Already Added)', '');
|
|
||||||
|
|
||||||
// IMPORTANT:
|
|
||||||
// keep currently selected option enabled
|
|
||||||
if (
|
|
||||||
selectedValues.includes(optionValue) &&
|
|
||||||
optionValue !== currentValue
|
|
||||||
) {
|
|
||||||
|
|
||||||
option.prop('disabled', true);
|
|
||||||
option.text(cleanText + ' (Already Added)');
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
option.prop('disabled', false);
|
|
||||||
option.text(cleanText);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// refresh select2 safely
|
|
||||||
if (currentSelect.hasClass("select2-hidden-accessible")) {
|
|
||||||
currentSelect.select2('destroy');
|
|
||||||
}
|
|
||||||
|
|
||||||
currentSelect.select2({
|
|
||||||
width: '100%',
|
|
||||||
placeholder: '-- Select Doctor --'
|
|
||||||
});
|
|
||||||
|
|
||||||
// VERY IMPORTANT FOR EDIT MODE
|
|
||||||
currentSelect.val(currentValue).trigger('change.select2');
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(document).on('change', 'select[id^="field-contact_id"]', function () {
|
|
||||||
|
|
||||||
let selectedOption = $(this).find(':selected');
|
|
||||||
|
|
||||||
let id = $(this).attr('id').split('-').pop(); // get doctor_count dynamically
|
|
||||||
|
|
||||||
$('#field-msl_code-' + id).val(selectedOption.attr('msl_code'));
|
|
||||||
$('#field-speciality-' + id).val(selectedOption.attr('speciality'));
|
|
||||||
|
|
||||||
preventDuplicateDoctors();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var doctor_count = 0
|
|
||||||
let numberOfSubmission=0;
|
|
||||||
console.log("Number of Submission : ",numberOfSubmission);
|
|
||||||
$('#adddoctor-btn').click(function() {
|
|
||||||
let doctorName=$('#field-contact_id').html();
|
|
||||||
|
|
||||||
console.log("Doctor Name : ",doctorName);
|
|
||||||
doctor_count++;
|
|
||||||
numberOfSubmission=numberOfSubmission+1;
|
|
||||||
console.log("Number of Submission : ",numberOfSubmission);
|
|
||||||
|
|
||||||
let empty_doctor = `
|
|
||||||
|
|
||||||
<div class="doctor-wrapper"><button type="button" class="btn btn-danger btn-remove float-end" style="margin-top:-25px; margin-right:-25px"><i class="mdi mdi-close"></i></button>
|
|
||||||
|
|
||||||
@foreach($questions as $question)
|
|
||||||
@if( in_array($question->code,
|
|
||||||
["record_date","select_rxber_type"] ) )
|
|
||||||
@continue;
|
|
||||||
@endif
|
|
||||||
|
|
||||||
<div class="col-md-12 mb-2">
|
|
||||||
<label for="field-{{$question->code}}" class="form-label">{{$question->question}} {!!$question->required == 'yes' ? '<span class="text-danger">*</span>':''!!} </label>
|
|
||||||
@switch($question->type)
|
|
||||||
@case('hidden')
|
|
||||||
<input type="{{$question->type}}" id="field-{{$question->code}}-${doctor_count}" name="{{$question->code}}[${doctor_count}]" value="{{isset($question->value)?$question->value:''}}">
|
|
||||||
@break
|
|
||||||
@case('text')
|
|
||||||
@case('file')
|
|
||||||
@case('email')
|
|
||||||
@case('tel')
|
|
||||||
@case('date')
|
|
||||||
<input type="{{$question->type}}" id="field-{{$question->code}}-${doctor_count}" name="{{$question->code}}[${doctor_count}]" class="form-control" {{$question->required == 'yes'?'required':'' }} value="{{isset($question->value)?$question->value:''}}">
|
|
||||||
@break
|
|
||||||
@case('number')
|
|
||||||
<input type="{{$question->type}}" min="0" max="9999999999" step="1" id="field-{{$question->code}}-${doctor_count}" name="{{$question->code}}[${doctor_count}]" class="form-control" {{$question->required == 'yes'?'required':'' }} value="{{isset($question->value)?$question->value:0}}">
|
|
||||||
@break
|
|
||||||
@case('dropdown')
|
|
||||||
<select class="form-control" id="field-{{$question->code}}-${doctor_count}" name="{{$question->code}}[${doctor_count}]" {{$question->required == 'yes'?'required':'' }}>
|
|
||||||
@if($question->code=='contact_id')
|
|
||||||
${doctorName}
|
|
||||||
@else
|
|
||||||
<option value=""> -- Select -- </option>
|
|
||||||
@foreach($question->options as $option)
|
|
||||||
<option value="{{ $option->value }}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }} {{ $question->code == 'contact_id' ? 'msl_code= ' . $option->contact->msl_code . ' ' : '' }} {{ $question->code == 'contact_id' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality :'') . ' ' : '' }} >
|
|
||||||
{{ $option->display }}
|
|
||||||
</option>
|
|
||||||
@endforeach
|
|
||||||
@endif
|
|
||||||
</select>
|
|
||||||
@break
|
|
||||||
@endswitch
|
|
||||||
</div>
|
|
||||||
@endforeach </div>`;
|
|
||||||
|
|
||||||
|
|
||||||
$('#doctor-group-wrapper').append(empty_doctor)
|
|
||||||
|
|
||||||
$('#field-contact_id-'+doctor_count).select2({
|
|
||||||
|
|
||||||
width: '100%',
|
|
||||||
placeholder: '-- Select Doctor --'
|
|
||||||
});
|
|
||||||
preventDuplicateDoctors();
|
|
||||||
|
|
||||||
|
|
||||||
$('select[id^="execution-"]').select2({
|
|
||||||
width: '100%'
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
$('#field-msl_code-'+doctor_count).attr('readonly',true);
|
|
||||||
$('#field-speciality-'+doctor_count).attr('readonly',true);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($('.doctor-wrapper').length >= 10) {
|
|
||||||
$('#adddoctor-btn').hide();
|
|
||||||
} else {
|
|
||||||
$('#adddoctor-btn').show();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$('.btn-remove').unbind();
|
|
||||||
$('.btn-remove').click(function() {
|
|
||||||
$(this).closest('.doctor-wrapper').find('select').select2('destroy');
|
|
||||||
$(this).closest('.doctor-wrapper').remove();
|
|
||||||
numberOfSubmission--;
|
|
||||||
doctor_count--
|
|
||||||
preventDuplicateDoctors();
|
preventDuplicateDoctors();
|
||||||
console.log("New Number of Submission : ",numberOfSubmission);
|
|
||||||
console.log("Number of doctors : ",doctor_count);
|
|
||||||
$('#adddoctor-btn').show();
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$('#field-user_id').change(function(){
|
|
||||||
let hierarchy = $('option:selected', this).attr('hierarchy');
|
|
||||||
$('#field-hierarchy_id').val(hierarchy)
|
|
||||||
event.preventDefault();
|
|
||||||
$('#pageloader').fadeIn();
|
|
||||||
$.ajax({
|
|
||||||
type: "GET",
|
|
||||||
url: '/form/getdoctorlist?partition={{$form->partition}}&hierarchy='+hierarchy,
|
|
||||||
processData: false,
|
|
||||||
contentType: false,
|
|
||||||
success: function( data ) {
|
|
||||||
$("#pageloader").fadeOut();
|
|
||||||
$('#field-contact_id').html('')
|
|
||||||
$('#field-contact_id').append($("<option></option>").attr("value",'').text('-- Select --'));
|
|
||||||
for (let itm of data) {
|
|
||||||
$('#field-contact_id').append($("<option></option>").attr("value",itm.value).text(itm.display).attr("msl_code", itm.contact.msl_code).attr("speciality", itm.contact.speciality));
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#field-contact_id').change(function() {
|
|
||||||
$('#field-msl_code').val($('option:selected', this).attr('msl_code'))
|
|
||||||
})
|
|
||||||
|
|
||||||
$('#field-contact_id').change(function() {
|
|
||||||
$('#field-speciality').val($('option:selected', this).attr('speciality'))
|
|
||||||
})
|
|
||||||
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(hierarchy)
|
// Restrict brand name inputs to letters and spaces only
|
||||||
})
|
$(document).on('input', 'input[id^="field-brand_name"]', function () {
|
||||||
|
this.value = this.value.replace(/[^a-zA-Z\s]/g, '');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize Select2 elements helper
|
||||||
$('#report-form').on('submit', function(event) {
|
function initSelect2(selector, placeholderText) {
|
||||||
event.preventDefault();
|
$(selector).each(function() {
|
||||||
if (numberOfSubmission !=10) {
|
if ($(this).hasClass("select2-hidden-accessible")) {
|
||||||
alert(`You must submit 10 Doctors for Levoswitch , Current Doctors : ${numberOfSubmission+1}`);
|
$(this).select2('destroy');
|
||||||
return;
|
}
|
||||||
|
$(this).select2({
|
||||||
|
width: '100%',
|
||||||
|
placeholder: placeholderText || '-- Select --'
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Core logic to disable already selected doctors in other dropdowns
|
||||||
|
function preventDuplicateDoctors() {
|
||||||
|
let selectedDoctorIds = [];
|
||||||
|
|
||||||
|
// Step 1: Collect all currently selected doctor values
|
||||||
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
|
let val = $(this).val();
|
||||||
|
if (val && val !== '') {
|
||||||
|
selectedDoctorIds.push(String(val));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$("#pageloader").fadeIn();
|
// Step 2: Traverse each doctor select element and update option states
|
||||||
$.ajax({
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
type: "POST",
|
let $currentSelect = $(this);
|
||||||
url: '/form/ajaxsubmitmultiple',
|
let currentVal = String($currentSelect.val() || '');
|
||||||
data: new FormData($('#report-form')[0]),
|
|
||||||
processData: false,
|
$currentSelect.find('option').each(function () {
|
||||||
contentType: false,
|
let $option = $(this);
|
||||||
success: function(data) {
|
let optionVal = String($option.val() || '');
|
||||||
$("#pageloader").fadeOut();
|
|
||||||
if (data.status == 'success') {
|
// Skip the default placeholder option
|
||||||
Swal.fire({
|
if (!optionVal) return;
|
||||||
title: 'Great!',
|
|
||||||
text: 'Your data is successfully submitted!',
|
// Clean any previously appended '(Already Added)' tags
|
||||||
icon: 'success'
|
let rawText = $option.text().replace(/\s*\(Already Added\)/g, '').trim();
|
||||||
}).then(() => {
|
|
||||||
location.reload(); // 🔥 page refresh here
|
// If selected in another dropdown, disable and tag it
|
||||||
});
|
if (selectedDoctorIds.includes(optionVal) && optionVal !== currentVal) {
|
||||||
$('#report-form').trigger("reset");
|
$option.prop('disabled', true);
|
||||||
} else {
|
$option.text(rawText + ' (Already Added)');
|
||||||
|
} else {
|
||||||
|
$option.prop('disabled', false);
|
||||||
|
$option.text(rawText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Step 3: Refresh Select2 cleanly to render updated disabled states
|
||||||
|
if ($currentSelect.hasClass("select2-hidden-accessible")) {
|
||||||
|
$currentSelect.select2('destroy');
|
||||||
|
}
|
||||||
|
$currentSelect.select2({
|
||||||
|
width: '100%',
|
||||||
|
placeholder: '-- Select Doctor --'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Preserve the selected value
|
||||||
|
$currentSelect.val(currentVal);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initial setup on page load
|
||||||
|
initSelect2('select[id^="field-contact_id"]', '-- Select Doctor --');
|
||||||
|
initSelect2('#field-user_id', '-- Select User / Territory --');
|
||||||
|
initSelect2('select[id^="execution-"]');
|
||||||
|
$('#field-msl_code,#field-pcode,#field-speciality').attr('readonly', true);
|
||||||
|
preventDuplicateDoctors();
|
||||||
|
|
||||||
|
// Calculate doctor count based on existing elements
|
||||||
|
var doctor_count = $('.doctor-wrapper').length ? ($('.doctor-wrapper').length - 1) : 0;
|
||||||
|
|
||||||
|
// Add doctor row dynamically
|
||||||
|
$('#adddoctor-btn').click(function() {
|
||||||
|
if ($('.doctor-wrapper').length >= 10) {
|
||||||
|
alert('You can only add up to 10 doctors.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
doctor_count++;
|
||||||
|
|
||||||
|
// Clean clone of doctor options from the primary select element
|
||||||
|
let $temp = $('#field-contact_id').clone();
|
||||||
|
$temp.find('option').each(function() {
|
||||||
|
$(this).prop('disabled', false);
|
||||||
|
$(this).text($(this).text().replace(/\s*\(Already Added\)/g, '').trim());
|
||||||
|
});
|
||||||
|
let doctorName = $temp.html();
|
||||||
|
|
||||||
|
let empty_doctor = `
|
||||||
|
<div class="doctor-wrapper">
|
||||||
|
<button type="button" class="btn btn-danger btn-remove float-end" style="margin-top:-25px; margin-right:-25px">
|
||||||
|
<i class="mdi mdi-close"></i>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
@foreach($questions as $question)
|
||||||
|
@if( in_array($question->code, ["record_date","select_rxber_type"] ) )
|
||||||
|
@continue;
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<div class="col-md-12 mb-2">
|
||||||
|
<label for="field-{{$question->code}}-${doctor_count}" class="form-label">
|
||||||
|
{{$question->question}} {!!$question->required == 'yes' ? '<span class="text-danger">*</span>':''!!}
|
||||||
|
</label>
|
||||||
|
@switch($question->type)
|
||||||
|
@case('hidden')
|
||||||
|
<input type="{{$question->type}}" id="field-{{$question->code}}-${doctor_count}" name="{{$question->code}}[${doctor_count}]" value="{{isset($question->value)?$question->value:''}}">
|
||||||
|
@break
|
||||||
|
@case('text')
|
||||||
|
@case('file')
|
||||||
|
@case('email')
|
||||||
|
@case('tel')
|
||||||
|
@case('date')
|
||||||
|
<input type="{{$question->type}}" id="field-{{$question->code}}-${doctor_count}" name="{{$question->code}}[${doctor_count}]" class="form-control" {{$question->required == 'yes'?'required':'' }} value="{{isset($question->value)?$question->value:''}}">
|
||||||
|
@break
|
||||||
|
@case('number')
|
||||||
|
<input type="{{$question->type}}" min="0" max="9999999999" step="1" id="field-{{$question->code}}-${doctor_count}" name="{{$question->code}}[${doctor_count}]" class="form-control" {{$question->required == 'yes'?'required':'' }} value="{{isset($question->value)?$question->value:0}}">
|
||||||
|
@break
|
||||||
|
@case('dropdown')
|
||||||
|
<select class="form-control" id="field-{{$question->code}}-${doctor_count}" name="{{$question->code}}[${doctor_count}]" {{$question->required == 'yes'?'required':'' }}>
|
||||||
|
@if($question->code=='contact_id')
|
||||||
|
${doctorName}
|
||||||
|
@else
|
||||||
|
<option value=""> -- Select -- </option>
|
||||||
|
@foreach($question->options as $option)
|
||||||
|
<option value="{{ $option->value }}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
||||||
|
{{ $option->display }}
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
|
@endif
|
||||||
|
</select>
|
||||||
|
@break
|
||||||
|
@case('checkbox')
|
||||||
|
<div class="checkbox-group">
|
||||||
|
@if(isset($question->options) && count($question->options) > 0)
|
||||||
|
@foreach($question->options as $option)
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" id="field-{{$question->code}}-${doctor_count}-{{ $loop->index }}" name="{{$question->code}}[${doctor_count}][]" value="{{ $option->value }}">
|
||||||
|
<label class="form-check-label" for="field-{{$question->code}}-${doctor_count}-{{ $loop->index }}">
|
||||||
|
{{ $option->display }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
@break
|
||||||
|
@endswitch
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
let $newRow = $(empty_doctor);
|
||||||
|
$('#doctor-group-wrapper').append($newRow);
|
||||||
|
|
||||||
|
// Initialize Select2 on the new elements
|
||||||
|
initSelect2('#field-contact_id-' + doctor_count, '-- Select Doctor --');
|
||||||
|
initSelect2($newRow.find('select[id^="execution-"]'));
|
||||||
|
|
||||||
|
// Set readonly attributes for metadata inputs in the new card
|
||||||
|
$('#field-msl_code-' + doctor_count).attr('readonly', true);
|
||||||
|
$('#field-pcode-' + doctor_count).attr('readonly', true);
|
||||||
|
$('#field-speciality-' + doctor_count).attr('readonly', true);
|
||||||
|
|
||||||
|
// Update duplicate validation state
|
||||||
|
preventDuplicateDoctors();
|
||||||
|
|
||||||
|
// Toggle Add Button visibility
|
||||||
|
if ($('.doctor-wrapper').length >= 10) {
|
||||||
|
$('#adddoctor-btn').hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remove a doctor row
|
||||||
|
$(document).on('click', '.btn-remove', function() {
|
||||||
|
let $row = $(this).closest('.doctor-wrapper');
|
||||||
|
$row.find('select').each(function() {
|
||||||
|
if ($(this).hasClass("select2-hidden-accessible")) {
|
||||||
|
$(this).select2('destroy');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$row.remove();
|
||||||
|
|
||||||
|
// Re-enable options freed by removing this doctor
|
||||||
|
preventDuplicateDoctors();
|
||||||
|
|
||||||
|
if ($('.doctor-wrapper').length < 10) {
|
||||||
|
$('#adddoctor-btn').show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Territory / User dropdown dynamic change
|
||||||
|
$('#field-user_id').change(function(event){
|
||||||
|
let hierarchy = $('option:selected', this).attr('hierarchy');
|
||||||
|
$('#field-hierarchy_id').val(hierarchy);
|
||||||
|
$('#pageloader').fadeIn();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: '/form/getdoctorlist?partition={{$form->partition}}&hierarchy=' + hierarchy,
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
success: function(data) {
|
||||||
|
$("#pageloader").fadeOut();
|
||||||
|
let $contactSelect = $('#field-contact_id');
|
||||||
|
$contactSelect.empty().append($("<option></option>").attr("value", '').text('-- Select --'));
|
||||||
|
|
||||||
|
for (let itm of data) {
|
||||||
|
$contactSelect.append(
|
||||||
|
$("<option></option>")
|
||||||
|
.attr("value", itm.value)
|
||||||
|
.text(itm.display)
|
||||||
|
.attr("msl_code", itm.contact ? itm.contact.msl_code : '')
|
||||||
|
.attr("pcode", itm.contact ? itm.contact.pcode : '')
|
||||||
|
.attr("speciality", itm.contact ? itm.contact.speciality : '')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$contactSelect.val('').trigger('change.select2');
|
||||||
|
preventDuplicateDoctors();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Form submit handler
|
||||||
|
$('#report-form').on('submit', function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
let currentTotal = $('.doctor-wrapper').length;
|
||||||
|
|
||||||
|
// Only enforce 10 submissions in Create Mode
|
||||||
|
if (!isEditMode && currentTotal !== 10) {
|
||||||
|
alert(`You must submit 10 Doctors for Levoswitch, Current Doctors: ${currentTotal}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#pageloader").fadeIn();
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: '/form/ajaxsubmitmultiple',
|
||||||
|
data: new FormData($('#report-form')[0]),
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
success: function(data) {
|
||||||
|
$("#pageloader").fadeOut();
|
||||||
|
if (data.status == 'success') {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Great!',
|
||||||
|
text: 'Your data is successfully submitted!',
|
||||||
|
icon: 'success'
|
||||||
|
}).then(() => {
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
$('#report-form').trigger("reset");
|
||||||
|
} else {
|
||||||
|
Swal.fire({
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Data not submitted',
|
||||||
|
text: data.message || 'Something went wrong, please try again after some time!'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function() {
|
||||||
|
$("#pageloader").fadeOut();
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
title: 'Data not submitted',
|
title: 'Server Error',
|
||||||
text: 'Something went wrong, please try again after some time!'
|
text: 'Something went wrong, please try again after some time!'
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script> --}}
|
</script> --}}
|
||||||
|
|
@ -694,10 +633,9 @@
|
||||||
<script>
|
<script>
|
||||||
jQuery(document).ready(function($) {
|
jQuery(document).ready(function($) {
|
||||||
|
|
||||||
// Check whether the form is loaded in Edit Mode
|
|
||||||
var isEditMode = @json((bool)$id);
|
var isEditMode = @json((bool)$id);
|
||||||
|
|
||||||
// Auto-fill metadata fields (MSL Code, Pcode, Speciality) dynamically
|
// Auto-fill metadata fields
|
||||||
$(document).on('change', 'select[id^="field-contact_id"]', function() {
|
$(document).on('change', 'select[id^="field-contact_id"]', function() {
|
||||||
let selectedOption = $(this).find(':selected');
|
let selectedOption = $(this).find(':selected');
|
||||||
let idParts = $(this).attr('id').split('-');
|
let idParts = $(this).attr('id').split('-');
|
||||||
|
|
@ -707,16 +645,15 @@
|
||||||
$('#field-pcode' + suffix).val(selectedOption.attr('pcode') || '');
|
$('#field-pcode' + suffix).val(selectedOption.attr('pcode') || '');
|
||||||
$('#field-speciality' + suffix).val(selectedOption.attr('speciality') || '');
|
$('#field-speciality' + suffix).val(selectedOption.attr('speciality') || '');
|
||||||
|
|
||||||
// Refresh disabled options across all doctor dropdowns
|
|
||||||
preventDuplicateDoctors();
|
preventDuplicateDoctors();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Restrict brand name inputs to letters and spaces only
|
// Restrict brand name
|
||||||
$(document).on('input', 'input[id^="field-brand_name"]', function () {
|
$(document).on('input', 'input[id^="field-brand_name"]', function () {
|
||||||
this.value = this.value.replace(/[^a-zA-Z\s]/g, '');
|
this.value = this.value.replace(/[^a-zA-Z\s]/g, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize Select2 elements helper
|
// Init Select2
|
||||||
function initSelect2(selector, placeholderText) {
|
function initSelect2(selector, placeholderText) {
|
||||||
$(selector).each(function() {
|
$(selector).each(function() {
|
||||||
if ($(this).hasClass("select2-hidden-accessible")) {
|
if ($(this).hasClass("select2-hidden-accessible")) {
|
||||||
|
|
@ -729,11 +666,10 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Core logic to disable already selected doctors in other dropdowns
|
// Duplicate doctor restriction
|
||||||
function preventDuplicateDoctors() {
|
function preventDuplicateDoctors() {
|
||||||
let selectedDoctorIds = [];
|
let selectedDoctorIds = [];
|
||||||
|
|
||||||
// Step 1: Collect all currently selected doctor values
|
|
||||||
$('select[id^="field-contact_id"]').each(function () {
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
let val = $(this).val();
|
let val = $(this).val();
|
||||||
if (val && val !== '') {
|
if (val && val !== '') {
|
||||||
|
|
@ -741,7 +677,6 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Step 2: Traverse each doctor select element and update option states
|
|
||||||
$('select[id^="field-contact_id"]').each(function () {
|
$('select[id^="field-contact_id"]').each(function () {
|
||||||
let $currentSelect = $(this);
|
let $currentSelect = $(this);
|
||||||
let currentVal = String($currentSelect.val() || '');
|
let currentVal = String($currentSelect.val() || '');
|
||||||
|
|
@ -750,13 +685,10 @@
|
||||||
let $option = $(this);
|
let $option = $(this);
|
||||||
let optionVal = String($option.val() || '');
|
let optionVal = String($option.val() || '');
|
||||||
|
|
||||||
// Skip the default placeholder option
|
|
||||||
if (!optionVal) return;
|
if (!optionVal) return;
|
||||||
|
|
||||||
// Clean any previously appended '(Already Added)' tags
|
|
||||||
let rawText = $option.text().replace(/\s*\(Already Added\)/g, '').trim();
|
let rawText = $option.text().replace(/\s*\(Already Added\)/g, '').trim();
|
||||||
|
|
||||||
// If selected in another dropdown, disable and tag it
|
|
||||||
if (selectedDoctorIds.includes(optionVal) && optionVal !== currentVal) {
|
if (selectedDoctorIds.includes(optionVal) && optionVal !== currentVal) {
|
||||||
$option.prop('disabled', true);
|
$option.prop('disabled', true);
|
||||||
$option.text(rawText + ' (Already Added)');
|
$option.text(rawText + ' (Already Added)');
|
||||||
|
|
@ -766,7 +698,6 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Step 3: Refresh Select2 cleanly to render updated disabled states
|
|
||||||
if ($currentSelect.hasClass("select2-hidden-accessible")) {
|
if ($currentSelect.hasClass("select2-hidden-accessible")) {
|
||||||
$currentSelect.select2('destroy');
|
$currentSelect.select2('destroy');
|
||||||
}
|
}
|
||||||
|
|
@ -775,20 +706,20 @@
|
||||||
placeholder: '-- Select Doctor --'
|
placeholder: '-- Select Doctor --'
|
||||||
});
|
});
|
||||||
|
|
||||||
// Preserve the selected value
|
|
||||||
$currentSelect.val(currentVal);
|
$currentSelect.val(currentVal);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial setup on page load
|
// Initialize elements
|
||||||
initSelect2('select[id^="field-contact_id"]', '-- Select Doctor --');
|
initSelect2('select[id^="field-contact_id"]', '-- Select Doctor --');
|
||||||
initSelect2('#field-user_id', '-- Select User / Territory --');
|
initSelect2('#field-user_id', '-- Select User / Territory --');
|
||||||
initSelect2('select[id^="execution-"]');
|
initSelect2('select[id^="execution-"]');
|
||||||
$('#field-msl_code,#field-pcode,#field-speciality').attr('readonly', true);
|
$('#field-msl_code,#field-pcode,#field-speciality').attr('readonly', true);
|
||||||
preventDuplicateDoctors();
|
|
||||||
|
|
||||||
// Calculate doctor count based on existing elements
|
// Populate metadata on initial edit load
|
||||||
var doctor_count = $('.doctor-wrapper').length ? ($('.doctor-wrapper').length - 1) : 0;
|
$('select[id^="field-contact_id"]').trigger('change');
|
||||||
|
|
||||||
|
var doctor_count = $('.doctor-wrapper').length || 0;
|
||||||
|
|
||||||
// Add doctor row dynamically
|
// Add doctor row dynamically
|
||||||
$('#adddoctor-btn').click(function() {
|
$('#adddoctor-btn').click(function() {
|
||||||
|
|
@ -799,7 +730,6 @@
|
||||||
|
|
||||||
doctor_count++;
|
doctor_count++;
|
||||||
|
|
||||||
// Clean clone of doctor options from the primary select element
|
|
||||||
let $temp = $('#field-contact_id').clone();
|
let $temp = $('#field-contact_id').clone();
|
||||||
$temp.find('option').each(function() {
|
$temp.find('option').each(function() {
|
||||||
$(this).prop('disabled', false);
|
$(this).prop('disabled', false);
|
||||||
|
|
@ -872,25 +802,21 @@
|
||||||
let $newRow = $(empty_doctor);
|
let $newRow = $(empty_doctor);
|
||||||
$('#doctor-group-wrapper').append($newRow);
|
$('#doctor-group-wrapper').append($newRow);
|
||||||
|
|
||||||
// Initialize Select2 on the new elements
|
|
||||||
initSelect2('#field-contact_id-' + doctor_count, '-- Select Doctor --');
|
initSelect2('#field-contact_id-' + doctor_count, '-- Select Doctor --');
|
||||||
initSelect2($newRow.find('select[id^="execution-"]'));
|
initSelect2($newRow.find('select[id^="execution-"]'));
|
||||||
|
|
||||||
// Set readonly attributes for metadata inputs in the new card
|
|
||||||
$('#field-msl_code-' + doctor_count).attr('readonly', true);
|
$('#field-msl_code-' + doctor_count).attr('readonly', true);
|
||||||
$('#field-pcode-' + doctor_count).attr('readonly', true);
|
$('#field-pcode-' + doctor_count).attr('readonly', true);
|
||||||
$('#field-speciality-' + doctor_count).attr('readonly', true);
|
$('#field-speciality-' + doctor_count).attr('readonly', true);
|
||||||
|
|
||||||
// Update duplicate validation state
|
|
||||||
preventDuplicateDoctors();
|
preventDuplicateDoctors();
|
||||||
|
|
||||||
// Toggle Add Button visibility
|
|
||||||
if ($('.doctor-wrapper').length >= 10) {
|
if ($('.doctor-wrapper').length >= 10) {
|
||||||
$('#adddoctor-btn').hide();
|
$('#adddoctor-btn').hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove a doctor row
|
// Remove row
|
||||||
$(document).on('click', '.btn-remove', function() {
|
$(document).on('click', '.btn-remove', function() {
|
||||||
let $row = $(this).closest('.doctor-wrapper');
|
let $row = $(this).closest('.doctor-wrapper');
|
||||||
$row.find('select').each(function() {
|
$row.find('select').each(function() {
|
||||||
|
|
@ -899,8 +825,6 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$row.remove();
|
$row.remove();
|
||||||
|
|
||||||
// Re-enable options freed by removing this doctor
|
|
||||||
preventDuplicateDoctors();
|
preventDuplicateDoctors();
|
||||||
|
|
||||||
if ($('.doctor-wrapper').length < 10) {
|
if ($('.doctor-wrapper').length < 10) {
|
||||||
|
|
@ -908,7 +832,7 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Territory / User dropdown dynamic change
|
// User/Territory Change
|
||||||
$('#field-user_id').change(function(event){
|
$('#field-user_id').change(function(event){
|
||||||
let hierarchy = $('option:selected', this).attr('hierarchy');
|
let hierarchy = $('option:selected', this).attr('hierarchy');
|
||||||
$('#field-hierarchy_id').val(hierarchy);
|
$('#field-hierarchy_id').val(hierarchy);
|
||||||
|
|
@ -941,18 +865,20 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Form submit handler
|
// Form Submit
|
||||||
$('#report-form').on('submit', function(event) {
|
$('#report-form').on('submit', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
let currentTotal = $('.doctor-wrapper').length;
|
let currentTotal = $('.doctor-wrapper').length;
|
||||||
|
|
||||||
// Only enforce 10 submissions in Create Mode
|
|
||||||
if (!isEditMode && currentTotal !== 10) {
|
if (!isEditMode && currentTotal !== 10) {
|
||||||
alert(`You must submit 10 Doctors for Levoswitch, Current Doctors: ${currentTotal}`);
|
alert(`You must submit 10 Doctors for Levoswitch, Current Doctors: ${currentTotal}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CRITICAL FIX: Re-enable disabled options so values are not skipped in FormData
|
||||||
|
$('select option:disabled').prop('disabled', false);
|
||||||
|
|
||||||
$("#pageloader").fadeIn();
|
$("#pageloader").fadeIn();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
|
@ -972,6 +898,7 @@
|
||||||
});
|
});
|
||||||
$('#report-form').trigger("reset");
|
$('#report-form').trigger("reset");
|
||||||
} else {
|
} else {
|
||||||
|
preventDuplicateDoctors(); // Re-apply restrictions on failure
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
title: 'Data not submitted',
|
title: 'Data not submitted',
|
||||||
|
|
@ -979,12 +906,19 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(xhr) {
|
||||||
$("#pageloader").fadeOut();
|
$("#pageloader").fadeOut();
|
||||||
|
preventDuplicateDoctors(); // Re-apply restrictions on failure
|
||||||
|
|
||||||
|
let errorMsg = 'Something went wrong, please try again after some time!';
|
||||||
|
if (xhr.responseJSON && xhr.responseJSON.message) {
|
||||||
|
errorMsg = xhr.responseJSON.message;
|
||||||
|
}
|
||||||
|
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
title: 'Server Error',
|
title: 'Server Error',
|
||||||
text: 'Something went wrong, please try again after some time!'
|
text: errorMsg
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -992,6 +926,8 @@
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue