diff options
| author | Debauche Stéphane <std@odoo.com> | 2019-10-10 12:39:25 +0000 |
|---|---|---|
| committer | Debauche Stéphane <std@odoo.com> | 2019-10-16 13:57:49 +0000 |
| commit | e981e3312d66cd6fcddef05feda0f49b37a4c858 (patch) | |
| tree | 4bb3b43be79ce8a69e48768f993aacff1a94ccf9 /addons/web/static/tests/fields/basic_fields_tests.js | |
| parent | 594206d4f3c2465ca104d5ef65365d9339b034e0 (diff) | |
[IMP] web: many2many_binary, binary, image, add the option ``accepted_file_extensions``
Purpose
=======
We want to add an option on the widgets
- many2many_binary,
- binary,
- image
This option specifies what file extensions the user can pick from the file input dialog box.
Examples
========
```xml
<field widget="many2many_binary" options="{'accepted_file_extensions': 'image/*'}"/>
<field widget="many2many_binary" options="{'accepted_file_extensions': '.png,.jpeg'}"/>
<field widget="many2many_binary" options="{'accepted_file_extensions': 'application/pdf'}"/>
<field widget="image" options="{'accepted_file_extensions': '.png,.jpeg'}"/>
<field widget="binary" options="{'accepted_file_extensions': '.pdf,.svg'}"/>
```
How
===
Add an option (accepted_file_extensions) in the template ``HiddenInputFile`` (the widget many2many_binary is using this template)
So, we can also use this new option in others widgets using ``HiddenInputFile``
In the many2many_binary, read the ``nodeOptions`` and set the widget attribute ``accepted_file_extensions``
We also have to fix some other widget, because an property ``image_only`` was already existing in the template ``HiddenInputFile``
(we just need to replace ``image_only=True`` to ``accepted_file_extensions='image/*'``
The widget ``FieldPdfViewer`` (pdf_viewer) now use the new option to filtrate PDF
(instead of removing the <input/> and adding <input accept='.pdf'/>).
Tests
=====
We also test if the option is correctly set on the <input/>
- binary
- image
- many2many_binary
Impacted widgets
===============
- many2many_binary
- image: this widget use ``options="{accepted_file_extensions='image/*'}"`` instead of ``image_only=True``
- tablet_image: same as ``image``
Task #2082815
closes odoo/odoo#38351
Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
Diffstat (limited to 'addons/web/static/tests/fields/basic_fields_tests.js')
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 44 |
1 files changed, 44 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 e864f6341f9..92f2e163b99 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -2095,6 +2095,22 @@ QUnit.module('basic_fields', { session.get_file = oldGetFile; }); + QUnit.test('binary fields: option accepted_file_extensions', async function (assert) { + assert.expect(1); + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: `<form string="Partners"> + <field name="document" widget="binary" options="{'accepted_file_extensions': '.dat,.bin'}"/> + </form>` + }); + assert.strictEqual(form.$('input.o_input_file').attr('accept'), '.dat,.bin', + "the input should have the correct ``accept`` attribute"); + form.destroy(); + }); + QUnit.test('binary fields that are readonly in create mode do not download', async function (assert) { assert.expect(2); @@ -2414,6 +2430,34 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('image: option accepted_file_extensions', async function (assert) { + assert.expect(2); + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: `<form string="Partners"> + <field name="document" widget="image" options="{'accepted_file_extensions': '.png,.jpeg'}"/> + </form>` + }); + assert.strictEqual(form.$('input.o_input_file').attr('accept'), '.png,.jpeg', + "the input should have the correct ``accept`` attribute"); + form.destroy(); + + var form = await createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: `<form string="Partners"> + <field name="document" widget="image"/> + </form>` + }); + assert.strictEqual(form.$('input.o_input_file').attr('accept'), 'image/*', + 'the default value for the attribute "accept" on the "image" widget must be "image/*"'); + form.destroy(); + }); + QUnit.test('image fields in subviews are loaded correctly', async function (assert) { assert.expect(6); |
