[13.0][MIG] web_drop_target

pull/2139/head
Núria Martín Xifré 2020-01-14 11:30:23 +01:00 committed by Jasmin Solanki
parent caab6f1f3a
commit 9826b68eb9
2 changed files with 12 additions and 13 deletions

View File

@ -2,13 +2,13 @@
# 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": "12.0.1.0.0", "version": "13.0.1.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",
"category": "Usability", "category": "Usability",
"summary": "Allows to drag files into Odoo", "summary": "Allows to drag files into Odoo",
"depends": ["web", "document"], "depends": ["web"],
"data": ["views/templates.xml"], "data": ["views/templates.xml"],
"qweb": ["static/src/xml/widgets.xml"], "qweb": ["static/src/xml/widgets.xml"],
} }

View File

@ -7,11 +7,11 @@ odoo.define('web_drop_target', function(require) {
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
// to make some widget a drop target. Read on how to use this yourself // To make some widget a drop target. Read on how to use this yourself
var DropTargetMixin = { var DropTargetMixin = {
// add the mime types you want to support here, leave empty for // Add the mime types you want to support here, leave empty for
// all types. For more control, override _get_drop_items in your class // All types. For more control, override _get_drop_items in your class
_drop_allowed_types: [], _drop_allowed_types: [],
_drop_overlay: null, _drop_overlay: null,
@ -64,15 +64,15 @@ odoo.define('web_drop_target', function(require) {
return drop_items; return drop_items;
}, },
// eslint-disable-next-line no-unused-vars // Eslint-disable-next-line no-unused-vars
_handle_drop_items: function(drop_items, e) { _handle_drop_items: function(drop_items, e) {
// do something here, for example call the helper function below // Do something here, for example call the helper function below
// e is the on_load_end handler for the FileReader above, // e is the on_load_end handler for the FileReader above,
// so e.target.result contains an ArrayBuffer of the data // so e.target.result contains an ArrayBuffer of the data
}, },
_create_attachment: function(file, reader, e, res_model, res_id, extra_data) { _create_attachment: function(file, reader, e, res_model, res_id, extra_data) {
// helper to upload an attachment and update the sidebar // Helper to upload an attachment and update the sidebar
var self = this; var self = this;
return this._rpc({ return this._rpc({
model: 'ir.attachment', model: 'ir.attachment',
@ -83,14 +83,13 @@ odoo.define('web_drop_target', function(require) {
datas: base64js.fromByteArray( datas: base64js.fromByteArray(
new Uint8Array(reader.result) new Uint8Array(reader.result)
), ),
datas_fname: file.name,
res_model: res_model, res_model: res_model,
res_id: res_id, res_id: res_id,
}, extra_data || {}) }, extra_data || {})
], ],
}) })
.then(function() { .then(function() {
// find the chatter among the children, there should be only // Find the chatter among the children, there should be only
// one // one
var res = _.filter(self.getChildren(), 'chatter') var res = _.filter(self.getChildren(), 'chatter')
if (res.length) { if (res.length) {
@ -147,11 +146,11 @@ odoo.define('web_drop_target', function(require) {
} }
}; };
// and here we apply the mixin to form views, allowing any files and // And here we apply the mixin to form views, allowing any files and
// adding them as attachment // adding them as attachment
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;
} }