From dbdd742d2046f208c0057fdc60b359e5c88814ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Fri, 15 Dec 2017 10:06:03 +0100 Subject: [FIX] web: better mode handling, prevent useless work in some cases Before this commit, the way mode was handled was not optimal. The end result was correct (the widget were properly created/displayed in edit/readonly as required), but useless work was done. In particular, if we have list/x2manys with widgets and modifiers, it could happen that widgets were created in edit mode, then destroyed and recreated in readonly mode. This could happen in some important views, for example, any view with a field many2many_tags with a readonly modifiers (pretty much all views handling taxes) In this commit, we add a 'editable' attribute to list renderer. This is necessary, because the list renderer is not actually editable when it is in a x2many in a form view which is in readonly mode. Also, we need to manage the distinction between the fact that a list view is editable, and the fact that some widgets are created in edit and other in readonly mode, depending on modifiers, and on which line is being edited. We also add a benchmark (courtesy of CHM) to be able to measure the performance impact of edit/readonly/onchange in a larger form view. Before this commit, running this form benchmark on my machine gave a number of 0.4 op/sec, and after, it increases to 1.26 op/sec, so a pretty large improvement. --- addons/web/static/src/js/fields/relational_fields.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/fields/relational_fields.js') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 9cdadb1051a..73e474b0342 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -839,7 +839,7 @@ var FieldX2Many = AbstractField.extend({ this.currentColInvisibleFields = this._evalColumnInvisibleFields(); this.renderer = new ListRenderer(this, this.value, { arch: arch, - mode: this.mode, + editable: this.mode === 'edit' && arch.attrs.editable, addCreateLine: !this.isReadonly && this.activeActions.create, addTrashIcon: !this.isReadonly && this.activeActions.delete, viewType: viewType, -- cgit v1.2.3 From 4843839b248137e51cdf374d2307b4481bde61b7 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 22 Dec 2017 13:02:15 +0100 Subject: [FIX] web: upload file widget keep metadata fresh When modifying files the a widget FieldMany2ManyBinaryMultiFiles would not keep its metadata (currently associating attachment to [url, allowUnlink]) up with current value. So with an attachment added after init: - clicking on it would error (because link is wrong) - deleting it would unlink attachment originating from from onchange The expected behavior is: - being able to download attachments - not unlinking attachment originating from onchange and this is what this commit fixes. opw-787746 closes #21813 --- addons/web/static/src/js/fields/relational_fields.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js/fields/relational_fields.js') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 73e474b0342..0a8dd126570 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -1380,12 +1380,12 @@ var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({ throw _.str.sprintf(msg, this.field.string); } + this.uploadedFiles = {}; this.uploadingFiles = []; this.fileupload_id = _.uniqueId('oe_fileupload_temp'); $(window).on(this.fileupload_id, this._onFileLoaded.bind(this)); this.metadata = {}; - this._generatedMetadata(); }, destroy: function () { @@ -1415,10 +1415,10 @@ var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({ _generatedMetadata: function () { var self = this; _.each(this.value.data, function (record) { - // attachments are tagged `allowUnlink` because only new attachments - // will be unlinked after deletion + // tagging `allowUnlink` ascertains if the attachment was user + // uploaded or was an existing or system generated attachment self.metadata[record.id] = { - allowUnlink: false, + allowUnlink: self.uploadedFiles[record.data.id] || false, url: self._getFileUrl(record.data), }; }); @@ -1430,6 +1430,7 @@ var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({ _render: function () { // render the attachments ; as the attachments will changes after each // _setValue, we put the rendering here to ensure they will be updated + this._generatedMetadata(); this.$('.oe_placeholder_files, .oe_attachments') .replaceWith($(qweb.render('FieldBinaryFileUploader.files', { widget: this, @@ -1537,6 +1538,7 @@ var FieldMany2ManyBinaryMultiFiles = AbstractField.extend({ self.do_warn(_t('Uploading Error'), file.error); } else { attachment_ids.push(file.id); + self.uploadedFiles[file.id] = true; } }); -- cgit v1.2.3 From a8527a16b6c887aa55eaf6ecb43a9a1a5067fd30 Mon Sep 17 00:00:00 2001 From: Sanjay Jamod Date: Tue, 2 Jan 2018 21:03:45 +0530 Subject: [FIX] web: Fix column_invisible issue (#21693) [FIX] web: Fix column_invisible issue This commit fixes an issue with the column_invisible attribute. When we choose product variant for BOM for any particular product, at that time from the BOM Lines column "Apply on Variants" is hidden, but when we unset product variant from BOM Form, at that time the column 'Variants" set to visible. but in this case, it is set to hidden always. PR 21693, OPW 779555 --- addons/web/static/src/js/fields/relational_fields.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js/fields/relational_fields.js') diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 0a8dd126570..9d8a7b6e170 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -824,12 +824,9 @@ var FieldX2Many = AbstractField.extend({ return this._super(); } if (this.renderer) { - this.renderer.updateState(this.value, {}); this.currentColInvisibleFields = this._evalColumnInvisibleFields(); - this.pager.updateState({ - size: this.value.count, - columnInvisibleFields: this.currentColInvisibleFields, - }); + this.renderer.updateState(this.value, {'columnInvisibleFields': this.currentColInvisibleFields}); + this.pager.updateState({ size: this.value.count }); return $.when(); } var arch = this.view.arch; -- cgit v1.2.3