]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/qemu/BootOrderEdit.js
use windowEdit from widget toolkit
[pve-manager.git] / www / manager6 / qemu / BootOrderEdit.js
CommitLineData
638a57e7
DM
1Ext.define('PVE.qemu.BootOrderPanel', {
2 extend: 'PVE.panel.InputPanel',
adaac36f 3 alias: 'widget.pveQemuBootOrderPanel',
638a57e7
DM
4 vmconfig: {}, // store loaded vm config
5
6 bootdisk: undefined,
adaac36f
DC
7 selection: [],
8 list: [],
9e7b4d8d 9 comboboxes: [],
638a57e7 10
4edfc518 11 isBootDisk: function(value) {
98a01af2 12 return PVE.Utils.bus_match.test(value);
4edfc518
DC
13 },
14
638a57e7
DM
15 setVMConfig: function(vmconfig) {
16 var me = this;
638a57e7 17 me.vmconfig = vmconfig;
638a57e7 18 var order = me.vmconfig.boot || 'cdn';
adaac36f
DC
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) {
4edfc518 28 if (me.isBootDisk(key) &&
adaac36f
DC
29 !(/media=cdrom/).test(value)) {
30 me.list.push([key, "Disk '" + key + "'"]);
31 }
32 });
638a57e7 33
adaac36f
DC
34 me.list.push(['d', 'CD-ROM']);
35 me.list.push(['n', gettext('Network')]);
e7ade592 36 me.list.push(['__none__', Proxmox.Utils.noneText]);
638a57e7 37
adaac36f 38 me.recomputeList();
9e7b4d8d
DC
39
40 me.comboboxes.forEach(function(box) {
41 box.resetOriginalValue();
42 });
638a57e7
DM
43 },
44
adaac36f 45 onGetValues: function(values) {
638a57e7 46 var me = this;
adaac36f
DC
47 var order = me.selection.join('');
48 var res = { boot: order };
638a57e7 49
adaac36f 50 if (me.bootdisk && order.indexOf('c') !== -1) {
ec0bd652 51 res.bootdisk = me.bootdisk;
adaac36f
DC
52 } else {
53 res['delete'] = 'bootdisk';
638a57e7
DM
54 }
55
adaac36f 56 return res;
638a57e7
DM
57 },
58
adaac36f
DC
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
4edfc518 67 if ((val === newVal || (me.isBootDisk(val) && me.isBootDisk(newVal))) &&
adaac36f
DC
68 item.name !== combobox.name &&
69 newVal !== '__none__') {
70 // swap items
71 val = oldVal;
72 }
638a57e7 73
adaac36f 74 // push 'c','d' or 'n' in the array
4edfc518 75 if (me.isBootDisk(val)) {
adaac36f
DC
76 me.selection.push('c');
77 me.bootdisk = val;
78 } else if (val === 'd' ||
79 val === 'n') {
80 me.selection.push(val);
81 }
82 });
638a57e7 83
adaac36f 84 me.recomputeList();
638a57e7
DM
85 },
86
adaac36f 87 recomputeList: function(){
638a57e7 88 var me = this;
adaac36f
DC
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));
638a57e7 95 } else {
adaac36f 96 item.store.loadData(me.list);
638a57e7 97 }
9e7b4d8d 98 item.suspendEvent('change');
adaac36f
DC
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('');
638a57e7 103 } else {
adaac36f 104 item.setValue('__none__');
638a57e7 105 }
adaac36f 106 cnt++;
9e7b4d8d 107 item.resumeEvent('change');
adaac36f 108 item.validate();
638a57e7 109 });
adaac36f 110 },
638a57e7 111
adaac36f
DC
112 initComponent : function() {
113 var me = this;
638a57e7 114
adaac36f
DC
115 // this has to be done here, because of
116 // the way our inputPanel class handles items
117 me.comboboxes = [
09cacce7 118 Ext.createWidget('proxmoxKVComboBox', {
adaac36f
DC
119 fieldLabel: gettext('Boot device') + " 1",
120 labelWidth: 120,
121 name: 'bd1',
122 allowBlank: false,
123 listeners: {
22f2f9d6 124 change: me.recomputeSelection
adaac36f
DC
125 }
126 }),
09cacce7 127 Ext.createWidget('proxmoxKVComboBox', {
adaac36f
DC
128 fieldLabel: gettext('Boot device') + " 2",
129 labelWidth: 120,
130 name: 'bd2',
131 allowBlank: false,
132 listeners: {
22f2f9d6 133 change: me.recomputeSelection
adaac36f
DC
134 }
135 }),
09cacce7 136 Ext.createWidget('proxmoxKVComboBox', {
adaac36f
DC
137 fieldLabel: gettext('Boot device') + " 3",
138 labelWidth: 120,
139 name: 'bd3',
140 allowBlank: false,
141 listeners: {
22f2f9d6 142 change: me.recomputeSelection
adaac36f 143 }
22f2f9d6 144 })
adaac36f
DC
145 ];
146 Ext.apply(me, { items: me.comboboxes });
638a57e7
DM
147 me.callParent();
148 }
149});
150
151Ext.define('PVE.qemu.BootOrderEdit', {
9fccc702 152 extend: 'Proxmox.window.Edit',
638a57e7 153
ec0bd652 154 items: [{
adaac36f 155 xtype: 'pveQemuBootOrderPanel',
ec0bd652
DC
156 itemId: 'inputpanel'
157 }],
638a57e7 158
adaac36f 159 subject: gettext('Boot Order'),
638a57e7 160
adaac36f
DC
161 initComponent : function() {
162 var me = this;
638a57e7 163 me.callParent();
638a57e7
DM
164 me.load({
165 success: function(response, options) {
adaac36f 166 me.down('#inputpanel').setVMConfig(response.result.data);
638a57e7
DM
167 }
168 });
169 }
170});