[MIG] attachment_preview: Migration to 16.0

Overall implementation remains the same as in previous versions:
* patch into attachment list to prepare prev/next buttons in the viewer
* patch into attachment cards to observe clicks on new buttons this
  module adds
* fetch attachment extensions
* add an iframe into the DOM tree next to the main form one, display
  viewer inside it
* add preview button within binary fields

Main changes in this migration:
* update imports/exports to proper JS modules - in particular, this
  fixes "service already defined" console messages we also get in 15.0
* rework FormRenderer injector, previous (legacy) one was no longer used
* patch attachment list / cards with new methods in the mail module
* fix preview button inclusion within binary fields
* fix previous/next viewer buttons
This commit is contained in:
Houzéfa Abbasbhay 2023-09-25 17:54:10 +02:00
parent 50b2e3fc74
commit 1dd376d35a
No known key found for this signature in database
GPG Key ID: B30E9425D9198EC1
10 changed files with 311 additions and 616 deletions

View File

@ -3,7 +3,7 @@
{ {
"name": "Preview attachments", "name": "Preview attachments",
"version": "15.0.1.0.0", "version": "16.0.1.0.0",
"author": "Therp BV," "Onestein," "Odoo Community Association (OCA)", "author": "Therp BV," "Onestein," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/knowledge", "website": "https://github.com/OCA/knowledge",
"license": "AGPL-3", "license": "AGPL-3",
@ -15,15 +15,15 @@
"assets": { "assets": {
"web._assets_primary_variables": [], "web._assets_primary_variables": [],
"web.assets_backend": [ "web.assets_backend": [
"attachment_preview/static/src/js/models/attachment_card/attachment_card.esm.js",
"attachment_preview/static/src/js/attachmentPreviewWidget.esm.js", "attachment_preview/static/src/js/attachmentPreviewWidget.esm.js",
"attachment_preview/static/src/js/models/attachment_card/attachment_card.esm.js",
"attachment_preview/static/src/js/components/chatter/chatter.esm.js", "attachment_preview/static/src/js/components/chatter/chatter.esm.js",
"attachment_preview/static/src/scss/attachment_preview.scss", "attachment_preview/static/src/scss/attachment_preview.scss",
"attachment_preview/static/src/xml/attachment_preview.xml",
], ],
"web.assets_frontend": [], "web.assets_frontend": [],
"web.assets_tests": [], "web.assets_tests": [],
"web.qunit_suite_tests": [], "web.qunit_suite_tests": [],
"web.assets_qweb": ["attachment_preview/static/src/xml/attachment_preview.xml"],
}, },
"installable": True, "installable": True,
} }

View File

@ -1,2 +1,5 @@
* Holger Brunn <mail@hunki-enterprises.com> * Holger Brunn <mail@hunki-enterprises.com>
* Dennis Sluijk <d.sluijk@onestein.nl> * Dennis Sluijk <d.sluijk@onestein.nl>
* `XCG Consulting <https://xcg-consulting.fr>`_:
* Houzéfa Abbasbhay

View File

@ -0,0 +1,8 @@
* Remove `FormRenderer` patch, convert `AttachmentPreviewWidget` into a component instead.
* Remove `BinaryField` patch, convert preview button into a component instead.
* Don't use `bus.trigger("open_attachment_preview", ...)` to open viewer from an attachment; there
must be a smoother way.
* Binary fields only have an external preview button. Also add inline preview; stub code is already
there.
* Add tests to ensure preview & open buttons are rendered in attachment cards.
* Add JS tests to ensure preview & open buttons work as expected (display viewer / open url).

View File

