diff --git a/web_drop_target/README.rst b/web_drop_target/README.rst index 5311ca60e..1227a4daa 100644 --- a/web_drop_target/README.rst +++ b/web_drop_target/README.rst @@ -14,13 +14,13 @@ Drop target support :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github - :target: https://github.com/OCA/web/tree/12.0/web_drop_target + :target: https://github.com/OCA/web/tree/13.0/web_drop_target :alt: OCA/web .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_drop_target + :target: https://translation.odoo-community.org/projects/web-13-0/web-13-0-web_drop_target :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/162/12.0 + :target: https://runbot.odoo-community.org/runbot/162/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -69,7 +69,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -102,6 +102,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/web `_ project on GitHub. +This module is part of the `OCA/web `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_drop_target/i18n/fr.po b/web_drop_target/i18n/fr.po index 93cb2f33a..af0478085 100644 --- a/web_drop_target/i18n/fr.po +++ b/web_drop_target/i18n/fr.po @@ -18,7 +18,14 @@ msgstr "" #. module: web_drop_target #. openerp-web -#: code:addons/web_drop_target/static/src/xml/widgets.xml:11 +#: code:addons/web_drop_target/static/src/xml/widgets.xml:0 #, python-format msgid "Drop your files here" msgstr "Déposez les fichiers ici" + +#. module: web_drop_target +#. openerp-web +#: code:addons/web_drop_target/static/src/xml/widgets.xml:0 +#, python-format +msgid "Please save the record before dropping a file" +msgstr "" diff --git a/web_drop_target/i18n/web_drop_target.pot b/web_drop_target/i18n/web_drop_target.pot index 66924ca08..905cbabd2 100644 --- a/web_drop_target/i18n/web_drop_target.pot +++ b/web_drop_target/i18n/web_drop_target.pot @@ -1,12 +1,12 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * web_drop_target +# * web_drop_target # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: <>\n" +"Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -15,8 +15,14 @@ msgstr "" #. module: web_drop_target #. openerp-web -#: code:addons/web_drop_target/static/src/xml/widgets.xml:11 +#: code:addons/web_drop_target/static/src/xml/widgets.xml:0 #, python-format msgid "Drop your files here" msgstr "" +#. module: web_drop_target +#. openerp-web +#: code:addons/web_drop_target/static/src/xml/widgets.xml:0 +#, python-format +msgid "Please save the record before dropping a file" +msgstr "" diff --git a/web_drop_target/static/description/index.html b/web_drop_target/static/description/index.html index 971f87f53..49080e2d6 100644 --- a/web_drop_target/static/description/index.html +++ b/web_drop_target/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

This module extends the functionality of the web client to support dropping local files into the web client.

By default, an attachment will be created when dropping a file on a form.

Further, this module is meant as a base drag&drop module supporting other actions after some file is dropped so that other modules can add more features.

