diff --git a/web_widget_image_paste_clipboard/README.rst b/web_widget_image_paste_clipboard/README.rst new file mode 100644 index 00000000..21cd7854 --- /dev/null +++ b/web_widget_image_paste_clipboard/README.rst @@ -0,0 +1,21 @@ +**This file is going to be generated by oca-gen-addon-readme.** + +*Manual changes will be overwritten.* + +Please provide content in the ``readme`` directory: + +* **DESCRIPTION.rst** (required) +* INSTALL.rst (optional) +* CONFIGURE.rst (optional) +* **USAGE.rst** (optional, highly recommended) +* DEVELOP.rst (optional) +* ROADMAP.rst (optional) +* HISTORY.rst (optional, recommended) +* **CONTRIBUTORS.rst** (optional, highly recommended) +* CREDITS.rst (optional) + +Content of this README will also be drawn from the addon manifest, +from keys such as name, authors, maintainers, development_status, +and license. + +A good, one sentence summary in the manifest is also highly recommended. diff --git a/web_widget_image_paste_clipboard/__init__.py b/web_widget_image_paste_clipboard/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/web_widget_image_paste_clipboard/__manifest__.py b/web_widget_image_paste_clipboard/__manifest__.py new file mode 100644 index 00000000..9254d1f7 --- /dev/null +++ b/web_widget_image_paste_clipboard/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2019 Florent de Labarre +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + 'name': "Web Widget Image Paste Clipboard", + 'summary': "Allow to paste an image from clipboard in Image field.", + 'author': "Florent de Labarre, Odoo Community Association (OCA)", + 'category': 'Web', + 'website': 'https://github.com/OCA/web', + 'version': '11.0.1.0.0', + 'depends': ['web'], + 'data': ['templates/assets.xml'], + 'qweb': ['static/src/xml/base.xml'], + 'installable': True, + 'license': 'AGPL-3', +} diff --git a/web_widget_image_paste_clipboard/readme/CONTRIBUTORS.rst b/web_widget_image_paste_clipboard/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..5cc75dc8 --- /dev/null +++ b/web_widget_image_paste_clipboard/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Florent de Labarre diff --git a/web_widget_image_paste_clipboard/readme/DESCRIPTION.rst b/web_widget_image_paste_clipboard/readme/DESCRIPTION.rst new file mode 100644 index 00000000..8f5c2fed --- /dev/null +++ b/web_widget_image_paste_clipboard/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +[ This file must be max 2-3 paragraphs, and is required. ] + +This module add the possibility to paste an image in binary image field. +Works with Google Chrome diff --git a/web_widget_image_paste_clipboard/readme/USAGE.rst b/web_widget_image_paste_clipboard/readme/USAGE.rst new file mode 100644 index 00000000..b24c8512 --- /dev/null +++ b/web_widget_image_paste_clipboard/readme/USAGE.rst @@ -0,0 +1,14 @@ +[ This file must be present and contains the usage instructions + for end-users. As all other rst files included in the README, + it MUST NOT contain reStructuredText sections + only body text (paragraphs, lists, tables, etc). Should you need + a more elaborate structure to explain the addon, please create a + Sphinx documentation (which may include this file as a "quick start" + section). ] + +To use this module, you need to: + +#. Copy an image (from : Paint, Gimps, Google Image, ...) +#. Edit a record with image field +#. Click on the paste Icon (between Edit icon and Delete Icon) +#. Press Ctrl + V (or Cmd + V on MacOS) diff --git a/web_widget_image_paste_clipboard/static/description/icon.png b/web_widget_image_paste_clipboard/static/description/icon.png new file mode 100644 index 00000000..e38f3a01 Binary files /dev/null and b/web_widget_image_paste_clipboard/static/description/icon.png differ diff --git a/web_widget_image_paste_clipboard/static/src/js/basic_fields.js b/web_widget_image_paste_clipboard/static/src/js/basic_fields.js new file mode 100644 index 00000000..3e823a2b --- /dev/null +++ b/web_widget_image_paste_clipboard/static/src/js/basic_fields.js @@ -0,0 +1,40 @@ +odoo.define('web_widget_image_paste_clipboard.FieldBinaryImage', function(require) { + "use strict"; + + var basicFields = require('web.basic_fields'); + + basicFields.FieldBinaryImage.include({ + _render: function() { + this._super.apply(this, arguments); + var self = this; + + function handlePaste(event) { + if (self.mode == 'edit') { + var items = (event.clipboardData || event.originalEvent.clipboardData).items; + var blob = null; + if (items) { + for (var i = 0; i < items.length; i++) { + if (items[i].type.indexOf("image") === 0) { + blob = items[i].getAsFile(); + break; + } + } + if (blob != null) { + var filereader = new FileReader(); + filereader.readAsDataURL(blob); + filereader.onloadend = function(upload) { + var data = upload.target.result; + data = data.split(',')[1]; + self.on_file_uploaded(blob.size, 'paste_image', blob.type, data); + }; + } + } + } + } + + this.$('.o_paste_image').on("paste", handlePaste); + + }, + }); + +}); diff --git a/web_widget_image_paste_clipboard/static/src/xml/base.xml b/web_widget_image_paste_clipboard/static/src/xml/base.xml new file mode 100644 index 00000000..b48c6733 --- /dev/null +++ b/web_widget_image_paste_clipboard/static/src/xml/base.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/web_widget_image_paste_clipboard/templates/assets.xml b/web_widget_image_paste_clipboard/templates/assets.xml new file mode 100644 index 00000000..4e8c54a6 --- /dev/null +++ b/web_widget_image_paste_clipboard/templates/assets.xml @@ -0,0 +1,8 @@ + + + +