mirror of
https://git.proxmox.com/git/pmg-gui
synced 2025-10-04 20:05:43 +00:00

format_size is the "lower" level helper and is not fit (anymore) to be set as renderer directly, as its parameter signature may clash with the extra, different ones, that renderers get passed. For example, the useSI param always gets evaluated as true due to the metaData "truthy" value that calls to a renderer get passed along most of the time. Use the render_size instead, a wrapper which only passes along value to format_size. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
112 lines
2.4 KiB
JavaScript
112 lines
2.4 KiB
JavaScript
Ext.define('PMG.grid.AttachmentGrid', {
|
|
extend: 'Ext.grid.GridPanel',
|
|
xtype: 'pmgAttachmentGrid',
|
|
mixins: ['Proxmox.Mixin.CBind'],
|
|
|
|
showDownloads: true,
|
|
|
|
title: gettext('Attachments'),
|
|
iconCls: 'fa fa-paperclip',
|
|
|
|
minHeight: 50,
|
|
maxHeight: 250,
|
|
scrollable: true,
|
|
|
|
collapsible: true,
|
|
titleCollapse: true,
|
|
|
|
store: {
|
|
autoDestroy: true,
|
|
fields: ['name', 'content-type', 'size'],
|
|
proxy: {
|
|
type: 'proxmox',
|
|
},
|
|
},
|
|
|
|
controller: {
|
|
xclass: 'Ext.app.ViewController',
|
|
init: function(view) {
|
|
view.store.on('load', this.onLoad, this);
|
|
},
|
|
onLoad: function(store, records, success) {
|
|
let me = this;
|
|
let view = me.getView();
|
|
if (!success) {
|
|
view.updateTitleStats(-1);
|
|
return;
|
|
}
|
|
let totalSize = records.reduce((sum, { data }) => sum + data.size, 0);
|
|
view.updateTitleStats(records.length, totalSize);
|
|
},
|
|
},
|
|
|
|
updateTitleStats: function(count, totalSize) {
|
|
let me = this;
|
|
let title;
|
|
if (count > 0) {
|
|
title = Ext.String.format(gettext('{0} Attachements'), count);
|
|
title += ` (${Proxmox.Utils.format_size(totalSize)})`;
|
|
if (me.collapsible) {
|
|
me.expand();
|
|
}
|
|
} else {
|
|
title = gettext('No Attachments');
|
|
if (me.collapsible) {
|
|
me.collapse();
|
|
}
|
|
}
|
|
me.setTitle(title);
|
|
},
|
|
|
|
setID: function(rec) {
|
|
var me = this;
|
|
if (!rec || !rec.data || !rec.data.id) {
|
|
me.getStore().removeAll();
|
|
return;
|
|
}
|
|
var url = '/api2/json/quarantine/listattachments?id=' + rec.data.id;
|
|
me.mailid = rec.data.id;
|
|
me.store.proxy.setUrl(url);
|
|
me.store.load();
|
|
},
|
|
|
|
emptyText: gettext('No Attachments'),
|
|
|
|
download: function() {
|
|
Ext.Msg.alert(arguments);
|
|
},
|
|
|
|
columns: [
|
|
{
|
|
text: gettext('Filename'),
|
|
dataIndex: 'name',
|
|
flex: 1,
|
|
},
|
|
{
|
|
text: gettext('Filetype'),
|
|
dataIndex: 'content-type',
|
|
renderer: PMG.Utils.render_filetype,
|
|
flex: 1,
|
|
},
|
|
{
|
|
text: gettext('Size'),
|
|
renderer: Proxmox.Utils.render_size,
|
|
dataIndex: 'size',
|
|
flex: 1,
|
|
},
|
|
{
|
|
header: gettext('Download'),
|
|
cbind: {
|
|
hidden: '{!showDownloads}',
|
|
},
|
|
renderer: function(value, mD, rec) {
|
|
var me = this;
|
|
let url = `/api2/json/quarantine/download?mailid=${me.mailid}&attachmentid=${rec.data.id}`;
|
|
return `<a target='_blank' class='download' download='${rec.data.name}' href='${url}'>
|
|
<i class='fa fa-fw fa-download'</i>
|
|
</a>`;
|
|
},
|
|
},
|
|
],
|
|
});
|