]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/BootOrderEdit.js
use InputPanel from widget toolkit
[pve-manager.git] / www / manager6 / qemu / BootOrderEdit.js
1 Ext.define('PVE.qemu.BootOrderPanel', {
2 extend: 'Proxmox.panel.InputPanel',
3 alias: 'widget.pveQemuBootOrderPanel',
4 vmconfig: {}, // store loaded vm config
5
6 bootdisk: undefined,
7 selection: [],
8 list: [],
9 comboboxes: [],
10
11 isBootDisk: function(value) {
12 return PVE.Utils.bus_match.test(value);
13 },
14
15 setVMConfig: function(vmconfig) {
16 var me = this;
17 me.vmconfig = vmconfig;
18 var order = me.vmconfig.boot || 'cdn';
19 me.bootdisk = me.vmconfig.bootdisk || undefined;
20
21 // get the first 3 characters
22 // ignore the rest (there should never be more than 3)
23 me.selection = order.split('').slice(0,3);
24
25 // build bootdev list
26 me.list = [];
27 Ext.Object.each(me.vmconfig, function(key, value) {
28 if (me.isBootDisk(key) &&
29 !(/media=cdrom/).test(value)) {
30 me.list.push([key, "Disk '" + key + "'"]);
31 }
32 });
33
34 me.list.push(['d', 'CD-ROM']);
35 me.list.push(['n', gettext('Network')]);
36 me.list.push(['__none__', Proxmox.Utils.noneText]);
37
38 me.recomputeList();
39
40 me.comboboxes.forEach(function(box) {
41 box.resetOriginalValue();
42 });
43 },
44
45 onGetValues: function(values) {
46 var me = this;
47 var order = me.selection.join('');
48 var res = { boot: order };
49
50 if (me.bootdisk && order.indexOf('c') !== -1) {
51 res.bootdisk = me.bootdisk;
52 } else {
53 res['delete'] = 'bootdisk';
54 }
55
56 return res;
57 },
58
59 recomputeSelection: function(combobox, newVal, oldVal) {
60 var me = this.up('#inputpanel');
61 me.selection = [];
62 me.comboboxes.forEach(function(item) {
63 var val = item.getValue();
64
65 // when selecting an already selected item,
66 // switch it around
67 if ((val === newVal || (me.isBootDisk(val) && me.isBootDisk(newVal))) &&
68 item.name !== combobox.name &&
69 newVal !== '__none__') {
70 // swap items
71 val = oldVal;
72 }
73
74 // push 'c','d' or 'n' in the array
75 if (me.isBootDisk(val)) {
76 me.selection.push('c');
77 me.bootdisk = val;
78 } else if (val === 'd' ||
79 val === 'n') {
80 me.selection.push(val);
81 }
82 });
83
84 me.recomputeList();
85 },
86
87 recomputeList: function(){
88 var me = this;
89 // set the correct values in the kvcomboboxes
90 var cnt = 0;
91 me.comboboxes.forEach(function(item) {
92 if (cnt === 0) {
93 // never show 'none' on first combobox
94 item.store.loadData(me.list.slice(0, me.list.length-1));
95 } else {
96 item.store.loadData(me.list);
97 }
98 item.suspendEvent('change');
99 if (cnt < me.selection.length) {
100 item.setValue((me.selection[cnt] !== 'c')?me.selection[cnt]:me.bootdisk);
101 } else if (cnt === 0){
102 item.setValue('');
103 } else {
104 item.setValue('__none__');
105 }
106 cnt++;
107 item.resumeEvent('change');
108 item.validate();
109 });
110 },
111
112 initComponent : function() {
113 var me = this;
114
115 // this has to be done here, because of
116 // the way our inputPanel class handles items
117 me.comboboxes = [
118 Ext.createWidget('proxmoxKVComboBox', {
119 fieldLabel: gettext('Boot device') + " 1",
120 labelWidth: 120,
121 name: 'bd1',
122 allowBlank: false,
123 listeners: {
124 change: me.recomputeSelection
125 }
126 }),
127 Ext.createWidget('proxmoxKVComboBox', {
128 fieldLabel: gettext('Boot device') + " 2",
129 labelWidth: 120,
130 name: 'bd2',
131 allowBlank: false,
132 listeners: {
133 change: me.recomputeSelection
134 }
135 }),
136 Ext.createWidget('proxmoxKVComboBox', {
137 fieldLabel: gettext('Boot device') + " 3",
138 labelWidth: 120,
139 name: 'bd3',
140 allowBlank: false,
141 listeners: {
142 change: me.recomputeSelection
143 }
144 })
145 ];
146 Ext.apply(me, { items: me.comboboxes });
147 me.callParent();
148 }
149 });
150
151 Ext.define('PVE.qemu.BootOrderEdit', {
152 extend: 'Proxmox.window.Edit',
153
154 items: [{
155 xtype: 'pveQemuBootOrderPanel',
156 itemId: 'inputpanel'
157 }],
158
159 subject: gettext('Boot Order'),
160
161 initComponent : function() {
162 var me = this;
163 me.callParent();
164 me.load({
165 success: function(response, options) {
166 me.down('#inputpanel').setVMConfig(response.result.data);
167 }
168 });
169 }
170 });