3
0
Fork 0

[FIX] web_drop_target: Process only if you are on the expected area

12.0
Enric Tobella 2019-06-25 16:16:31 +02:00 committed by George Daramouskas
parent b01ae3262b
commit 24631fe75b
No known key found for this signature in database
GPG Key ID: 5B4EF742F8CD859C
5 changed files with 17 additions and 13 deletions

View File

@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{ {
"name": "Drop target support", "name": "Drop target support",
"version": "11.0.1.0.0", "version": "11.0.2.0.0",
"author": "Therp BV,Odoo Community Association (OCA)", "author": "Therp BV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web", "website": "https://github.com/OCA/web",
"license": "AGPL-3", "license": "AGPL-3",

View File

@ -1,3 +1,4 @@
* Holger Brunn <hbrunn@therp.nl> * Holger Brunn <hbrunn@therp.nl>
* Pablo Fuentes <pablo@studio73.es> * Pablo Fuentes <pablo@studio73.es>
* Akim Juillerat <akim.juillerat@camptocamp.com> * Akim Juillerat <akim.juillerat@camptocamp.com>
* Enric Tobella <etobella@creublanca.es>

View File

@ -3,8 +3,8 @@
/*global Uint8Array base64js*/ /*global Uint8Array base64js*/
odoo.define('web_drop_target', function(require) { odoo.define('web_drop_target', function(require) {
var FormController = require('web.FormController'); var FormController = require('web.FormController');
var core = require('web.core'); var core = require('web.core');
var qweb = core.qweb; var qweb = core.qweb;
// this is the main contribution of this addon: A mixin you can use // this is the main contribution of this addon: A mixin you can use
@ -26,10 +26,13 @@ odoo.define('web_drop_target', function(require) {
}, },
_on_drop: function(e) { _on_drop: function(e) {
if (!this._drop_overlay){
return;
}
var drop_items = this._get_drop_items(e); var drop_items = this._get_drop_items(e);
e.preventDefault(); e.preventDefault();
this._remove_overlay(); this._remove_overlay();
if(!drop_items) { if (!drop_items) {
return; return;
} }
this._handle_drop_items(drop_items, e) this._handle_drop_items(drop_items, e)
@ -51,7 +54,7 @@ odoo.define('web_drop_target', function(require) {
dataTransfer = e.originalEvent.dataTransfer, dataTransfer = e.originalEvent.dataTransfer,
drop_items = []; drop_items = [];
_.each(dataTransfer.files, function(item) { _.each(dataTransfer.files, function(item) {
if( if (
_.contains(self._drop_allowed_types, item.type) || _.contains(self._drop_allowed_types, item.type) ||
_.isEmpty(self._drop_allowed_types) _.isEmpty(self._drop_allowed_types)
) { ) {
@ -92,9 +95,9 @@ odoo.define('web_drop_target', function(require) {
while(p && !p.sidebar) { while(p && !p.sidebar) {
p = p.getParent ? p.getParent() : null; p = p.getParent ? p.getParent() : null;
} }
if(p) { if (p) {
var sidebar = p.sidebar; var sidebar = p.sidebar;
if(sidebar && _.isFunction(sidebar._onFileUploaded)) { if (sidebar && _.isFunction(sidebar._onFileUploaded)) {
sidebar._onFileUploaded(); sidebar._onFileUploaded();
} }
} }
@ -110,7 +113,7 @@ odoo.define('web_drop_target', function(require) {
) { ) {
var self = this; var self = this;
var file = item; var file = item;
if(!file || !(file instanceof Blob)) { if (!file || !(file instanceof Blob)) {
return; return;
} }
var reader = new FileReader(); var reader = new FileReader();
@ -122,7 +125,7 @@ odoo.define('web_drop_target', function(require) {
}, },
_add_overlay: function() { _add_overlay: function() {
if(!this._drop_overlay){ if (!this._drop_overlay){
var o_content = jQuery('.o_content'), var o_content = jQuery('.o_content'),
view_manager = jQuery('.o_view_manager_content'); view_manager = jQuery('.o_view_manager_content');
this._drop_overlay = jQuery( this._drop_overlay = jQuery(
@ -152,7 +155,7 @@ odoo.define('web_drop_target', function(require) {
FormController.include(_.extend(DropTargetMixin, { FormController.include(_.extend(DropTargetMixin, {
_get_drop_file: function() { _get_drop_file: function() {
// disable drag&drop when we're on an unsaved record // disable drag&drop when we're on an unsaved record
if(!this.datarecord.id) { if (!this.datarecord.id) {
return null; return null;
} }
return this._super.apply(this, arguments); return this._super.apply(this, arguments);