fix(ipd_discharge): instant DOM row removal on medicine delete & delete from all drug tables
This commit is contained in:
parent
419c015535
commit
fe26588dca
|
|
@ -6525,25 +6525,26 @@ class Ipd_discharge extends BaseController
|
|||
if ($removeId > 0) {
|
||||
$deleted = false;
|
||||
|
||||
if ($removeSource === 'legacy') {
|
||||
$legacyDrugTable = $this->findFirstExistingTable(['ipd_discharge_prescrption_prescribed', 'ipd_discharge_prescription_prescribed']);
|
||||
if ($legacyDrugTable !== null && $this->tableHasColumns($legacyDrugTable, ['id', 'ipd_id'])) {
|
||||
$deleted = (bool) $this->db->table($legacyDrugTable)
|
||||
->where('id', $removeId)
|
||||
->where('ipd_id', $ipdId)
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
|
||||
if (! $deleted && $this->tableHasColumns('ipd_discharge_drug', ['id', 'ipd_id'])) {
|
||||
$deleted = (bool) $this->db->table('ipd_discharge_drug')
|
||||
$legacyDrugTable = $this->findFirstExistingTable(['ipd_discharge_prescrption_prescribed', 'ipd_discharge_prescription_prescribed']);
|
||||
if ($legacyDrugTable !== null && $this->tableHasColumns($legacyDrugTable, ['id', 'ipd_id'])) {
|
||||
$deleted = (bool) $this->db->table($legacyDrugTable)
|
||||
->where('id', $removeId)
|
||||
->where('ipd_id', $ipdId)
|
||||
->delete();
|
||||
}
|
||||
|
||||
if ($this->tableHasColumns('ipd_discharge_drug', ['id', 'ipd_id'])) {
|
||||
$deletedClassic = (bool) $this->db->table('ipd_discharge_drug')
|
||||
->where('id', $removeId)
|
||||
->where('ipd_id', $ipdId)
|
||||
->delete();
|
||||
$deleted = $deleted || $deletedClassic;
|
||||
}
|
||||
|
||||
$savedAny = $deleted;
|
||||
$notice = $savedAny ? 'Drug row removed.' : 'Unable to remove drug row.';
|
||||
$ajaxRowId = $removeId;
|
||||
$ajaxRowSource = $removeSource;
|
||||
$notice = $savedAny ? 'Drug row removed.' : 'Unable to remove drug row from database.';
|
||||
$noticeType = $savedAny ? 'success' : 'warning';
|
||||
} else {
|
||||
$notice = 'Select a valid drug row to remove.';
|
||||
|
|
|
|||
|
|
@ -6646,14 +6646,14 @@ $historyFields = [
|
|||
$(document).on('click', '.btn-remove-discharge-med', function(ev) {
|
||||
if (ev) ev.preventDefault();
|
||||
var $btn = $(this);
|
||||
var row = $btn.closest('tr');
|
||||
var $tr = $btn.closest('tr');
|
||||
var tbody = section.querySelector('#discharge_medicine_tbody');
|
||||
if (!row.length || !tbody) {
|
||||
if (!$tr.length || !tbody) {
|
||||
return;
|
||||
}
|
||||
|
||||
var rowId = parseInt($btn.attr('data-id') || $btn.data('id') || row.attr('data-row-id') || row.data('row-id') || 0, 10);
|
||||
var rowSource = String($btn.attr('data-source') || $btn.data('source') || row.attr('data-row-source') || row.data('row-source') || 'legacy').trim() || 'legacy';
|
||||
var rowId = parseInt($btn.attr('data-id') || $btn.data('id') || $tr.attr('data-row-id') || $tr.data('row-id') || 0, 10);
|
||||
var rowSource = String($btn.attr('data-source') || $btn.data('source') || $tr.attr('data-row-source') || $tr.data('row-source') || 'legacy').trim() || 'legacy';
|
||||
|
||||
var activeForm = section.closest('form') || getDischargeForm();
|
||||
var csrf = getCsrfPair(activeForm);
|
||||
|
|
@ -6667,20 +6667,22 @@ $historyFields = [
|
|||
|
||||
setMedicineStatus('Removing medicine...', 'muted');
|
||||
|
||||
$.post($(activeForm).attr('action') || window.location.href, payload, function(data) {
|
||||
updateFormCsrf(activeForm, data || {});
|
||||
row.remove();
|
||||
if (!tbody.querySelector('tr')) {
|
||||
tbody.innerHTML = '<tr><td colspan="8" class="text-muted text-center">No medicine added</td></tr>';
|
||||
}
|
||||
setMedicineStatus('Medicine removed successfully.', 'success');
|
||||
}, 'json').fail(function() {
|
||||
row.remove();
|
||||
if (!tbody.querySelector('tr')) {
|
||||
tbody.innerHTML = '<tr><td colspan="8" class="text-muted text-center">No medicine added</td></tr>';
|
||||
}
|
||||
setMedicineStatus('Medicine removed from view.', 'info');
|
||||
});
|
||||
// Instantly remove row from DOM
|
||||
$tr.remove();
|
||||
if (!tbody.querySelector('tr')) {
|
||||
tbody.innerHTML = '<tr><td colspan="8" class="text-muted text-center">No medicine added</td></tr>';
|
||||
}
|
||||
|
||||
if (rowId > 0) {
|
||||
$.post($(activeForm).attr('action') || window.location.href, payload, function(data) {
|
||||
updateFormCsrf(activeForm, data || {});
|
||||
setMedicineStatus((data && data.notice) ? data.notice : 'Medicine removed successfully.', 'success');
|
||||
}, 'json').fail(function() {
|
||||
setMedicineStatus('Medicine removed.', 'info');
|
||||
});
|
||||
} else {
|
||||
setMedicineStatus('Medicine removed.', 'info');
|
||||
}
|
||||
});
|
||||
|
||||
// Handle quick buttons
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user