Team 4 (Mother Forum ) then() function cahnges
Specific Folder FTP Upload / ftp-deploy (push) Successful in 51s
Details
Specific Folder FTP Upload / ftp-deploy (push) Successful in 51s
Details
This commit is contained in:
parent
76bbdaa236
commit
6feeac68cb
|
|
@ -265,152 +265,93 @@
|
||||||
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'
|
// Filter out contacts where value == 'sample'
|
||||||
contacts = contacts.filter(function(itm) { return itm.value !== 'sample' && itm.contact && itm.contact.type === 'doctor' });
|
contacts = contacts.filter(function(itm) {
|
||||||
|
return itm.value !== 'sample' && itm.contact && itm.contact.type === 'doctor';
|
||||||
|
});
|
||||||
|
|
||||||
contacts.sort(function(a, b) {
|
contacts.sort(function(a, b) {
|
||||||
return (a.display || '').localeCompare(b.display || '', undefined, { sensitivity: 'base' });
|
return (a.display || '').localeCompare(b.display || '', undefined, { sensitivity: 'base' });
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(contacts);
|
console.log("Filtered Contacts:", 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() {
|
|
||||||
$("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);
|
$('input[id^="field-msl_code"], input[id^="field-speciality"]').prop('readonly', true);
|
||||||
|
|
||||||
|
// १. सर्व Dropdowns मध्ये options भरा
|
||||||
|
|
||||||
function enforceUniqueDoctorSelections() {
|
|
||||||
var selectedValues = [];
|
|
||||||
|
|
||||||
|
|
||||||
$("select[id^='field-contact_id']").each(function () {
|
|
||||||
var v = $(this).val();
|
|
||||||
if (v) selectedValues.push(String(v));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$("select[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.hasClass("select2-hidden-accessible")) {
|
|
||||||
|
|
||||||
currentSelect.select2({
|
|
||||||
width: "100%",
|
|
||||||
placeholder: "-- Select --",
|
|
||||||
allowClear: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$("select[id^='field-contact_id']").each(function() {
|
$("select[id^='field-contact_id']").each(function() {
|
||||||
var select = $(this);
|
var select = $(this);
|
||||||
// Clear previous options
|
var savedValue = select.attr('data-selected') || select.data('selected') || select.val() || '';
|
||||||
|
|
||||||
var savedValue = select.attr('data-selected') || select.data('selected') || select.val() || '';
|
// आधीपासून Select2 असेल तर तात्पुरते नष्ट करा जेणेकरून नवीन options व्यवस्थित लोड होतील
|
||||||
select.empty();
|
if (select.hasClass("select2-hidden-accessible")) {
|
||||||
|
select.select2('destroy');
|
||||||
|
}
|
||||||
|
|
||||||
// Add a default 'Select' option
|
// जुने options रिकामे करा
|
||||||
select.append(
|
select.empty();
|
||||||
$("<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);
|
|
||||||
|
|
||||||
|
|
||||||
|
// Default option जोडा
|
||||||
|
select.append($("<option></option>").attr("value", '').text('-- Select --'));
|
||||||
|
|
||||||
// If doctor options have extra attributes
|
// नवीन options जोडा
|
||||||
if (itm.contact && itm.contact.msl_code) {
|
contacts.forEach(function(itm) {
|
||||||
option.attr("msl_code", itm.contact.msl_code);
|
var option = $("<option></option>")
|
||||||
}
|
.attr("value", itm.value)
|
||||||
if (itm.contact && itm.contact.speciality) {
|
.text(itm.display);
|
||||||
option.attr("speciality", itm.contact.speciality);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (savedValue && String(savedValue) === String(itm.value)) {
|
if (itm.contact && itm.contact.msl_code) {
|
||||||
option.prop('selected', true);
|
option.attr("msl_code", itm.contact.msl_code);
|
||||||
}
|
}
|
||||||
|
if (itm.contact && itm.contact.speciality) {
|
||||||
select.append(option);
|
option.attr("speciality", itm.contact.speciality);
|
||||||
});
|
|
||||||
|
|
||||||
// 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 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);
|
|
||||||
|
|
||||||
if (mslCodeField.length) {
|
|
||||||
mslCodeField.val(selected.attr('msl_code') || '');
|
|
||||||
}
|
|
||||||
if (specialityField.length) {
|
|
||||||
specialityField.val(selected.attr('speciality') || '');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent selecting the same doctor across multiple dropdowns
|
|
||||||
enforceUniqueDoctorSelections();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (savedValue) {
|
|
||||||
select.val(savedValue).trigger('change');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (savedValue && String(savedValue) === String(itm.value)) {
|
||||||
});
|
option.prop('selected', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
select.append(option);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Change event 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] : '';
|
||||||
|
|
||||||
|
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') || '');
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure unique selection is enforced after initial render
|
|
||||||
enforceUniqueDoctorSelections();
|
enforceUniqueDoctorSelections();
|
||||||
// Enable search on doctor dropdowns
|
});
|
||||||
applySelect2ToDoctorDropdowns();
|
|
||||||
$("#pageloader").fadeOut();
|
// Select2 पुन्हा लागू करा
|
||||||
|
select.select2({
|
||||||
|
width: "100%",
|
||||||
|
placeholder: "-- Select --",
|
||||||
|
allowClear: true
|
||||||
|
});
|
||||||
|
|
||||||
|
if (savedValue) {
|
||||||
|
select.val(savedValue).trigger('change');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Unique doctor selections नियम लागू करा
|
||||||
|
enforceUniqueDoctorSelections();
|
||||||
|
|
||||||
|
$("#pageloader").fadeOut();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue