RessourceView.js 2.38 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// fixme: howto avoid jslint type confusion?
/*jslint confusion: true */
Ext.define('PVE.openvz.RessourceView', {
    extend: 'PVE.grid.ObjectGrid',
    alias: ['widget.pveOpenVZRessourceView'],

    initComponent : function() {
	var me = this;
	var i, confid;

	var nodename = me.pveSelNode.data.node;
	if (!nodename) { 
	    throw "no node name specified";
	}

	var vmid = me.pveSelNode.data.vmid;
	if (!vmid) {
	    throw "no VM ID specified";
	}

21 22 23 24 25 26
	var caps = Ext.state.Manager.get('GuiCap');

	var resEditor = (caps.vms['VM.Config.Memory'] || caps.vms['VM.Config.Disk'] ||
		      caps.vms['VM.Config.CPU']) ? 'PVE.openvz.RessourceEdit' : undefined;


27 28
	var rows = {
	    memory: {
29
		header: gettext('Memory'),
30
		editor: resEditor,
31 32 33 34 35 36
		never_delete: true,
		renderer: function(value) {
		    return PVE.Utils.format_size(value*1024*1024);
		}
	    },
	    swap: {
37
		header: gettext('Swap'),
38
		editor: resEditor,
39 40 41 42 43 44
		never_delete: true,
		renderer: function(value) {
		    return PVE.Utils.format_size(value*1024*1024);
		}
	    },
	    cpus: {
45
		header: gettext('Processors'),
46
		never_delete: true,
47
		editor: resEditor,
Dietmar Maurer's avatar
Dietmar Maurer committed
48
		defaultValue: 1
49 50
	    },
	    disk: {
51
		header: gettext('Disk size'),
52
		editor: resEditor,
53 54 55 56 57 58 59 60 61 62 63 64 65
		never_delete: true,
		renderer: function(value) {
		    return PVE.Utils.format_size(value*1024*1024*1024);
		}
	    }
	};

	var reload = function() {
	    me.rstore.load();
	};

	var baseurl = 'nodes/' + nodename + '/openvz/' + vmid + '/config';

66 67
	var sm = Ext.create('Ext.selection.RowModel', {});

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
	var run_editor = function() {
	    var rec = sm.getSelection()[0];
	    if (!rec) {
		return;
	    }

	    var rowdef = rows[rec.data.key];
	    if (!rowdef.editor) {
		return;
	    }

	    var editor = rowdef.editor;

	    var win = Ext.create(editor, {
		pveSelNode: me.pveSelNode,
		confid: rec.data.key,
		url: '/api2/extjs/' + baseurl
	    });

	    win.show();
	    win.on('destroy', reload);
	};

91 92 93
	var edit_btn = new PVE.button.Button({
	    text: gettext('Edit'),
	    selModel: sm,
94
	    disabled: true,
95 96 97 98 99 100 101
	    enableFn: function(rec) {
		if (!rec) {
		    return false;
		}
		var rowdef = rows[rec.data.key];
		return !!rowdef.editor;
	    },
102 103 104 105 106
	    handler: run_editor
	});

	Ext.applyIf(me, {
	    url: '/api2/json/' + baseurl,
107
	    selModel: sm,
108 109 110 111 112
	    cwidth1: 170,
	    tbar: [ edit_btn ],
	    rows: rows,
	    listeners: {
		show: reload,
113
		itemdblclick: run_editor
114 115 116 117 118 119
	    }
	});

	me.callParent();
    }
});