Browse Source

[MIG] web_drop_target : Migration to 11.0

pull/974/head
Akim Juillerat 6 years ago
parent
commit
82616c4748
  1. 4
      web_drop_target/README.rst
  2. 1
      web_drop_target/__init__.py
  3. 3
      web_drop_target/__manifest__.py
  4. 2
      web_drop_target/readme/CONTRIBUTORS.rst
  5. 5
      web_drop_target/readme/DESCRIPTION.rst
  6. 4
      web_drop_target/readme/DEVELOP.rst
  7. 5
      web_drop_target/readme/ROADMAP.rst
  8. 4
      web_drop_target/readme/USAGE.rst
  9. 37
      web_drop_target/static/src/js/web_drop_target.js
  10. 20
      web_drop_target/views/templates.xml

4
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 <hbrunn@therp.nl>
* Akim Juillerat <akim.juillerat@camptocamp.com>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.

1
web_drop_target/__init__.py

@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

3
web_drop_target/__manifest__.py

@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Therp BV <https://therp.nl>
# 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",

2
web_drop_target/readme/CONTRIBUTORS.rst

@ -0,0 +1,2 @@
* Holger Brunn <hbrunn@therp.nl>
* Akim Juillerat <akim.juillerat@camptocamp.com>

5
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.

4
web_drop_target/readme/DEVELOP.rst

@ -0,0 +1,4 @@
Libraries
---------
* `base64js <https://raw.githubusercontent.com/beatgammit/base64-js>`_.

5
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

4
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

37
web_drop_target/static/src/js/web_drop_target.js

@ -1,11 +1,9 @@
//-*- coding: utf-8 -*-
//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 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
);
}
}));

20
web_drop_target/views/templates.xml

@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<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/css/web_drop_target.css"/>
</xpath>
</template>
</data>
</openerp>
<odoo>
<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/css/web_drop_target.css"/>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save