mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-14 01:41:26 -06:00
[MIG] document_url: Migration to 17.0
This commit is contained in:
parent
7c1a3cff02
commit
2ee541112c
@ -2,7 +2,7 @@
|
|||||||
# Copyright 2020 Tecnativa - Manuel Calero
|
# Copyright 2020 Tecnativa - Manuel Calero
|
||||||
{
|
{
|
||||||
"name": "URL attachment",
|
"name": "URL attachment",
|
||||||
"version": "16.0.1.0.4",
|
"version": "17.0.1.0.0",
|
||||||
"category": "Tools",
|
"category": "Tools",
|
||||||
"author": "Tecnativa, Odoo Community Association (OCA)",
|
"author": "Tecnativa, Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/knowledge",
|
"website": "https://github.com/OCA/knowledge",
|
||||||
|
@ -1,47 +1,51 @@
|
|||||||
/** @odoo-module **/
|
/** @odoo-module **/
|
||||||
|
|
||||||
import {registerPatch} from "@mail/model/model_core";
|
import {Chatter} from "@mail/core/web/chatter";
|
||||||
import {AttachmentCard} from "@mail/components/attachment_card/attachment_card";
|
import {patch} from "@web/core/utils/patch";
|
||||||
import {patch} from "web.utils";
|
|
||||||
import {url} from "@web/core/utils/urls";
|
import {url} from "@web/core/utils/urls";
|
||||||
|
import {AttachmentList} from "@mail/core/common/attachment_list";
|
||||||
|
|
||||||
registerPatch({
|
patch(Chatter.prototype, {
|
||||||
name: "AttachmentBoxView",
|
|
||||||
recordMethods: {
|
|
||||||
_onAddUrl(event) {
|
_onAddUrl(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
this.env.services.action.doAction(
|
this.action.doAction("document_url.action_ir_attachment_add_url", {
|
||||||
"document_url.action_ir_attachment_add_url",
|
|
||||||
{
|
|
||||||
additionalContext: {
|
additionalContext: {
|
||||||
active_id: this.chatter.thread.id,
|
active_id: this.state.thread.id,
|
||||||
active_ids: [this.chatter.thread.id],
|
active_ids: [this.state.thread.id],
|
||||||
active_model: this.chatter.thread.model,
|
active_model: this.state.thread.model,
|
||||||
},
|
},
|
||||||
onClose: this._onAddedUrl.bind(this),
|
onClose: async () => {
|
||||||
|
await this.updateThreadAttachments();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async updateThreadAttachments() {
|
||||||
|
const attachments = await this.orm.call("ir.attachment", "search_read", [
|
||||||
|
[
|
||||||
|
["res_model", "=", this.state.thread.model],
|
||||||
|
["res_id", "=", this.state.thread.id],
|
||||||
|
],
|
||||||
|
["id", "name", "mimetype", "url"],
|
||||||
|
]);
|
||||||
|
this.state.thread.attachments = attachments.map((att) => ({
|
||||||
|
id: att.id,
|
||||||
|
name: att.name,
|
||||||
|
mimetype: att.mimetype,
|
||||||
|
url: att.url,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
onClickAddAttachments(ev) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
this.state.isAttachmentBoxOpened = !this.state.isAttachmentBoxOpened;
|
||||||
|
if (this.state.isAttachmentBoxOpened) {
|
||||||
|
this.rootRef.el.scrollTop = 0;
|
||||||
|
this.state.thread.scrollTop = 0;
|
||||||
}
|
}
|
||||||
);
|
|
||||||
},
|
|
||||||
_onAddedUrl() {
|
|
||||||
this.chatter.refresh();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
registerPatch({
|
patch(AttachmentList.prototype, {
|
||||||
name: "Chatter",
|
|
||||||
recordMethods: {
|
|
||||||
/**
|
|
||||||
* Handles click on the attach button.
|
|
||||||
*/
|
|
||||||
async onClickButtonAddAttachments() {
|
|
||||||
await this.onClickButtonToggleAttachments();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
patch(AttachmentCard.prototype, "document_url/static/src/js/url.js", {
|
|
||||||
/**
|
/**
|
||||||
* Return the url of the attachment. Temporary attachments, a.k.a. uploading
|
* Return the url of the attachment. Temporary attachments, a.k.a. uploading
|
||||||
* attachments, do not have an url.
|
* attachments, do not have an url.
|
||||||
@ -50,7 +54,7 @@ patch(AttachmentCard.prototype, "document_url/static/src/js/url.js", {
|
|||||||
*/
|
*/
|
||||||
get attachmentUrl() {
|
get attachmentUrl() {
|
||||||
return url("/web/content", {
|
return url("/web/content", {
|
||||||
id: this.attachmentCard.attachment.id,
|
id: this.attachment.id,
|
||||||
download: true,
|
download: true,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -4,67 +4,67 @@
|
|||||||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||||
<templates>
|
<templates>
|
||||||
|
|
||||||
<t t-inherit="mail.AttachmentBox" t-inherit-mode="extension" owl="1">
|
<t t-inherit="mail.Chatter" t-inherit-mode="extension">
|
||||||
<xpath
|
<xpath expr="//AttachmentList//..//FileUploader/t" position="replace">
|
||||||
expr="//button[hasclass('o_AttachmentBox_buttonAdd')]"
|
<t t-set-slot="toggler">
|
||||||
position="replace"
|
<div class="d-flex mx-auto">
|
||||||
>
|
|
||||||
<div align="center">
|
|
||||||
<button
|
<button
|
||||||
class="o_AttachmentBox_buttonAdd btn btn-link"
|
class="btn btn-link"
|
||||||
type="button"
|
type="button"
|
||||||
t-on-click="attachmentBoxView.onClickAddAttachment"
|
t-att-disabled="!state.thread.hasWriteAccess"
|
||||||
t-att-disabled="!attachmentBoxView.chatter.isTemporary and !attachmentBoxView.chatter.hasWriteAccess"
|
|
||||||
>
|
>
|
||||||
<i class="fa fa-plus-square" />
|
<i class="fa fa-plus-square" />
|
||||||
Attach files
|
Attach files
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
|
class="btn btn-link"
|
||||||
type="button"
|
type="button"
|
||||||
class="o_add_url_button btn btn-link"
|
t-att-disabled="!state.thread.hasWriteAccess"
|
||||||
t-on-click="attachmentBoxView._onAddUrl"
|
t-on-click="_onAddUrl"
|
||||||
>
|
>
|
||||||
<i class="fa fa-plus-square" />
|
<i class="fa fa-plus-square" />
|
||||||
Add URL
|
Add URL
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</t>
|
||||||
</xpath>
|
</xpath>
|
||||||
</t>
|
</t>
|
||||||
<t t-inherit="mail.AttachmentCard" t-inherit-mode="extension" owl="1">
|
<t t-inherit="mail.AttachmentList" t-inherit-mode="extension">
|
||||||
<xpath
|
<xpath
|
||||||
expr="//button[hasclass('o_AttachmentCard_asideItemDownload')]"
|
expr="//div[contains(@class, 'o-mail-AttachmentCard-aside')]//button[@title='Download']"
|
||||||
position="attributes"
|
position="attributes"
|
||||||
>
|
>
|
||||||
<attribute
|
<attribute name="t-if">attachment.mimetype != 'application/link'</attribute>
|
||||||
name="t-if"
|
|
||||||
>attachmentCard.attachment.mimetype != 'application/link'</attribute>
|
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath
|
<xpath
|
||||||
expr="//button[hasclass('o_AttachmentCard_asideItemDownload')]"
|
expr="//div[hasclass('o-mail-AttachmentCard-aside')]//button[@title='Download']"
|
||||||
position="after"
|
position="after"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
class="o_AttachmentCard_asideItem o_AttachmentCard_asideItemDownload btn d-flex justify-content-center align-items-center w-100 h-100 rounded-0 bg-300"
|
class="btn d-flex justify-content-center align-items-center w-100 h-100 rounded-0"
|
||||||
|
t-attf-class="bg-300"
|
||||||
t-on-click="() => window.open(attachmentUrl, '_blank')"
|
t-on-click="() => window.open(attachmentUrl, '_blank')"
|
||||||
title="Open"
|
title="Open"
|
||||||
t-if="attachmentCard.attachment.mimetype === 'application/link'"
|
t-if="attachment.mimetype === 'application/link'"
|
||||||
target="new"
|
target="_blank"
|
||||||
>
|
>
|
||||||
<i class="fa fa-link" role="img" aria-label="Open" />
|
<i class="fa fa-link" role="img" aria-label="Open" />
|
||||||
</button>
|
</button>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
<xpath
|
||||||
<xpath expr="//div[hasclass('o_AttachmentCard_image')]" position="attributes">
|
expr="//div[hasclass('o-mail-AttachmentCard-image')]"
|
||||||
|
position="attributes"
|
||||||
|
>
|
||||||
<attribute
|
<attribute
|
||||||
name="t-if"
|
name="t-if"
|
||||||
>attachmentCard.attachment.mimetype != 'application/link'</attribute>
|
>attachment.mimetype !== 'application/link'</attribute>
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//div[hasclass('o_AttachmentCard_image')]" position="before">
|
<xpath expr="//div[hasclass('o-mail-AttachmentCard-image')]" position="before">
|
||||||
<a
|
<a
|
||||||
class="o_Attachment_url_ico o_image flex-shrink-0 m-1"
|
class="o_Attachment_url_ico o_image flex-shrink-0 m-1"
|
||||||
t-att-href="attachmentUrl"
|
t-att-href="attachmentUrl"
|
||||||
target="new"
|
target="_blank"
|
||||||
t-if="attachmentCard.attachment.mimetype=='application/link'"
|
t-if="attachment.mimetype === 'application/link'"
|
||||||
>
|
>
|
||||||
<i class="fa fa-link fa-2x" />
|
<i class="fa fa-link fa-2x" />
|
||||||
</a>
|
</a>
|
||||||
|
@ -24,8 +24,7 @@
|
|||||||
class="oe_highlight"
|
class="oe_highlight"
|
||||||
type="object"
|
type="object"
|
||||||
/>
|
/>
|
||||||
or
|
<button special="cancel" string="Cancel" class="btn-secondary" />
|
||||||
<button special="cancel" string="Cancel" class="oe_link" />
|
|
||||||
</footer>
|
</footer>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
|
Loading…
Reference in New Issue
Block a user