@@ -417,7 +417,7 @@ ul.auto-toc {

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -444,7 +444,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

-

This module is part of the OCA/web project on GitHub.

+

This module is part of the OCA/web project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/web_drop_target/static/src/js/web_drop_target.js b/web_drop_target/static/src/js/web_drop_target.js index 980ea314d..c4acc06cc 100644 --- a/web_drop_target/static/src/js/web_drop_target.js +++ b/web_drop_target/static/src/js/web_drop_target.js @@ -1,10 +1,12 @@ -//Copyright 2018 Therp BV -//License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -/*global Uint8Array base64js*/ +// Copyright 2018 Therp BV +// License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +/* global Uint8Array base64js*/ -odoo.define('web_drop_target', function(require) { - var FormController = require('web.FormController'); - var core = require('web.core'); +odoo.define("web_drop_target", function(require) { + "use strict"; + + var FormController = require("web.FormController"); + var core = require("web.core"); var qweb = core.qweb; // This is the main contribution of this addon: A mixin you can use @@ -18,15 +20,15 @@ odoo.define('web_drop_target', function(require) { start: function() { var result = this._super.apply(this, arguments); - this.$el.on('drop.widget_events', this.proxy('_on_drop')); - this.$el.on('dragenter.widget_events', this.proxy('_on_dragenter')); - this.$el.on('dragover.widget_events', this.proxy('_on_dragenter')); - this.$el.on('dragleave.widget_events', this.proxy('_on_dragleave')); + this.$el.on("drop.widget_events", this.proxy("_on_drop")); + this.$el.on("dragenter.widget_events", this.proxy("_on_dragenter")); + this.$el.on("dragover.widget_events", this.proxy("_on_dragenter")); + this.$el.on("dragleave.widget_events", this.proxy("_on_dragleave")); return result; }, _on_drop: function(e) { - if (!this._drop_overlay){ + if (!this._drop_overlay) { return; } var drop_items = this._get_drop_items(e); @@ -35,7 +37,7 @@ odoo.define('web_drop_target', function(require) { if (!drop_items) { return; } - this._handle_drop_items(drop_items, e) + this._handle_drop_items(drop_items, e); }, _on_dragenter: function(e) { @@ -50,21 +52,24 @@ odoo.define('web_drop_target', function(require) { }, _get_drop_items: function(e) { - var self = this, - dataTransfer = e.originalEvent.dataTransfer, - drop_items = []; - _.each(dataTransfer.files, function(item) { - if ( - _.contains(self._drop_allowed_types, item.type) || - _.isEmpty(self._drop_allowed_types) - ) { - drop_items.push(item); - } - }); - return drop_items; + if (this.renderer.state.res_id) { + var self = this, + dataTransfer = e.originalEvent.dataTransfer, + drop_items = []; + _.each(dataTransfer.files, function(item) { + if ( + _.contains(self._drop_allowed_types, item.type) || + _.isEmpty(self._drop_allowed_types) + ) { + drop_items.push(item); + } + }); + return drop_items; + } + return null; }, - // Eslint-disable-next-line no-unused-vars + // eslint-disable-next-line no-unused-vars _handle_drop_items: function(drop_items, e) { // Do something here, for example call the helper function below // e is the on_load_end handler for the FileReader above, @@ -75,38 +80,38 @@ odoo.define('web_drop_target', function(require) { // Helper to upload an attachment and update the sidebar var self = this; return this._rpc({ - model: 'ir.attachment', - method: 'create', + model: "ir.attachment", + method: "create", args: [ - _.extend({ - name: file.name, - datas: base64js.fromByteArray( - new Uint8Array(reader.result) - ), - res_model: res_model, - res_id: res_id, - }, extra_data || {}) + _.extend( + { + name: file.name, + datas: base64js.fromByteArray( + new Uint8Array(reader.result) + ), + res_model: res_model, + res_id: res_id, + }, + extra_data || {} + ), ], - }) - .then(function() { + }).then(function() { // Find the chatter among the children, there should be only // one - var res = _.filter(self.getChildren(), 'chatter') + var res = _.filter(self.getChildren(), "chatter"); if (res.length) { res[0].chatter._reloadAttachmentBox(); - res[0].chatter.trigger_up('reload'); - res[0].chatter.$('.o_chatter_button_attachment').click(); + res[0].chatter.trigger_up("reload"); + res[0].chatter.$(".o_chatter_button_attachment").click(); } }); }, - _file_reader_error_handler: function(e){ + _file_reader_error_handler: function(e) { console.error(e); }, - _handle_file_drop_attach: function( - item, e, res_model, res_id, extra_data - ) { + _handle_file_drop_attach: function(item, e, res_model, res_id, extra_data) { var self = this; var file = item; if (!file || !(file instanceof Blob)) { @@ -114,26 +119,40 @@ odoo.define('web_drop_target', function(require) { } var reader = new FileReader(); reader.onloadend = self.proxy( - _.partial(self._create_attachment, file, reader, e, res_model, res_id, extra_data) + _.partial( + self._create_attachment, + file, + reader, + e, + res_model, + res_id, + extra_data + ) ); - reader.onerror = self.proxy('_file_reader_error_handler'); + reader.onerror = self.proxy("_file_reader_error_handler"); reader.readAsArrayBuffer(file); }, _add_overlay: function() { - if (!this._drop_overlay){ - var o_content = jQuery('.o_content'), - view_manager = jQuery('.o_view_manager_content'); + var self = this; + if (!this._drop_overlay) { + var o_content = jQuery(".o_content"), + view_manager = jQuery(".o_view_manager_content"); this._drop_overlay = jQuery( - qweb.render('web_drop_target.drop_overlay') + qweb.render("web_drop_target.drop_overlay", { + id: self.renderer.state.res_id, + }) ); var o_content_position = o_content.position(); this._drop_overlay.css({ - 'top': o_content_position.top, - 'left': o_content_position.left, - 'width': view_manager.width(), - 'height': view_manager.height() + top: o_content_position.top, + left: o_content_position.left, + width: view_manager.width(), + height: view_manager.height(), }); + if (!this.renderer.state.res_id) { + this._drop_overlay.css("background", "#FF000020"); + } o_content.append(this._drop_overlay); } }, @@ -143,32 +162,29 @@ odoo.define('web_drop_target', function(require) { this._drop_overlay.remove(); this._drop_overlay = null; } - } + }, }; // And here we apply the mixin to form views, allowing any files and // adding them as attachment - FormController.include(_.extend(DropTargetMixin, { - _get_drop_file: function() { - // Disable drag&drop when we're on an unsaved record - if (!this.datarecord.id) { - return null; - } - return this._super.apply(this, arguments); - }, - _handle_drop_items: function(drop_items, e) { - var self = this; - _.each(drop_items, function(item, e) { - return self._handle_file_drop_attach( - item, e, self.renderer.state.model, - self.renderer.state.res_id - ); - }); - } - })); - + FormController.include( + _.extend(DropTargetMixin, { + // eslint-disable-next-line no-unused-vars + _handle_drop_items: function(drop_items, e) { + var self = this; + _.each(drop_items, function(item, e) { + return self._handle_file_drop_attach( + item, + e, + self.renderer.state.model, + self.renderer.state.res_id + ); + }); + }, + }) + ); return { - 'DropTargetMixin': DropTargetMixin, + DropTargetMixin: DropTargetMixin, }; }); diff --git a/web_drop_target/static/src/less/web_drop_target.less b/web_drop_target/static/src/less/web_drop_target.less index 97dc557d5..e0b5140e7 100644 --- a/web_drop_target/static/src/less/web_drop_target.less +++ b/web_drop_target/static/src/less/web_drop_target.less @@ -1,14 +1,14 @@ .o_content { - .o_drag_over{ + .o_drag_over { position: fixed; top: 0; left: 0; width: 100%; height: 100%; - background-color: rgba(255,255,255,0.6); + background-color: rgba(255, 255, 255, 0.6); border: 1px dashed #4c4c4c; pointer-events: none; - .o_drag_over_content{ + .o_drag_over_content { position: relative; top: 50%; transform: translate(0%, -50%); diff --git a/web_drop_target/static/src/xml/widgets.xml b/web_drop_target/static/src/xml/widgets.xml index e6c9ee052..df2b85889 100644 --- a/web_drop_target/static/src/xml/widgets.xml +++ b/web_drop_target/static/src/xml/widgets.xml @@ -1,14 +1,18 @@ - - +