@ -1,10 +1,7 @@
/** @odoo-module */ /** @odoo-module */
import Widget from "web.Widget"; import Widget from "web.Widget";
var active_attachment_index = 0; export const AttachmentPreviewWidget = Widget.extend({
var is_first_click = true;
var AttachmentPreviewWidget = Widget.extend({
template: "attachment_preview.AttachmentPreviewWidget", template: "attachment_preview.AttachmentPreviewWidget",
activeIndex: 0, activeIndex: 0,
@ -16,7 +13,6 @@ var AttachmentPreviewWidget = Widget.extend({
}, },
start: function () { start: function () {
// First_click = true;
var res = this._super.apply(this, arguments); var res = this._super.apply(this, arguments);
this.$overlay = $(".attachment_preview_overlay"); this.$overlay = $(".attachment_preview_overlay");
this.$iframe = $(".attachment_preview_iframe"); this.$iframe = $(".attachment_preview_iframe");
@ -37,17 +33,11 @@ var AttachmentPreviewWidget = Widget.extend({
}, },
_onPopoutClick: function () { _onPopoutClick: function () {
if (!this.attachments[this.activeIndex]) { if (!this.attachments[this.activeIndex]) return;
return;
}
window.open(this.attachments[this.activeIndex].previewUrl); window.open(this.attachments[this.activeIndex].previewUrl);
}, },
next: function () { next: function () {
if (is_first_click) {
is_first_click = !is_first_click;
}
var index = this.activeIndex + 1; var index = this.activeIndex + 1;
if (index >= this.attachments.length) { if (index >= this.attachments.length) {
index = 0; index = 0;
@ -58,9 +48,6 @@ var AttachmentPreviewWidget = Widget.extend({
}, },
previous: function () { previous: function () {
if (is_first_click) {
is_first_click = !is_first_click;
}
var index = this.activeIndex - 1; var index = this.activeIndex - 1;
if (index < 0) { if (index < 0) {
index = this.attachments.length - 1; index = this.attachments.length - 1;
@ -76,7 +63,6 @@ var AttachmentPreviewWidget = Widget.extend({
}, },
hide: function () { hide: function () {
is_first_click = true;
this.$el.addClass("d-none"); this.$el.addClass("d-none");
this.trigger("hidden"); this.trigger("hidden");
}, },
@ -98,37 +84,19 @@ var AttachmentPreviewWidget = Widget.extend({
this.$iframe.attr("src", "about:blank"); this.$iframe.attr("src", "about:blank");
return; return;
} }
var att = this.attachments[this.activeIndex];
if (is_first_click) {
for (let i = 0; i < this.attachments.length; i++) {
if (
parseInt(this.attachments[i].id, 10) === this.active_attachment_id
) {
active_attachment_index = i;
is_first_click = false;
}
}
} else {
active_attachment_index = this.activeIndex;
}
var att = this.attachments[active_attachment_index];
this.$iframe.attr("src", att.previewUrl); this.$iframe.attr("src", att.previewUrl);
}, },
setAttachments: function (attachments, active_attachment_id, first_click) { setAttachments: function (attachments, active_attachment_id) {
is_first_click = first_click; this.attachments = attachments;
if (!attachments) return;
if (active_attachment_id) { for (let i = 0; i < attachments.length; ++i) {
this.active_attachment_id = active_attachment_id; if (parseInt(attachments[i].id, 10) === active_attachment_id) {
} this.activeIndex = i;
if (attachments) { }
this.attachments = attachments;
this.activeIndex = 0;
this.updatePaginator();
this.loadPreview();
} }
this.updatePaginator();
this.loadPreview();
}, },
}); });
export default AttachmentPreviewWidget;

View File

@ -1,277 +1,65 @@
/** @odoo-module **/ /** @odoo-module **/
import AttachmentPreviewWidget from "../../attachmentPreviewWidget"; import {
import {Chatter} from "@mail/components/chatter/chatter"; canPreview,
import {patch} from "web.utils"; showPreview,
} from "../../models/attachment_card/attachment_card.esm";
import {BinaryField} from "@web/views/fields/binary/binary_field";
import {_t} from "@web/core/l10n/translation";
import {onMounted} from "@odoo/owl";
import {patch} from "@web/core/utils/patch";
import {query} from "web.rpc";
import {sprintf} from "@web/core/utils/strings";
odoo.define("attachment_preview.chatter", function (require) { patch(BinaryField.prototype, "attachment_preview.BinaryField", {
const components = {Chatter}; setup() {
var rpc = require("web.rpc"); var res = this._super(...arguments);
var basic_fields = require("web.basic_fields"); onMounted(this._preview_onMounted);
var core = require("web.core"); return res;
var _t = core._t; },
function getUrl( _preview_onMounted() {
attachment_id, if (this.props.record.data.id) {
attachment_url,
attachment_extension,
attachment_title
) {
var url = "";
if (attachment_url) {
if (attachment_url.slice(0, 21) === "/web/static/lib/pdfjs") {
url = (window.location.origin || "") + attachment_url;
} else {
url =
(window.location.origin || "") +
"/attachment_preview/static/lib/ViewerJS/index.html" +
"?type=" +
encodeURIComponent(attachment_extension) +
"&zoom=automatic" +
"&title=" +
encodeURIComponent(attachment_title) +
"#" +
attachment_url.replace(window.location.origin, "");
}
} else {
url =
(window.location.origin || "") +
"/attachment_preview/static/lib/ViewerJS/index.html" +
"?type=" +
encodeURIComponent(attachment_extension) +
"&title=" +
encodeURIComponent(attachment_title) +
"&zoom=automatic" +
"#" +
"/web/content/" +
attachment_id +
"?model%3Dir.attachment";
}
return url;
}
function canPreview(extension) {
return (
$.inArray(extension, [
"odt",
"odp",
"ods",
"fodt",
"pdf",
"ott",
"fodp",
"otp",
"fods",
"ots",
]) > -1
);
}
patch(
components.Chatter.prototype,
"attachment_preview/static/src/js/components/chatter/chatter.js",
{
/**
* @override
*/
constructor(...args) {
this._super(...args);
this._showPreview = this._showPreview.bind(this);
this.canPreview = this.canPreview.bind(this);
},
/**
* @override
*/
_update() {
// Var res = this._super.apply(this, arguments);
var self = this;
self._getPreviewableAttachments().then(function (atts) {
self.previewableAttachments = atts;
self._updatePreviewButtons(self.previewableAttachments);
if (!self.attachmentPreviewWidget) {
self.attachmentPreviewWidget = new AttachmentPreviewWidget(
self
);
self.attachmentPreviewWidget.setAttachments(atts);
}
self.previewableAttachments = atts;
// ChatterpreviewableAttachments = atts;
self.attachmentPreviewWidget.setAttachments(atts);
});
},
_getPreviewableAttachments: function () {
var self = this;
var deferred = $.Deferred();
const chatter = self.messaging.models["mail.chatter"].get(
self.props.chatterLocalId
);
const thread = chatter ? chatter.thread : undefined;
var attachments = {};
if (thread) {
attachments = thread.allAttachments;
}
attachments = _.object(
attachments.map((attachment) => {
return attachment.id;
}),
attachments.map((attachment) => {
if (attachment.defaultSource) {
return {
url: attachment.defaultSource,
extension: attachment.extension,
title: attachment.name,
};
}
return {
url: "/web/content?id=" + attachment.id + "&download=true",
extension: attachment.extension,
title: attachment.name,
};
})
);
rpc.query({
model: "ir.attachment",
method: "get_attachment_extension",
args: [
_.map(_.keys(attachments), function (id) {
return parseInt(id, 10);
}),
],
}).then(
function (extensions) {
var reviewableAttachments = _.map(
_.keys(
_.pick(extensions, function (extension) {
return canPreview(extension);
})
),
function (id) {
return {
id: id,
url: attachments[id].url,
extension: extensions[id],
title: attachments[id].title,
previewUrl: getUrl(
id,
attachments[id].url,
extensions[id],
attachments[id].title
),
};
}
);
deferred.resolve(reviewableAttachments);
},
function () {
deferred.reject();
}
);
return deferred.promise();
},
_updatePreviewButtons: function (previewableAttachments) {
$(this)
.find(".o_attachment_preview")
.each(function () {
var $this = $(this);
var att = _.findWhere(previewableAttachments, {
id: $this.attr("data-id"),
});
if (att) {
$this.attr("data-extension", att.extension);
} else {
$this.remove();
}
});
},
}
);
basic_fields.FieldBinaryFile.include(components.Chatter);
basic_fields.FieldBinaryFile.include({
showPreview(
attachment_id,
attachment_url,
attachment_extension,
attachment_title,
split_screen
) {
if (!canPreview(attachment_extension)) {
return;
}
var url = getUrl(
attachment_id,
attachment_url,
attachment_extension,
attachment_title
);
if (split_screen) {
this.trigger("onAttachmentPreview", {url: url});
} else {
window.open(url);
}
},
_renderReadonly: function () {
var self = this; var self = this;
this._super.apply(this, arguments); query({
if (this.recordData.id) {
this._getBinaryExtension().then(function (extension) {
if (canPreview(extension)) {
// Self._renderPreviewButton(extension, recordData);
self._renderPreviewButton(extension);
}
});
}
},
_renderPreviewButton: function (extension) {
this.$previewBtn = $("<a/>");
this.$previewBtn.addClass("fa fa-external-link mr-2");
this.$previewBtn.attr("href");
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.$previewBtn.on("click", this._onPreview.bind(this));
},
_getBinaryExtension: function () {
return rpc.query({
model: "ir.attachment", model: "ir.attachment",
method: "get_binary_extension", method: "get_attachment_extension",
args: [this.model, this.recordData.id, this.name, this.attrs.filename], args: [this.props.record.data.id],
}).then(function (extension) {
if (canPreview(extension)) {
self._renderPreviewButton(extension);
}
}); });
}, }
},
_onPreview: function (event) { _renderPreviewButton(extension) {
this.showPreview( // Add a button same as standard fa-download one.
null, var dl_button = $(this.__owl__.bdom.parentEl).find("button.fa-download");
_.str.sprintf( if (dl_button.length !== 1) return;
"/web/content?model=%s&field=%s&id=%d", var preview_button = $("<button/>");
this.model, preview_button.addClass("btn btn-secondary fa fa-external-link");
this.name, preview_button.attr("data-tooltip", "Preview");
this.recordData.id preview_button.attr("aria-label", "Preview");
), preview_button.attr("title");
$(event.currentTarget).attr("data-extension"), preview_button.attr("data-extension", extension);
_.str.sprintf(_t("Preview %s"), this.field.string), dl_button.after(preview_button);
false preview_button.on("click", this._onPreview.bind(this));
); },
event.stopPropagation();
}, _onPreview(event) {
}); showPreview(
null,
sprintf(
"/web/content?model=%s&field=%s&id=%s",
this.props.record.resModel,
this.props.name,
this.props.record.data.id
),
$(event.currentTarget).attr("data-extension"),
sprintf(_t("Preview %s"), this.state.fileName),
false,
null
);
event.stopPropagation();
},
}); });

View File

@ -1,265 +1,218 @@
/** @odoo-module **/ /** @odoo-module **/
import AttachmentPreviewWidget from "../../attachmentPreviewWidget.esm"; import {onMounted, onWillUnmount} from "@odoo/owl";
import FormRenderer from "web.FormRenderer"; import {AttachmentPreviewWidget} from "../../attachmentPreviewWidget.esm";
import {registerInstancePatchModel} from "@mail/model/model_core"; import {FormRenderer} from "@web/views/form/form_renderer";
import {bus} from "web.core";
import {patch} from "@web/core/utils/patch";
import {query} from "web.rpc";
import {registerPatch} from "@mail/model/model_core";
odoo.define("attachment_preview.attachment_card", function (require) { patch(FormRenderer.prototype, "attachment_preview.FormRenderer", {
var rpc = require("web.rpc"); attachmentPreviewWidget: null,
var chatterpreviewableAttachments = []; setup() {
var active_attachment_id = 0; var res = this._super(...arguments);
var first_click = true; this.attachmentPreviewWidget = new AttachmentPreviewWidget(this);
this.attachmentPreviewWidget.on(
FormRenderer.include({ "hidden",
custom_events: _.extend({}, FormRenderer.prototype.custom_events, { this,
onAttachmentPreview: "_onAttachmentPreview", this._attachmentPreviewWidgetHidden
}),
attachmentPreviewWidget: null,
init: function () {
var res = this._super(...arguments);
this.attachmentPreviewWidget = new AttachmentPreviewWidget(this);
this.attachmentPreviewWidget.on(
"hidden",
this,
this._attachmentPreviewWidgetHidden
);
return res;
},
start: function () {
var self = this;
return this._super.apply(this, arguments).then(function () {
self.attachmentPreviewWidget.insertAfter(self.$el);
});
},
_attachmentPreviewWidgetHidden: function () {
this.$el.removeClass("attachment_preview");
},
showAttachmentPreviewWidget: function (first_c) {
this.$el.addClass("attachment_preview");
this.attachmentPreviewWidget.setAttachments(
chatterpreviewableAttachments,
active_attachment_id,
first_c
);
this.attachmentPreviewWidget.show();
},
on_detach_callback: function () {
this.attachmentPreviewWidget.hide();
return this._super.apply(this, arguments);
},
_onAttachmentPreview: function () {
first_click = true;
this.showAttachmentPreviewWidget(first_click);
},
});
function canPreview(extension) {
return (
$.inArray(extension, [
"odt",
"odp",
"ods",
"fodt",
"pdf",
"ott",
"fodp",
"otp",
"fods",
"ots",
]) > -1
); );
} onMounted(() => {
this.attachmentPreviewWidget.insertAfter($(".o_form_view"));
bus.on("open_attachment_preview", this, this._onAttachmentPreview);
});
onWillUnmount(() => {
bus.off("open_attachment_preview", this, this._onAttachmentPreview);
this.attachmentPreviewWidget.hide();
this.attachmentPreviewWidget.destroy();
});
return res;
},
function getUrl( _attachmentPreviewWidgetHidden() {
attachment_id, $(".o_form_view").removeClass("attachment_preview");
attachment_url, },
attachment_extension,
attachment_title _onAttachmentPreview(attachment_id, attachment_info_list) {
) { $(".o_form_view").addClass("attachment_preview");
var url = ""; this.attachmentPreviewWidget.setAttachments(
if (attachment_url) { attachment_info_list,
if (attachment_url.slice(0, 21) === "/web/static/lib/pdfjs") { attachment_id
url = (window.location.origin || "") + attachment_url; );
} else { this.attachmentPreviewWidget.show();
url = },
(window.location.origin || "") + });
"/attachment_preview/static/lib/ViewerJS/index.html" + // FormRenderer patch
"?type=" +
encodeURIComponent(attachment_extension) + export function canPreview(extension) {
"&title=" + return (
encodeURIComponent(attachment_title) + $.inArray(extension, [
"&zoom=automatic" + "odt",
"#" + "odp",
attachment_url.replace(window.location.origin, ""); "ods",
} "fodt",
return url; "pdf",
"ott",
"fodp",
"otp",
"fods",
"ots",
]) > -1
);
}
function getUrl(attachment_id, attachment_url, attachment_extension, attachment_title) {
var url = "";
if (attachment_url) {
if (attachment_url.slice(0, 21) === "/web/static/lib/pdfjs") {
url = (window.location.origin || "") + attachment_url;
} else {
url =
(window.location.origin || "") +
"/attachment_preview/static/lib/ViewerJS/index.html" +
"?type=" +
encodeURIComponent(attachment_extension) +
"&title=" +
encodeURIComponent(attachment_title) +
"&zoom=automatic" +
"#" +
attachment_url.replace(window.location.origin, "");
} }
url =
(window.location.origin || "") +
"/attachment_preview/static/lib/ViewerJS/index.html" +
"?type=" +
encodeURIComponent(attachment_extension) +
"&title=" +
encodeURIComponent(attachment_title) +
"&zoom=automatic" +
"#" +
"/web/content/" +
attachment_id +
"?model%3Dir.attachment";
return url; return url;
} }
url =
(window.location.origin || "") +
"/attachment_preview/static/lib/ViewerJS/index.html" +
"?type=" +
encodeURIComponent(attachment_extension) +
"&title=" +
encodeURIComponent(attachment_title) +
"&zoom=automatic" +
"#" +
"/web/content/" +
attachment_id +
"?model%3Dir.attachment";
registerInstancePatchModel( return url;
"mail.attachment_card", }
"attachment_preview/static/src/js/models/attachment_card/attachment_card.js",
{
/**
* @override
*/
_created() {
this._super();
this._onPreviewAttachment = this._onPreviewAttachment.bind(this);
var attachments = _.object( export function showPreview(
this.attachmentList.attachments.map((attachment) => { attachment_id,
console.log("attachment", attachment); attachment_url,
return attachment.id; attachment_extension,
}), attachment_title,
this.attachmentList.attachments.map((attachment) => { split_screen,
if ( attachment_info_list
attachment.defaultSource && ) {
attachment.defaultSource.length > 38 if (split_screen && attachment_info_list) {
) { bus.trigger("open_attachment_preview", attachment_id, attachment_info_list);
return { } else {
url: attachment.defaultSource, window.open(
extension: attachment.extension, getUrl(
title: attachment.name,
};
}
return {
url: "/web/content?id=" + attachment.id + "&download=true",
extension: attachment.extension,
title: attachment.name,
};
})
);
rpc.query({
model: "ir.attachment",
method: "get_attachment_extension",
args: [
_.map(_.keys(attachments), function (id) {
return parseInt(id, 10);
}),
],
}).then(function (extensions) {
var reviewableAttachments = _.map(
_.keys(
_.pick(extensions, function (extension) {
return canPreview(extension);
})
),
function (id) {
return {
id: id,
url: attachments[id].url,
extension: extensions[id],
title: attachments[id].title,
previewUrl: getUrl(
id,
attachments[id].url,
extensions[id],
attachments[id].title
),
};
}
);
chatterpreviewableAttachments = reviewableAttachments;
});
},
/**
* @private
* @param {attachment_id} attachment_id of the attachment
* @param {attachment_url} attachment_url of the attachment
* @param {attachment_extension} attachment_extension of the attachment
* @param {attachment_title} attachment_title of the attachment
* @param {split_screen} split_screen of the attachment
*/
_showPreview(
attachment_id, attachment_id,
attachment_url, attachment_url,
attachment_extension, attachment_extension,
attachment_title, attachment_title
split_screen )
) { );
// Let active_attURL = ""; }
// this.attachmentList.attachments.forEach((att) => { }
// if (
// parseInt(att.localId.slice(20).slice(0, -1)) === attachment_id registerPatch({
// ) { name: "AttachmentList",
// if (att.__values.url === undefined) { lifecycleHooks: {
// att.__values.url = attachment_url.slice( _created() {
// window.location.origin.length var attachments = _.object(
// ); this.attachments.map((attachment) => {
// active_attURL = att.__values.url; return attachment.id;
// } }),
// } this.attachments.map((attachment) => {
// }); if (
var url = getUrl( attachment.defaultSource &&
attachment_id, attachment.defaultSource.length > 38
attachment_url, ) {
attachment_extension, return {
attachment_title url: attachment.defaultSource,
extension: attachment.extension,
title: attachment.name,
};
}
return {
url: "/web/content?id=" + attachment.id + "&download=true",
extension: attachment.extension,
title: attachment.name,
};
})
);
var self = this;
query({
model: "ir.attachment",
method: "get_attachment_extension",
args: [
_.map(_.keys(attachments), function (id) {
return parseInt(id, 10);
}),
],
}).then(function (extensions) {
self.previewableAttachments = _.map(
_.keys(
_.pick(extensions, function (extension) {
return canPreview(extension);
})
),
function (id) {
return {
id: id,
url: attachments[id].url,
extension: extensions[id],
title: attachments[id].title,
previewUrl: getUrl(
id,
attachments[id].url,
extensions[id],
attachments[id].title
),
};
}
); );
});
if (split_screen) { },
this.component.trigger("onAttachmentPreview", { },
url: url,
active_attachment_id: active_attachment_id,
});
} else {
window.open(url);
}
},
/**
* @private
* @param {event} event
*/
_onPreviewAttachment(event) {
event.preventDefault();
var self = this,
$target = $(event.currentTarget),
split_screen = $target.attr("data-target") !== "new",
attachment_id = this.attachment.id,
attachment_title = this.attachment.filename,
attachment_url = this.attachment.defaultSource;
active_attachment_id = attachment_id;
rpc.query({
model: "ir.attachment",
method: "get_attachment_extension",
args: [attachment_id],
}).then(function (extension) {
self._showPreview(
attachment_id,
attachment_url,
extension,
attachment_title,
split_screen
);
});
},
}
);
}); });
// AttachmentList patch
registerPatch({
name: "AttachmentCard",
recordMethods: {
/**
* @private
* @param {event} event
*/
_onPreviewAttachment(event) {
event.preventDefault();
var self = this,
$target = $(event.currentTarget),
split_screen = $target.attr("data-target") !== "new",
attachment_id = this.attachment.id;
query({
model: "ir.attachment",
method: "get_attachment_extension",
args: [attachment_id],
}).then(function (extension) {
showPreview(
attachment_id,
self.attachment.defaultSource,
extension,
self.attachment.filename,
split_screen,
self.attachmentList.previewableAttachments
);
});
},
},
});
// AttachmentCard patch

View File

@ -1,38 +1,16 @@
.o_attachments_list .o_attachment_wrap { /* This style applies to the form as a whole when we display preview widget next to it. */
.o_attachment_preview {
cursor: pointer;
float: right;
padding-top: 1px;
padding-bottom: 1px;
&.o_attachment_preview_new_tab {
right: 43px;
}
}
.open .dropdown-menu > li > a {
padding-right: 60px;
}
}
.o_form_uri .fa-search {
padding-left: 5px;
padding-right: 5px;
}
/* Preview widget */
.o_form_view.attachment_preview { .o_form_view.attachment_preview {
width: 60%; width: 60%;
float: left; float: left;
} }
/* Styles below apply to the preview widget itself. */
.o_form_view + .attachment_preview_widget { .o_form_view + .attachment_preview_widget {
width: 40%; width: 40%;
height: 100%; height: 100%;
float: right; float: right;
position: relative; position: relative;
z-index: 999; z-index: 100; /* Lower than 200 in web_responsive */
> .attachment_preview_iframe { > .attachment_preview_iframe {
width: 100%; width: 100%;
@ -55,10 +33,3 @@
} }
} }
} }
.o_group {
.mr-2,
.mx-2 {
margin-left: 0.5rem !important;
}
}

