From 2ee541112c5f0d68bb6c197d3717f2df53f33e19 Mon Sep 17 00:00:00 2001 From: Franco Leyes Date: Wed, 22 May 2024 15:42:24 -0300 Subject: [PATCH] [MIG] document_url: Migration to 17.0 --- document_url/__manifest__.py | 2 +- document_url/static/src/js/url.esm.js | 80 ++++++++++--------- document_url/static/src/xml/url.xml | 100 ++++++++++++------------ document_url/view/document_url_view.xml | 3 +- 4 files changed, 94 insertions(+), 91 deletions(-) diff --git a/document_url/__manifest__.py b/document_url/__manifest__.py index 4a289b0b..bf59b7a0 100644 --- a/document_url/__manifest__.py +++ b/document_url/__manifest__.py @@ -2,7 +2,7 @@ # Copyright 2020 Tecnativa - Manuel Calero { "name": "URL attachment", - "version": "16.0.1.0.4", + "version": "17.0.1.0.0", "category": "Tools", "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/knowledge", diff --git a/document_url/static/src/js/url.esm.js b/document_url/static/src/js/url.esm.js index 6d4bd8b8..b11953e7 100644 --- a/document_url/static/src/js/url.esm.js +++ b/document_url/static/src/js/url.esm.js @@ -1,47 +1,51 @@ /** @odoo-module **/ -import {registerPatch} from "@mail/model/model_core"; -import {AttachmentCard} from "@mail/components/attachment_card/attachment_card"; -import {patch} from "web.utils"; +import {Chatter} from "@mail/core/web/chatter"; +import {patch} from "@web/core/utils/patch"; import {url} from "@web/core/utils/urls"; +import {AttachmentList} from "@mail/core/common/attachment_list"; -registerPatch({ - name: "AttachmentBoxView", - recordMethods: { - _onAddUrl(event) { - event.preventDefault(); - event.stopPropagation(); - this.env.services.action.doAction( - "document_url.action_ir_attachment_add_url", - { - additionalContext: { - active_id: this.chatter.thread.id, - active_ids: [this.chatter.thread.id], - active_model: this.chatter.thread.model, - }, - onClose: this._onAddedUrl.bind(this), - } - ); - }, - _onAddedUrl() { - this.chatter.refresh(); - }, +patch(Chatter.prototype, { + _onAddUrl(event) { + event.preventDefault(); + event.stopPropagation(); + this.action.doAction("document_url.action_ir_attachment_add_url", { + additionalContext: { + active_id: this.state.thread.id, + active_ids: [this.state.thread.id], + active_model: this.state.thread.model, + }, + 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; + } }, }); -registerPatch({ - name: "Chatter", - recordMethods: { - /** - * Handles click on the attach button. - */ - async onClickButtonAddAttachments() { - await this.onClickButtonToggleAttachments(); - }, - }, -}); - -patch(AttachmentCard.prototype, "document_url/static/src/js/url.js", { +patch(AttachmentList.prototype, { /** * Return the url of the attachment. Temporary attachments, a.k.a. uploading * attachments, do not have an url. @@ -50,7 +54,7 @@ patch(AttachmentCard.prototype, "document_url/static/src/js/url.js", { */ get attachmentUrl() { return url("/web/content", { - id: this.attachmentCard.attachment.id, + id: this.attachment.id, download: true, }); }, diff --git a/document_url/static/src/xml/url.xml b/document_url/static/src/xml/url.xml index 568a2378..ce6793b6 100644 --- a/document_url/static/src/xml/url.xml +++ b/document_url/static/src/xml/url.xml @@ -4,67 +4,67 @@ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> - - -
- - -
+ + + +
+ + +
+
- + + attachment.mimetype != 'application/link' + + + + + attachmentCard.attachment.mimetype != 'application/link' + >attachment.mimetype !== 'application/link' - - - - - - attachmentCard.attachment.mimetype != 'application/link' - - + diff --git a/document_url/view/document_url_view.xml b/document_url/view/document_url_view.xml index 5c0b208a..6ce77e80 100644 --- a/document_url/view/document_url_view.xml +++ b/document_url/view/document_url_view.xml @@ -24,8 +24,7 @@ class="oe_highlight" type="object" /> - or -