refactor(js): avoid use of window.XXX and move to import/export
- change worker: do not cache html pages (not necessary) - remove use of window.XXX and maximize import/export, this will provide more clarety, show circular dependencies + you will benefit IDE help
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import { getCsrfHeaders } from '../../core/csrf.js';
|
||||
import { escapeHtml } from '../../core/formatters.js';
|
||||
import { i18n } from '../../core/i18n.js';
|
||||
|
||||
const API = '/api';
|
||||
let currentAdminId = '';
|
||||
let usersPage = 0;
|
||||
@@ -6,7 +10,7 @@ let totalUsers = 0;
|
||||
|
||||
/* ── i18n helper — falls back to key if i18n not ready ── */
|
||||
function t(key, params) {
|
||||
if (window.i18n && typeof window.i18n.t === 'function') return window.i18n.t(key, params);
|
||||
if (i18n && typeof i18n.t === 'function') return i18n.t(key, params);
|
||||
// fallback: strip prefix and humanise
|
||||
return key.split('.').pop().replace(/_/g, ' ');
|
||||
}
|
||||
@@ -748,13 +752,13 @@ function showAccessDenied() {
|
||||
|
||||
/* ── Apply i18n when translations load / change ── */
|
||||
document.addEventListener('translationsLoaded', () => {
|
||||
if (window.i18n?.translatePage) window.i18n.translatePage();
|
||||
if (i18n?.translatePage) i18n.translatePage();
|
||||
// Re-render dynamic content that uses t()
|
||||
loadDashboard();
|
||||
if (activeTabName === 'users') loadUsers();
|
||||
});
|
||||
document.addEventListener('localeChanged', () => {
|
||||
if (window.i18n?.translatePage) window.i18n.translatePage();
|
||||
if (i18n?.translatePage) i18n.translatePage();
|
||||
loadDashboard();
|
||||
if (activeTabName === 'users') loadUsers();
|
||||
});
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// device-verify.js — Extracted from inline <script> in device-verify.html
|
||||
import { getCsrfHeaders } from '../../core/csrf.js';
|
||||
|
||||
(() => {
|
||||
var API_BASE = window.location.origin;
|
||||
var codeInput = document.getElementById('user-code');
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { getCsrfHeaders } from '../../core/csrf.js';
|
||||
import { i18n } from '../../core/i18n.js';
|
||||
|
||||
const API = '/api';
|
||||
|
||||
/* ── i18n helper — falls back to key if i18n not ready ── */
|
||||
function t(key, params) {
|
||||
if (window.i18n && typeof window.i18n.t === 'function') return window.i18n.t(key, params);
|
||||
if (i18n && typeof i18n.t === 'function') return i18n.t(key, params);
|
||||
return key.split('.').pop().replace(/_/g, ' ');
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
* In-app shared files view. All operations go through the backend API.
|
||||
*/
|
||||
|
||||
import { switchToFilesSection } from '../../app/navigation.js';
|
||||
import { ui } from '../../app/ui.js';
|
||||
import { getCsrfHeaders } from '../../core/csrf.js';
|
||||
import { formatDateShort } from '../../core/formatters.js';
|
||||
import { i18n } from '../../core/i18n.js';
|
||||
import { fileSharing } from '../../features/sharing/fileSharing.js';
|
||||
|
||||
const sharedView = {
|
||||
// State
|
||||
items: [],
|
||||
@@ -181,8 +188,8 @@ const sharedView = {
|
||||
</div>
|
||||
`;
|
||||
|
||||
if (window.i18n?.translateElement) {
|
||||
window.i18n.translateElement(container);
|
||||
if (i18n?.translateElement) {
|
||||
i18n.translateElement(container);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -246,7 +253,7 @@ const sharedView = {
|
||||
const goToFilesBtn = document.getElementById('go-to-files-btn');
|
||||
if (goToFilesBtn) {
|
||||
goToFilesBtn.addEventListener('click', () => {
|
||||
if (window.switchToFilesSection) window.switchToFilesSection();
|
||||
if (switchToFilesSection) switchToFilesSection();
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -590,8 +597,8 @@ const sharedView = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.fileSharing?.sendShareNotification) {
|
||||
window.fileSharing
|
||||
if (fileSharing?.sendShareNotification) {
|
||||
fileSharing
|
||||
.sendShareNotification(this.currentItem.url, email, message)
|
||||
.then(() => {
|
||||
this.closeNotificationDialog();
|
||||
@@ -602,8 +609,8 @@ const sharedView = {
|
||||
},
|
||||
|
||||
showNotification(message, type = 'success') {
|
||||
if (window.ui?.showNotification) {
|
||||
window.ui.showNotification(message, type);
|
||||
if (ui?.showNotification) {
|
||||
ui.showNotification(message, type);
|
||||
} else {
|
||||
alert(message);
|
||||
}
|
||||
@@ -614,13 +621,13 @@ const sharedView = {
|
||||
},
|
||||
|
||||
formatDate(value) {
|
||||
return window.formatDateShort ? window.formatDateShort(value) : String(value);
|
||||
return formatDateShort(value);
|
||||
},
|
||||
|
||||
translate(key, defaultText) {
|
||||
if (window.i18n?.t) return window.i18n.t(key, defaultText);
|
||||
if (i18n?.t) return i18n.t(key, defaultText);
|
||||
return defaultText;
|
||||
}
|
||||
};
|
||||
|
||||
window.sharedView = sharedView;
|
||||
export { sharedView };
|
||||
|
||||
Reference in New Issue
Block a user