]>
Commit | Line | Data |
---|---|---|
c87d46fb | 1 | Ext.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 | ||
38229fc8 TL |
15 | collapsible: true, |
16 | titleCollapse: true, | |
17 | ||
0023ef6a DC |
18 | store: { |
19 | autoDestroy: true, | |
c87d46fb | 20 | fields: ['name', 'content-type', 'size'], |
0023ef6a DC |
21 | proxy: { |
22 | type: 'proxmox', | |
c87d46fb | 23 | }, |
0023ef6a DC |
24 | }, |
25 | ||
550ec9a8 TL |
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) { | |
86c2fdb6 | 47 | title = Ext.String.format(gettext('{0} Attachments'), count); |
550ec9a8 TL |
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 | ||
0023ef6a DC |
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() { | |
28eb60c0 | 76 | Ext.Msg.alert(arguments); |
0023ef6a DC |
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'), | |
ff23b1b3 | 93 | renderer: Proxmox.Utils.render_size, |
0023ef6a DC |
94 | dataIndex: 'size', |
95 | flex: 1, | |
96 | }, | |
97 | { | |
98 | header: gettext('Download'), | |
1a96ec32 DC |
99 | cbind: { |
100 | hidden: '{!showDownloads}', | |
101 | }, | |
0023ef6a DC |
102 | renderer: function(value, mD, rec) { |
103 | var me = this; | |
28eb60c0 TL |
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>`; | |
0023ef6a | 108 | }, |
c87d46fb TL |
109 | }, |
110 | ], | |
0023ef6a | 111 | }); |