All checks were successful
CI / lint-and-test (push) Successful in 14s
- Introduced a new `i18n.js` module for handling translations and language detection, supporting both Russian and English. - Updated various components to utilize the new translation functions, enhancing user experience by providing localized messages for errors, hints, and UI elements. - Refactored existing code in `api.js`, `calendar.js`, `dutyList.js`, `hints.js`, and `ui.js` to replace hardcoded strings with translated messages, improving maintainability and accessibility. - Enhanced the initialization process in `main.js` to set the document language and update UI elements based on the user's language preference.
74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
/**
|
|
* Screen states: access denied, error, nav enabled.
|
|
*/
|
|
|
|
import {
|
|
state,
|
|
calendarEl,
|
|
dutyListEl,
|
|
loadingEl,
|
|
errorEl,
|
|
accessDeniedEl,
|
|
headerEl,
|
|
weekdaysEl,
|
|
prevBtn,
|
|
nextBtn
|
|
} from "./dom.js";
|
|
import { t } from "./i18n.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) {
|
|
const msg = t(state.lang, "access_denied");
|
|
accessDeniedEl.innerHTML = "<p>" + msg + "</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;
|
|
}
|