[IMP] web_editor: Wysiwyg: Allow to save given editable
Before this commit, the save operation of wysiwyg was applied on the current editable. After this commit, the save operation of wysiwyg can be used on a given element. This advantage of this change is that saving can now be triggered on a copy of the original editable element, or on any document in memory. This makes the use case of the report editor easier to handle. That is, when the save fails, we need to go back to the state of the editor before the save: that is WITH the changes of the user, but not cleaned by the wysiwyg yet. task-id-3457404 Part-of: odoo/odoo#135265
This commit is contained in:
committed by
Lucas Perais
parent
b643f7666a
commit
d5b839f713
@@ -997,18 +997,25 @@ export class Wysiwyg extends Component {
|
||||
this.odooEditor.historyReset();
|
||||
}
|
||||
/**
|
||||
* Saves the content.
|
||||
* Saves the content or the given editable.
|
||||
*
|
||||
* @param {boolean} [reload=true]
|
||||
* @param {Object} [editable=false] Specific editable to save
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async saveContent(reload = true) {
|
||||
async saveContent(reload = true, editable = false) {
|
||||
this.savingContent = true;
|
||||
await this.cleanForSave();
|
||||
if (!editable) {
|
||||
await this.cleanForSave();
|
||||
const editables = "getContentEditableAreas" in this.options ? this.options.getContentEditableAreas(this.odooEditor) : [];
|
||||
await this.savePendingImages(editables.length ? $(editables) : this.$editable);
|
||||
await this._saveViewBlocks();
|
||||
} else {
|
||||
await this.cleanForSave(editable);
|
||||
await this.savePendingImages(editable);
|
||||
await this._saveViewBlocks(false, editable);
|
||||
}
|
||||
|
||||
const editables = "getContentEditableAreas" in this.options ? this.options.getContentEditableAreas(this.odooEditor) : [];
|
||||
await this.savePendingImages(editables.length ? $(editables) : this.$editable);
|
||||
await this._saveViewBlocks();
|
||||
this.savingContent = false;
|
||||
|
||||
window.removeEventListener('beforeunload', this._onBeforeUnload);
|
||||
@@ -1130,10 +1137,10 @@ export class Wysiwyg extends Component {
|
||||
closestElement(...args) {
|
||||
return closestElement(...args);
|
||||
}
|
||||
async cleanForSave() {
|
||||
async cleanForSave(editable = this.odooEditor.editable) {
|
||||
if (this.odooEditor) {
|
||||
this.odooEditor.cleanForSave();
|
||||
this._attachHistoryIds();
|
||||
this.odooEditor.cleanForSave(editable);
|
||||
this._attachHistoryIds(editable);
|
||||
}
|
||||
|
||||
if (this.snippetsMenu) {
|
||||
@@ -2522,18 +2529,20 @@ export class Wysiwyg extends Component {
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches all the dirty element on the page and saves them one by one. If
|
||||
* Searches all the dirty element on the page or given element and saves them one by one. If
|
||||
* one cannot be saved, this notifies it to the user and restarts rte
|
||||
* edition.
|
||||
*
|
||||
* @param {Object} [context] - the context to use for saving rpc, default to
|
||||
* the editor context found on the page
|
||||
* @param {Object} [element] - Specific given element to save
|
||||
* @return {Promise} rejected if the save cannot be done
|
||||
*/
|
||||
_saveViewBlocks(context) {
|
||||
_saveViewBlocks(context, element = false) {
|
||||
// TODO should be review to probably not search in the whole body,
|
||||
// iframe or not.
|
||||
const $ = getJqueryFromDocument(this.$editable[0].ownerDocument);
|
||||
// If the element is given, then search within not from the document.
|
||||
const $ = element ? getJqueryFromDocument(element) : getJqueryFromDocument(this.$editable[0].ownerDocument);
|
||||
const $allBlocks = $((this.options || {}).savableSelector).filter('.o_dirty');
|
||||
|
||||
const $dirty = $('.o_dirty');
|
||||
|
||||
Reference in New Issue
Block a user