[IMP] document_url: Visual and functional improvements in UI.

Define the add attachment and add URL buttons on the same line.
Allow downloading of url type attachments by clicking on the icon or the name.
Define the name of the url type attachments as links (allows to open it in a new tab).
Hide the download button for url attachments.
Force to set mimetype to "application/link" for url attachments.
Displays a link icon for url attachments.
TT30263
This commit is contained in:
Víctor Martínez 2021-10-13 17:27:50 +02:00 committed by Bhavesh Heliconia
parent b029c7ac0a
commit 620aac5041
9 changed files with 92 additions and 0 deletions

View File

@ -1,4 +1,5 @@
# Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
# Copyright 2014 Tecnativa - Pedro M. Baeza
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
from . import models
from . import wizard

View File

@ -0,0 +1,16 @@
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade
@openupgrade.migrate()
def migrate(env, version):
openupgrade.logged_query(
env.cr,
"""
UPDATE ir_attachment
SET mimetype = 'application/link'
WHERE type = 'link'
""",
)

View File

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import ir_attachment

View File

@ -0,0 +1,13 @@
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
class IrAttachment(models.Model):
_inherit = "ir.attachment"
def _compute_mimetype(self, values):
if values.get("url"):
return "application/link"
return super()._compute_mimetype(values)

View File

@ -10,6 +10,7 @@ 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", {
@ -30,4 +31,12 @@ odoo.define("document_url", function (require) {
this.trigger("reload");
},
});
patch(Attachment, "document_url", {
_onClickImage(ev) {
if (!this.attachment.isViewable) {
this._onClickDownload(ev);
}
this._super.apply(this, arguments);
},
});
});

View File

@ -0,0 +1,15 @@
.o_AttachmentBox_content {
text-align: center;
display: block;
}
.o_AttachmentList_partialListNonImages {
.o_Attachment_image {
cursor: pointer;
}
.o_Attachment_filename a {
color: #4c4c4c;
}
}
.o_Attachment_url_icon {
margin: 4px 2px 0px 4px;
}

View File

@ -15,4 +15,33 @@
</button>
</xpath>
</t>
<t t-inherit="mail.Attachment" 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"
position="replace"
>
<a t-att-href="attachmentUrl" target="new">
<t t-esc="attachment.displayName" />
</a>
</xpath>
<xpath
expr="//div[hasclass('o_Attachment_asideItemDownload')]"
position="attributes"
>
<attribute name="t-if">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>
<xpath expr="//div[hasclass('o_Attachment_image')]" position="before">
<a
class="o_Attachment_url_icon"
t-att-href="attachmentUrl"
target="new"
t-if="attachment.mimetype=='application/link'"
>
<i class="fa fa-link fa-2x" />
</a>
</xpath>
</t>
</templates>

View File

@ -27,3 +27,5 @@ class TestDocumentUrl(common.TransactionCase):
]
attachment_added_count = self.env["ir.attachment"].search_count(domain)
self.assertEqual(attachment_added_count, 1)
attachment = self.env["ir.attachment"].search(domain)
self.assertEqual(attachment.mimetype, "application/link")

View File

@ -7,6 +7,10 @@
>
<xpath expr="." position="inside">
<script type="text/javascript" src="/document_url/static/src/js/url.js" />
<link
href="/document_url/static/src/scss/document_url.scss"
rel="stylesheet"
/>
</xpath>
</template>
<record model="ir.actions.act_window" id='action_ir_attachment_add_url'>