feat(js): add app-http contracts and migrate helpdesk runtime layer

This commit is contained in:
2026-04-20 22:31:13 +02:00
parent ec2f03e0cf
commit f189ef9df6
34 changed files with 2023 additions and 1134 deletions

View File

@@ -1,3 +1,5 @@
import { postForm as postFormRequest } from '../core/app-http.js';
export const buildUrl = (appBase, path) => new URL(path, appBase).toString();
export const getAppBase = () => {
@@ -125,15 +127,7 @@ export const buildBadgeList = (items, options = {}) => {
export const postAction = async (url, csrf, data = {}) => {
const body = new URLSearchParams({ ...data, [csrf.key]: csrf.token });
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
'X-Requested-With': 'fetch'
},
body
});
return postFormRequest(url, body);
};
export const badgeHtml = (gridjs, value = '') => {

View File

@@ -1,5 +1,6 @@
import { confirmDialog } from '../core/app-confirm-dialog.js';
import { warnOnce } from '../core/app-dom.js';
import { postForm } from '../core/app-http.js';
export function initUsersListPage(options = {}) {
const {
@@ -29,15 +30,7 @@ export function initUsersListPage(options = {}) {
const postAction = async (url, data = {}) => {
const body = new URLSearchParams({ ...data, [csrf.key]: csrf.token });
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
'X-Requested-With': 'fetch'
},
body
});
return postForm(url, body);
};
const exportButton = document.querySelector(exportSelector);
@@ -118,9 +111,11 @@ export function initUsersListPage(options = {}) {
const executeBulk = async () => {
const url = resolveBulkUrl(action);
const response = await postAction(url, { uuids: ids.join(',') });
const data = await response.json().catch(() => null);
if (response.ok && data && data.ok) {
try {
const data = await postAction(url, { uuids: ids.join(',') });
if (!data || data.ok !== true) {
throw new Error('Bulk action failed');
}
gridConfig.selection?.clear?.();
gridConfig.grid?.forceRender();
@@ -136,7 +131,7 @@ export function initUsersListPage(options = {}) {
showFlash('success', text);
}
}
} else {
} catch {
if (showFlash && labels.bulkMessages) {
const msg = labels.bulkMessages[action];
if (msg?.error) {