BeanCounterGrid.js 1.82 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
/*jslint confusion: true */
Ext.define('PVE.openvz.BeanCounterGrid', {
    extend: 'Ext.grid.GridPanel',
    alias: ['widget.pveBeanCounterGrid'],

    renderUbc: function(value, metaData, record, rowIndex, colIndex, store) {

	if (value === 9223372036854775807) {
	    return '-';
	}

	if (record.id.match(/pages$/)) {
	    	return PVE.Utils.format_size(value*4096);
	}
	if (record.id.match(/(size|buf)$/)) {
	    	return PVE.Utils.format_size(value);
	}

	return value;
    },

    initComponent : function() {
	var me = this;

	if (!me.url) {
	    throw "no url specified";
	}

	var store = new Ext.data.Store({
	    model: 'pve-openvz-ubc',
	    proxy: {
		type: 'pve',
		url: me.url
	    },
	    sorters: [
		{
		    property : 'id',
		    direction: 'ASC'
		}
	    ]
	});

	var reload = function() {
	    store.load();
	};

	Ext.applyIf(me, {
	    store: store,
	    stateful: false,
	    columns: [
		{
		    header: 'Ressource',
		    width: 100,
		    dataIndex: 'id'
		},
		{
		    header: 'held',
		    width: 100,
		    renderer: me.renderUbc,
		    dataIndex: 'held'
		},
		{
		    header: 'maxheld',
		    width: 100,
		    renderer: me.renderUbc,
		    dataIndex: 'maxheld'
		},
		{
		    header: 'barrier',
		    width: 100,
		    renderer: me.renderUbc,
		    dataIndex: 'bar'
		},
		{
		    header: 'limit',
		    width: 100,
		    renderer: me.renderUbc,
		    dataIndex: 'lim'
		},
		{
		    header: 'failcnt',
		    width: 100,
		    dataIndex: 'failcnt'
		}
	    ],
	    listeners: {
		show: reload
	    }
	});

	me.callParent();

   }
}, function() {

    Ext.define('pve-openvz-ubc', {
	extend: "Ext.data.Model",
	fields: [ 'id', 
		  { name: 'held', type: 'number' },
		  { name: 'maxheld', type: 'number' },
		  { name: 'bar', type: 'number' },
		  { name: 'lim', type: 'number' },
		  { name: 'failcnt', type: 'number' }
		]
    });

});