diff options
| author | Alexandre Kühn <alex.e.kuhn@gmail.com> | 2018-01-05 15:00:57 +0100 |
|---|---|---|
| committer | Alexandre Kühn <alex.e.kuhn@gmail.com> | 2018-01-08 10:17:44 +0100 |
| commit | 255e8ca3d92e3a77d7c2a145677623518bc2f978 (patch) | |
| tree | 921f15c6eadbc8a2a726711c2d492b30ee3b1034 /addons/web/static/src/js/fields/field_utils.js | |
| parent | bd2e783d30ece1f2b56d492ed1dc704d96d548a0 (diff) | |
[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
Diffstat (limited to 'addons/web/static/src/js/fields/field_utils.js')
| -rw-r--r-- | addons/web/static/src/js/fields/field_utils.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index 6a6ad5a7a98..812a7f380f7 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -28,6 +28,20 @@ var _t = core._t; //------------------------------------------------------------------------------ /** + * + * @param {string} value base64 representation of the binary + * @param {Object} [field] + * a description of the field (note: this parameter is ignored) + * @param {Object} [options] additional options (note: this parameter is ignored) + */ +function formatBinary(value, field, options) { + if (!value) { + return ''; + } + return utils.human_size(value.length / 1.37); // base64 estimated size: http://en.wikipedia.org/wiki/Base64#MIME +} + +/** * @todo Really? it returns a jQuery element... We should try to avoid this and * let DOM utility functions handle this directly. And replace this with a * function that returns a string so we can get rid of the forceString. @@ -561,7 +575,7 @@ function parseMany2one(value) { return { format: { - binary: _.identity, // todo + binary: formatBinary, boolean: formatBoolean, char: formatChar, date: formatDate, |
