[FIX] mail: no message attachment delete in discuss and chat window
Delete attachment from message makes only sense from chatter. Task-Id 2058455
This commit is contained in:
@@ -43,6 +43,7 @@ var ThreadField = AbstractField.extend({
|
||||
displayOrder: ThreadWidget.ORDER.DESC,
|
||||
displayDocumentLinks: false,
|
||||
displayMarkAsRead: false,
|
||||
hasMessageAttachmentDeletable: true,
|
||||
squashCloseMessages: false,
|
||||
});
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ var ThreadWidget = Widget.extend({
|
||||
displayEmailIcons: true,
|
||||
displayReplyIcons: false,
|
||||
loadMoreOnScroll: false,
|
||||
hasMessageAttachmentDeletable: false,
|
||||
});
|
||||
// options when the thread is disabled
|
||||
this._disabledOptions = {
|
||||
@@ -81,6 +82,7 @@ var ThreadWidget = Widget.extend({
|
||||
displayEmailIcons: false,
|
||||
displayReplyIcons: false,
|
||||
loadMoreOnScroll: this._enabledOptions.loadMoreOnScroll,
|
||||
hasMessageAttachmentDeletable: false,
|
||||
};
|
||||
this._selectedMessageID = null;
|
||||
this._currentThreadID = null;
|
||||
|
||||
@@ -254,6 +254,7 @@
|
||||
@param {boolean} [options.displayReplyIcons]
|
||||
@param {boolean} [options.displayStars]
|
||||
@param {boolean} [options.displaySubjectsOnMessages]
|
||||
@param {boolean} options.hasMessageAttachmentDeletable
|
||||
@param {string|integer} [options.messagesSeparatorPosition] 'top' or
|
||||
message ID, the separator is placed just after this message.
|
||||
@param {integer} [options.selectedMessageID]
|
||||
@@ -354,12 +355,16 @@
|
||||
<t t-if="message.hasAttachments()">
|
||||
<div t-if="message.hasImageAttachments()" class="o_attachments_previews">
|
||||
<t t-foreach="message.getImageAttachments()" t-as="attachment">
|
||||
<t t-call="mail.AttachmentPreview"/>
|
||||
<t t-call="mail.AttachmentPreview">
|
||||
<t t-set="isDeletable" t-value="options.hasMessageAttachmentDeletable"/>
|
||||
</t>
|
||||
</t>
|
||||
</div>
|
||||
<div t-if="message.hasNonImageAttachments()" class="o_attachments_list">
|
||||
<t t-foreach="message.getNonImageAttachments()" t-as="attachment">
|
||||
<t t-call="mail.Attachment"/>
|
||||
<t t-call="mail.Attachment">
|
||||
<t t-set="isDeletable" t-value="options.hasMessageAttachmentDeletable"/>
|
||||
</t>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
@@ -526,6 +531,7 @@
|
||||
@param {integer} attachment.id
|
||||
@param {string} attachment.name
|
||||
@param {string} attachment.url
|
||||
@param {boolean} [isDeletable=false]
|
||||
-->
|
||||
<t t-name="mail.AttachmentPreview">
|
||||
<div class="o_attachment" t-att-title="attachment.name">
|
||||
@@ -533,7 +539,7 @@
|
||||
<div class="o_image_box">
|
||||
<div class="o_attachment_image" t-attf-style="background-image:url('/web/image/#{attachment.id}/160x160/?crop=true')"/>
|
||||
<div t-attf-class="o_image_overlay o_attachment_view" t-att-data-id="attachment.id">
|
||||
<span class="fa fa-times o_attachment_delete_cross" t-att-title="'Delete ' + attachment.name" t-att-data-id="attachment.id" t-att-data-name="attachment.name"/>
|
||||
<span t-if="isDeletable" class="fa fa-times o_attachment_delete_cross" t-att-title="'Delete ' + attachment.name" t-att-data-id="attachment.id" t-att-data-name="attachment.name"/>
|
||||
<span class="o_attachment_title text-white"><t t-esc="attachment.name"/></span>
|
||||
<a class="o_attachment_download" t-att-href='attachment.url'>
|
||||
<i t-attf-class="fa fa-download text-white" t-att-title="'Download ' + attachment.name" role="img" aria-label="Download"></i>
|
||||
@@ -552,12 +558,15 @@
|
||||
@param {string} attachment.name
|
||||
@param {boolean} attachment.upload
|
||||
@param {string} attachment.url
|
||||
@param {boolean} [editable=false] if set, it means the attachment is rendered in the composer.
|
||||
Some changes are required in that case, such as "delete" button is not visible (pretty unlink is used instead).
|
||||
@param {boolean} [isDeletable=false]
|
||||
-->
|
||||
<t t-name="mail.Attachment">
|
||||
<t t-set="type" t-value="attachment.mimetype and attachment.mimetype.split('/').shift()"/>
|
||||
<div t-attf-class="o_attachment #{ editable ? 'o_attachment_editable' : '' } #{attachment.upload ? 'o_attachment_uploading' : ''}" t-att-title="attachment.name">
|
||||
<div class="o_attachment_wrap">
|
||||
<span t-if="!editable" class="fa fa-times o_attachment_delete_cross" t-att-title="'Delete ' + attachment.name" t-att-data-id="attachment.id" t-att-data-name="attachment.name"/>
|
||||
<span t-if="!editable and isDeletable" class="fa fa-times o_attachment_delete_cross" t-att-title="'Delete ' + attachment.name" t-att-data-id="attachment.id" t-att-data-name="attachment.name"/>
|
||||
<t t-set="has_preview" t-value="type == 'image' or type == 'video' or attachment.mimetype == 'application/pdf'"/>
|
||||
<t t-set="ext" t-value="attachment.filename.split('.').pop()"/>
|
||||
|
||||
|
||||
@@ -1119,6 +1119,53 @@ QUnit.test('drag and drop file in composer [REQUIRE NON-INCOGNITO WINDOW]', asyn
|
||||
discuss.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('non-deletable message attachments', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
this.data['mail.message'].records = [{
|
||||
attachment_ids: [{
|
||||
filename: "text.txt",
|
||||
id: 250,
|
||||
mimetype: 'text/plain',
|
||||
name: "text.txt",
|
||||
}, {
|
||||
filename: "image.png",
|
||||
id: 251,
|
||||
mimetype: 'image/png',
|
||||
name: "image.png",
|
||||
}],
|
||||
author_id: [5, "Demo User"],
|
||||
body: "<p>test</p>",
|
||||
id: 1,
|
||||
needaction: true,
|
||||
needaction_partner_ids: [3],
|
||||
model: 'some.document',
|
||||
record_name: "SomeDocument",
|
||||
res_id: 100,
|
||||
}];
|
||||
|
||||
const discuss = await createDiscuss({
|
||||
context: {},
|
||||
data: this.data,
|
||||
params: {},
|
||||
services: this.services,
|
||||
session: {
|
||||
partner_id: 3,
|
||||
},
|
||||
});
|
||||
assert.containsN(
|
||||
discuss,
|
||||
'.o_attachment',
|
||||
2,
|
||||
"should display 2 attachments");
|
||||
assert.containsNone(
|
||||
discuss.$('.o_attachment'),
|
||||
'o_attachment_delete_cross',
|
||||
"attachments should not be deletable");
|
||||
|
||||
discuss.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('reply to message from inbox', async function (assert) {
|
||||
assert.expect(11);
|
||||
|
||||
|
||||
@@ -850,6 +850,59 @@ QUnit.test('receive 2 new DM messages in quick succession (no chat window initia
|
||||
parent.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('non-deletable message attachments', async function (assert) {
|
||||
assert.expect(3);
|
||||
|
||||
this.data['mail.channel'].records = [{
|
||||
id: 1,
|
||||
name: "General",
|
||||
channel_type: 'channel',
|
||||
}];
|
||||
this.data['mail.message'].records = [{
|
||||
attachment_ids: [{
|
||||
filename: "text.txt",
|
||||
id: 250,
|
||||
mimetype: 'text/plain',
|
||||
name: "text.txt",
|
||||
}, {
|
||||
filename: "image.png",
|
||||
id: 251,
|
||||
mimetype: 'image/png',
|
||||
name: "image.png",
|
||||
}],
|
||||
author_id: [5, "Demo User"],
|
||||
body: "<p>test</p>",
|
||||
channel_ids: [1],
|
||||
id: 100,
|
||||
model: 'mail.channel',
|
||||
record_name: "general",
|
||||
res_id: 1,
|
||||
}];
|
||||
const parent = this.createParent({
|
||||
data: this.data,
|
||||
services: this.services,
|
||||
});
|
||||
await testUtils.nextTick();
|
||||
const channel = parent.call('mail_service', 'getChannel', 1);
|
||||
channel.detach();
|
||||
await testUtils.nextTick();
|
||||
assert.containsOnce(
|
||||
$,
|
||||
'.o_thread_window',
|
||||
"a thread window should be open");
|
||||
assert.containsN(
|
||||
$('.o_thread_window'),
|
||||
'.o_attachment',
|
||||
2,
|
||||
"thread window should have 2 attachments");
|
||||
assert.containsNone(
|
||||
$('.o_thread_window .o_attachment'),
|
||||
'o_attachment_delete_cross',
|
||||
"attachments should not be deletable");
|
||||
|
||||
parent.destroy();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user