]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/DisplayEdit.js
ui: qemu: change logic to use ViewModel instead of listener function
[pve-manager.git] / www / manager6 / qemu / DisplayEdit.js
1 Ext.define('PVE.qemu.DisplayInputPanel', {
2 extend: 'Proxmox.panel.InputPanel',
3 xtype: 'pveDisplayInputPanel',
4 onlineHelp: 'qm_display',
5
6 onGetValues: function(values) {
7 let ret = PVE.Parser.printPropertyString(values, 'type');
8 if (ret === '') {
9 return { 'delete': 'vga' };
10 }
11 return { vga: ret };
12 },
13
14 viewModel: {
15 data: {
16 type: '__default__',
17 clipboard: '__default__',
18 },
19 formulas: {
20 matchNonGUIOption: function(get) {
21 return get('type').match(/^(serial\d|none)$/);
22 },
23 memoryEmptyText: function(get) {
24 let val = get('type');
25 if (val === "cirrus") {
26 return "4";
27 } else if (val === "std" || val.match(/^qxl\d?$/) || val === "vmware") {
28 return "16";
29 } else if (val.match(/^virtio/)) {
30 return "256";
31 } else if (get('matchNonGUIOption')) {
32 return "N/A";
33 } else {
34 console.debug("unexpected display type", val);
35 return Proxmox.Utils.defaultText;
36 }
37 },
38 },
39 },
40
41 items: [{
42 name: 'type',
43 xtype: 'proxmoxKVComboBox',
44 value: '__default__',
45 deleteEmpty: false,
46 fieldLabel: gettext('Graphic card'),
47 comboItems: Object.entries(PVE.Utils.kvm_vga_drivers),
48 validator: function(v) {
49 let cfg = this.up('proxmoxWindowEdit').vmconfig || {};
50
51 if (v.match(/^serial\d+$/) && (!cfg[v] || cfg[v] !== 'socket')) {
52 let fmt = gettext("Serial interface '{0}' is not correctly configured.");
53 return Ext.String.format(fmt, v);
54 }
55 return true;
56 },
57 bind: {
58 value: '{type}',
59 },
60 },
61 {
62 xtype: 'proxmoxintegerfield',
63 emptyText: Proxmox.Utils.defaultText,
64 fieldLabel: gettext('Memory') + ' (MiB)',
65 minValue: 4,
66 maxValue: 512,
67 step: 4,
68 name: 'memory',
69 bind: {
70 emptyText: '{memoryEmptyText}',
71 disabled: '{matchNonGUIOption}',
72 },
73 }],
74 });
75
76 Ext.define('PVE.qemu.DisplayEdit', {
77 extend: 'Proxmox.window.Edit',
78
79 vmconfig: undefined,
80
81 subject: gettext('Display'),
82 width: 350,
83
84 items: [{
85 xtype: 'pveDisplayInputPanel',
86 }],
87
88 initComponent: function() {
89 let me = this;
90
91 me.callParent();
92
93 me.load({
94 success: function(response) {
95 me.vmconfig = response.result.data;
96 let vga = me.vmconfig.vga || '__default__';
97 me.setValues(PVE.Parser.parsePropertyString(vga, 'type'));
98 },
99 });
100 },
101 });