]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/OSTypeEdit.js
OSType edit: switch to combobox
[pve-manager.git] / www / manager6 / qemu / OSTypeEdit.js
1 Ext.define('PVE.qemu.OSTypeInputPanel', {
2 extend: 'PVE.panel.InputPanel',
3 alias: 'widget.pveQemuOSTypePanel',
4 onlineHelp: 'qm_os_settings',
5 insideWizard: false,
6
7 controller: {
8 xclass: 'Ext.app.ViewController',
9 control: {
10 'combobox[name=osbase]': {
11 change: 'onOSBaseChange'
12 },
13 'combobox[name=ostype]': {
14 afterrender: 'onOSTypeChange',
15 change: 'onOSTypeChange'
16 }
17 },
18 onOSBaseChange: function(field, value) {
19 this.lookup('ostype').getStore().setData(PVE.Utils.kvm_ostypes[value]);
20 },
21 onOSTypeChange: function(field) {
22 var me = this, ostype = field.getValue();
23 if (!me.getView().insideWizard) {
24 return;
25 }
26 var targetValues = PVE.qemu.OSDefaults.getDefaults(ostype);
27
28 me.setWidget('pveBusSelector', targetValues.busType);
29 me.setWidget('pveNetworkCardSelector', targetValues.networkCard);
30 me.setWizardHiddenValue('qemuScsiController', targetValues.scsihw);
31 },
32 setWidget: function(widget, newValue) {
33 // changing a widget is safe only if ComponentQuery.query returns us
34 // a single value array
35 var widgets = Ext.ComponentQuery.query('pveQemuCreateWizard ' + widget);
36 if (widgets.length === 1) {
37 widgets[0].setValue(newValue);
38 } else {
39 throw 'non unique widget :' + widget + ' in Wizard';
40 }
41 },
42 setWizardHiddenValue: function(property, newValue) {
43 var wizards = Ext.ComponentQuery.query('pveQemuCreateWizard ');
44 if (wizards.length === 1) {
45 wizards[0][property] = newValue;
46 } else {
47 throw 'non unique wizard, unable to set ' + property;
48 }
49 }
50 },
51
52 initComponent : function() {
53 var me = this;
54
55 /*jslint confusion: true */
56 me.items = [
57 {
58 xtype: 'displayfield',
59 value: gettext('Guest OS') + ':',
60 hidden: !me.insideWizard
61 },
62 {
63 xtype: 'combobox',
64 submitValue: false,
65 name: 'osbase',
66 fieldLabel: gettext('Type'),
67 editable: false,
68 queryMode: 'local',
69 value: 'Linux',
70 store: Object.keys(PVE.Utils.kvm_ostypes)
71 },
72 {
73 xtype: 'combobox',
74 name: 'ostype',
75 reference: 'ostype',
76 fieldLabel: gettext('Version'),
77 value: 'l26',
78 allowBlank : false,
79 editable: false,
80 queryMode: 'local',
81 valueField: 'val',
82 displayField: 'desc',
83 store: {
84 fields: ['desc', 'val'],
85 data: PVE.Utils.kvm_ostypes.Linux,
86 listeners: {
87 datachanged: function (store) {
88 var ostype = me.lookup('ostype');
89 var old_val = ostype.getValue();
90 if (!me.insideWizard && old_val && store.find('val', old_val) != -1) {
91 ostype.setValue(old_val);
92 } else {
93 ostype.setValue(store.getAt(0));
94 }
95 }
96 }
97 }
98 }
99 ];
100 /*jslint confusion: false */
101
102 me.callParent();
103 }
104 });
105
106 Ext.define('PVE.qemu.OSTypeEdit', {
107 extend: 'PVE.window.Edit',
108
109 initComponent : function() {
110 var me = this;
111
112 Ext.apply(me, {
113 subject: 'OS Type',
114 items: [{ xtype: 'pveQemuOSTypePanel' }]
115 });
116
117 me.callParent();
118
119 me.load({
120 success: function(response, options) {
121 var value = response.result.data.ostype || 'other';
122 var osinfo = PVE.Utils.get_kvm_osinfo(value);
123 me.setValues({ ostype: value, osbase: osinfo.base });
124 }
125 });
126 }
127 });