mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-17 20:46:35 -06:00
[ADD] attachment_edit
This commit is contained in:
parent
e438d7c7a0
commit
ab62d11f54
62
attachment_edit/README.rst
Normal file
62
attachment_edit/README.rst
Normal file
@ -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
|
||||
<https://github.com/OCA/knowledge/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/
|
||||
knowledge/issues/new?body=module:%20
|
||||
attachment_edit%0Aversion:%20
|
||||
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Holger Brunn <hbrunn@therp.nl>
|
||||
|
||||
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.
|
21
attachment_edit/__init__.py
Normal file
21
attachment_edit/__init__.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from . import models
|
44
attachment_edit/__openerp__.py
Normal file
44
attachment_edit/__openerp__.py
Normal file
@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
{
|
||||
"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': [],
|
||||
},
|
||||
}
|
21
attachment_edit/models/__init__.py
Normal file
21
attachment_edit/models/__init__.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# This module copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from . import ir_attachment
|
53
attachment_edit/models/ir_attachment.py
Normal file
53
attachment_edit/models/ir_attachment.py
Normal file
@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# This module copyright (C) 2015 Therp BV (<http://therp.nl>).
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
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))
|
BIN
attachment_edit/static/description/icon.png
Normal file
BIN
attachment_edit/static/description/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
22
attachment_edit/static/src/css/attachment_edit.css
Normal file
22
attachment_edit/static/src/css/attachment_edit.css
Normal file
@ -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;
|
||||
}
|
||||
|
52
attachment_edit/static/src/js/attachment_edit.js
Normal file
52
attachment_edit/static/src/js/attachment_edit.js
Normal file
@ -0,0 +1,52 @@
|
||||
//-*- coding: utf-8 -*-
|
||||
//############################################################################
|
||||
//
|
||||
// OpenERP, Open Source Management Solution
|
||||
// This module copyright (C) 2015 Therp BV <http://therp.nl>.
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//############################################################################
|
||||
|
||||
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',
|
||||
},
|
||||
});
|
||||
},
|
||||
})
|
||||
}
|
10
attachment_edit/static/src/xml/attachment_edit.xml
Normal file
10
attachment_edit/static/src/xml/attachment_edit.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
<t t-extend="Sidebar">
|
||||
<t t-jquery="a.oe_sidebar_delete_item" t-operation="before">
|
||||
<a t-if="section.name == 'files' and !item.callback and item.url" href="#" class="oe-sidebar-attachment-edit" t-att-data-id="item.id" t-attf-title="Edit #{item.name}">
|
||||
<img t-att-src='_s + "/web/static/src/img/pencil.gif"' width="12" height="12" border="0"/>
|
||||
</a>
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
14
attachment_edit/views/ir_attachment.xml
Normal file
14
attachment_edit/views/ir_attachment.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_attachment_form" model="ir.ui.view">
|
||||
<field name="model">ir.attachment</field>
|
||||
<field name="inherit_id" ref="base.view_attachment_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="res_model" position="before">
|
||||
<field name="res_reference" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
11
attachment_edit/views/templates.xml
Normal file
11
attachment_edit/views/templates.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<template id="assets_backend" name="attachment_edit assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/attachment_edit/static/src/js/attachment_edit.js"></script>
|
||||
<link rel="stylesheet" href="/attachment_edit/static/src/css/attachment_edit.css"/>
|
||||
</xpath>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue
Block a user