From 01191a155c0a6f0089a224e903544a9445a6c224 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 5 May 2015 15:11:48 +0200 Subject: [PATCH] [ADD] attachment_edit --- attachment_edit/README.rst | 62 ++++++++++++++++++ attachment_edit/__init__.py | 21 ++++++ attachment_edit/__openerp__.py | 44 +++++++++++++ attachment_edit/models/__init__.py | 21 ++++++ attachment_edit/models/ir_attachment.py | 53 +++++++++++++++ attachment_edit/static/description/icon.png | Bin 0 -> 4554 bytes .../static/src/css/attachment_edit.css | 22 +++++++ .../static/src/js/attachment_edit.js | 52 +++++++++++++++ .../static/src/xml/attachment_edit.xml | 10 +++ attachment_edit/views/ir_attachment.xml | 14 ++++ attachment_edit/views/templates.xml | 11 ++++ 11 files changed, 310 insertions(+) create mode 100644 attachment_edit/README.rst create mode 100644 attachment_edit/__init__.py create mode 100644 attachment_edit/__openerp__.py create mode 100644 attachment_edit/models/__init__.py create mode 100644 attachment_edit/models/ir_attachment.py create mode 100644 attachment_edit/static/description/icon.png create mode 100644 attachment_edit/static/src/css/attachment_edit.css create mode 100644 attachment_edit/static/src/js/attachment_edit.js create mode 100644 attachment_edit/static/src/xml/attachment_edit.xml create mode 100644 attachment_edit/views/ir_attachment.xml create mode 100644 attachment_edit/views/templates.xml diff --git a/attachment_edit/README.rst b/attachment_edit/README.rst new file mode 100644 index 00000000..d5f657e3 --- /dev/null +++ b/attachment_edit/README.rst @@ -0,0 +1,62 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================ +Edit attachments +================ + +This module adds a button on the records' attachment dropdown that allows to +open the attachment's form in edit mode. This makes it convenient to edit the +attachment's properties after upload. + +On the attachment's form, a field is added to move the attachment to another +record. + +Usage +===== + +Click the pencil that appears next to the delete button when you hover over +an attachment in order to edit it. + +To change the resource the attachment belongs to, edit the field `Resource +reference`. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/118/8.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 +`_. + +Credits +======= + +Contributors +------------ + +* Holger Brunn + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/attachment_edit/__init__.py b/attachment_edit/__init__.py new file mode 100644 index 00000000..48f5a694 --- /dev/null +++ b/attachment_edit/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import models diff --git a/attachment_edit/__openerp__.py b/attachment_edit/__openerp__.py new file mode 100644 index 00000000..3c2a38a9 --- /dev/null +++ b/attachment_edit/__openerp__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + "name": "Edit attachments", + "version": "8.0.1.0.0", + "author": "Therp BV", + "license": "AGPL-3", + "category": "Knowledge Management", + "summary": "Edit attachments after upload", + "depends": [ + 'web', + ], + "data": [ + "views/ir_attachment.xml", + 'views/templates.xml', + ], + "qweb": [ + 'static/src/xml/attachment_edit.xml', + ], + "auto_install": False, + "installable": True, + "application": False, + "external_dependencies": { + 'python': [], + }, +} diff --git a/attachment_edit/models/__init__.py b/attachment_edit/models/__init__.py new file mode 100644 index 00000000..ce46c857 --- /dev/null +++ b/attachment_edit/models/__init__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from . import ir_attachment diff --git a/attachment_edit/models/ir_attachment.py b/attachment_edit/models/ir_attachment.py new file mode 100644 index 00000000..67bb0f0a --- /dev/null +++ b/attachment_edit/models/ir_attachment.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp import models, fields, api + + +class IrAttachment(models.Model): + _inherit = 'ir.attachment' + + res_reference = fields.Reference( + selection='_selection_res_reference', + string='Resource reference', compute='_compute_res_reference', + inverse='_inverse_res_reference') + + @api.one + @api.depends('res_id', 'res_model') + def _compute_res_reference(self): + if self.res_model and self.res_id: + self.res_reference = '%s,%s' % (self.res_model, self.res_id) + + @api.one + def _inverse_res_reference(self): + if self.res_reference: + self.write({ + 'res_model': self.res_reference._model._model, + 'res_id': self.res_reference.id, + }) + else: + self.write({'res_model': False, 'res_id': False}) + + @api.model + def _selection_res_reference(self): + return self.env['ir.model'].search([ + ('osv_memory', '=', False), + ('access_ids.group_id.users', '=', self.env.uid) + ]).mapped(lambda rec: (rec.model, rec.name)) diff --git a/attachment_edit/static/description/icon.png b/attachment_edit/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..14d87f86fb996b1d417b6cb78ac30b41060525e0 GIT binary patch literal 4554 zcmZ`-XH-*7yA7g%QluBDLTD1{FVc|`Ab^A}NRb+l7Nj>pks=*J?@}~0L8*o+O%z0= z_|mI}jtByw1i0h6_kRDrb=Ju_nKkpAbDr7Hp1mj5Kwpdc+Kp=v2!tA;tziVNPT+K; zAOpWeJm;?9LT0b4r2)D4d%SGNrh%5LUfLEu5C|p1-;)HAo6iaw$$b&`;N%Neu27Rh zt5|cbK@*!V+}u|k?cw3%=?hW!cCzzza^wkkoAoZik4 z@-i{)=vN{56Sns;6w(wLjucc$+6K{c{dtTouhJ10Bz=Bd2*5>uka59fzR>BQ;8UCUt1U}U-_e9OcL9OY$1otwS= z{Z*8h%2(wE2t$NnF{T7lviwjpP9Iy^*48#uq>tq@3M$Z_SVq4w8x$-GjWDY^ga7ks zSas)Z?vLeVNVZaljAyeY0`21R!B%{6H*gxp&B7AX|HJOvOI21XG7Uq=4^K(5hfp=v zt%vb9``l$N1`lZJ8QX2H-}UqRM<(yyaYjbQ$m}fDhnK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Ku^%E&?*C&*9|-Xka^DYZ9%}z2^~8*IVlomeZFK%Ja_0%5?&ux z{6hs9!y-GCv~i)wb@V`ToBe{WkCc*g4gn)%Rx=;n#h1M>x*ZZ0v~W) zg(wc(q)r$xOCXRF5O%jc-vWyVu?5o)zOBoWmd8toH!xYptG1OdsQBRtc+tBk6sq@{ zlLZQV8L+fQMn(^gihwo6U@#F~wu`A+T(~EkPu9*%iV5%D&w0w{l6&ng!|UqnEgD=> zz0Yi*vyb~Z?=E(H{I;nM5{{~8d;d6X&I6$X97~3FtxbD*MFq*?K!%8~bZt#dQijNV zVDE=>yM1b zbg%k#rQT1edIUND)Vr`yen zXZvIMD&d7mE1YuPk-(4&+{-N^s%hDF9c$7)IX!gxnlHzp9GWfXvm&&PR61acxy~&h zC6z`(%8UMfKE0b(OOMQzUT@&BE6eY!44 Y6BeQcU%D|Pz!nPx0oT{4QL~NsA0Cv&n*aa+ literal 0 HcmV?d00001 diff --git a/attachment_edit/static/src/css/attachment_edit.css b/attachment_edit/static/src/css/attachment_edit.css new file mode 100644 index 00000000..3b25edd3 --- /dev/null +++ b/attachment_edit/static/src/css/attachment_edit.css @@ -0,0 +1,22 @@ +.openerp .oe_sidebar .oe_dropdown_menu li .oe-sidebar-attachment-edit +{ + position: absolute; + right: 32px; + top: 0px; + display: none; +} +.openerp .oe_sidebar .oe_dropdown_menu li:hover .oe-sidebar-attachment-edit +{ + display: inherit; +} +.openerp .oe_sidebar .oe_dropdown_menu li .oe-sidebar-attachment-edit:hover +{ + text-decoration: none; + color: white; + background: #8786b7; + text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4); + -moz-border-radius: 2px; + -webkit-border-radius: 2px; + border-radius: 2px; +} + diff --git a/attachment_edit/static/src/js/attachment_edit.js b/attachment_edit/static/src/js/attachment_edit.js new file mode 100644 index 00000000..65234fd2 --- /dev/null +++ b/attachment_edit/static/src/js/attachment_edit.js @@ -0,0 +1,52 @@ +//-*- coding: utf-8 -*- +//############################################################################ +// +// OpenERP, Open Source Management Solution +// This module copyright (C) 2015 Therp BV . +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +//############################################################################ + +openerp.attachment_edit = function(instance) +{ + instance.web.Sidebar.include( + { + on_attachments_loaded: function(attachments) + { + var result = this._super.apply(this, arguments); + this.$el.find('.oe-sidebar-attachment-edit') + .click(this.on_attachment_edit); + return result; + }, + on_attachment_edit: function(e) + { + var $target = jQuery(e.currentTarget), + attachment_id = parseInt($target.attr('data-id')), + title = $target.attr('title'); + e.preventDefault(); + e.stopPropagation(); + this.do_action({ + type: 'ir_actions.act_window', + name: title, + views: [[false, 'form']], + res_model: 'ir.attachment', + res_id: attachment_id, + flags: { + initial_mode: 'edit', + }, + }); + }, + }) +} diff --git a/attachment_edit/static/src/xml/attachment_edit.xml b/attachment_edit/static/src/xml/attachment_edit.xml new file mode 100644 index 00000000..2a648aa9 --- /dev/null +++ b/attachment_edit/static/src/xml/attachment_edit.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/attachment_edit/views/ir_attachment.xml b/attachment_edit/views/ir_attachment.xml new file mode 100644 index 00000000..ec6eb9da --- /dev/null +++ b/attachment_edit/views/ir_attachment.xml @@ -0,0 +1,14 @@ + + + + + ir.attachment + + + + + + + + + diff --git a/attachment_edit/views/templates.xml b/attachment_edit/views/templates.xml new file mode 100644 index 00000000..e4da3b4b --- /dev/null +++ b/attachment_edit/views/templates.xml @@ -0,0 +1,11 @@ + + + + + +