From 02655f5443ff4b136bfeefd5eac60e3e94efed9e Mon Sep 17 00:00:00 2001 From: alokhyland Date: Tue, 6 Feb 2024 19:01:46 +0530 Subject: [PATCH] WEBUI-1385: Fix update of Template properties --- .../elements/nuxeo-template-rendering-page.js | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/addons/nuxeo-template-rendering/elements/nuxeo-template-rendering-page.js b/addons/nuxeo-template-rendering/elements/nuxeo-template-rendering-page.js index 4bb2f0a3dc..61b42d3050 100644 --- a/addons/nuxeo-template-rendering/elements/nuxeo-template-rendering-page.js +++ b/addons/nuxeo-template-rendering/elements/nuxeo-template-rendering-page.js @@ -175,6 +175,7 @@ Polymer({ type: String, value: 'view', }, + originalDocument: Object, }, _getProcessorLabel(processor) { @@ -191,7 +192,8 @@ Polymer({ _documentChanged() { if (this.document) { this.set('document.properties.tmpl:templateType', this.document.properties['tmpl:templateType'] || 'auto'); - this.set('editedDocument', JSON.parse(JSON.stringify(this.document))); + this.set('editedDocument', this._parseJSON(this.document)); + if (this.originalDocument === undefined) this.originalDocument = this._parseJSON(this.document); } }, @@ -216,12 +218,33 @@ Polymer({ }, _resetConfig() { - this.set('editedDocument', JSON.parse(JSON.stringify(this.document))); + this.set('editedDocument', this._parseJSON(this.document)); + }, + + _findChangedValues(originalDocument, modifiedDocument) { + return Object.fromEntries( + Object.entries(modifiedDocument).filter(([key, val]) => { + if (typeof originalDocument[key] === 'object') { + return key in originalDocument && JSON.stringify(originalDocument[key]) !== JSON.stringify(val); + } + return key in originalDocument && originalDocument[key] !== val; + }), + ); + }, + + _parseJSON(obj) { + return JSON.parse(JSON.stringify(obj)); }, _save() { - delete this.editedDocument.properties['dc:contributors']; - return this.$.doc.put(); + const modified = this._parseJSON(this.editedDocument.properties); + const originalDocument = this._parseJSON(this.originalDocument.properties); + const changedvalue = this._findChangedValues(originalDocument, modified); + + this.editedDocument.properties = changedvalue; + return this.$.doc.put().then(() => { + this.originalDocument = this._parseJSON(this.editedDocument); + }); }, _editConfig() {