Skip to content

Commit

Permalink
[MOV] attachment_preview: Reorganize JS modules
Browse files Browse the repository at this point in the history
  • Loading branch information
houzefa-abba committed Sep 29, 2023
1 parent 38faa14 commit 838485f
Show file tree
Hide file tree
Showing 7 changed files with 233 additions and 223 deletions.
7 changes: 5 additions & 2 deletions attachment_preview/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
"web._assets_primary_variables": [],
"web.assets_backend": [
"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/utils.esm.js",
"attachment_preview/static/src/js/mail_models/attachment_card.esm.js",
"attachment_preview/static/src/js/mail_models/attachment_list.esm.js",
"attachment_preview/static/src/js/web_views/binary_field.esm.js",
"attachment_preview/static/src/js/web_views/form_renderer.esm.js",
"attachment_preview/static/src/scss/attachment_preview.scss",
"attachment_preview/static/src/xml/attachment_preview.xml",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/** @odoo-module **/
import {query} from "web.rpc";
import {registerPatch} from "@mail/model/model_core";
import {showPreview} from "../utils.esm";

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
);
});
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/** @odoo-module **/
import {canPreview, getUrl} from "../utils.esm";
import {query} from "web.rpc";
import {registerPatch} from "@mail/model/model_core";

registerPatch({
name: "AttachmentList",
lifecycleHooks: {
_created() {
var attachments = _.object(
this.attachments.map((attachment) => {
return attachment.id;
}),
this.attachments.map((attachment) => {
if (
attachment.defaultSource &&
attachment.defaultSource.length > 38
) {
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,
};
})
);

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
),
};
}
);
});
},
},
});

This file was deleted.

Loading

0 comments on commit 838485f

Please sign in to comment.