3
0
Fork 0

[FIX] prevent drop when no record id is found

[UPD] Update web_drop_target.pot

[UPD] README.rst

Update translation files

Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: web-13.0/web-13.0-web_drop_target
Translate-URL: https://translation.odoo-community.org/projects/web-13-0/web-13-0-web_drop_target/
14.0
Adrià Gil Sorribes 2020-03-18 15:32:30 +01:00 committed by Víctor Martínez
parent 613e8b1f4a
commit 10509eb374
8 changed files with 146 additions and 100 deletions

View File

@ -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 <https://github.com/OCA/web/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 <https://github.com/OCA/web/issues/new?body=module:%20web_drop_target%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_drop_target%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
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 <https://github.com/OCA/web/tree/12.0/web_drop_target>`_ project on GitHub.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/13.0/web_drop_target>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -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 ""

View File

@ -4,9 +4,9 @@
#
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 ""

View File

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/12.0/web_drop_target"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_drop_target"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/13.0/web_drop_target"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-13-0/web-13-0-web_drop_target"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of the web client to support dropping local files into the web client.</p>
<p>By default, an attachment will be created when dropping a file on a form.</p>
<p>Further, this module is meant as a base drag&amp;drop module supporting other actions after some file is dropped so that other modules can add more features.</p>
@ -417,7 +417,7 @@ ul.auto-toc {
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_drop_target%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_drop_target%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
@ -444,7 +444,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/12.0/web_drop_target">OCA/web</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/13.0/web_drop_target">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

View File

@ -1,10 +1,12 @@
//Copyright 2018 Therp BV <https://therp.nl>
//License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
/*global Uint8Array base64js*/
// Copyright 2018 Therp BV <https://therp.nl>
// 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,6 +52,7 @@ odoo.define('web_drop_target', function(require) {
},
_get_drop_items: function(e) {
if (this.renderer.state.res_id) {
var self = this,
dataTransfer = e.originalEvent.dataTransfer,
drop_items = [];
@ -62,9 +65,11 @@ odoo.define('web_drop_target', function(require) {
}
});
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({
_.extend(
{
name: file.name,
datas: base64js.fromByteArray(
new Uint8Array(reader.result)
),
res_model: res_model,
res_id: res_id,
}, extra_data || {})
},
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);
},
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,
item,
e,
self.renderer.state.model,
self.renderer.state.res_id
);
});
}
}));
},
})
);
return {
'DropTargetMixin': DropTargetMixin,
DropTargetMixin: DropTargetMixin,
};
});

View File

@ -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%);

View File

@ -1,14 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<template>
<t t-name="web_drop_target.drop_overlay">
<div class="o_drag_over">
<div class="o_drag_over_content">
<div>
<i class="fa fa-file-o fa-5x" aria-hidden="true"></i>
<i class="fa fa-file-o fa-5x" aria-hidden="true" />
</div>
<div>
<t t-if="id">
<h2>Drop your files here</h2>
</t>
<t t-else="">
<h2>Please save the record before dropping a file</h2>
</t>
</div>
</div>
</div>

View File

@ -1,10 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="assets_backend" name="web_drop_target assets" inherit_id="web.assets_backend">
<template
id="assets_backend"
name="web_drop_target assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_drop_target/static/lib/base64js.min.js"></script>
<script type="text/javascript" src="/web_drop_target/static/src/js/web_drop_target.js"></script>
<link rel="stylesheet" href="/web_drop_target/static/src/less/web_drop_target.less"/>
<script
type="text/javascript"
src="/web_drop_target/static/lib/base64js.min.js"
/>
<script
type="text/javascript"
src="/web_drop_target/static/src/js/web_drop_target.js"
/>
<link
rel="stylesheet"
href="/web_drop_target/static/src/less/web_drop_target.less"
/>
</xpath>
</template>
</odoo>