]>
git.proxmox.com Git - pmg-gui.git/blob - js/AttachmentGrid.js
1 Ext
.define('PMG.grid.AttachmentGrid', {
2 extend
: 'Ext.grid.GridPanel',
3 xtype
: 'pmgAttachmentGrid',
4 mixins
: ['Proxmox.Mixin.CBind'],
8 title
: gettext('Attachments'),
9 iconCls
: 'fa fa-paperclip',
19 boxLabel
: gettext('show all parts'),
20 boxLabelAlgign
: 'before',
22 change: function(cb
, value
) {
23 let grid
= this.up('pmgAttachmentGrid');
24 let store
= grid
.getStore();
28 property
: 'content-disposition',
39 let type
= me
.type
=== 'up' ? 'down' : 'up';
40 me
.up('pmgAttachmentGrid').toggleCollapse();
47 padding
: '6 10 6 10', // make same height as normal panel
52 fields
: ['name', 'content-type', 'size', 'content-disposition'],
57 property
: 'content-disposition',
63 xclass
: 'Ext.app.ViewController',
64 init: function(view
) {
65 view
.store
.on('load', this.onLoad
, this);
67 onLoad: function(store
, records
, success
) {
69 let view
= me
.getView();
71 view
.updateTitleStats(-1);
74 let attachments
= records
.filter(({ data
}) => data
['content-disposition'] === 'attachment');
75 let totalSize
= attachments
.reduce((sum
, { data
}) => sum
+ data
.size
, 0);
76 view
.updateTitleStats(attachments
.length
, totalSize
);
80 updateTitleStats: function(count
, totalSize
) {
84 title
= Ext
.String
.format(gettext('{0} Attachments'), count
);
85 title
+= ` (${Proxmox.Utils.format_size(totalSize)})`;
88 title
= gettext('No Attachments');
94 setID: function(rec
) {
96 if (!rec
|| !rec
.data
|| !rec
.data
.id
) {
97 me
.getStore().removeAll();
100 var url
= '/api2/json/quarantine/listattachments?id=' + rec
.data
.id
;
101 me
.mailid
= rec
.data
.id
;
102 me
.store
.proxy
.setUrl(url
);
106 emptyText
: gettext('No Attachments'),
108 download: function() {
109 Ext
.Msg
.alert(arguments
);
114 text
: gettext('Filename'),
119 text
: gettext('Filetype'),
120 dataIndex
: 'content-type',
121 renderer
: PMG
.Utils
.render_filetype
,
125 text
: gettext('Size'),
126 renderer
: Proxmox
.Utils
.render_size
,
131 header
: gettext('Download'),
133 hidden
: '{!showDownloads}',
135 renderer: function(value
, mD
, rec
) {
137 let url
= `/api2/json/quarantine/download?mailid=${me.mailid}&attachmentid=${rec.data.id}`;
138 return `<a target='_blank' class='download' download='${rec.data.name}' href='${url}'>
139 <i class='fa fa-fw fa-download'</i>