[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>
This commit is contained in:
Debauche Stéphane
2019-10-16 13:57:49 +00:00
parent 594206d4f3
commit e981e3312d
7 changed files with 69 additions and 15 deletions
+12
View File
@@ -1777,6 +1777,9 @@ order.
option is useful to inform the web client that the default field name is
not the name of the current field, but the name of another field.
- accepted_file_extensions: the file extension the user can pick from the file input dialog box (default value is 'image/*')
(cf: ``accept`` attribute on <input type="file"/>)
.. code-block:: xml
<field name="image" widget='image' options='{"preview_image":"image_128"}'/>
@@ -1786,6 +1789,11 @@ order.
- Supported field types: *binary*
Options:
- accepted_file_extensions: the file extension the user can pick from the file input dialog box
(cf: ``accept`` attribute on <input type="file"/>)
Attribute:
- filename: saving a binary file will lose its file name, since it only
@@ -2117,6 +2125,10 @@ Relational fields
- Supported field types: *many2many*
Options:
- accepted_file_extensions: the file extension the user can pick from the file input dialog box
(cf: ``accept`` attribute on <input type="file"/>)
- many2many_tags (FieldMany2ManyTags)
Display many2many as a list of tags.