Skip to content
Snippets Groups Projects
Commit 7f4b3fbe authored by Daniel Hornung's avatar Daniel Hornung
Browse files

Merge branch 'f-wysiwyg-source-saving' into 'dev'

FIX: Save WYSIWYG saving in source mode

See merge request !62
parents 8be8ead5 421257be
No related branches found
No related tags found
2 merge requests!68DOC: update CHANGELOG,!62FIX: Save WYSIWYG saving in source mode
Pipeline #18149 passed
...@@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -19,6 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed (for any bug fixes) ### Fixed (for any bug fixes)
* Fixed saving of text properties that were changed in the Source-Editing mode
of the WYSIWYG editor.
### Security (in case of vulnerabilities) ### Security (in case of vulnerabilities)
### Documentation (for notable additions or changes of the documentation) ### Documentation (for notable additions or changes of the documentation)
...@@ -40,7 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -40,7 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Optional WYSIWYG editor with markdown output for text properties. Controled by * Optional WYSIWYG editor with markdown output for text properties. Controled by
the `BUILD_MODULE_EXT_EDITMODE_WYSIWYG_TEXT` build variable which is set do the `BUILD_MODULE_EXT_EDITMODE_WYSIWYG_TEXT` build variable which is set do
`DISABLED` by default. `DISABLED` by default.
- Added button to version history panel that allows restoring old versions * Added button to version history panel that allows restoring old versions
### Changed (for changes in existing functionality) ### Changed (for changes in existing functionality)
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
*/ */
var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode, getPropertyElements, getPropertyDatatype, getPropertyName) { var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode, getPropertyElements, getPropertyDatatype, getPropertyName) {
var _callOnSave = [];
var insertEditorInProperty = async function (prop) { var insertEditorInProperty = async function (prop) {
if (!(getPropertyDatatype(prop) === 'TEXT')) { if (!(getPropertyDatatype(prop) === 'TEXT')) {
// Ignore anything that isn't a list property, even LIST<TEXT> // Ignore anything that isn't a list property, even LIST<TEXT>
...@@ -62,7 +64,7 @@ var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode, g ...@@ -62,7 +64,7 @@ var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode, g
logger.debug('Initialized editor for ' + getPropertyName(prop)); logger.debug('Initialized editor for ' + getPropertyName(prop));
// Manually implement saving the data since edit mode is not // Manually implement saving the data since edit mode is not
// a form to be submitted. // a form to be submitted.
editor.model.document.on("change:data", (e) => { _callOnSave.push(() => {
editor.updateSourceElement(); editor.updateSourceElement();
}); });
} catch (error) { } catch (error) {
...@@ -70,7 +72,23 @@ var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode, g ...@@ -70,7 +72,23 @@ var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode, g
} }
} }
const proxySaveMethod = function (original) {
const result = function (entity) {
_callOnSave.forEach(cb => {
cb();
});
if (typeof original === "function") {
return original(entity);
}
return undefined;
}
return result;
}
var replaceTextAreas = function (entity) { var replaceTextAreas = function (entity) {
// on save, call callbacks
edit_mode.app.onBeforeInsert = proxySaveMethod(edit_mode.app.onBeforeInsert);
edit_mode.app.onBeforeUpdate = proxySaveMethod(edit_mode.app.onBeforeUpdate);
const properties = getPropertyElements(entity); const properties = getPropertyElements(entity);
for (let prop of properties) { for (let prop of properties) {
// TODO(fspreck): This will be replaced by a whitelist of properties // TODO(fspreck): This will be replaced by a whitelist of properties
...@@ -107,6 +125,12 @@ var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode, g ...@@ -107,6 +125,12 @@ var ext_editmode_wysiwyg_text = function ($, logger, ClassicEditor, edit_mode, g
logger.debug('Re-rendering ' + getPropertyName(e.target)); logger.debug('Re-rendering ' + getPropertyName(e.target));
ext_editmode_wysiwyg_text.insertEditorInProperty(e.target); ext_editmode_wysiwyg_text.insertEditorInProperty(e.target);
}, true); }, true);
// Clear list of saving callbacks when leaving the edit mode (regardless
// of saving or cancelling)
document.body.addEventListener(edit_mode.end_edit.type, (e) => {
this._callOnSave = [];
}, true);
}; };
return { return {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment