From 271d86ca5cdfb47e064d4363fe11da692c46cd9e Mon Sep 17 00:00:00 2001 From: tarteo Date: Fri, 20 Sep 2019 12:56:20 +0200 Subject: [PATCH] [MIG] attachment_preview: Migration to 12.0 [REM] Old files [ADD] Magic to travis file [FIX] Nagivation refresh widget --- attachment_preview/README.rst | 10 +- attachment_preview/__manifest__.py | 3 +- .../i18n/attachment_preview.pot | 16 ++-- attachment_preview/i18n/de.po | 14 +-- attachment_preview/i18n/es.po | 14 +-- attachment_preview/i18n/it.po | 14 +-- attachment_preview/i18n/nl.po | 14 +-- .../static/description/index.html | 6 +- .../static/src/js/attachment_preview.js | 96 +++++++++++-------- .../attachment_preview.scss} | 18 ++-- .../static/src/xml/attachment_preview.xml | 36 +++---- attachment_preview/templates/assets.xml | 2 +- 12 files changed, 130 insertions(+), 113 deletions(-) rename attachment_preview/static/src/{less/attachment_preview.less => scss/attachment_preview.scss} (72%) diff --git a/attachment_preview/README.rst b/attachment_preview/README.rst index c65b0349..db3ed088 100644 --- a/attachment_preview/README.rst +++ b/attachment_preview/README.rst @@ -14,13 +14,13 @@ Preview attachments :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |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 .. |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 .. |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 |badge1| |badge2| |badge3| |badge4| |badge5| @@ -64,7 +64,7 @@ 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 `_. +`feedback `_. 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 promote its widespread use. -This module is part of the `OCA/knowledge `_ project on GitHub. +This module is part of the `OCA/knowledge `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/attachment_preview/__manifest__.py b/attachment_preview/__manifest__.py index 77da9c13..4986d41a 100644 --- a/attachment_preview/__manifest__.py +++ b/attachment_preview/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Preview attachments", - "version": "11.0.1.3.0", + "version": "12.0.1.0.0", "author": "Therp BV," "Onestein," "Odoo Community Association (OCA)", @@ -12,6 +12,7 @@ "category": "Knowledge Management", "depends": [ 'web', + 'mail' ], "data": [ "templates/assets.xml", diff --git a/attachment_preview/i18n/attachment_preview.pot b/attachment_preview/i18n/attachment_preview.pot index 3a310898..d9f9efe3 100644 --- a/attachment_preview/i18n/attachment_preview.pot +++ b/attachment_preview/i18n/attachment_preview.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 11.0\n" +"Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: <>\n" "Language-Team: \n" @@ -13,16 +13,16 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: attachment_preview +#: model:ir.model,name:attachment_preview.model_ir_attachment +msgid "Attachment" +msgstr "" + #. module: attachment_preview #. openerp-web -#: code:addons/attachment_preview/static/src/js/attachment_preview.js:165 -#: code:addons/attachment_preview/static/src/js/attachment_preview.js:193 +#: code:addons/attachment_preview/static/src/js/attachment_preview.js:188 +#: code:addons/attachment_preview/static/src/js/attachment_preview.js:216 #, python-format msgid "Preview %s" msgstr "" -#. module: attachment_preview -#: model:ir.model,name:attachment_preview.model_ir_attachment -msgid "ir.attachment" -msgstr "" - diff --git a/attachment_preview/i18n/de.po b/attachment_preview/i18n/de.po index 30fe2d08..ef1547dd 100644 --- a/attachment_preview/i18n/de.po +++ b/attachment_preview/i18n/de.po @@ -19,15 +19,15 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +#. module: attachment_preview +#: model:ir.model,name:attachment_preview.model_ir_attachment +msgid "Attachment" +msgstr "" + #. module: attachment_preview #. openerp-web -#: code:addons/attachment_preview/static/src/js/attachment_preview.js:165 -#: code:addons/attachment_preview/static/src/js/attachment_preview.js:193 +#: code:addons/attachment_preview/static/src/js/attachment_preview.js:188 +#: code:addons/attachment_preview/static/src/js/attachment_preview.js:216 #, python-format msgid "Preview %s" msgstr "Vorschau %s" - -#. module: attachment_preview -#: model:ir.model,name:attachment_preview.model_ir_attachment -msgid "ir.attachment" -msgstr "" diff --git a/attachment_preview/i18n/es.po b/attachment_preview/i18n/es.po index aa4ee6ea..b8caacd1 100644 --- a/attachment_preview/i18n/es.po +++ b/attachment_preview/i18n/es.po @@ -19,15 +19,15 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +#. module: attachment_preview +#: model:ir.model,name:attachment_preview.model_ir_attachment +msgid "Attachment" +msgstr "" + #. module: attachment_preview #. openerp-web -#: code:addons/attachment_preview/static/src/js/attachment_preview.js:165 -#: code:addons/attachment_preview/static/src/js/attachment_preview.js:193 +#: code:addons/attachment_preview/static/src/js/attachment_preview.js:188 +#: code:addons/attachment_preview/static/src/js/attachment_preview.js:216 #, python-format msgid "Preview %s" msgstr "Previsualizar %s" - -#. module: attachment_preview -#: model:ir.model,name:attachment_preview.model_ir_attachment -msgid "ir.attachment" -msgstr "" diff --git a/attachment_preview/i18n/it.po b/attachment_preview/i18n/it.po index 2d2f6552..da59b04f 100644 --- a/attachment_preview/i18n/it.po +++ b/attachment_preview/i18n/it.po @@ -19,15 +19,15 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +#. module: attachment_preview +#: model:ir.model,name:attachment_preview.model_ir_attachment +msgid "Attachment" +msgstr "" + #. module: attachment_preview #. openerp-web -#: code:addons/attachment_preview/static/src/js/attachment_preview.js:165 -#: code:addons/attachment_preview/static/src/js/attachment_preview.js:193 +#: code:addons/attachment_preview/static/src/js/attachment_preview.js:188 +#: code:addons/attachment_preview/static/src/js/attachment_preview.js:216 #, python-format msgid "Preview %s" msgstr "Anteprima %s" - -#. module: attachment_preview -#: model:ir.model,name:attachment_preview.model_ir_attachment -msgid "ir.attachment" -msgstr "" diff --git a/attachment_preview/i18n/nl.po b/attachment_preview/i18n/nl.po index 987639b8..d342e606 100644 --- a/attachment_preview/i18n/nl.po +++ b/attachment_preview/i18n/nl.po @@ -18,15 +18,15 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +#. module: attachment_preview +#: model:ir.model,name:attachment_preview.model_ir_attachment +msgid "Attachment" +msgstr "" + #. module: attachment_preview #. openerp-web -#: code:addons/attachment_preview/static/src/js/attachment_preview.js:165 -#: code:addons/attachment_preview/static/src/js/attachment_preview.js:193 +#: code:addons/attachment_preview/static/src/js/attachment_preview.js:188 +#: code:addons/attachment_preview/static/src/js/attachment_preview.js:216 #, python-format msgid "Preview %s" msgstr "Voorbeeld %s" - -#. module: attachment_preview -#: model:ir.model,name:attachment_preview.model_ir_attachment -msgid "ir.attachment" -msgstr "" diff --git a/attachment_preview/static/description/index.html b/attachment_preview/static/description/index.html index 3104fb6a..5569ebc6 100644 --- a/attachment_preview/static/description/index.html +++ b/attachment_preview/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/knowledge Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/knowledge Translate me on Weblate Try me on Runbot

This addon allows to preview attachments supported by http://viewerjs.org.

Currently, that’s most Libreoffice files and PDFs.

Screenshot of split form view @@ -409,7 +409,7 @@ next to the navigational buttons you can open the preview in a separate window.<

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.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -444,7 +444,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

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.

-

This module is part of the OCA/knowledge project on GitHub.

+

This module is part of the OCA/knowledge project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/attachment_preview/static/src/js/attachment_preview.js b/attachment_preview/static/src/js/attachment_preview.js index b2c6b339..865e1f04 100644 --- a/attachment_preview/static/src/js/attachment_preview.js +++ b/attachment_preview/static/src/js/attachment_preview.js @@ -7,7 +7,7 @@ odoo.define('attachment_preview', function (require) { var core = require('web.core'); var _t = core._t; var qweb = core.qweb; - var Sidebar = require('web.Sidebar'); + var Chatter = require('mail.Chatter'); var basic_fields = require('web.basic_fields'); var FormRenderer = require('web.FormRenderer'); var FormController = require('web.FormController'); @@ -42,21 +42,40 @@ odoo.define('attachment_preview', function (require) { }, }; - Sidebar.include(AttachmentPreviewMixin); - Sidebar.include({ - events: _.extend({}, Sidebar.prototype.events, { - 'click .o_sidebar_preview_attachment': '_onPreviewAttachment', + Chatter.include(AttachmentPreviewMixin); + Chatter.include({ + events: _.extend({}, Chatter.prototype.events, { + 'click .o_attachment_preview': '_onPreviewAttachment', }), previewableAttachments: null, - _redraw: function () { - this._super.apply(this, arguments); + _openAttachmentBox: function () { + var res = this._super.apply(this, arguments); + this.getPreviewableAttachments().done(function (atts) { this.previewableAttachments = atts; this.updatePreviewButtons(atts); - this.trigger_up('setPreviewableAttachments', {attachments: atts}); + this.getParent().attachmentPreviewWidget.setAttachments(atts); }.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) { @@ -86,7 +105,7 @@ odoo.define('attachment_preview', function (require) { var self = this; 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 () { return parseInt($(this).attr('data-id'), 10); }), $items.map(function () { @@ -111,14 +130,14 @@ odoo.define('attachment_preview', function (require) { })), function (id) { return { id: id, - url: attachments[id]['url'], + url: attachments[id].url, extension: extensions[id], - title: attachments[id]['title'], + title: attachments[id].title, previewUrl: self.getUrl( id, - attachments[id]['url'], + attachments[id].url, extensions[id], - id + ' - ' + attachments[id]['title'] + id + ' - ' + attachments[id].title ), }; }); @@ -130,7 +149,7 @@ odoo.define('attachment_preview', function (require) { }, updatePreviewButtons: function (previewableAttachments) { - this.$el.find('.o_sidebar_preview_attachment').each(function () { + this.$el.find('.o_attachment_preview').each(function () { var $this = $(this); var id = $this.attr('data-id'); var att = _.findWhere(previewableAttachments, {id: id}); @@ -152,19 +171,23 @@ odoo.define('attachment_preview', function (require) { _renderReadonly: function () { var self = this; this._super.apply(this, arguments); - this._getBinaryExtension().done(function (extension) { - if (self.canPreview(extension)) { - self._renderPreviewButton(extension); - } - }); + + if (this.recordData.id) { + this._getBinaryExtension().done(function (extension) { + if (self.canPreview(extension)) { + self._renderPreviewButton(extension); + } + }); + } }, _renderPreviewButton: function (extension) { - this.$previewBtn = $(""); - this.$previewBtn.addClass('fa fa-search'); + this.$previewBtn = $(""); + 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('data-extension', extension); - this.$el.find('.fa-download').after(this.$previewBtn); + this.$el.find('.fa-download').before(this.$previewBtn); }, _getBinaryExtension: function () { @@ -193,6 +216,7 @@ odoo.define('attachment_preview', function (require) { _.str.sprintf(_t('Preview %s'), this.field.string), false ); + event.stopPropagation(); }, }); @@ -257,12 +281,12 @@ odoo.define('attachment_preview', function (require) { }, show: function () { - this.$el.removeClass('hidden'); + this.$el.removeClass('d-none'); this.trigger('shown'); }, hide: function () { - this.$el.addClass('hidden'); + this.$el.addClass('d-none'); this.trigger('hidden'); }, @@ -290,6 +314,10 @@ odoo.define('attachment_preview', function (require) { }); FormRenderer.include({ + custom_events: _.extend({}, FormRenderer.prototype.custom_events, { + onAttachmentPreview: '_onAttachmentPreview', + }), + attachmentPreviewWidget: null, init: function () { @@ -310,8 +338,9 @@ odoo.define('attachment_preview', function (require) { showAttachmentPreviewWidget: function () { this.$el.addClass('attachment_preview'); + this.attachmentPreviewWidget.setAttachments( - this.getParent().sidebar.previewableAttachments + this.chatter.previewableAttachments ); this.attachmentPreviewWidget.show(); }, @@ -321,25 +350,12 @@ odoo.define('attachment_preview', function (require) { return this._super.apply(this, arguments); }, - }); - - FormController.include({ - custom_events: _.extend({}, FormController.prototype.custom_events, { - onAttachmentPreview: '_onAttachmentPreview', - setPreviewableAttachments: '_setPreviewableAttachments', - }), - _onAttachmentPreview: function (event) { - this.renderer.showAttachmentPreviewWidget(); - }, - - _setPreviewableAttachments: function (event) { - this.renderer.attachmentPreviewWidget.setAttachments( - event.data.attachments - ); + this.showAttachmentPreviewWidget(); }, }); + return { AttachmentPreviewMixin: AttachmentPreviewMixin, AttachmentPreviewWidget: AttachmentPreviewWidget, diff --git a/attachment_preview/static/src/less/attachment_preview.less b/attachment_preview/static/src/scss/attachment_preview.scss similarity index 72% rename from attachment_preview/static/src/less/attachment_preview.less rename to attachment_preview/static/src/scss/attachment_preview.scss index 17c42ac1..48318dee 100644 --- a/attachment_preview/static/src/less/attachment_preview.less +++ b/attachment_preview/static/src/scss/attachment_preview.scss @@ -1,11 +1,11 @@ -.o_cp_sidebar { - li .o_sidebar_preview_attachment { - position: absolute; - top: 5px; - right: 26px; - background-color: #FFF; +.o_attachments_list .o_attachment_wrap { + .o_attachment_preview { + cursor: pointer; + float: right; + padding-top: 1px; + padding-bottom: 1px; - &.o_sidebar_preview_attachment_new_tab { + &.o_attachment_preview_new_tab { right: 43px; } } @@ -35,7 +35,7 @@ > .attachment_preview_iframe { width: 100%; - height: calc(~"100% - 30px"); + height: calc(100% - 30px); float: left; } @@ -44,7 +44,7 @@ float: left; width: 100%; background-color: #FFF; - border-left: 1px solid @gray-lighter-dark; + border-left: 1px solid $gray-800; button { min-width: 25px; diff --git a/attachment_preview/static/src/xml/attachment_preview.xml b/attachment_preview/static/src/xml/attachment_preview.xml index fd2a9665..da3f10f5 100644 --- a/attachment_preview/static/src/xml/attachment_preview.xml +++ b/attachment_preview/static/src/xml/attachment_preview.xml @@ -1,33 +1,33 @@ - - - + + + - + t-att-data-id="attachment.id" + t-att-data-url="attachment.url" + t-attf-title="Open preview #{attachment.name} in a new tab"/> -