diff --git a/muk_web_preview_attachment/__manifest__.py b/muk_web_preview_attachment/__manifest__.py index 2eff68b..1b9a536 100644 --- a/muk_web_preview_attachment/__manifest__.py +++ b/muk_web_preview_attachment/__manifest__.py @@ -25,8 +25,10 @@ "description": """ Adds a button to the Attachment Sidebar to preview the content directly in the browser. + The module also enables the possibility to + preview attachment in the Odoo Chat Widgets. """, - "version": "10.0.1.0.4", + "version": "10.0.1.0.5", "category": "Extra Tools", "license": "AGPL-3", "website": "http://www.mukit.at", diff --git a/muk_web_preview_attachment/static/description/screenshot.png b/muk_web_preview_attachment/static/description/screenshot.png index bf7e54b..d1d4678 100644 Binary files a/muk_web_preview_attachment/static/description/screenshot.png and b/muk_web_preview_attachment/static/description/screenshot.png differ diff --git a/muk_web_preview_attachment/static/src/js/attachment_preview.js b/muk_web_preview_attachment/static/src/js/attachment_preview.js index 0441d65..3955051 100644 --- a/muk_web_preview_attachment/static/src/js/attachment_preview.js +++ b/muk_web_preview_attachment/static/src/js/attachment_preview.js @@ -26,8 +26,7 @@ var Model = require("web.Model"); var KanbanView = require('web_kanban.KanbanView'); -var PreviewGenerator = require('muk_preview.PreviewGenerator'); -var PreviewDialog = require('muk_preview.PreviewDialog'); +var PreviewHelper = require('muk_preview_attachment.PreviewHelper'); var Attachment = new Model('ir.attachment', session.user_context); @@ -44,18 +43,7 @@ KanbanView.include({ preview: function(e) { e.preventDefault(); e.stopPropagation(); - var self = this; - var $target = $(e.currentTarget); - - Attachment.query(['name', 'url', 'type', 'mimetype', 'extension']) - .filter([['id', '=', $target.data('id')]]) - .first().then(function(attachment) { - if(!attachment.url && attachment.type === "binary") { - attachment.url = '/web/content/' + attachment.id + '?download=true'; - } - PreviewDialog.createPreviewDialog(self, attachment.url, attachment.mimetype, - attachment.extension, attachment.name); - }); + PreviewHelper.createAttachmentPreview($(e.currentTarget).data('id')); }, }); diff --git a/muk_web_preview_attachment/static/src/js/chatter_preview.js b/muk_web_preview_attachment/static/src/js/chatter_preview.js index a7ce671..cbc9b02 100644 --- a/muk_web_preview_attachment/static/src/js/chatter_preview.js +++ b/muk_web_preview_attachment/static/src/js/chatter_preview.js @@ -27,8 +27,7 @@ var Model = require("web.Model"); var ChatThread = require('mail.ChatThread'); var Chatter = require('mail.Chatter'); -var PreviewGenerator = require('muk_preview.PreviewGenerator'); -var PreviewDialog = require('muk_preview.PreviewDialog'); +var PreviewHelper = require('muk_preview_attachment.PreviewHelper'); var Attachment = new Model('ir.attachment', session.user_context); @@ -45,18 +44,8 @@ ChatThread.include({ preview: function(e) { e.preventDefault(); e.stopPropagation(); - var self = this; - var $target = $(e.currentTarget); - - Attachment.query(['name', 'url', 'type', 'mimetype', 'extension']) - .filter([['id', '=', $target.find('.o_attachment_id ').data('id')]]) - .first().then(function(attachment) { - if(!attachment.url && attachment.type === "binary") { - attachment.url = '/web/content/' + attachment.id + '?download=true'; - } - PreviewDialog.createPreviewDialog(self, attachment.url, attachment.mimetype, - attachment.extension, attachment.name); - }); + PreviewHelper.createAttachmentPreview($(e.currentTarget) + .find('.o_attachment_id ').data('id')); }, }); @@ -70,18 +59,8 @@ Chatter.include({ preview: function(e) { e.preventDefault(); e.stopPropagation(); - var self = this; - var $target = $(e.currentTarget); - - Attachment.query(['name', 'url', 'type', 'mimetype', 'extension']) - .filter([['id', '=', $target.find('.o_attachment_id ').data('id')]]) - .first().then(function(attachment) { - if(!attachment.url && attachment.type === "binary") { - attachment.url = '/web/content/' + attachment.id + '?download=true'; - } - PreviewDialog.createPreviewDialog(self, attachment.url, attachment.mimetype, - attachment.extension, attachment.name); - }); + PreviewHelper.createAttachmentPreview($(e.currentTarget) + .find('.o_attachment_id ').data('id')); }, }); diff --git a/muk_web_preview_attachment/static/src/js/preview_helper.js b/muk_web_preview_attachment/static/src/js/preview_helper.js new file mode 100644 index 0000000..aaa2928 --- /dev/null +++ b/muk_web_preview_attachment/static/src/js/preview_helper.js @@ -0,0 +1,55 @@ +/********************************************************************************** +* +* Copyright (C) 2017 MuK IT GmbH +* +* 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 . +* +**********************************************************************************/ + +odoo.define('muk_preview_attachment.PreviewHelper', function (require) { +"use strict"; + +var core = require('web.core'); +var session = require('web.session'); +var Model = require("web.Model"); + +var PreviewGenerator = require('muk_preview.PreviewGenerator'); +var PreviewDialog = require('muk_preview.PreviewDialog'); + +var Attachment = new Model('ir.attachment', session.user_context); + +var QWeb = core.qweb; +var _t = core._t; + +var PreviewHelper = core.Class.extend({ + createAttachmentPreview: function(id) { + Attachment.query(['name', 'url', 'type', 'mimetype', 'extension']) + .filter([['id', '=', id]]) + .first().then(function(attachment) { + if(!attachment.url && attachment.type === "binary") { + attachment.url = '/web/content/' + attachment.id + '?download=true'; + } + PreviewDialog.createPreviewDialog(self, attachment.url, attachment.mimetype, + attachment.extension, attachment.name); + }); + } +}); + +PreviewHelper.createAttachmentPreview = function(id) { + return new PreviewHelper().createAttachmentPreview(id); +}; + +return PreviewHelper; + +}); \ No newline at end of file diff --git a/muk_web_preview_attachment/static/src/js/sidebar_preview.js b/muk_web_preview_attachment/static/src/js/sidebar_preview.js index 5f13d0b..73297ba 100644 --- a/muk_web_preview_attachment/static/src/js/sidebar_preview.js +++ b/muk_web_preview_attachment/static/src/js/sidebar_preview.js @@ -25,8 +25,7 @@ var session = require('web.session'); var Sidebar = require('web.Sidebar'); var Model = require("web.Model"); -var PreviewGenerator = require('muk_preview.PreviewGenerator'); -var PreviewDialog = require('muk_preview.PreviewDialog'); +var PreviewHelper = require('muk_preview_attachment.PreviewHelper'); var Attachment = new Model('ir.attachment', session.user_context); @@ -41,18 +40,7 @@ Sidebar.include({ on_attachment_preview: function(e) { e.preventDefault(); e.stopPropagation(); - var self = this; - var $target = $(e.currentTarget); - - Attachment.query(['name', 'url', 'type', 'mimetype', 'extension']) - .filter([['id', '=', $target.data('id')]]) - .first().then(function(attachment) { - if(!attachment.url && attachment.type === "binary") { - attachment.url = '/web/content/' + attachment.id + '?download=true'; - } - PreviewDialog.createPreviewDialog(self, attachment.url, attachment.mimetype, - attachment.extension, attachment.name); - }); + PreviewHelper.createAttachmentPreview($(e.currentTarget).data('id')); }, }); diff --git a/muk_web_preview_attachment/template/assets.xml b/muk_web_preview_attachment/template/assets.xml index c046b83..8648d3d 100644 --- a/muk_web_preview_attachment/template/assets.xml +++ b/muk_web_preview_attachment/template/assets.xml @@ -24,6 +24,7 @@ +