feat: add configurable sidebar auto-hide in hospital settings
This commit is contained in:
parent
fdd3256ecb
commit
d230d8960d
|
|
@ -35,6 +35,9 @@ class HospitalProfile extends BaseController
|
|||
'pharmacy_gst' => $this->readSettingValue('H_Med_GST'),
|
||||
'pharmacy_logo' => $pharmacyLogo,
|
||||
'pharmacy_logo_url' => $pharmacyLogo !== '' ? base_url('assets/images/' . rawurlencode($pharmacyLogo)) : '',
|
||||
'sidebar_auto_hide_seconds' => $this->readSettingValue('SIDEBAR_AUTO_HIDE_SECONDS') !== ''
|
||||
? $this->readSettingValue('SIDEBAR_AUTO_HIDE_SECONDS')
|
||||
: '7',
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -64,6 +67,8 @@ class HospitalProfile extends BaseController
|
|||
$pharmacyAddress = trim((string) $this->request->getPost('pharmacy_address'));
|
||||
$pharmacyPhone = trim((string) $this->request->getPost('pharmacy_phone'));
|
||||
$pharmacyGst = trim((string) $this->request->getPost('pharmacy_gst'));
|
||||
$sidebarAutoHideSecondsRaw = trim((string) $this->request->getPost('sidebar_auto_hide_seconds'));
|
||||
$sidebarAutoHideSeconds = $sidebarAutoHideSecondsRaw === '' ? 7 : (int) $sidebarAutoHideSecondsRaw;
|
||||
|
||||
if ($name === '' || $address === '') {
|
||||
return $this->response->setJSON([
|
||||
|
|
@ -83,6 +88,15 @@ class HospitalProfile extends BaseController
|
|||
]);
|
||||
}
|
||||
|
||||
if ($sidebarAutoHideSeconds < 0 || $sidebarAutoHideSeconds > 60) {
|
||||
return $this->response->setJSON([
|
||||
'update' => 0,
|
||||
'error_text' => 'Sidebar auto hide seconds must be between 0 and 60.',
|
||||
'csrfName' => csrf_token(),
|
||||
'csrfHash' => csrf_hash(),
|
||||
]);
|
||||
}
|
||||
|
||||
$savedCount = 0;
|
||||
if ($this->upsertSettingValue('H_Name', $name)) {
|
||||
$savedCount++;
|
||||
|
|
@ -117,6 +131,9 @@ class HospitalProfile extends BaseController
|
|||
if ($this->upsertSettingValue('H_Med_GST', $pharmacyGst)) {
|
||||
$savedCount++;
|
||||
}
|
||||
if ($this->upsertSettingValue('SIDEBAR_AUTO_HIDE_SECONDS', (string) $sidebarAutoHideSeconds)) {
|
||||
$savedCount++;
|
||||
}
|
||||
|
||||
$logoResult = $this->processLogoUpload(
|
||||
$this->request->getFile('hospital_logo'),
|
||||
|
|
@ -226,6 +243,7 @@ class HospitalProfile extends BaseController
|
|||
'H_Med_phone_No',
|
||||
'H_Med_GST',
|
||||
'H_Med_logo',
|
||||
'SIDEBAR_AUTO_HIDE_SECONDS',
|
||||
])->delete();
|
||||
|
||||
if ($logo !== '') {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,11 @@
|
|||
<input type="text" class="form-control" id="footer_version" value="<?= esc($footer_version ?? '') ?>" placeholder="e.g. 2026.03.27.01">
|
||||
<div class="form-text">Shown in the footer so live deployments can be verified without code changes.</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Sidebar Auto Hide (seconds)</label>
|
||||
<input type="number" class="form-control" id="sidebar_auto_hide_seconds" min="0" max="60" step="1" value="<?= esc($sidebar_auto_hide_seconds ?? '7') ?>" placeholder="7">
|
||||
<div class="form-text">Desktop only. Set 0 to disable auto-hide.</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-7">
|
||||
<label class="form-label">Hospital Logo</label>
|
||||
|
|
@ -153,6 +158,7 @@
|
|||
fd.append('hospital_email', ($('#hospital_email').val() || '').trim());
|
||||
fd.append('hospital_hfr_id', ($('#hospital_hfr_id').val() || '').trim());
|
||||
fd.append('footer_version', ($('#footer_version').val() || '').trim());
|
||||
fd.append('sidebar_auto_hide_seconds', ($('#sidebar_auto_hide_seconds').val() || '').trim());
|
||||
fd.append('pharmacy_name', ($('#pharmacy_name').val() || '').trim());
|
||||
fd.append('pharmacy_address', ($('#pharmacy_address').val() || '').trim());
|
||||
fd.append('pharmacy_phone', ($('#pharmacy_phone').val() || '').trim());
|
||||
|
|
@ -268,6 +274,7 @@
|
|||
$('#hospital_email').val('');
|
||||
$('#hospital_hfr_id').val('');
|
||||
$('#footer_version').val('');
|
||||
$('#sidebar_auto_hide_seconds').val('7');
|
||||
$('#pharmacy_name').val('');
|
||||
$('#pharmacy_address').val('');
|
||||
$('#pharmacy_phone').val('');
|
||||
|
|
|
|||
|
|
@ -122,6 +122,19 @@
|
|||
<script src="<?= base_url('assets/vendor/tinymce/tinymce.min.js') ?>"></script>
|
||||
<script src="<?= base_url('assets/vendor/php-email-form/validate.js') ?>"></script>
|
||||
|
||||
<?php
|
||||
$sidebarAutoHideSeconds = (int) hospital_setting_value('SIDEBAR_AUTO_HIDE_SECONDS', '7');
|
||||
if ($sidebarAutoHideSeconds < 0) {
|
||||
$sidebarAutoHideSeconds = 0;
|
||||
}
|
||||
if ($sidebarAutoHideSeconds > 60) {
|
||||
$sidebarAutoHideSeconds = 60;
|
||||
}
|
||||
?>
|
||||
<script>
|
||||
window.SIDEBAR_AUTO_HIDE_DELAY_MS = <?= (int) ($sidebarAutoHideSeconds * 1000) ?>;
|
||||
</script>
|
||||
|
||||
<script src="<?= base_url('assets/js/main.js') ?>"></script>
|
||||
|
||||
<script>
|
||||
|
|
|
|||
|
|
@ -48,6 +48,71 @@
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto-hide sidebar after a short idle period on desktop
|
||||
* to provide larger work area for clinical forms.
|
||||
*/
|
||||
const configuredDelay = parseInt(window.SIDEBAR_AUTO_HIDE_DELAY_MS || 7000, 10)
|
||||
const SIDEBAR_AUTO_HIDE_DELAY_MS = isNaN(configuredDelay) ? 7000 : Math.max(0, configuredDelay)
|
||||
let sidebarAutoHideTimer = null
|
||||
let lastActivityTs = 0
|
||||
|
||||
const clearSidebarAutoHideTimer = () => {
|
||||
if (sidebarAutoHideTimer) {
|
||||
clearTimeout(sidebarAutoHideTimer)
|
||||
sidebarAutoHideTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
const canAutoHideSidebar = () => {
|
||||
return SIDEBAR_AUTO_HIDE_DELAY_MS > 0
|
||||
&& window.innerWidth >= 1200
|
||||
&& !select('body').classList.contains('toggle-sidebar')
|
||||
}
|
||||
|
||||
const scheduleSidebarAutoHide = () => {
|
||||
clearSidebarAutoHideTimer()
|
||||
if (!canAutoHideSidebar()) {
|
||||
return
|
||||
}
|
||||
|
||||
sidebarAutoHideTimer = setTimeout(() => {
|
||||
if (canAutoHideSidebar()) {
|
||||
select('body').classList.add('toggle-sidebar')
|
||||
}
|
||||
}, SIDEBAR_AUTO_HIDE_DELAY_MS)
|
||||
}
|
||||
|
||||
const trackActivityForSidebar = () => {
|
||||
const now = Date.now()
|
||||
if (now - lastActivityTs < 400) {
|
||||
return
|
||||
}
|
||||
lastActivityTs = now
|
||||
scheduleSidebarAutoHide()
|
||||
}
|
||||
|
||||
if (select('.toggle-sidebar-btn')) {
|
||||
// Re-arm timer after manual toggle when sidebar is visible again.
|
||||
on('click', '.toggle-sidebar-btn', function() {
|
||||
if (select('body').classList.contains('toggle-sidebar')) {
|
||||
clearSidebarAutoHideTimer()
|
||||
} else {
|
||||
scheduleSidebarAutoHide()
|
||||
}
|
||||
})
|
||||
|
||||
;['click', 'keydown'].forEach((evtName) => {
|
||||
document.addEventListener(evtName, trackActivityForSidebar)
|
||||
})
|
||||
;['wheel', 'touchstart'].forEach((evtName) => {
|
||||
document.addEventListener(evtName, trackActivityForSidebar, { passive: true })
|
||||
})
|
||||
|
||||
window.addEventListener('resize', scheduleSidebarAutoHide)
|
||||
window.addEventListener('load', scheduleSidebarAutoHide)
|
||||
}
|
||||
|
||||
/**
|
||||
* Search bar toggle
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user