]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/AttachmentGrid.js
attachment grid: fix typo in title
[pmg-gui.git] / js / AttachmentGrid.js
index 7e630dee2bcf15268781604536bcd7b6688c7f13..3187a58de399adbeaf24b0e780549370b844a4ca 100644 (file)
@@ -1,6 +1,19 @@
 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,
@@ -10,6 +23,41 @@ Ext.define('PMG.grid.AttachmentGrid', {
        },
     },
 
+    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} Attachments'), 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) {
@@ -42,12 +90,15 @@ Ext.define('PMG.grid.AttachmentGrid', {
        },
        {
            text: gettext('Size'),
-           renderer: Proxmox.Utils.format_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}`;