Loading editor/html/js/api.js +5 −2 Original line number Diff line number Diff line Loading @@ -258,8 +258,11 @@ var EditorApi = (function() { }, // HTML import/export importHtml: function(html) { return request('POST', '/api/document/import-html', { html: html }); importHtml: function(html, mode, parentUuid) { var data = { html: html }; if (mode) data.mode = mode; if (parentUuid) data.parent_uuid = parentUuid; return request('POST', '/api/document/import-html', data); }, exportHtml: function() { Loading editor/html/js/editor.js +18 −6 Original line number Diff line number Diff line Loading @@ -734,12 +734,15 @@ }); actions.appendChild(copyBtn); var importBtn = document.createElement('button'); importBtn.textContent = I18n.t('I18N_AI_IMPORT_HTML', 'Als HTML importieren'); importBtn.addEventListener('click', function() { function doImport(mode) { var htmlContent = extractHtml(text); var parentUuid = (mode === 'child') ? DocumentTree.getSelectedUuid() : null; if (mode === 'child' && !parentUuid) { addMessage('error', 'Kein Element ausgew\u00e4hlt. Bitte im Dokumentbaum ein Element ausw\u00e4hlen.'); return; } var statusEl = addMessage('status', I18n.t('I18N_AI_PROCESSING', 'Importiere...')); EditorApi.importHtml(htmlContent).then(function() { EditorApi.importHtml(htmlContent, mode, parentUuid).then(function() { statusEl.remove(); addMessage('status', '\u2713 ' + I18n.t('I18N_IMPORT_HTML', 'Importiert')); DocumentTree.clearSelection(); Loading @@ -749,8 +752,17 @@ statusEl.remove(); addMessage('error', I18n.t('I18N_IMPORT_FAILED', 'Import fehlgeschlagen') + ': ' + (err.error || '')); }); }); actions.appendChild(importBtn); } var replaceBtn = document.createElement('button'); replaceBtn.textContent = '\uD83D\uDCC4 ' + I18n.t('I18N_REPLACE_DOC', 'Dokument ersetzen'); replaceBtn.addEventListener('click', function() { doImport('replace'); }); actions.appendChild(replaceBtn); var childBtn = document.createElement('button'); childBtn.textContent = '\u2B07 ' + I18n.t('I18N_INSERT_CHILD', 'Child einf\u00fcgen'); childBtn.addEventListener('click', function() { doImport('child'); }); actions.appendChild(childBtn); div.appendChild(actions); chatHistory.appendChild(div); Loading editor/src/webedit_api.cpp +38 −6 Original line number Diff line number Diff line Loading @@ -2107,6 +2107,12 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, json_object_object_get_ex(req, "html", &htmlObj); const char *html = htmlObj ? json_object_get_string(htmlObj) : nullptr; json_object *modeObj = nullptr, *parentUuidObj = nullptr; json_object_object_get_ex(req, "mode", &modeObj); json_object_object_get_ex(req, "parent_uuid", &parentUuidObj); std::string mode = modeObj ? json_object_get_string(modeObj) : "replace"; const char *parentUuid = parentUuidObj ? json_object_get_string(parentUuidObj) : nullptr; if (!html) { json_object_put(req); sendJsonError(curreq, 400, "Missing html"); Loading @@ -2125,8 +2131,10 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, auto &doc = getDocState(sessionid); std::lock_guard<std::mutex> lk(doc.mtx); if (mode == "replace") { doc.root = nullptr; doc.ownedElements.clear(); } tinyxml2::XMLDocument xmlDoc; if (xmlDoc.Parse(widgetXml.c_str()) != tinyxml2::XML_SUCCESS) { Loading @@ -2143,6 +2151,17 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, return; } // Find insertion target for "child" mode blogi::webedit::EditPlugin *insertParent = nullptr; if (mode == "child" && parentUuid && strlen(parentUuid) > 0) { insertParent = findElement(doc.root, parentUuid); if (!insertParent) { json_object_put(req); sendJsonError(curreq, 404, "Parent element not found"); return; } } blogi::webedit::EditPlugin *lastTop = nullptr; for (auto *child = rootEl->FirstChildElement(); child; child = child->NextSiblingElement()) { Loading @@ -2153,11 +2172,24 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, el->fromXmlObject(child); if (insertParent) { // Child mode: add as children of target element if (!insertParent->getChildElement()) { insertParent->setChildElement(*el); } else { auto *last = const_cast<blogi::webedit::EditPlugin*>(insertParent->getChildElement()); while (last->nextElement()) last = const_cast<blogi::webedit::EditPlugin*>(last->nextElement()); last->setNextEl(el); } } else { // Replace mode: build new top-level chain if (!doc.root) { doc.root = el; } else if (lastTop) { lastTop->setNextEl(el); } } lastTop = el; loadChildrenFromXml(child, el, doc); Loading Loading
editor/html/js/api.js +5 −2 Original line number Diff line number Diff line Loading @@ -258,8 +258,11 @@ var EditorApi = (function() { }, // HTML import/export importHtml: function(html) { return request('POST', '/api/document/import-html', { html: html }); importHtml: function(html, mode, parentUuid) { var data = { html: html }; if (mode) data.mode = mode; if (parentUuid) data.parent_uuid = parentUuid; return request('POST', '/api/document/import-html', data); }, exportHtml: function() { Loading
editor/html/js/editor.js +18 −6 Original line number Diff line number Diff line Loading @@ -734,12 +734,15 @@ }); actions.appendChild(copyBtn); var importBtn = document.createElement('button'); importBtn.textContent = I18n.t('I18N_AI_IMPORT_HTML', 'Als HTML importieren'); importBtn.addEventListener('click', function() { function doImport(mode) { var htmlContent = extractHtml(text); var parentUuid = (mode === 'child') ? DocumentTree.getSelectedUuid() : null; if (mode === 'child' && !parentUuid) { addMessage('error', 'Kein Element ausgew\u00e4hlt. Bitte im Dokumentbaum ein Element ausw\u00e4hlen.'); return; } var statusEl = addMessage('status', I18n.t('I18N_AI_PROCESSING', 'Importiere...')); EditorApi.importHtml(htmlContent).then(function() { EditorApi.importHtml(htmlContent, mode, parentUuid).then(function() { statusEl.remove(); addMessage('status', '\u2713 ' + I18n.t('I18N_IMPORT_HTML', 'Importiert')); DocumentTree.clearSelection(); Loading @@ -749,8 +752,17 @@ statusEl.remove(); addMessage('error', I18n.t('I18N_IMPORT_FAILED', 'Import fehlgeschlagen') + ': ' + (err.error || '')); }); }); actions.appendChild(importBtn); } var replaceBtn = document.createElement('button'); replaceBtn.textContent = '\uD83D\uDCC4 ' + I18n.t('I18N_REPLACE_DOC', 'Dokument ersetzen'); replaceBtn.addEventListener('click', function() { doImport('replace'); }); actions.appendChild(replaceBtn); var childBtn = document.createElement('button'); childBtn.textContent = '\u2B07 ' + I18n.t('I18N_INSERT_CHILD', 'Child einf\u00fcgen'); childBtn.addEventListener('click', function() { doImport('child'); }); actions.appendChild(childBtn); div.appendChild(actions); chatHistory.appendChild(div); Loading
editor/src/webedit_api.cpp +38 −6 Original line number Diff line number Diff line Loading @@ -2107,6 +2107,12 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, json_object_object_get_ex(req, "html", &htmlObj); const char *html = htmlObj ? json_object_get_string(htmlObj) : nullptr; json_object *modeObj = nullptr, *parentUuidObj = nullptr; json_object_object_get_ex(req, "mode", &modeObj); json_object_object_get_ex(req, "parent_uuid", &parentUuidObj); std::string mode = modeObj ? json_object_get_string(modeObj) : "replace"; const char *parentUuid = parentUuidObj ? json_object_get_string(parentUuidObj) : nullptr; if (!html) { json_object_put(req); sendJsonError(curreq, 400, "Missing html"); Loading @@ -2125,8 +2131,10 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, auto &doc = getDocState(sessionid); std::lock_guard<std::mutex> lk(doc.mtx); if (mode == "replace") { doc.root = nullptr; doc.ownedElements.clear(); } tinyxml2::XMLDocument xmlDoc; if (xmlDoc.Parse(widgetXml.c_str()) != tinyxml2::XML_SUCCESS) { Loading @@ -2143,6 +2151,17 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, return; } // Find insertion target for "child" mode blogi::webedit::EditPlugin *insertParent = nullptr; if (mode == "child" && parentUuid && strlen(parentUuid) > 0) { insertParent = findElement(doc.root, parentUuid); if (!insertParent) { json_object_put(req); sendJsonError(curreq, 404, "Parent element not found"); return; } } blogi::webedit::EditPlugin *lastTop = nullptr; for (auto *child = rootEl->FirstChildElement(); child; child = child->NextSiblingElement()) { Loading @@ -2153,11 +2172,24 @@ void webedit::Api::handleImportHtml(libhttppp::HttpRequest &curreq, el->fromXmlObject(child); if (insertParent) { // Child mode: add as children of target element if (!insertParent->getChildElement()) { insertParent->setChildElement(*el); } else { auto *last = const_cast<blogi::webedit::EditPlugin*>(insertParent->getChildElement()); while (last->nextElement()) last = const_cast<blogi::webedit::EditPlugin*>(last->nextElement()); last->setNextEl(el); } } else { // Replace mode: build new top-level chain if (!doc.root) { doc.root = el; } else if (lastTop) { lastTop->setNextEl(el); } } lastTop = el; loadChildrenFromXml(child, el, doc); Loading