mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-13 15:34:49 -06:00
[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:
parent
b029c7ac0a
commit
620aac5041
@ -1,4 +1,5 @@
|
|||||||
# Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
|
# Copyright 2014 Serv. Tecnol. Avanzados (http://www.serviciosbaeza.com)
|
||||||
# Copyright 2014 Tecnativa - Pedro M. Baeza
|
# Copyright 2014 Tecnativa - Pedro M. Baeza
|
||||||
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||||
|
from . import models
|
||||||
from . import wizard
|
from . import wizard
|
||||||
|
16
document_url/migrations/14.0.1.0.0/post-migration.py
Normal file
16
document_url/migrations/14.0.1.0.0/post-migration.py
Normal 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'
|
||||||
|
""",
|
||||||
|
)
|
3
document_url/models/__init__.py
Normal file
3
document_url/models/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from . import ir_attachment
|
13
document_url/models/ir_attachment.py
Normal file
13
document_url/models/ir_attachment.py
Normal 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)
|
@ -10,6 +10,7 @@ odoo.define("document_url", function (require) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const AttachmentBox = require("mail/static/src/components/attachment_box/attachment_box.js");
|
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");
|
const {patch} = require("web.utils");
|
||||||
|
|
||||||
patch(AttachmentBox, "document_url", {
|
patch(AttachmentBox, "document_url", {
|
||||||
@ -30,4 +31,12 @@ odoo.define("document_url", function (require) {
|
|||||||
this.trigger("reload");
|
this.trigger("reload");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
patch(Attachment, "document_url", {
|
||||||
|
_onClickImage(ev) {
|
||||||
|
if (!this.attachment.isViewable) {
|
||||||
|
this._onClickDownload(ev);
|
||||||
|
}
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
15
document_url/static/src/scss/document_url.scss
Normal file
15
document_url/static/src/scss/document_url.scss
Normal 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;
|
||||||
|
}
|
@ -15,4 +15,33 @@
|
|||||||
</button>
|
</button>
|
||||||
</xpath>
|
</xpath>
|
||||||
</t>
|
</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>
|
</templates>
|
||||||
|
@ -27,3 +27,5 @@ class TestDocumentUrl(common.TransactionCase):
|
|||||||
]
|
]
|
||||||
attachment_added_count = self.env["ir.attachment"].search_count(domain)
|
attachment_added_count = self.env["ir.attachment"].search_count(domain)
|
||||||
self.assertEqual(attachment_added_count, 1)
|
self.assertEqual(attachment_added_count, 1)
|
||||||
|
attachment = self.env["ir.attachment"].search(domain)
|
||||||
|
self.assertEqual(attachment.mimetype, "application/link")
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
>
|
>
|
||||||
<xpath expr="." position="inside">
|
<xpath expr="." position="inside">
|
||||||
<script type="text/javascript" src="/document_url/static/src/js/url.js" />
|
<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>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
<record model="ir.actions.act_window" id='action_ir_attachment_add_url'>
|
<record model="ir.actions.act_window" id='action_ir_attachment_add_url'>
|
||||||
|
Loading…
Reference in New Issue
Block a user