Team 4 (Mother Forum)Doctors load
Specific Folder FTP Upload / ftp-deploy (push) Successful in 39s
Details
Specific Folder FTP Upload / ftp-deploy (push) Successful in 39s
Details
This commit is contained in:
parent
1ef595af46
commit
66368f7a1c
|
|
@ -89,72 +89,27 @@
|
|||
@case('textarea')
|
||||
<textarea id="field-{{$question->code}}" name="{{$question->code}}" class="form-control" {{$question->required == 'yes'?'required':'' }}>{{isset($question->value)?$question->value:''}}</textarea>
|
||||
@break
|
||||
{{-- @case('dropdown')
|
||||
@php
|
||||
$isContact = str_starts_with($question->code, 'contact_id');
|
||||
$options = collect($question->options)->sortBy('display', SORT_NATURAL | SORT_FLAG_CASE);
|
||||
@endphp
|
||||
|
||||
<select class="form-control" {!!($isContact)?'data-toggle="select2"':'' !!} id="field-{{ $question->code }}" name="{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }}>
|
||||
<option value=""> -- Select -- </option>
|
||||
@foreach ($question->options as $option)
|
||||
@if($isContact && isset($option->contact->type) && $option->contact->type == 'doctor' )
|
||||
<option value="{{ $option->value }}"
|
||||
@if(isset($question->value) && $question->value == $option->value) selected @endif
|
||||
@if($isContact)
|
||||
msl_code="{{ (isset($option->contact->msl_code) ? $option->contact->msl_code : '') }}"
|
||||
speciality="{{ (isset($option->contact->speciality) ? $option->contact->speciality : '') }}"
|
||||
@endif
|
||||
>
|
||||
{{ $option->display }}
|
||||
</option>
|
||||
@elseif(!$isContact)
|
||||
<option value="{{ $option->value }}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }} {{ $question->code == 'contact_id' ? 'pcode= ' . (isset($option->contact->pcode)?$option->contact->pcode:'') . ' ' : '' }} {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }} {{ $question->code == 'contact_id' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality :'') . ' ' : '' }} >
|
||||
{{ $option->display }}
|
||||
</option>
|
||||
@endif
|
||||
|
||||
|
||||
|
||||
@endforeach
|
||||
</select>
|
||||
@break --}}
|
||||
|
||||
|
||||
|
||||
@case('dropdown')
|
||||
@php
|
||||
$isContact = str_starts_with($question->code, 'contact_id');
|
||||
|
||||
// जर options collection किंवा array असेल तर display field नुसार alphabetize करा
|
||||
$options = collect($question->options)->sortBy('display', SORT_NATURAL | SORT_FLAG_CASE);
|
||||
@endphp
|
||||
|
||||
<select class="form-control" {!!($isContact)?'data-toggle="select2"':'' !!} id="field-{{ $question->code }}" name="{{ $question->code }}" data-selected="{{ isset($question->value) ? $question->value : '' }}" {{ $question->required == 'yes' ? 'required' : '' }}>
|
||||
{{-- $isContact असल्यास data-toggle="select2" देऊ नका, जेणेकरून AJAX लोड होण्यापूर्वी Select2 चुकीच्या options सह bind होणार नाही --}}
|
||||
<select class="form-control" {!! (!$isContact) ? 'data-toggle="select2"' : '' !!} id="field-{{ $question->code }}" name="{{ $question->code }}" data-selected="{{ isset($question->value) ? $question->value : '' }}" {{ $question->required == 'yes' ? 'required' : '' }}>
|
||||
<option value=""> -- Select -- </option>
|
||||
|
||||
{{-- $question->options ऐवजी $options वापरा --}}
|
||||
@foreach ($options as $option)
|
||||
@if($isContact && isset($option->contact->type) && $option->contact->type == 'doctor' )
|
||||
<option value="{{ $option->value }}"
|
||||
@if(isset($question->value) && $question->value == $option->value) selected @endif
|
||||
@if($isContact)
|
||||
msl_code="{{ (isset($option->contact->msl_code) ? $option->contact->msl_code : '') }}"
|
||||
speciality="{{ (isset($option->contact->speciality) ? $option->contact->speciality : '') }}"
|
||||
@endif
|
||||
>
|
||||
@if(!$isContact)
|
||||
@foreach ($options as $option)
|
||||
<option value="{{ $option->value }}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
||||
{{ $option->display }}
|
||||
</option>
|
||||
@elseif(!$isContact)
|
||||
<option value="{{ $option->value }}"
|
||||
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}
|
||||
{{ $question->code == 'contact_id' ? 'pcode= ' . (isset($option->contact->pcode)?$option->contact->pcode:'') . ' ' : '' }}
|
||||
{{ $question->code == 'contact_id' ? 'speciality= ' . (isset($option->contact->speciality) ? $option->contact->speciality :'') . ' ' : '' }}>
|
||||
{{ $option->display }}
|
||||
</option>
|
||||
@endif
|
||||
@endforeach
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
@break
|
||||
|
||||
@case('checkbox')
|
||||
@foreach($question->options as $option)
|
||||
<div class="form-check mb-2 form-check-primary">
|
||||
|
|
@ -265,9 +220,7 @@
|
|||
});
|
||||
})
|
||||
).then(function() {
|
||||
// All contacts loaded for each hierarchy
|
||||
// Example usage: console.log(contacts);
|
||||
// Filter out contacts where value == 'sample'
|
||||
|
||||
contacts = contacts.filter(function(itm) { return itm.value !== 'sample' && itm.contact && itm.contact.type === 'doctor' });
|
||||
|
||||
contacts.sort(function(a, b) {
|
||||
|
|
@ -278,18 +231,7 @@
|
|||
|
||||
// Loop through contacts and append options to select elements whose id starts with 'field-contact_id'
|
||||
// We assume contact_id fields may be suffixed, e.g. field-contact_id_1, field-contact_id, etc.
|
||||
function applySelect2ToDoctorDropdowns() {
|
||||
$("select[id^='field-contact_id']").each(function () {
|
||||
var select = $(this);
|
||||
// Avoid re-initializing select2
|
||||
if (select.data("select2")) return;
|
||||
select.select2({
|
||||
width: "100%",
|
||||
placeholder: "-- Select --",
|
||||
allowClear: true
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$('input[id^="field-msl_code"], input[id^="field-speciality"]').prop('readonly', true);
|
||||
|
||||
|
|
@ -309,8 +251,10 @@
|
|||
var currentSelect = $(this);
|
||||
var currentVal = currentSelect.val() ? String(currentSelect.val()) : "";
|
||||
|
||||
|
||||
currentSelect.find("option").prop("disabled", false);
|
||||
|
||||
|
||||
selectedValues.forEach(function (v) {
|
||||
if (v && v !== currentVal) {
|
||||
currentSelect
|
||||
|
|
@ -321,95 +265,64 @@
|
|||
|
||||
|
||||
if (currentSelect.hasClass("select2-hidden-accessible")) {
|
||||
|
||||
currentSelect.select2({
|
||||
width: "100%",
|
||||
placeholder: "-- Select --",
|
||||
allowClear: true
|
||||
});
|
||||
currentSelect.trigger('change.select2');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$("select[id^='field-contact_id']").each(function() {
|
||||
var select = $(this);
|
||||
// Clear previous options
|
||||
var select = $(this);
|
||||
var savedValue = select.attr('data-selected') || select.data('selected') || select.val() || '';
|
||||
|
||||
var savedValue = select.attr('data-selected') || select.data('selected') || select.val() || '';
|
||||
select.empty();
|
||||
// जुने select2 नष्ट करा (जर आधी लागले असेल तर)
|
||||
if (select.hasClass("select2-hidden-accessible")) {
|
||||
select.select2('destroy');
|
||||
}
|
||||
|
||||
// Add a default 'Select' option
|
||||
select.append(
|
||||
$("<option></option>")
|
||||
.attr("value", '')
|
||||
.text('-- Select --')
|
||||
);
|
||||
// Append options from contacts
|
||||
contacts.forEach(function(itm) {
|
||||
var option = $("<option></option>")
|
||||
.attr("value", itm.value)
|
||||
.text(itm.display);
|
||||
|
||||
// Options रीसेट करा
|
||||
select.empty();
|
||||
select.append($("<option></option>").attr("value", '').text('-- Select --'));
|
||||
|
||||
// नवीन contacts append करा
|
||||
contacts.forEach(function(itm) {
|
||||
var option = $("<option></option>").attr("value", itm.value).text(itm.display);
|
||||
|
||||
// If doctor options have extra attributes
|
||||
if (itm.contact && itm.contact.msl_code) {
|
||||
option.attr("msl_code", itm.contact.msl_code);
|
||||
}
|
||||
if (itm.contact && itm.contact.speciality) {
|
||||
option.attr("speciality", itm.contact.speciality);
|
||||
}
|
||||
if (itm.contact && itm.contact.msl_code) {
|
||||
option.attr("msl_code", itm.contact.msl_code);
|
||||
}
|
||||
if (itm.contact && itm.contact.speciality) {
|
||||
option.attr("speciality", itm.contact.speciality);
|
||||
}
|
||||
|
||||
if (savedValue && String(savedValue) === String(itm.value)) {
|
||||
option.prop('selected', true);
|
||||
}
|
||||
if (savedValue && String(savedValue) === String(itm.value)) {
|
||||
option.prop('selected', true);
|
||||
}
|
||||
|
||||
select.append(option);
|
||||
});
|
||||
select.append(option);
|
||||
});
|
||||
|
||||
// For each select element, add a change event handler to populate `msl_code` and `speciality`
|
||||
// We assume dropdowns and targets follow the pattern:
|
||||
// - select: field-contact_id_1, field-contact_id_2, ..., field-contact_id
|
||||
// - result: field-msl_code_1, field-speciality_1, etc.
|
||||
// Event listener bind करा
|
||||
select.off('change').on('change', function () {
|
||||
var selected = $(this).find(':selected');
|
||||
var selectId = $(this).attr('id');
|
||||
var match = selectId.match(/^field-contact_id(_\d+)?$/);
|
||||
var suffix = match && match[1] ? match[1] : '';
|
||||
|
||||
// Remove any old event handlers first to prevent duplicate bindings
|
||||
select.off('change').on('change', function () {
|
||||
var selected = $(this).find(':selected');
|
||||
|
||||
var selectId = $(this).attr('id'); // e.g., field-contact_id_1
|
||||
// Extract the suffix (e.g., _1 or empty)
|
||||
var match = selectId.match(/^field-contact_id(_\d+)?$/);
|
||||
var suffix = match && match[1] ? match[1] : '';
|
||||
var mslCodeField = $('#field-msl_code' + suffix);
|
||||
var specialityField = $('#field-speciality' + suffix);
|
||||
|
||||
// Build the target msl_code and speciality field ids
|
||||
var mslCodeField = $('#field-msl_code' + suffix);
|
||||
var specialityField = $('#field-speciality' + suffix);
|
||||
if (mslCodeField.length) {
|
||||
mslCodeField.val(selected.attr('msl_code') || '');
|
||||
}
|
||||
if (specialityField.length) {
|
||||
specialityField.val(selected.attr('speciality') || '');
|
||||
}
|
||||
|
||||
if (mslCodeField.length) {
|
||||
mslCodeField.val(selected.attr('msl_code') || '');
|
||||
}
|
||||
if (specialityField.length) {
|
||||
specialityField.val(selected.attr('speciality') || '');
|
||||
}
|
||||
enforceUniqueDoctorSelections();
|
||||
});
|
||||
|
||||
// Prevent selecting the same doctor across multiple dropdowns
|
||||
enforceUniqueDoctorSelections();
|
||||
});
|
||||
|
||||
if (savedValue) {
|
||||
select.val(savedValue).trigger('change');
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
// Ensure unique selection is enforced after initial render
|
||||
enforceUniqueDoctorSelections();
|
||||
// Enable search on doctor dropdowns
|
||||
applySelect2ToDoctorDropdowns();
|
||||
$("#pageloader").fadeOut();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue