[MIG] document_url: Migration to 15.0

This commit is contained in:
matiasperalta1
2022-07-18 16:33:26 -03:00
committed by FernandoRomera
parent 0cb4d31789
commit 9b0b25a4c9
9 changed files with 122 additions and 96 deletions

View File

@@ -0,0 +1,49 @@
/** @odoo-module **/
import {AttachmentBox} from "@mail/components/attachment_box/attachment_box";
import {AttachmentCard} from "@mail/components/attachment_card/attachment_card";
import {patch} from "web.utils";
patch(AttachmentBox.prototype, "document_url/static/src/js/url.js", {
_onAddUrl(event) {
event.preventDefault();
event.stopPropagation();
this.env.bus.trigger("do-action", {
action: "document_url.action_ir_attachment_add_url",
options: {
additional_context: {
active_id: this.messaging.models["mail.chatter"].get(
this.props.chatterLocalId
).threadId,
active_ids: [
this.messaging.models["mail.chatter"].get(
this.props.chatterLocalId
).threadId,
],
active_model: this.messaging.models["mail.chatter"].get(
this.props.chatterLocalId
).threadModel,
},
on_close: this._onAddedUrl.bind(this),
},
});
},
_onAddedUrl() {
this.trigger("reload");
},
});
patch(AttachmentCard.prototype, "document_url/static/src/js/url.js", {
/**
* Return the url of the attachment. Temporary attachments, a.k.a. uploading
* attachments, do not have an url.
*
* @returns {String}
*/
get attachmentUrl() {
return this.env.session.url("/web/content", {
id: this.attachmentCard.attachment.id,
download: true,
});
},
});

View File

@@ -1,42 +0,0 @@
/* Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
* Copyright 2019 Tecnativa - Ernesto Tejeda
* Copyright 2020 Tecnativa - Manuel Calero
* Copyright 2021 Tecnativa - Víctor Martínez
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
odoo.define("document_url", function (require) {
"use strict";
const AttachmentBox = require("mail/static/src/components/attachment_box/attachment_box.js");
const Attachment = require("mail/static/src/components/attachment/attachment.js");
const {patch} = require("web.utils");
patch(AttachmentBox, "document_url", {
_onAddUrl() {
this.env.bus.trigger("do-action", {
action: "document_url.action_ir_attachment_add_url",
options: {
additional_context: {
active_id: this.thread.id,
active_ids: [this.thread.id],
active_model: this.thread.model,
},
on_close: this._onAddedUrl.bind(this),
},
});
},
_onAddedUrl() {
this.trigger("reload");
},
});
patch(Attachment, "document_url", {
_onClickImage(ev) {
if (!this.attachment.isViewable) {
this._onClickDownload(ev);
}
this._super.apply(this, arguments);
},
});
});

View File

@@ -2,43 +2,66 @@
<!-- Copyright 2018 Tecnativa - Ernesto Tejeda
Copyright 2021 Tecnativa - Víctor Martínez
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<templates xml:space="preserve">
<templates>
<t t-inherit="mail.AttachmentBox" t-inherit-mode="extension" owl="1">
<xpath expr="//button[hasclass('o_AttachmentBox_buttonAdd')]" position="after">
<button
type="button"
class="o_add_url_button btn btn-link"
t-on-click="_onAddUrl"
>
<xpath
expr="//button[hasclass('o_AttachmentBox_buttonAdd')]"
position="replace"
>
<div align="center">
<button
class="o_AttachmentBox_buttonAdd btn btn-link"
type="button"
t-on-click="_onClickAdd"
>
<i class="fa fa-plus-square" />
Add attachments
</button>
<button
type="button"
class="o_add_url_button btn btn-link"
t-on-click="_onAddUrl"
>
<i class="fa fa-plus-square" />
Add URL
</button>
</button>
</div>
</xpath>
</t>
<t t-inherit="mail.Attachment" t-inherit-mode="extension" owl="1">
<t t-inherit="mail.AttachmentCard" t-inherit-mode="extension" owl="1">
<xpath
expr="//t[@t-if='attachment']/t/div[1][hasclass('o_Attachment_details')]//div[hasclass('o_Attachment_filename')]/t"
expr="//div[hasclass('o_AttachmentCard_details')]/t/div"
position="replace"
>
<a t-att-href="attachmentUrl" target="new">
<t t-esc="attachment.displayName" />
<t t-esc="attachmentCard.attachment.displayName" />
</a>
</xpath>
<xpath
expr="//div[hasclass('o_Attachment_asideItemDownload')]"
expr="//div[hasclass('o_AttachmentCard_details')]/t[2]/div"
position="replace"
>
</xpath>
<xpath
expr="//div[hasclass('o_AttachmentCard_asideItemDownload')]"
position="attributes"
>
<attribute name="t-if">attachment.mimetype != 'application/link'</attribute>
<attribute
name="t-if"
>attachmentCard.attachment.mimetype != 'application/link'</attribute>
</xpath>
<xpath expr="//div[hasclass('o_Attachment_image')]" position="attributes">
<attribute name="t-if">attachment.mimetype != 'application/link'</attribute>
<xpath expr="//div[hasclass('o_AttachmentCard_image')]" position="attributes">
<attribute
name="t-if"
>attachmentCard.attachment.mimetype != 'application/link'</attribute>
</xpath>
<xpath expr="//div[hasclass('o_Attachment_image')]" position="before">
<xpath expr="//div[hasclass('o_AttachmentCard_image')]" position="before">
<a
class="o_Attachment_url_icon"
t-att-href="attachmentUrl"
target="new"
t-if="attachment.mimetype=='application/link'"
t-if="attachmentCard.attachment.mimetype=='application/link'"
>
<i class="fa fa-link fa-2x" />
</a>