View File

@ -8,38 +8,35 @@
> >
<xpath expr="//div[hasclass('o_AttachmentCard_aside')]" position="before"> <xpath expr="//div[hasclass('o_AttachmentCard_aside')]" position="before">
<div <div
class="o_AttachmentCard_aside position-relative overflow-hidden" t-if="attachmentCard.attachment.downloadUrl"
t-att-class="{ 'o-has-multiple-action d-flex flex-column': !attachmentCard.attachmentList.composerView and attachmentCard.attachment.isEditable }" class="o_AttachmentCard_aside position-relative rounded-end overflow-hidden"
t-att-class="{ 'o-hasMultipleActions d-flex flex-column': attachmentCard.hasMultipleActions }"
> >
<div <button
t-if="attachmentCard.attachment.downloadUrl" class="o_AttachmentCard_asideItem btn d-flex justify-content-center align-items-center w-100 h-100 rounded-0 bg-300"
class="o_AttachmentCard_asideItem d-flex justify-content-center align-items-center ml4"
t-att-data-id="attachmentCard.attachment.id" t-att-data-id="attachmentCard.attachment.id"
t-att-data-url="attachmentCard.attachment.defaultSource" t-att-data-url="attachmentCard.attachment.defaultSource"
t-on-click="attachmentCard._onPreviewAttachment" t-on-click="attachmentCard._onPreviewAttachment"
t-att-data-original-title="attachmentCard.attachment.name" t-att-data-original-title="attachmentCard.attachment.name"
t-attf-title="Preview {{attachmentCard.attachment.displayName}} in side panel" t-attf-title="Preview {{attachmentCard.attachment.displayName}} in side panel"
tabindex="0"
role="menuitem"
aria-label="Preview"
> >
<i class="fa fa-search" /> <i class="fa fa-search" role="img" aria-label="Preview" />
</div> </button>
<div <button
t-if="attachmentCard.attachment.downloadUrl" class="o_AttachmentCard_asideItem btn d-flex justify-content-center align-items-center w-100 h-100 rounded-0 bg-300"
class="o_AttachmentCard_asideItem d-flex justify-content-center align-items-center ml4 o_attachment_preview_new_tab"
data-target="new" data-target="new"
t-att-data-id="attachmentCard.attachment.id" t-att-data-id="attachmentCard.attachment.id"
t-att-data-url="attachmentCard.attachment.defaultSource" t-att-data-url="attachmentCard.attachment.defaultSource"
t-on-click="attachmentCard._onPreviewAttachment" t-on-click="attachmentCard._onPreviewAttachment"
t-att-data-original-title="attachmentCard.attachment.name" t-att-data-original-title="attachmentCard.attachment.name"
t-attf-title="Open preview {{attachmentCard.attachment.name}} in a new tab" t-attf-title="Open preview {{attachmentCard.attachment.name}} in a new tab"
tabindex="0"
role="menuitem"
aria-label="Open in new page"
> >
<i class="fa fa-external-link" /> <i
</div> class="fa fa-external-link"
role="img"
aria-label="Open in new page"
/>
</button>
</div> </div>
</xpath> </xpath>
</t> </t>

View File

@ -0,0 +1 @@
../../../../attachment_preview

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)