StorageSelector.js 2 KB
Newer Older
1 2 3 4
Ext.define('PVE.form.StorageSelector', {
    extend: 'PVE.form.ComboGrid',
    alias: ['widget.PVE.form.StorageSelector'],

5
    reloadStorageList: function() {
6
	var me = this;
7
	if (!me.nodename) {
8 9 10
	    return;
	}

11
	var params = {};
12 13
	var url = '/api2/json/nodes/' + me.nodename + '/storage';
	if (me.storageContent) {
14 15 16 17 18
	    params.content = me.storageContent;
	}
	if (me.targetNode) {
	    params.target = me.targetNode;
	    params.enabled = 1; // skip disabled storages
19 20 21
	}
	me.store.setProxy({
	    type: 'pve',
22 23
	    url: url,
	    extraParams: params
24 25 26
	});

	me.store.load();
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
 
    },

    setTargetNode: function(targetNode) {
	var me = this;

	if (!targetNode || (me.targetNode === targetNode)) {
	    return;
	}

	me.targetNode = targetNode;

	me.reloadStorageList();
    },

    setNodename: function(nodename) {
	var me = this;

	if (!nodename || (me.nodename === nodename)) {
	    return;
	}

	me.nodename = nodename;

	me.reloadStorageList();
52 53 54 55 56 57 58 59 60
    },

    initComponent: function() {
	var me = this;

	var nodename = me.nodename;
	me.nodename = undefined; 

	var store = Ext.create('Ext.data.Store', {
61
	    model: 'pve-storage-status',
62 63 64 65
	    sorters: {
		property: 'storage', 
		order: 'DESC' 
	    }
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
	});

	Ext.apply(me, {
	    store: store,
	    allowBlank: false,
	    valueField: 'storage',
	    displayField: 'storage',
            listConfig: {
		columns: [
		    {
			header: 'Name',
			dataIndex: 'storage',
			hideable: false,
			flex: 1
		    },
		    {
			header: 'Type',  
			width: 60, 
			dataIndex: 'type'
		    },
		    {
			header: 'Avail',  
			width: 80, 
			dataIndex: 'avail', 
			renderer: PVE.Utils.format_size 
		    },
		    {
			header: 'Capacity',  
			width: 80, 
			dataIndex: 'total', 
			renderer: PVE.Utils.format_size 
		    }
		]
	    }
	});

        me.callParent();

	if (nodename) {
	    me.setNodename(nodename);
	}
    }
108 109 110 111 112 113 114 115 116
}, function() {

    Ext.define('pve-storage-status', {
	extend: 'Ext.data.Model',
	fields: [ 'storage', 'active', 'type', 'avail', 'total' ],
	idProperty: 'storage'
    });

});