Investigation profile: preserve select2 item order in edit panel
This commit is contained in:
parent
0a48fa6d2c
commit
0c85dddd43
|
|
@ -3922,10 +3922,10 @@ class Opd_prescription extends BaseController
|
|||
$pName = $this->resolveFirstField($pFields, ['Name', 'name']);
|
||||
$jProfileCode = $this->resolveFirstField($jFields, ['ProfileCode', 'profile_code']);
|
||||
$jInvestCode = $this->resolveFirstField($jFields, ['InvestigationCode', 'investigation_code']);
|
||||
$jPrintOrder = $this->resolveFirstField($jFields, ['printOrder', 'print_order', 'id']);
|
||||
$jPrintOrder = $this->resolveFirstField($jFields, ['printOrder', 'print_order']);
|
||||
$jId = $this->resolveFirstField($jFields, ['id']);
|
||||
$iCode = $this->resolveFirstField($iFields, ['Code', 'code']);
|
||||
$iName = $this->resolveFirstField($iFields, ['Name', 'name']);
|
||||
$iSortOrder = $this->resolveFirstField($iFields, ['sort_id', 'sort_order', 'id', 'Code', 'code']);
|
||||
|
||||
if ($pCode === null || $pName === null || $jProfileCode === null || $jInvestCode === null || $iCode === null || $iName === null) {
|
||||
return [];
|
||||
|
|
@ -3947,10 +3947,12 @@ class Opd_prescription extends BaseController
|
|||
$params[] = '%' . $filter . '%';
|
||||
}
|
||||
$sql .= 'ORDER BY p.`' . $pName . '` ASC';
|
||||
if ($iSortOrder !== null) {
|
||||
$sql .= ', i.`' . $iSortOrder . '` ASC';
|
||||
} elseif ($jPrintOrder !== null) {
|
||||
if ($jPrintOrder !== null) {
|
||||
$sql .= ', j.`' . $jPrintOrder . '` ASC';
|
||||
} elseif ($jId !== null) {
|
||||
$sql .= ', j.`' . $jId . '` ASC';
|
||||
} else {
|
||||
$sql .= ', i.`' . $iName . '` ASC';
|
||||
}
|
||||
|
||||
$rows = $this->db->query($sql, $params)->getResultArray();
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@
|
|||
function clearForm() {
|
||||
$('#inv_profile_code').val('0');
|
||||
$('#inv_profile_name_master').val('');
|
||||
$('#inv_profile_tests_select').empty();
|
||||
$('#inv_profile_tests_select').val(null).trigger('change');
|
||||
$('#inv_profile_form_title').text('New Profile');
|
||||
setMsg('normal', 'Ready.');
|
||||
|
|
@ -120,6 +121,7 @@
|
|||
row = row || {};
|
||||
$('#inv_profile_code').val(row.profile_code || 0);
|
||||
$('#inv_profile_name_master').val(row.profile_name || '');
|
||||
$('#inv_profile_tests_select').empty();
|
||||
var values = [];
|
||||
(row.tests || []).forEach(function(test) {
|
||||
var code = (test.code || '').toString();
|
||||
|
|
@ -127,9 +129,7 @@
|
|||
if (!code || !name) {
|
||||
return;
|
||||
}
|
||||
if (!$('#inv_profile_tests_select option[value="' + code + '"]').length) {
|
||||
$('#inv_profile_tests_select').append(new Option(name + ' [' + code + ']', code, true, true));
|
||||
}
|
||||
$('#inv_profile_tests_select').append(new window.Option(name + ' [' + code + ']', code, true, true));
|
||||
values.push(code);
|
||||
});
|
||||
$('#inv_profile_tests_select').val(values).trigger('change');
|
||||
|
|
@ -137,10 +137,15 @@
|
|||
}
|
||||
|
||||
function buildPayload() {
|
||||
var orderedCodes = [];
|
||||
$('#inv_profile_tests_select option:selected').each(function() {
|
||||
orderedCodes.push((this.value || '').toString());
|
||||
});
|
||||
|
||||
return {
|
||||
profile_code: parseInt($('#inv_profile_code').val() || '0', 10),
|
||||
profile_name: ($('#inv_profile_name_master').val() || '').trim(),
|
||||
investigation_codes: ($('#inv_profile_tests_select').val() || []).join(',')
|
||||
investigation_codes: orderedCodes.join(',')
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -179,6 +184,21 @@
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Keep selected option order stable by appending newly selected options at the end.
|
||||
$select.on('select2:select', function(e) {
|
||||
var id = ((e.params || {}).data || {}).id;
|
||||
if (id === undefined || id === null) {
|
||||
return;
|
||||
}
|
||||
var value = id.toString().replace(/"/g, '\\"');
|
||||
var $option = $select.find('option[value="' + value + '"]');
|
||||
if ($option.length) {
|
||||
$option.detach();
|
||||
$select.append($option);
|
||||
}
|
||||
$select.trigger('change.select2');
|
||||
});
|
||||
}
|
||||
|
||||
function initTable() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user