]> git.proxmox.com Git - pmg-gui.git/blame - js/AttachmentGrid.js
mail-proxy-relaying: add help to Default Relay
[pmg-gui.git] / js / AttachmentGrid.js
CommitLineData
c87d46fb 1Ext.define('PMG.grid.AttachmentGrid', {
0023ef6a
DC
2 extend: 'Ext.grid.GridPanel',
3 xtype: 'pmgAttachmentGrid',
1a96ec32
DC
4 mixins: ['Proxmox.Mixin.CBind'],
5
6 showDownloads: true,
0023ef6a 7
38229fc8
TL
8 title: gettext('Attachments'),
9 iconCls: 'fa fa-paperclip',
10
ecab0d0e
TL
11 minHeight: 50,
12 maxHeight: 250,
13 scrollable: true,
14
57be3ef3
TL
15 collapsible: true,
16 titleCollapse: true,
17
18 tbar: [
19 '->',
db3264f2
DC
20 {
21 xtype: 'checkbox',
0bd715f1 22 boxLabel: gettext('Show All Parts'),
db3264f2
DC
23 boxLabelAlgign: 'before',
24 listeners: {
57be3ef3
TL
25 change: function(checkBox, value) {
26 let store = this.up('pmgAttachmentGrid').getStore();
db3264f2
DC
27 store.clearFilter();
28 if (!value) {
29 store.filter({
30 property: 'content-disposition',
31 value: 'attachment',
32 });
33 }
34 },
35 },
36 },
db3264f2
DC
37 ],
38
0023ef6a
DC
39 store: {
40 autoDestroy: true,
db3264f2 41 fields: ['name', 'content-type', 'size', 'content-disposition'],
0023ef6a
DC
42 proxy: {
43 type: 'proxmox',
c87d46fb 44 },
db3264f2
DC
45 filters: {
46 property: 'content-disposition',
47 value: 'attachment',
48 },
0023ef6a
DC
49 },
50
550ec9a8
TL
51 controller: {
52 xclass: 'Ext.app.ViewController',
53 init: function(view) {
54 view.store.on('load', this.onLoad, this);
55 },
56 onLoad: function(store, records, success) {
57 let me = this;
58 let view = me.getView();
59 if (!success) {
60 view.updateTitleStats(-1);
61 return;
62 }
17589a84
TL
63 let attachments = records.filter(({ data }) => data['content-disposition'] === 'attachment');
64 let totalSize = attachments.reduce((sum, { data }) => sum + data.size, 0);
65 view.updateTitleStats(attachments.length, totalSize);
550ec9a8
TL
66 },
67 },
68
69 updateTitleStats: function(count, totalSize) {
70 let me = this;
71 let title;
72 if (count > 0) {
86c2fdb6 73 title = Ext.String.format(gettext('{0} Attachments'), count);
550ec9a8 74 title += ` (${Proxmox.Utils.format_size(totalSize)})`;
57be3ef3
TL
75 if (me.collapsible) {
76 me.expand();
77 }
550ec9a8
TL
78 } else {
79 title = gettext('No Attachments');
57be3ef3
TL
80 if (me.collapsible) {
81 me.collapse();
82 }
550ec9a8
TL
83 }
84 me.setTitle(title);
85 },
86
0023ef6a
DC
87 setID: function(rec) {
88 var me = this;
89 if (!rec || !rec.data || !rec.data.id) {
90 me.getStore().removeAll();
91 return;
92 }
93 var url = '/api2/json/quarantine/listattachments?id=' + rec.data.id;
94 me.mailid = rec.data.id;
95 me.store.proxy.setUrl(url);
96 me.store.load();
97 },
98
99 emptyText: gettext('No Attachments'),
100
101 download: function() {
28eb60c0 102 Ext.Msg.alert(arguments);
0023ef6a
DC
103 },
104
105 columns: [
106 {
107 text: gettext('Filename'),
108 dataIndex: 'name',
109 flex: 1,
110 },
111 {
112 text: gettext('Filetype'),
113 dataIndex: 'content-type',
114 renderer: PMG.Utils.render_filetype,
115 flex: 1,
116 },
117 {
118 text: gettext('Size'),
ff23b1b3 119 renderer: Proxmox.Utils.render_size,
0023ef6a
DC
120 dataIndex: 'size',
121 flex: 1,
122 },
123 {
124 header: gettext('Download'),
1a96ec32
DC
125 cbind: {
126 hidden: '{!showDownloads}',
127 },
0023ef6a
DC
128 renderer: function(value, mD, rec) {
129 var me = this;
28eb60c0
TL
130 let url = `/api2/json/quarantine/download?mailid=${me.mailid}&attachmentid=${rec.data.id}`;
131 return `<a target='_blank' class='download' download='${rec.data.name}' href='${url}'>
132 <i class='fa fa-fw fa-download'</i>
133 </a>`;
0023ef6a 134 },
c87d46fb
TL
135 },
136 ],
0023ef6a 137});