Team 4 (Mother Forum)
Specific Folder FTP Upload / ftp-deploy (push) Successful in 41s
Details
Specific Folder FTP Upload / ftp-deploy (push) Successful in 41s
Details
This commit is contained in:
parent
7f87a36b81
commit
8c81e89669
|
|
@ -180,18 +180,61 @@
|
|||
top: 50%;
|
||||
}
|
||||
</style>
|
||||
|
||||
@include('layouts.shared/footer-script')
|
||||
<script src="{{asset('assets/libs/sweetalert2/sweetalert2.min.js')}}"></script>
|
||||
<script src="{{ asset('assets/libs/select2/select2.min.js') }}"></script>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function($){
|
||||
$('[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 contacts = [];
|
||||
|
||||
@if(isset($form->manager_can_submit) && $form->manager_can_submit == true)
|
||||
@foreach($form->users as $option)
|
||||
hierarcies.push('{{$option->hierarchy_id}}');
|
||||
hierarcies.push('{{$option->hierarchy_id}}');
|
||||
@endforeach
|
||||
$("#pageloader").fadeIn();
|
||||
Promise.all(
|
||||
|
|
@ -202,82 +245,24 @@
|
|||
processData: false,
|
||||
contentType: false
|
||||
}).then(data => {
|
||||
console.log(data);
|
||||
contacts = contacts.concat(data);
|
||||
}).catch(function(err) {
|
||||
console.log(err);
|
||||
});
|
||||
})
|
||||
).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'; });
|
||||
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() {
|
||||
var select = $(this);
|
||||
// Clear previous options
|
||||
select.html('');
|
||||
// Add a default 'Select' option
|
||||
select.append(
|
||||
$("<option></option>")
|
||||
.attr("value", '')
|
||||
.text('-- Select --')
|
||||
);
|
||||
// Append options from contacts
|
||||
select.append($("<option></option>").attr("value", '').text('-- Select --'));
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -287,21 +272,12 @@
|
|||
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 () {
|
||||
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 selectId = $(this).attr('id');
|
||||
var match = selectId.match(/^field-contact_id(_\d+)?$/);
|
||||
var suffix = match && match[1] ? match[1] : '';
|
||||
|
||||
// Build the target msl_code and speciality field ids
|
||||
var mslCodeField = $('#field-msl_code' + suffix);
|
||||
var specialityField = $('#field-speciality' + suffix);
|
||||
|
||||
|
|
@ -312,131 +288,98 @@
|
|||
specialityField.val(selected.attr('speciality') || '');
|
||||
}
|
||||
|
||||
// Prevent selecting the same doctor across multiple dropdowns
|
||||
enforceUniqueDoctorSelections();
|
||||
});
|
||||
|
||||
// Ensure unique selection is enforced after initial render
|
||||
enforceUniqueDoctorSelections();
|
||||
});
|
||||
|
||||
// Enable search on doctor dropdowns
|
||||
applySelect2ToDoctorDropdowns();
|
||||
$("#pageloader").fadeOut();
|
||||
});
|
||||
|
||||
// 1. Blade मधील आधीचे submissions JavaScript मध्ये घ्या
|
||||
var existingSubmissions = @json($submissions ?? []);
|
||||
|
||||
// 2. Month change event
|
||||
$('#field-month').on('change', function () {
|
||||
var selectedMonth = $(this).val();
|
||||
|
||||
if (!selectedMonth) {
|
||||
return;
|
||||
}
|
||||
|
||||
// निवडलेल्या महिन्यासाठी आधीचे submission शोधा
|
||||
var prevSubmission = existingSubmissions.find(function (sub) {
|
||||
// Backend key नुसार sub.month किंवा sub.data.month तपासा
|
||||
return (sub.month === selectedMonth) || (sub.data && sub.data.month === selectedMonth);
|
||||
});
|
||||
|
||||
if (prevSubmission) {
|
||||
var values = prevSubmission.data || prevSubmission;
|
||||
|
||||
// Form submission update करण्यासाठी hidden 'id' सेट करा
|
||||
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 + '">');
|
||||
}
|
||||
}
|
||||
|
||||
// सर्व fields मध्ये जुना डेटा भरा
|
||||
$.each(values, function (fieldKey, val) {
|
||||
if (fieldKey === 'month') return; // महिना परत ओव्हरराईट करू नये
|
||||
|
||||
var field = $('[name="' + fieldKey + '"]');
|
||||
if (!field.length) {
|
||||
field = $('[name="' + fieldKey + '[]"]'); // checkboxes
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// Dropdown ला msl_code / speciality सेट करण्यासाठी change trigger करा
|
||||
field.trigger('change');
|
||||
|
||||
// Select2 UI sync करा
|
||||
if (field.data('select2')) {
|
||||
field.trigger('change.select2');
|
||||
}
|
||||
} else {
|
||||
field.val(val);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Unique doctor validation पुन्हा लागू करा
|
||||
if (typeof enforceUniqueDoctorSelections === "function") {
|
||||
enforceUniqueDoctorSelections();
|
||||
}
|
||||
|
||||
$('#submit-btn').text('Update');
|
||||
|
||||
Swal.fire({
|
||||
icon: 'info',
|
||||
title: 'Data Found',
|
||||
text: selectedMonth + ' चा आधीचा डेटा फॉर्ममध्ये भरला गेला आहे.',
|
||||
timer: 2000,
|
||||
showConfirmButton: false
|
||||
});
|
||||
|
||||
} else {
|
||||
// जर या महिन्यासाठी आधी डेटा भरलेला नसेल, तर फॉर्म नवीन submission साठी तयार ठेवा
|
||||
$('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');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
@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){
|
||||
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();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
|
|
@ -452,33 +395,31 @@ $('#field-month').on('change', function () {
|
|||
text: 'Your data is successfully submitted!',
|
||||
icon: 'success'
|
||||
}).then(() => {
|
||||
location.reload(); // 🔥 page refresh here
|
||||
});
|
||||
location.reload();
|
||||
});
|
||||
$('#report-form').trigger("reset");
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Data not submitted',
|
||||
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>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Reference in New Issue