dsd
This commit is contained in:
@@ -15,8 +15,10 @@
|
||||
const log = (message, color = '#1E90FF', type = 'info', force = false) => B.log(PluginName, message, color, type, force);
|
||||
|
||||
const qs = new URLSearchParams(location.search);
|
||||
B.EDITOR_MODE = (qs.get('mode') || 'templates').toUpperCase();
|
||||
log(`START: SKRIPT-AUSFÜHRUNG GESTARTET. Editor Modus: ${B.EDITOR_MODE}.`, '#DC143C');
|
||||
const requestedMode = (qs.get('mode') || 'templates').toLowerCase();
|
||||
B.EDITOR_MODE = (B.EDITOR_MODE || requestedMode.toUpperCase());
|
||||
const EDITOR_MODE = (B.EDITOR_MODE || 'TEMPLATES').toLowerCase();
|
||||
log(`START: SKRIPT-AUSFÜHRUNG GESTARTET. Editor Modus: ${EDITOR_MODE}.`, '#DC143C');
|
||||
|
||||
const TARGET_CAT_ID = 'custom';
|
||||
const PLACEHOLDER_ID = 'api-placeholder-loading';
|
||||
@@ -24,9 +26,9 @@
|
||||
|
||||
// --- NEUE KONSTANTEN FÜR SPEICHERN-LOGIK ---
|
||||
// Annahme: ID der aktuellen Seite/Template ist global in B verfügbar
|
||||
const CURRENT_ENTITY_ID = B.CURRENT_ENTITY_ID || qs.get('id') || 0;
|
||||
const CURRENT_ENTITY_ID = Number(B.CURRENT_ENTITY_ID || qs.get('id') || 0);
|
||||
// Annahme: Basis-URL der API ist in B verfügbar
|
||||
const API_KERNEL_URL = B.API_KERNEL_URL || '/api/ApiKernel.php';
|
||||
const API_KERNEL_URL = B.API_KERNEL_URL || B.API_BASE || '/api.php';
|
||||
// -------------------------------------------
|
||||
|
||||
// --------------------------------------------------------
|
||||
@@ -173,20 +175,26 @@
|
||||
// 1. Daten extrahieren
|
||||
const htmlContent = editor.getHtml() + '<style>' + editor.getCss() + '</style>';
|
||||
// 2. KRITISCH: Holt die JSON-Repräsentation des Editors
|
||||
const jsonProjectData = editor.getProjectData();
|
||||
const jsonProjectData = editor.getProjectData();
|
||||
|
||||
const resource = EDITOR_MODE;
|
||||
const action = `${resource}.update`;
|
||||
|
||||
log('SAVE START', 'Starte Speichern des Inhalts an die API...', '#FF4500');
|
||||
|
||||
// 3. Daten für den POST-Request vorbereiten
|
||||
const dataToSend = {
|
||||
action: 'blocks.update', // Oder 'templates.update', je nach Entity
|
||||
id: CURRENT_ENTITY_ID,
|
||||
action,
|
||||
id: CURRENT_ENTITY_ID,
|
||||
html: htmlContent,
|
||||
// 🚨 KRITISCH: Korrigiert auf 'json_content' für das PHP-Backend
|
||||
json_content: jsonProjectData,
|
||||
name: B.CURRENT_ENTITY_NAME || 'Unbenannt', // Optional
|
||||
// 🚨 KRITISCH: Server erwartet das Feld 'json'
|
||||
json: jsonProjectData,
|
||||
};
|
||||
|
||||
if (B.CURRENT_ENTITY_NAME) {
|
||||
dataToSend.name = B.CURRENT_ENTITY_NAME;
|
||||
}
|
||||
|
||||
// 4. API-Aufruf (fetch)
|
||||
fetch(API_KERNEL_URL, {
|
||||
method: 'POST',
|
||||
@@ -208,7 +216,7 @@
|
||||
log('SAVE FAILED (API)', `Speichern fehlgeschlagen: API-Fehler: ${data.error || 'Unbekannt'}`, 'red', 'error', true);
|
||||
alert(`Speichern fehlgeschlagen: ${data.error || 'API-Fehler'}`);
|
||||
} else {
|
||||
log('SAVE SUCCESS', 'Speichern erfolgreich. JSON-Daten wurden gesendet.', '#008000', 'info', true);
|
||||
log('SAVE SUCCESS', `Speichern erfolgreich für Aktion ${action}.`, '#008000', 'info', true);
|
||||
// 💡 HINZUGEFÜGT: Bestätigung an das Elternfenster senden
|
||||
window.parent.postMessage({ source: 'editor', type: 'save:success' }, '*');
|
||||
editor.refresh(); // Optional: Editor-Ansicht aktualisieren
|
||||
|
||||
Reference in New Issue
Block a user