[FIX] web: binary field format in list view
Binary fields were simply shown simply by their textual representation in list views,
e.g. the base64 string.
There was no formatter for binary fields, therefore it has been implemented so that
it displays its estimated size.
Binary fields in list views had a download link in v10.0.
We provide this feature back by means of a widget called 'download_link'.
It is also possible to define an option to set the field name having the filename as its value.
Example:
<tree>
<field name="fname"/>
<field name="datas" widget="download_link" options="{'filename': 'fname'}"/>
</tree>
with the following record: {fname: 'document.txt', datas: 'Cg=='},
we get a file named "document.txt" by clicking on the download link.
Closes #21996
This commit is contained in:
@@ -1298,6 +1298,25 @@ var FieldBinaryFile = AbstractFieldBinary.extend({
|
||||
},
|
||||
});
|
||||
|
||||
var FieldBinaryDownloadLink = AbstractFieldBinary.extend({
|
||||
template: 'FieldBinaryDownloadLink',
|
||||
events: _.extend({}, AbstractFieldBinary.prototype.events, {
|
||||
'click': function (ev) {
|
||||
ev.stopPropagation();
|
||||
},
|
||||
}),
|
||||
supportedFieldTypes: ['binary'],
|
||||
init: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this.filename = _t("Binary File");
|
||||
if (this.nodeOptions.filename && this.recordData[this.nodeOptions.filename]) {
|
||||
this.filename = this.recordData[this.nodeOptions.filename];
|
||||
}
|
||||
this.url = "data:application/octet-stream;base64," + this.value;
|
||||
this.text = _t("Download");
|
||||
},
|
||||
});
|
||||
|
||||
var PriorityWidget = AbstractField.extend({
|
||||
// the current implementation of this widget makes it
|
||||
// only usable for fields of type selection
|
||||
@@ -2528,6 +2547,7 @@ return {
|
||||
TranslatableFieldMixin: TranslatableFieldMixin,
|
||||
DebouncedField: DebouncedField,
|
||||
FieldEmail: FieldEmail,
|
||||
FieldBinaryDownloadLink: FieldBinaryDownloadLink,
|
||||
FieldBinaryFile: FieldBinaryFile,
|
||||
FieldBinaryImage: FieldBinaryImage,
|
||||
FieldBoolean: FieldBoolean,
|
||||
|
||||
Reference in New Issue
Block a user