-
-
Notifications
You must be signed in to change notification settings - Fork 403
/
attachment_image.js
135 lines (133 loc) · 4.44 KB
/
attachment_image.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/** @odoo-module **/
import { registerModel } from '@mail/model/model_core';
import { attr, one } from '@mail/model/model_field';
import { clear } from '@mail/model/model_field_command';
import { isEventHandled, markEventHandled } from '@mail/utils/utils';
registerModel({
name: 'AttachmentImage',
recordMethods: {
/**
* Called when clicking on download icon.
*
* @param {MouseEvent} ev
*/
onClickDownload(ev) {
markEventHandled(ev, 'AttachmentImage.onClickDownload');
if (!this.exists()) {
return;
}
this.attachment.download();
},
/**
* Opens the attachment viewer when clicking on viewable attachment.
*
* @param {MouseEvent} ev
*/
onClickImage(ev) {
if (isEventHandled(ev, 'AttachmentImage.onClickDownload')) {
return;
}
if (isEventHandled(ev, 'AttachmentImage.onClickUnlink')) {
return;
}
if (!this.attachment || !this.attachment.isViewable) {
return;
}
this.attachmentList.update({
attachmentListViewDialog: {},
selectedAttachment: this.attachment,
});
},
/**
* Handles the click on delete attachment and open the confirm dialog.
*
* @param {MouseEvent} ev
*/
onClickUnlink(ev) {
markEventHandled(ev, 'AttachmentImage.onClickUnlink');
if (!this.exists()) {
return;
}
if (this.attachmentList.composerViewOwner) {
this.attachment.remove();
} else {
this.update({ attachmentDeleteConfirmDialog: {} });
}
},
},
fields: {
/**
* Determines the attachment of this attachment image..
*/
attachment: one('Attachment', {
identifying: true,
}),
attachmentDeleteConfirmDialog: one('Dialog', {
inverse: 'attachmentImageOwnerAsAttachmentDeleteConfirm',
}),
/**
* States the attachmentList displaying this attachment image.
*/
attachmentList: one('AttachmentList', {
identifying: true,
inverse: 'attachmentImages',
}),
/**
* Determines whether `this` should display a download button.
*/
hasDownloadButton: attr({
compute() {
if (!this.attachment || !this.attachmentList) {
return clear();
}
return !this.attachmentList.composerViewOwner && !this.attachment.isUploading;
},
default: false,
}),
/**
* Determines the max height of this attachment image in px.
*/
height: attr({
compute() {
if (!this.attachmentList) {
return clear();
}
if (this.attachmentList.composerViewOwner) {
return 50;
}
if (this.attachmentList.attachmentBoxViewOwner) {
return 160;
}
if (this.attachmentList.messageViewOwner) {
return 300;
}
},
required: true,
}),
imageUrl: attr({
compute() {
if (!this.attachment) {
return;
}
if (!this.attachment.accessToken && this.attachment.originThread && this.attachment.originThread.model === 'mail.channel') {
return `/mail/channel/${this.attachment.originThread.id}/image/${this.attachment.id}/${this.width}x${this.height}`;
}
const accessToken = this.attachment.accessToken ? `?access_token=${this.attachment.accessToken}` : '';
return `/web/image/${this.attachment.id}/${this.width}x${this.height}${accessToken}`;
},
}),
/**
* Determines the max width of this attachment image in px.
*/
width: attr({
/**
* Returns an arbitrary high value, this is effectively a max-width and
* the height should be more constrained.
*/
compute() {
return 1920;
},
required: true,
}),
},
});