]> git.proxmox.com Git - pmg-gui.git/blob - js/AttachmentGrid.js
spam quarantine controller: fix args when calling the parent multiSelect
[pmg-gui.git] / js / AttachmentGrid.js
1 Ext.define('PMG.grid.AttachmentGrid', {
2 extend: 'Ext.grid.GridPanel',
3 xtype: 'pmgAttachmentGrid',
4 mixins: ['Proxmox.Mixin.CBind'],
5
6 showDownloads: true,
7
8 title: gettext('Attachments'),
9 iconCls: 'fa fa-paperclip',
10
11 minHeight: 50,
12 maxHeight: 250,
13 scrollable: true,
14
15 collapsible: true,
16 titleCollapse: true,
17
18 store: {
19 autoDestroy: true,
20 fields: ['name', 'content-type', 'size'],
21 proxy: {
22 type: 'proxmox',
23 },
24 },
25
26 controller: {
27 xclass: 'Ext.app.ViewController',
28 init: function(view) {
29 view.store.on('load', this.onLoad, this);
30 },
31 onLoad: function(store, records, success) {
32 let me = this;
33 let view = me.getView();
34 if (!success) {
35 view.updateTitleStats(-1);
36 return;
37 }
38 let totalSize = records.reduce((sum, { data }) => sum + data.size, 0);
39 view.updateTitleStats(records.length, totalSize);
40 },
41 },
42
43 updateTitleStats: function(count, totalSize) {
44 let me = this;
45 let title;
46 if (count > 0) {
47 title = Ext.String.format(gettext('{0} Attachements'), count);
48 title += ` (${Proxmox.Utils.format_size(totalSize)})`;
49 if (me.collapsible) {
50 me.expand();
51 }
52 } else {
53 title = gettext('No Attachments');
54 if (me.collapsible) {
55 me.collapse();
56 }
57 }
58 me.setTitle(title);
59 },
60
61 setID: function(rec) {
62 var me = this;
63 if (!rec || !rec.data || !rec.data.id) {
64 me.getStore().removeAll();
65 return;
66 }
67 var url = '/api2/json/quarantine/listattachments?id=' + rec.data.id;
68 me.mailid = rec.data.id;
69 me.store.proxy.setUrl(url);
70 me.store.load();
71 },
72
73 emptyText: gettext('No Attachments'),
74
75 download: function() {
76 Ext.Msg.alert(arguments);
77 },
78
79 columns: [
80 {
81 text: gettext('Filename'),
82 dataIndex: 'name',
83 flex: 1,
84 },
85 {
86 text: gettext('Filetype'),
87 dataIndex: 'content-type',
88 renderer: PMG.Utils.render_filetype,
89 flex: 1,
90 },
91 {
92 text: gettext('Size'),
93 renderer: Proxmox.Utils.render_size,
94 dataIndex: 'size',
95 flex: 1,
96 },
97 {
98 header: gettext('Download'),
99 cbind: {
100 hidden: '{!showDownloads}',
101 },
102 renderer: function(value, mD, rec) {
103 var me = this;
104 let url = `/api2/json/quarantine/download?mailid=${me.mailid}&attachmentid=${rec.data.id}`;
105 return `<a target='_blank' class='download' download='${rec.data.name}' href='${url}'>
106 <i class='fa fa-fw fa-download'</i>
107 </a>`;
108 },
109 },
110 ],
111 });