Team 4 (Mother Forum) new Code
Specific Folder FTP Upload / ftp-deploy (push) Successful in 37s
Details
Specific Folder FTP Upload / ftp-deploy (push) Successful in 37s
Details
This commit is contained in:
parent
8c81e89669
commit
446a15061d
|
|
@ -180,61 +180,18 @@
|
||||||
top: 50%;
|
top: 50%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@include('layouts.shared/footer-script')
|
@include('layouts.shared/footer-script')
|
||||||
<script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
|
<script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
|
||||||
<script src="{{ asset('assets/libs/select2/select2.min.js') }}"></script>
|
<script src="{{ asset('assets/libs/select2/select2.min.js') }}"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
jQuery(document).ready(function($){
|
jQuery(document).ready(function($){
|
||||||
$('[data-toggle="select2"]').select2();
|
$('[data-toggle="select2"]').select2();
|
||||||
|
|
||||||
// 1. दोन्ही helper functions वर global scope मध्ये ठेवा
|
|
||||||
function applySelect2ToDoctorDropdowns() {
|
|
||||||
$("[id^='field-contact_id']").each(function () {
|
|
||||||
var select = $(this);
|
|
||||||
if (select.data("select2")) return;
|
|
||||||
select.select2({
|
|
||||||
width: "100%",
|
|
||||||
placeholder: "-- Select --",
|
|
||||||
allowClear: true
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function enforceUniqueDoctorSelections() {
|
|
||||||
var selectedValues = [];
|
|
||||||
|
|
||||||
$("[id^='field-contact_id']").each(function () {
|
|
||||||
var v = $(this).val();
|
|
||||||
if (v) selectedValues.push(String(v));
|
|
||||||
});
|
|
||||||
|
|
||||||
$("[id^='field-contact_id']").each(function () {
|
|
||||||
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
|
|
||||||
.find("option[value=\"" + v.replace(/"/g, '\\"') + "\"]")
|
|
||||||
.prop("disabled", true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (currentSelect.data("select2")) {
|
|
||||||
currentSelect.trigger("change.select2");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var hierarcies = [];
|
var hierarcies = [];
|
||||||
var contacts = [];
|
var contacts = [];
|
||||||
|
|
||||||
@if(isset($form->manager_can_submit) && $form->manager_can_submit == true)
|
@if(isset($form->manager_can_submit) && $form->manager_can_submit == true)
|
||||||
@foreach($form->users as $option)
|
@foreach($form->users as $option)
|
||||||
hierarcies.push('{{$option->hierarchy_id}}');
|
hierarcies.push('{{$option->hierarchy_id}}');
|
||||||
@endforeach
|
@endforeach
|
||||||
$("#pageloader").fadeIn();
|
$("#pageloader").fadeIn();
|
||||||
Promise.all(
|
Promise.all(
|
||||||
|
|
@ -245,24 +202,82 @@
|
||||||
processData: false,
|
processData: false,
|
||||||
contentType: false
|
contentType: false
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
|
console.log(data);
|
||||||
contacts = contacts.concat(data);
|
contacts = contacts.concat(data);
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
).then(function() {
|
).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'; });
|
contacts = contacts.filter(function(itm) { return itm.value !== 'sample'; });
|
||||||
|
console.log(contacts);
|
||||||
|
|
||||||
|
// 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() {
|
||||||
|
$("[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
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function enforceUniqueDoctorSelections() {
|
||||||
|
var selectedValues = [];
|
||||||
|
|
||||||
|
// Collect selected values (ignore empty)
|
||||||
|
$("[id^='field-contact_id']").each(function () {
|
||||||
|
var v = $(this).val();
|
||||||
|
if (v) selectedValues.push(String(v));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Reset all option disabled states, then disable duplicates across selects
|
||||||
|
$("[id^='field-contact_id']").each(function () {
|
||||||
|
var currentSelect = $(this);
|
||||||
|
var currentVal = currentSelect.val() ? String(currentSelect.val()) : "";
|
||||||
|
|
||||||
|
currentSelect.find("option").prop("disabled", false);
|
||||||
|
|
||||||
|
// Disable values selected in OTHER selects (keep current selection enabled)
|
||||||
|
selectedValues.forEach(function (v) {
|
||||||
|
if (v && v !== currentVal) {
|
||||||
|
currentSelect
|
||||||
|
.find("option[value=\"" + v.replace(/"/g, '\\"') + "\"]")
|
||||||
|
.prop("disabled", true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Refresh select2 UI if present
|
||||||
|
if (currentSelect.data("select2")) {
|
||||||
|
currentSelect.trigger("change.select2");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$("[id^='field-contact_id']").each(function() {
|
$("[id^='field-contact_id']").each(function() {
|
||||||
var select = $(this);
|
var select = $(this);
|
||||||
|
// Clear previous options
|
||||||
select.html('');
|
select.html('');
|
||||||
select.append($("<option></option>").attr("value", '').text('-- Select --'));
|
// Add a default 'Select' option
|
||||||
|
select.append(
|
||||||
|
$("<option></option>")
|
||||||
|
.attr("value", '')
|
||||||
|
.text('-- Select --')
|
||||||
|
);
|
||||||
|
// Append options from contacts
|
||||||
contacts.forEach(function(itm) {
|
contacts.forEach(function(itm) {
|
||||||
var option = $("<option></option>")
|
var option = $("<option></option>")
|
||||||
.attr("value", itm.value)
|
.attr("value", itm.value)
|
||||||
.text(itm.display);
|
.text(itm.display);
|
||||||
|
// If doctor options have extra attributes
|
||||||
if (itm.contact && itm.contact.msl_code) {
|
if (itm.contact && itm.contact.msl_code) {
|
||||||
option.attr("msl_code", itm.contact.msl_code);
|
option.attr("msl_code", itm.contact.msl_code);
|
||||||
}
|
}
|
||||||
|
|
@ -272,12 +287,21 @@
|
||||||
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.
|
||||||
|
|
||||||
|
// Remove any old event handlers first to prevent duplicate bindings
|
||||||
select.off('change').on('change', function () {
|
select.off('change').on('change', function () {
|
||||||
var selected = $(this).find(':selected');
|
var selected = $(this).find(':selected');
|
||||||
var selectId = $(this).attr('id');
|
|
||||||
|
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 match = selectId.match(/^field-contact_id(_\d+)?$/);
|
||||||
var suffix = match && match[1] ? match[1] : '';
|
var suffix = match && match[1] ? match[1] : '';
|
||||||
|
|
||||||
|
// Build the target msl_code and speciality field ids
|
||||||
var mslCodeField = $('#field-msl_code' + suffix);
|
var mslCodeField = $('#field-msl_code' + suffix);
|
||||||
var specialityField = $('#field-speciality' + suffix);
|
var specialityField = $('#field-speciality' + suffix);
|
||||||
|
|
||||||
|
|
@ -288,98 +312,38 @@
|
||||||
specialityField.val(selected.attr('speciality') || '');
|
specialityField.val(selected.attr('speciality') || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prevent selecting the same doctor across multiple dropdowns
|
||||||
enforceUniqueDoctorSelections();
|
enforceUniqueDoctorSelections();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Ensure unique selection is enforced after initial render
|
||||||
enforceUniqueDoctorSelections();
|
enforceUniqueDoctorSelections();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Enable search on doctor dropdowns
|
||||||
applySelect2ToDoctorDropdowns();
|
applySelect2ToDoctorDropdowns();
|
||||||
$("#pageloader").fadeOut();
|
$("#pageloader").fadeOut();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
// 2. Month change handler
|
|
||||||
var existingSubmissions = @json($submissions ?? []);
|
|
||||||
|
|
||||||
$('#field-month').on('change', function () {
|
|
||||||
var selectedMonth = $(this).val();
|
|
||||||
if (!selectedMonth) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var prevSubmission = existingSubmissions.find(function (sub) {
|
|
||||||
var subData = typeof sub.data === 'string' ? JSON.parse(sub.data) : (sub.data || {});
|
|
||||||
return (sub.month === selectedMonth) || (subData.month === selectedMonth);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (prevSubmission) {
|
|
||||||
var rawValues = prevSubmission.data || prevSubmission;
|
|
||||||
var values = typeof rawValues === 'string' ? JSON.parse(rawValues) : rawValues;
|
|
||||||
|
|
||||||
if (prevSubmission.id) {
|
|
||||||
if ($('input[name="id"]').length) {
|
|
||||||
$('input[name="id"]').val(prevSubmission.id);
|
|
||||||
} else {
|
|
||||||
$('#report-form').append('<input type="hidden" name="id" value="' + prevSubmission.id + '">');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$.each(values, function (fieldKey, val) {
|
|
||||||
if (fieldKey === 'month') return;
|
|
||||||
|
|
||||||
var field = $('[name="' + fieldKey + '"]');
|
|
||||||
if (!field.length) {
|
|
||||||
field = $('[name="' + fieldKey + '[]"]');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (field.length) {
|
|
||||||
if (field.is(':checkbox')) {
|
|
||||||
field.prop('checked', false);
|
|
||||||
if (Array.isArray(val)) {
|
|
||||||
val.forEach(function (v) {
|
|
||||||
field.filter('[value="' + v + '"]').prop('checked', true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (field.is('select')) {
|
|
||||||
field.val(val);
|
|
||||||
field.trigger('change');
|
|
||||||
if (field.data('select2')) {
|
|
||||||
field.trigger('change.select2');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
field.val(val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
enforceUniqueDoctorSelections();
|
|
||||||
$('#submit-btn').text('Update');
|
|
||||||
|
|
||||||
Swal.fire({
|
|
||||||
icon: 'info',
|
|
||||||
title: 'Data Loaded',
|
|
||||||
text: selectedMonth + ' चा आधीचा डेटा फॉर्ममध्ये भरला गेला आहे.',
|
|
||||||
timer: 2000,
|
|
||||||
showConfirmButton: false
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$('input[name="id"]').remove();
|
|
||||||
$('#submit-btn').text('Submit');
|
|
||||||
|
|
||||||
$("[id^='field-contact_id']").each(function () {
|
|
||||||
$(this).val('').trigger('change');
|
|
||||||
if ($(this).data('select2')) {
|
|
||||||
$(this).trigger('change.select2');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 3. Form submit handler
|
|
||||||
$('#report-form').on('submit', function(event){
|
$('#report-form').on('submit', function(event){
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
const formData = new FormData($('#report-form')[0]);
|
||||||
|
// Log form data to console
|
||||||
|
for (let [key, value] of formData.entries()) {
|
||||||
|
console.log(key, value);
|
||||||
|
}
|
||||||
$("#pageloader").fadeIn();
|
$("#pageloader").fadeIn();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
|
@ -395,31 +359,33 @@
|
||||||
text: 'Your data is successfully submitted!',
|
text: 'Your data is successfully submitted!',
|
||||||
icon: 'success'
|
icon: 'success'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
location.reload();
|
location.reload(); // 🔥 page refresh here
|
||||||
});
|
});
|
||||||
$('#report-form').trigger("reset");
|
$('#report-form').trigger("reset");
|
||||||
} else {
|
} else {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
title: 'Data not submitted',
|
title: 'Data not submitted',
|
||||||
text: 'Something went wrong, please try again after some time!'
|
text: 'Something went wrong, please try again after some time!'
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function() {
|
|
||||||
$("#pageloader").fadeOut();
|
|
||||||
Swal.fire({
|
|
||||||
icon: 'error',
|
|
||||||
title: 'Server Error',
|
|
||||||
text: 'An unexpected error occurred.'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var today = new Date();
|
||||||
|
var dd = String(today.getDate()).padStart(2, '0');
|
||||||
|
var mm = String(today.getMonth() + 1).padStart(2, '0');
|
||||||
|
var yyyy = today.getFullYear();
|
||||||
|
today = yyyy + '-' + mm + '-' + dd;
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue