diff --git a/src/core/js/edit_mode.js b/src/core/js/edit_mode.js index 59ceeea04dc38b560efac3ee276379a26ebbb1fb..1c72d1ce9677e556f74cc8402080c3991f91b415 100644 --- a/src/core/js/edit_mode.js +++ b/src/core/js/edit_mode.js @@ -961,7 +961,14 @@ var edit_mode = new function () { this.createElementForProperty = function (property, options) { var result; if (property.datatype == "TEXT") { - result = `<textarea id=${property.name}>${property.value || ""}</textarea>`; + let area_id; + if (property.name) { + area_id = property.name; + } else { + // TODO: Treat list properties + area_id = ""; + } + result = `<textarea id=${area_id}>${property.value || ""}</textarea>`; } else if (property.datatype == "DATETIME") { var dateandtime = [""]; if (property.value) { diff --git a/src/core/js/ext_editmode_wysiwyg_text.js b/src/core/js/ext_editmode_wysiwyg_text.js index 101c77bd7712b94699bd993e9515d058a8c9a510..07f9117d1365de5213d63cb287feb36804f9aee0 100644 --- a/src/core/js/ext_editmode_wysiwyg_text.js +++ b/src/core/js/ext_editmode_wysiwyg_text.js @@ -23,16 +23,37 @@ /** * Replaces textareas in the edit mode by a wysiwyg editor */ -var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor) { +var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode) { var _insertEditor = function (fieldId) { + let editor; + ClassicEditor .create(document.querySelector('#' + fieldId), { + // use all plugins since we built the editor dependency to + // contain only those we need. plugins: ClassicEditor.builtinPlugins, + // Markdown needs a header row so enforce this + table: { + defaultHeadings: { + rows: 1, + columns: 0 + }, + }, }) - .then(editor => { + .then(newEditor => { console.log('Initialized editor for ' + fieldId); - }) + editor = newEditor; + }).then( + () => { + // Manually implement saving the data since edit mode is not + // a form to be submitted. + editor.model.document.on("change:data", (e) => { + console.log('Something changed...'); + editor.updateSourceElement(); + }); + } + ) .catch(error => { console.error(error.stack); }); @@ -49,13 +70,19 @@ var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor) { } } - var init = function () {}; + var init = function () { + + document.body.addEventListener(edit_mode.start_edit.type, (e) => { + console.log('Replacing text areas ...'); + ext_editmode_wysiwyg_text.replaceTextAreas(); + }, true); + }; return { init: init, replaceTextAreas: replaceTextAreas, }; -}($, log.getLogger("ext_editmode_wysiwyg_text"), ClassicEditor); +}($, log.getLogger("ext_editmode_wysiwyg_text"), ClassicEditor, edit_mode); $(document).ready(() => { if ("${BUILD_MODULE_EXT_EDITMODE_WYSIWYG_TEXT}" == "ENABLED") {