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/tests/fields/basic_fields_tests.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/tests/fields/basic_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 9ea423250e4..a2f59a68e2a 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1481,6 +1481,40 @@ QUnit.module('basic_fields', { session.get_file = oldGetFile; }); + QUnit.test('download_link widget in list view', function (assert) { + assert.expect(5); + + this.data.partner.fields.filename = { string: "Filename", type: "char" }; + this.data.partner.records[0].filename = "document.txt"; + + var form = createView({ + View: ListView, + model: 'partner', + data: this.data, + arch: '<tree string="Partners">' + + '<field name="document" widget="download_link" options="{\'filename\': \'filename\'}"/>' + + '<field name="filename"/>' + + '</tree>', + res_id: 1, + }); + + assert.ok(form.$('.o_data_cell').first().hasClass("o_download_link_cell"), + "this should be a download link cell"); + assert.ok(form.$('.o_data_cell').first().find('a').eq(0), + "there should be a link in the cell"); + assert.strictEqual(form.$('.o_data_cell').first().find('a').eq(0).attr('download'), + "document.txt", + "it should download a file named 'document.txt'"); + assert.strictEqual(form.$('.o_data_cell').first().find('a').eq(0).attr('href').trim(), + "data:application/octet-stream;base64,coucou==", + "it should have the appropriate link of a binary"); + assert.strictEqual(form.$('.o_data_cell').first().find('a').eq(0).text(), + "Download", + "the text of the link should be 'Download'"); + + form.destroy(); + }); + QUnit.test('text field rendering in list view', function (assert) { assert.expect(1); |
