Files
duty-teller/webapp/js/ui.js
Nikolay Tatarinov dd14d48824 style: enhance layout and functionality of duty markers and calendar
- Updated CSS for `.day` and `.access-denied` to improve layout and visual consistency.
- Introduced a new function `dutyOverlapsLocalRange` in `dateUtils.js` to check duty overlaps within a specified date range.
- Refactored `dutyItemHtml` in `dutyList.js` to utilize `formatTimeLocal` for time formatting, enhancing readability.
- Added utility functions in `hints.js` for parsing duty marker data and building time prefixes, streamlining hint rendering logic.
- Improved the `showAccessDenied` function in `ui.js` to display detailed server messages when access is denied.
2026-02-19 15:40:34 +03:00

71 lines
1.8 KiB
JavaScript

/**
* Screen states: access denied, error, nav enabled.
*/
import {
calendarEl,
dutyListEl,
loadingEl,
errorEl,
accessDeniedEl,
headerEl,
weekdaysEl,
prevBtn,
nextBtn
} from "./dom.js";
/**
* Show access-denied view and hide calendar/list/loading/error.
* @param {string} [serverDetail] - message from API 403 detail (shown below main text when present)
*/
export function showAccessDenied(serverDetail) {
if (headerEl) headerEl.hidden = true;
if (weekdaysEl) weekdaysEl.hidden = true;
if (calendarEl) calendarEl.hidden = true;
if (dutyListEl) dutyListEl.hidden = true;
if (loadingEl) loadingEl.classList.add("hidden");
if (errorEl) errorEl.hidden = true;
if (accessDeniedEl) {
accessDeniedEl.innerHTML = "<p>Доступ запрещён.</p>";
if (serverDetail && serverDetail.trim()) {
const detail = document.createElement("p");
detail.className = "access-denied-detail";
detail.textContent = serverDetail;
accessDeniedEl.appendChild(detail);
}
accessDeniedEl.hidden = false;
}
}
/**
* Hide access-denied and show calendar/list/header/weekdays.
*/
export function hideAccessDenied() {
if (accessDeniedEl) accessDeniedEl.hidden = true;
if (headerEl) headerEl.hidden = false;
if (weekdaysEl) weekdaysEl.hidden = false;
if (calendarEl) calendarEl.hidden = false;
if (dutyListEl) dutyListEl.hidden = false;
}
/**
* Show error message and hide loading.
* @param {string} msg - Error text
*/
export function showError(msg) {
if (errorEl) {
errorEl.textContent = msg;
errorEl.hidden = false;
}
if (loadingEl) loadingEl.classList.add("hidden");
}
/**
* Enable or disable prev/next month buttons.
* @param {boolean} enabled
*/
export function setNavEnabled(enabled) {
if (prevBtn) prevBtn.disabled = !enabled;
if (nextBtn) nextBtn.disabled = !enabled;
}