summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/fields
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2017-12-22 13:02:15 +0100
committerNicolas Lempereur <nle@odoo.com>2017-12-22 16:49:56 +0100
commit4843839b248137e51cdf374d2307b4481bde61b7 (patch)
treecaa0b2c7fceaa5a876cdeb44ce30f4c1fa3a6ae2 /addons/web/static/src/js/fields
parent174cd2aeee78a2d66c31cf3bbe3cccc32ebda282 (diff)
[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
Diffstat (limited to 'addons/web/static/src/js/fields')
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js10
1 files changed, 6 insertions, 4 deletions
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;
}
});