[RFR] add base module for actions on attachments

This commit is contained in:
Holger Brunn 2018-02-03 18:56:21 +01:00
parent 0eab33b259
commit 4f88b026c5
No known key found for this signature in database
GPG Key ID: 01C9760FECA3AE18
15 changed files with 185 additions and 55 deletions

View File

@ -0,0 +1,52 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
======================
Actions on attachments
======================
This module was written to provide a container for other modules to add buttons for actions on attachments.
Usage
=====
This module does nothing useful on its own.
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.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Holger Brunn <hbrunn@therp.nl>
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.
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.

View File

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

View File

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Actions on attachments",
"version": "8.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Hidden/Dependency",
"summary": "Enable/disable actions on attachments",
"depends": [
'web',
'knowledge',
'document',
],
"data": [
'views/templates.xml',
],
"qweb": [
'static/src/xml/attachment_action.xml',
],
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -0,0 +1,37 @@
.openerp .oe_sidebar .oe_dropdown_menu li span.oe_sidebar_attachment_action .oe_sidebar_delete_item
{
position: static;
}
.openerp .oe_sidebar .oe_dropdown_menu li span.oe_sidebar_attachment_action
{
display: none;
position: absolute;
right: 0;
top: 0;
left: 50%;
text-align: right;
padding: 0px 6px;
}
.openerp .oe_sidebar .oe_dropdown_menu li span.oe_sidebar_attachment_action > *
{
display: inline-block;
padding: 2px;
color: #8786b7;
font-weight: bold;
text-shadow: 0 1px 1px white;
margin-right: 1px;
}
.openerp .oe_sidebar .oe_dropdown_menu li span.oe_sidebar_attachment_action > *: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
}
.openerp .oe_sidebar .oe_dropdown_menu li:hover span.oe_sidebar_attachment_action
{
display: block;
}

View File

@ -0,0 +1,32 @@
//-*- coding: utf-8 -*-
//Copyright 2018 Therp BV <https://therp.nl>
//License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
openerp.attachment_action = function(instance)
{
instance.web.Sidebar.include({
_extra_sidebar_attachment_fields: [],
on_attachments_loaded: function(attachments)
{
var self = this, _super = this._super;
return new instance.web.Model('ir.attachment')
.query(this._extra_sidebar_attachment_fields)
.filter([['id', 'in', _.pluck(attachments, 'id')]])
.all()
.then(function(extra_data)
{
_.each(attachments, function(attachment)
{
_.extend(attachment, _.find(
extra_data, function(x)
{
return x.id == attachment.id
}
));
});
_super.apply(self, [attachments]);
return attachments;
});
},
});
};

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-extend="Sidebar">
<t t-jquery="a.oe_sidebar_delete_item" t-operation="before">
<span class="oe_sidebar_attachment_action" />
</t>
<t t-jquery="a.oe_sidebar_delete_item">
jQuery(this).appendTo(this.siblings('.oe_sidebar_attachment_action'));
</t>
</t>
</templates>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="assets_backend" name="attachment_action assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/attachment_action/static/src/js/attachment_action.js"></script>
<link rel="stylesheet" href="/attachment_action/static/src/css/attachment_action.css"/>
</xpath>
</template>
</data>
</openerp>

View File

@ -9,7 +9,7 @@
"category": "Knowledge Management",
"summary": "Edit attachments after upload",
"depends": [
'web',
'attachment_action',
],
"data": [
"views/ir_attachment.xml",

View File

@ -1,22 +0,0 @@
.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;
}

View File

@ -25,10 +25,13 @@ openerp.attachment_edit = function(instance)
{
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;
var self = this;
return jQuery.when(this._super.apply(this, arguments))
.then(function()
{
self.$el.find('.oe-sidebar-attachment-edit')
.click(self.on_attachment_edit);
});
},
on_attachment_edit: function(e)
{

View File

@ -4,7 +4,6 @@
<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>

View File

@ -27,7 +27,7 @@
'summary': 'Preview attachments supported by Viewer.js',
"category": "Knowledge Management",
"depends": [
'web',
'attachment_action',
],
"data": [
"view/attachment_preview.xml",

View File

@ -1,24 +1,3 @@
.openerp .oe_sidebar .oe_dropdown_menu li .oe-sidebar-attachment-preview
{
position: absolute;
right: 18px;
top: 0px;
display: none;
}
.openerp .oe_sidebar .oe_dropdown_menu li:hover .oe-sidebar-attachment-preview
{
display: inherit;
}
.openerp .oe_sidebar .oe_dropdown_menu li .oe-sidebar-attachment-preview: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;
}
.openerp .oe-binary-preview
{
cursor: pointer;

View File

@ -47,11 +47,14 @@ openerp.attachment_preview = function(instance)
{
on_attachments_loaded: function(attachments)
{
var result = this._super.apply(this, arguments);
this.$el.find('.oe-sidebar-attachment-preview')
.click(this.on_attachment_preview);
this.update_preview_buttons();
return result;
var self = this;
return jQuery.when(this._super.apply(this, arguments))
.then(function()
{
self.$el.find('.oe-sidebar-attachment-preview')
.click(self.on_attachment_preview);
self.update_preview_buttons();
});
},
on_attachment_preview: function(e)
{