diff --git a/web_drop_target/README.rst b/web_drop_target/README.rst index 66d085ac..d6a06113 100644 --- a/web_drop_target/README.rst +++ b/web_drop_target/README.rst @@ -22,7 +22,7 @@ To use this module, you need to: .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/162/10.0 + :target: https://runbot.odoo-community.org/runbot/162/11.0 Known issues / Roadmap ====================== @@ -31,6 +31,7 @@ Known issues / Roadmap * handle multiple files * add an upload progress meter for huge files * trigger custom events about different stages of the drop operation for other addons to hook in +* Install document module to display attachments in the sidebar Bug Tracker =========== @@ -57,6 +58,7 @@ Contributors ------------ * Holger Brunn +* Akim Juillerat Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list `_ or the `appropriate specialized mailinglist `_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues. diff --git a/web_drop_target/__init__.py b/web_drop_target/__init__.py index 8c501711..f7c59d20 100644 --- a/web_drop_target/__init__.py +++ b/web_drop_target/__init__.py @@ -1,3 +1,2 @@ -# -*- coding: utf-8 -*- # Copyright 2018 Therp BV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). diff --git a/web_drop_target/__manifest__.py b/web_drop_target/__manifest__.py index 4fe4edc3..3c357d1c 100644 --- a/web_drop_target/__manifest__.py +++ b/web_drop_target/__manifest__.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- # Copyright 2018 Therp BV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "Drop target support", - "version": "10.0.1.0.0", + "version": "11.0.1.0.0", "author": "Therp BV,Odoo Community Association (OCA)", "website": "https://github.com/OCA/web", "license": "AGPL-3", diff --git a/web_drop_target/readme/CONTRIBUTORS.rst b/web_drop_target/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..5e315a74 --- /dev/null +++ b/web_drop_target/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Holger Brunn +* Akim Juillerat \ No newline at end of file diff --git a/web_drop_target/readme/DESCRIPTION.rst b/web_drop_target/readme/DESCRIPTION.rst new file mode 100644 index 00000000..0701cee0 --- /dev/null +++ b/web_drop_target/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +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. diff --git a/web_drop_target/readme/DEVELOP.rst b/web_drop_target/readme/DEVELOP.rst new file mode 100644 index 00000000..1a531118 --- /dev/null +++ b/web_drop_target/readme/DEVELOP.rst @@ -0,0 +1,4 @@ +Libraries +--------- + +* `base64js `_. \ No newline at end of file diff --git a/web_drop_target/readme/ROADMAP.rst b/web_drop_target/readme/ROADMAP.rst new file mode 100644 index 00000000..cffa9915 --- /dev/null +++ b/web_drop_target/readme/ROADMAP.rst @@ -0,0 +1,5 @@ +* dropping on list or kanban views would be nice too +* handle multiple files +* add an upload progress meter for huge files +* trigger custom events about different stages of the drop operation for other addons to hook in +* Install document module to display attachments in the sidebar \ No newline at end of file diff --git a/web_drop_target/readme/USAGE.rst b/web_drop_target/readme/USAGE.rst new file mode 100644 index 00000000..a24356e6 --- /dev/null +++ b/web_drop_target/readme/USAGE.rst @@ -0,0 +1,4 @@ +To use this module, you need to: + +#. drag a file from your local computer onto an Odoo form view +#. it should become an attachment of the currently opened record \ No newline at end of file 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 e157768c..165e71cb 100644 --- a/web_drop_target/static/src/js/web_drop_target.js +++ b/web_drop_target/static/src/js/web_drop_target.js @@ -1,11 +1,9 @@ -//-*- coding: utf-8 -*- //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 Model = require('web.Model'), - FormView = require('web.FormView'); + var FormController = require('web.FormController'); // 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 @@ -79,20 +77,19 @@ odoo.define('web_drop_target', function(require) { ) { // helper to upload an attachment and update the sidebar var self = this; - return new Model('ir.attachment').call( - 'create', - [ - _.extend({ - name: drop_file.name, - datas: base64js.fromByteArray( + return this._rpc({ + model: 'ir.attachment', + method: 'create', + args: [{ + 'name': drop_file.name, + 'datas': base64js.fromByteArray( new Uint8Array(e.target.result) ), - datas_fname: drop_file.name, - res_model: res_model, - res_id: res_id, - }, extra_data || {}) - ] - ) + 'datas_fname': drop_file.name, + 'res_model': res_model, + 'res_id': res_id, + }], + }) .then(function() { // try to find a sidebar and update it if we found one var p = self; @@ -101,9 +98,9 @@ odoo.define('web_drop_target', function(require) { } if(p) { var sidebar = p.sidebar; - sidebar.do_attachement_update( - sidebar.dataset, sidebar.model_id - ); + if(sidebar && _.isFunction(sidebar._onFileUploaded)) { + sidebar._onFileUploaded(); + } } }); } @@ -111,7 +108,7 @@ odoo.define('web_drop_target', function(require) { // and here we apply the mixin to form views, allowing any files and // adding them as attachment - FormView.include(_.extend(DropTargetMixin, { + FormController.include(_.extend(DropTargetMixin, { _get_drop_file: function() { // disable drag&drop when we're on an unsaved record if(!this.datarecord.id) { @@ -121,7 +118,7 @@ odoo.define('web_drop_target', function(require) { }, _handle_file_drop: function(drop_file, e) { return this._handle_file_drop_attach( - drop_file, e, this.dataset.model, this.datarecord.id + drop_file, e, this.renderer.state.model, this.renderer.state.res_id ); } })); diff --git a/web_drop_target/views/templates.xml b/web_drop_target/views/templates.xml index 6021a21e..318dc7ab 100644 --- a/web_drop_target/views/templates.xml +++ b/web_drop_target/views/templates.xml @@ -1,12 +1,10 @@ - - - - - + + +