[MIG] attachment_preview: Migration to 12.0

[REM] Old files

[ADD] Magic to travis file

[FIX] Nagivation refresh widget
This commit is contained in:
tarteo 2019-09-20 12:56:20 +02:00
parent 004fb26e65
commit 063c58e25a
8 changed files with 96 additions and 78 deletions

View File

@ -30,6 +30,7 @@ env:
install: install:
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- pip install --upgrade python-magic
- travis_install_nightly - travis_install_nightly

View File

@ -14,13 +14,13 @@ Preview attachments
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github
:target: https://github.com/OCA/knowledge/tree/11.0/attachment_preview :target: https://github.com/OCA/knowledge/tree/12.0/attachment_preview
:alt: OCA/knowledge :alt: OCA/knowledge
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/knowledge-11-0/knowledge-11-0-attachment_preview :target: https://translation.odoo-community.org/projects/knowledge-12-0/knowledge-12-0-attachment_preview
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/118/11.0 :target: https://runbot.odoo-community.org/runbot/118/12.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -64,7 +64,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/knowledge/issues>`_. 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. 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 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:%20attachment_preview%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/knowledge/issues/new?body=module:%20attachment_preview%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -104,6 +104,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/11.0/attachment_preview>`_ project on GitHub. This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/12.0/attachment_preview>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -3,7 +3,7 @@
{ {
"name": "Preview attachments", "name": "Preview attachments",
"version": "11.0.1.3.0", "version": "12.0.1.0.0",
"author": "Therp BV," "author": "Therp BV,"
"Onestein," "Onestein,"
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
@ -12,6 +12,7 @@
"category": "Knowledge Management", "category": "Knowledge Management",
"depends": [ "depends": [
'web', 'web',
'mail'
], ],
"data": [ "data": [
"templates/assets.xml", "templates/assets.xml",

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" /> <meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
<title>Preview attachments</title> <title>Preview attachments</title>
<style type="text/css"> <style type="text/css">
@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/knowledge/tree/11.0/attachment_preview"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/knowledge-11-0/knowledge-11-0-attachment_preview"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/118/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/knowledge/tree/12.0/attachment_preview"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/knowledge-12-0/knowledge-12-0-attachment_preview"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/118/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This addon allows to preview attachments supported by <a class="reference external" href="http://viewerjs.org">http://viewerjs.org</a>.</p> <p>This addon allows to preview attachments supported by <a class="reference external" href="http://viewerjs.org">http://viewerjs.org</a>.</p>
<p>Currently, thats most Libreoffice files and PDFs.</p> <p>Currently, thats most Libreoffice files and PDFs.</p>
<img alt="Screenshot of split form view" src="https://raw.githubusercontent.com/attachment_preview/static/description/screenshot-split.png" style="width: 100%;" /> <img alt="Screenshot of split form view" src="https://raw.githubusercontent.com/attachment_preview/static/description/screenshot-split.png" style="width: 100%;" />
@ -409,7 +409,7 @@ next to the navigational buttons you can open the preview in a separate window.<
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/knowledge/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/knowledge/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/knowledge/issues/new?body=module:%20attachment_preview%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/knowledge/issues/new?body=module:%20attachment_preview%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -444,7 +444,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/knowledge/tree/11.0/attachment_preview">OCA/knowledge</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/knowledge/tree/12.0/attachment_preview">OCA/knowledge</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@ -7,7 +7,7 @@ odoo.define('attachment_preview', function (require) {
var core = require('web.core'); var core = require('web.core');
var _t = core._t; var _t = core._t;
var qweb = core.qweb; var qweb = core.qweb;
var Sidebar = require('web.Sidebar'); var Chatter = require('mail.Chatter');
var basic_fields = require('web.basic_fields'); var basic_fields = require('web.basic_fields');
var FormRenderer = require('web.FormRenderer'); var FormRenderer = require('web.FormRenderer');
var FormController = require('web.FormController'); var FormController = require('web.FormController');
@ -42,21 +42,40 @@ odoo.define('attachment_preview', function (require) {
}, },
}; };
Sidebar.include(AttachmentPreviewMixin); Chatter.include(AttachmentPreviewMixin);
Sidebar.include({ Chatter.include({
events: _.extend({}, Sidebar.prototype.events, { events: _.extend({}, Chatter.prototype.events, {
'click .o_sidebar_preview_attachment': '_onPreviewAttachment', 'click .o_attachment_preview': '_onPreviewAttachment',
}), }),
previewableAttachments: null, previewableAttachments: null,
_redraw: function () { _openAttachmentBox: function () {
this._super.apply(this, arguments); var res = this._super.apply(this, arguments);
this.getPreviewableAttachments().done(function (atts) { this.getPreviewableAttachments().done(function (atts) {
this.previewableAttachments = atts; this.previewableAttachments = atts;
this.updatePreviewButtons(atts); this.updatePreviewButtons(atts);
this.trigger_up('setPreviewableAttachments', {attachments: atts}); this.getParent().attachmentPreviewWidget.setAttachments(atts);
}.bind(this)); }.bind(this));
return res;
},
update: function () {
var res = this._super.apply(this, arguments);
var self = this;
if (this.getParent().$el.hasClass('attachment_preview')) {
this._fetchAttachments().done(function () {
self._openAttachmentBox();
self.getPreviewableAttachments().done(function (atts) {
self.updatePreviewButtons(self.previewableAttachments);
self.previewableAttachments = atts;
self.getParent().attachmentPreviewWidget.setAttachments(atts);
});
});
}
return res;
}, },
_onPreviewAttachment: function (event) { _onPreviewAttachment: function (event) {
@ -86,7 +105,7 @@ odoo.define('attachment_preview', function (require) {
var self = this; var self = this;
var deferred = $.Deferred(); var deferred = $.Deferred();
var $items = this.$el.find('.o_sidebar_preview_attachment'); var $items = this.$el.find('.o_attachment_preview');
var attachments = _.object($items.map(function () { var attachments = _.object($items.map(function () {
return parseInt($(this).attr('data-id'), 10); return parseInt($(this).attr('data-id'), 10);
}), $items.map(function () { }), $items.map(function () {
@ -111,14 +130,14 @@ odoo.define('attachment_preview', function (require) {
})), function (id) { })), function (id) {
return { return {
id: id, id: id,
url: attachments[id]['url'], url: attachments[id].url,
extension: extensions[id], extension: extensions[id],
title: attachments[id]['title'], title: attachments[id].title,
previewUrl: self.getUrl( previewUrl: self.getUrl(
id, id,
attachments[id]['url'], attachments[id].url,
extensions[id], extensions[id],
id + ' - ' + attachments[id]['title'] id + ' - ' + attachments[id].title
), ),
}; };
}); });
@ -130,7 +149,7 @@ odoo.define('attachment_preview', function (require) {
}, },
updatePreviewButtons: function (previewableAttachments) { updatePreviewButtons: function (previewableAttachments) {
this.$el.find('.o_sidebar_preview_attachment').each(function () { this.$el.find('.o_attachment_preview').each(function () {
var $this = $(this); var $this = $(this);
var id = $this.attr('data-id'); var id = $this.attr('data-id');
var att = _.findWhere(previewableAttachments, {id: id}); var att = _.findWhere(previewableAttachments, {id: id});
@ -152,19 +171,23 @@ odoo.define('attachment_preview', function (require) {
_renderReadonly: function () { _renderReadonly: function () {
var self = this; var self = this;
this._super.apply(this, arguments); this._super.apply(this, arguments);
this._getBinaryExtension().done(function (extension) {
if (self.canPreview(extension)) { if (this.recordData.id) {
self._renderPreviewButton(extension); this._getBinaryExtension().done(function (extension) {
} if (self.canPreview(extension)) {
}); self._renderPreviewButton(extension);
}
});
}
}, },
_renderPreviewButton: function (extension) { _renderPreviewButton: function (extension) {
this.$previewBtn = $("<span/>"); this.$previewBtn = $("<a/>");
this.$previewBtn.addClass('fa fa-search'); this.$previewBtn.addClass('fa fa-search mr-2');
this.$previewBtn.attr('href', 'javascript:void(0)');
this.$previewBtn.attr('title', _.str.sprintf(_t('Preview %s'), this.field.string)); this.$previewBtn.attr('title', _.str.sprintf(_t('Preview %s'), this.field.string));
this.$previewBtn.attr('data-extension', extension); this.$previewBtn.attr('data-extension', extension);
this.$el.find('.fa-download').after(this.$previewBtn); this.$el.find('.fa-download').before(this.$previewBtn);
}, },
_getBinaryExtension: function () { _getBinaryExtension: function () {
@ -193,6 +216,7 @@ odoo.define('attachment_preview', function (require) {
_.str.sprintf(_t('Preview %s'), this.field.string), _.str.sprintf(_t('Preview %s'), this.field.string),
false false
); );
event.stopPropagation();
}, },
}); });
@ -257,12 +281,12 @@ odoo.define('attachment_preview', function (require) {
}, },
show: function () { show: function () {
this.$el.removeClass('hidden'); this.$el.removeClass('d-none');
this.trigger('shown'); this.trigger('shown');
}, },
hide: function () { hide: function () {
this.$el.addClass('hidden'); this.$el.addClass('d-none');
this.trigger('hidden'); this.trigger('hidden');
}, },
@ -290,6 +314,10 @@ odoo.define('attachment_preview', function (require) {
}); });
FormRenderer.include({ FormRenderer.include({
custom_events: _.extend({}, FormRenderer.prototype.custom_events, {
onAttachmentPreview: '_onAttachmentPreview',
}),
attachmentPreviewWidget: null, attachmentPreviewWidget: null,
init: function () { init: function () {
@ -310,8 +338,9 @@ odoo.define('attachment_preview', function (require) {
showAttachmentPreviewWidget: function () { showAttachmentPreviewWidget: function () {
this.$el.addClass('attachment_preview'); this.$el.addClass('attachment_preview');
this.attachmentPreviewWidget.setAttachments( this.attachmentPreviewWidget.setAttachments(
this.getParent().sidebar.previewableAttachments this.chatter.previewableAttachments
); );
this.attachmentPreviewWidget.show(); this.attachmentPreviewWidget.show();
}, },
@ -321,25 +350,12 @@ odoo.define('attachment_preview', function (require) {
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
}, },
});
FormController.include({
custom_events: _.extend({}, FormController.prototype.custom_events, {
onAttachmentPreview: '_onAttachmentPreview',
setPreviewableAttachments: '_setPreviewableAttachments',
}),
_onAttachmentPreview: function (event) { _onAttachmentPreview: function (event) {
this.renderer.showAttachmentPreviewWidget(); this.showAttachmentPreviewWidget();
},
_setPreviewableAttachments: function (event) {
this.renderer.attachmentPreviewWidget.setAttachments(
event.data.attachments
);
}, },
}); });
return { return {
AttachmentPreviewMixin: AttachmentPreviewMixin, AttachmentPreviewMixin: AttachmentPreviewMixin,
AttachmentPreviewWidget: AttachmentPreviewWidget, AttachmentPreviewWidget: AttachmentPreviewWidget,

View File

@ -1,11 +1,11 @@
.o_cp_sidebar { .o_attachments_list .o_attachment_wrap {
li .o_sidebar_preview_attachment { .o_attachment_preview {
position: absolute; cursor: pointer;
top: 5px; float: right;
right: 26px; padding-top: 1px;
background-color: #FFF; padding-bottom: 1px;
&.o_sidebar_preview_attachment_new_tab { &.o_attachment_preview_new_tab {
right: 43px; right: 43px;
} }
} }
@ -35,7 +35,7 @@
> .attachment_preview_iframe { > .attachment_preview_iframe {
width: 100%; width: 100%;
height: calc(~"100% - 30px"); height: calc(100% - 30px);
float: left; float: left;
} }
@ -44,7 +44,7 @@
float: left; float: left;
width: 100%; width: 100%;
background-color: #FFF; background-color: #FFF;
border-left: 1px solid @gray-lighter-dark; border-left: 1px solid $gray-800;
button { button {
min-width: 25px; min-width: 25px;

View File

@ -1,33 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<templates> <templates>
<t t-extend="Sidebar"> <t t-extend="mail.Attachment">
<t t-jquery="span.o_sidebar_delete_attachment" t-operation="before"> <t t-jquery=".o_attachment_download" t-operation="after">
<span t-if="section.name == 'files' and widget.options.editable and !item.callback and item.url" <span t-if="!attachment.callback and attachment.url"
class="fa fa-search o_sidebar_preview_attachment" class="fa fa-search ml4 o_attachment_preview"
t-att-data-id="item.id" t-att-data-id="attachment.id"
t-att-data-url="item.url" t-att-data-url="attachment.url"
t-attf-title="Preview #{item.name}"/> t-attf-title="Preview #{attachment.name} in side panel"/>
<span t-if="section.name == 'files' and widget.options.editable and !item.callback and item.url" <span t-if="!attachment.callback and attachment.url"
class="fa fa-external-link o_sidebar_preview_attachment o_sidebar_preview_attachment_new_tab" class="fa fa-external-link ml4 o_attachment_preview o_attachment_preview_new_tab"
data-target="new" data-target="new"
t-att-data-id="item.id" t-att-data-id="attachment.id"
t-att-data-url="item.url" t-att-data-url="attachment.url"
t-attf-title="Open preview #{item.name} in a new tab"/> t-attf-title="Open preview #{attachment.name} in a new tab"/>
</t> </t>
</t> </t>
<t t-name="attachment_preview.AttachmentPreviewWidget"> <t t-name="attachment_preview.AttachmentPreviewWidget">
<div class="attachment_preview_widget hidden"> <div class="attachment_preview_widget d-none">
<div class="attachment_preview_buttons"> <div class="attachment_preview_buttons">
<div class="button-group pull-left"> <div class="button-group pull-left">
<button class="btn btn-sm btn-default attachment_preview_previous"><i class="fa fa-chevron-left"/></button> <button class="btn btn-sm btn-secondary attachment_preview_previous"><i class="fa fa-chevron-left"/></button>
<button class="btn btn-sm btn-default disabled attachment_preview_current">1 / 5</button> <button class="btn btn-sm btn-secondary disabled attachment_preview_current">1 / 5</button>
<button class="btn btn-sm btn-default attachment_preview_next"><i class="fa fa-chevron-right"/></button> <button class="btn btn-sm btn-secondary attachment_preview_next"><i class="fa fa-chevron-right"/></button>
</div> </div>
<button class="btn btn-sm btn-default pull-left ml8 attachment_preview_popout"><i class="fa fa-external-link"/></button> <button class="btn btn-sm btn-secondary pull-left ml8 attachment_preview_popout"><i class="fa fa-external-link"/></button>
<button class="btn btn-sm btn-default pull-right attachment_preview_close"><i class="fa fa-times"/></button> <button class="btn btn-sm btn-secondary pull-right attachment_preview_close"><i class="fa fa-times"/></button>
</div> </div>
<iframe class="attachment_preview_iframe"></iframe> <iframe class="attachment_preview_iframe"></iframe>
</div> </div>

View File

@ -3,7 +3,7 @@
<template id="assets_backend" name="attachment_preview assets" inherit_id="web.assets_backend"> <template id="assets_backend" name="attachment_preview assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside"> <xpath expr="." position="inside">
<script type="text/javascript" src="/attachment_preview/static/src/js/attachment_preview.js"></script> <script type="text/javascript" src="/attachment_preview/static/src/js/attachment_preview.js"></script>
<link rel="stylesheet" type="text/less" href="/attachment_preview/static/src/less/attachment_preview.less" /> <link rel="stylesheet" type="text/scss" href="/attachment_preview/static/src/scss/attachment_preview.scss" />
</xpath> </xpath>
</template> </template>
</odoo> </odoo>