Minor UI tweaks
This commit is contained in:
+10
-6
@@ -1618,11 +1618,14 @@ async function handleAddDrug(e) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!drugResponse.ok) throw new Error('Failed to add drug');
|
if (!drugResponse.ok) throw new Error('Failed to add drug');
|
||||||
|
const createdDrug = await drugResponse.json();
|
||||||
|
|
||||||
document.getElementById('drugForm').reset();
|
document.getElementById('drugForm').reset();
|
||||||
closeModal(document.getElementById('addModal'));
|
expandedDrugs.add(createdDrug.id);
|
||||||
await loadDrugs();
|
await loadDrugs();
|
||||||
showToast('Drug added successfully!', 'success');
|
closeModal(document.getElementById('addModal'));
|
||||||
|
openAddVariantModal(createdDrug.id);
|
||||||
|
showToast('Drug added successfully. Add the first variant next.', 'success');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error adding drug:', error);
|
console.error('Error adding drug:', error);
|
||||||
showToast('Failed to add drug. Check the console for details.', 'error');
|
showToast('Failed to add drug. Check the console for details.', 'error');
|
||||||
@@ -1882,7 +1885,7 @@ function inferBaseUnitFromStrength(strength) {
|
|||||||
if (value.includes('/ml') || value.includes('ml')) return 'ml';
|
if (value.includes('/ml') || value.includes('ml')) return 'ml';
|
||||||
if (value.includes('tablet')) return 'tablets';
|
if (value.includes('tablet')) return 'tablets';
|
||||||
if (value.includes('capsule')) return 'capsules';
|
if (value.includes('capsule')) return 'capsules';
|
||||||
return 'units';
|
return 'tablets';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVariantPackRowsContainer() {
|
function getVariantPackRowsContainer() {
|
||||||
@@ -1928,7 +1931,7 @@ function appendVariantPackRow(prefill = {}) {
|
|||||||
const row = document.createElement('div');
|
const row = document.createElement('div');
|
||||||
row.className = 'delivery-line variant-pack-row';
|
row.className = 'delivery-line variant-pack-row';
|
||||||
|
|
||||||
const selectedPackUnit = prefill.packUnit || 'bottle';
|
const selectedPackUnit = prefill.packUnit || 'box';
|
||||||
const selectedSize = prefill.packSize || '';
|
const selectedSize = prefill.packSize || '';
|
||||||
const baseUnit = document.getElementById('variantUnit')?.value || 'units';
|
const baseUnit = document.getElementById('variantUnit')?.value || 'units';
|
||||||
|
|
||||||
@@ -1983,7 +1986,7 @@ function initializeVariantPackRows() {
|
|||||||
variantUnitSelect.value = inferredBaseUnit;
|
variantUnitSelect.value = inferredBaseUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
appendVariantPackRow({ packUnit: 'bottle' });
|
appendVariantPackRow({ packUnit: 'box' });
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendEditVariantPackRow(prefill = {}) {
|
function appendEditVariantPackRow(prefill = {}) {
|
||||||
@@ -2965,8 +2968,9 @@ function buildDeliveryPackOptions(variant, selectedPackId = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildDeliveryLocationOptions(selectedLocationId = '') {
|
function buildDeliveryLocationOptions(selectedLocationId = '') {
|
||||||
|
const fallbackLocationId = selectedLocationId || (deliveryLocations.length > 0 ? String(deliveryLocations[0].id) : '');
|
||||||
return [`<option value="">-- Select location --</option>`, ...deliveryLocations.map(location => {
|
return [`<option value="">-- Select location --</option>`, ...deliveryLocations.map(location => {
|
||||||
const selected = String(location.id) === String(selectedLocationId) ? ' selected' : '';
|
const selected = String(location.id) === String(fallbackLocationId) ? ' selected' : '';
|
||||||
return `<option value="${location.id}"${selected}>${escapeHtml(location.name)}</option>`;
|
return `<option value="${location.id}"${selected}>${escapeHtml(location.name)}</option>`;
|
||||||
})].join('');
|
})].join('');
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -274,7 +274,7 @@
|
|||||||
<label for="variantUnit">Base Unit *</label>
|
<label for="variantUnit">Base Unit *</label>
|
||||||
<select id="variantUnit">
|
<select id="variantUnit">
|
||||||
<option value="ml">ml</option>
|
<option value="ml">ml</option>
|
||||||
<option value="tablets">tablets</option>
|
<option value="tablets" selected>tablets</option>
|
||||||
<option value="capsules">capsules</option>
|
<option value="capsules">capsules</option>
|
||||||
<option value="units">units</option>
|
<option value="units">units</option>
|
||||||
<option value="vials">vials</option>
|
<option value="vials">vials</option>
|
||||||
|
|||||||
Reference in New Issue
Block a user