]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/OSTypeEdit.js
refactor OSDefaults, OSTypeEdit: add and use getDefaults
[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 'radiogroup': {
11 change: 'onOSTypeChange'
12 }
13 },
14 onOSTypeChange: function(field) {
15 var me = this, ostype = field.getValue();
16 if (!me.getView().insideWizard) {
17 return;
18 }
19 var targetValues = PVE.qemu.OSDefaults.getDefaults(ostype);
20
21 me.setWidget('pveBusSelector', targetValues.busType);
22 me.setWidget('pveNetworkCardSelector', targetValues.networkCard);
23 me.setWizardHiddenValue('qemuScsiController', targetValues.scsihw);
24 },
25 setWidget: function(widget, newValue) {
26 // changing a widget is safe only if ComponentQuery.query returns us
27 // a single value array
28 var widgets = Ext.ComponentQuery.query('pveQemuCreateWizard ' + widget);
29 if (widgets.length === 1) {
30 widgets[0].setValue(newValue);
31 } else {
32 throw 'non unique widget :' + widget + ' in Wizard';
33 }
34 },
35 setWizardHiddenValue: function(property, newValue) {
36 var wizards = Ext.ComponentQuery.query('pveQemuCreateWizard ');
37 if (wizards.length === 1) {
38 wizards[0][property] = newValue;
39 } else {
40 throw 'non unique wizard, unable to set ' + property;
41 }
42 }
43 },
44
45 initComponent : function() {
46 var me = this;
47
48 me.column1 = [
49 {
50 xtype: 'component',
51 html: 'Microsoft Windows',
52 cls:'x-form-check-group-label'
53 },
54 {
55 xtype: 'radiofield',
56 name: 'ostype',
57 inputValue: 'win10'
58 },
59 {
60 xtype: 'radiofield',
61 name: 'ostype',
62 inputValue: 'win8'
63 },
64 {
65 xtype: 'radiofield',
66 name: 'ostype',
67 inputValue: 'win7'
68 },
69 {
70 xtype: 'radiofield',
71 name: 'ostype',
72 inputValue: 'w2k8'
73 },
74 {
75 xtype: 'radiofield',
76 name: 'ostype',
77 inputValue: 'wxp'
78 },
79 {
80 xtype: 'radiofield',
81 name: 'ostype',
82 inputValue: 'w2k'
83 }
84 ];
85
86 me.column2 = [
87 {
88 xtype: 'component',
89 html: 'Linux/' + gettext('Other OS types'),
90 cls:'x-form-check-group-label'
91 },
92 {
93 xtype: 'radiofield',
94 name: 'ostype',
95 inputValue: 'l26'
96 },
97 {
98 xtype: 'radiofield',
99 name: 'ostype',
100 inputValue: 'l24'
101 },
102 {
103 xtype: 'radiofield',
104 name: 'ostype',
105 inputValue: 'solaris'
106 },
107 {
108 xtype: 'radiofield',
109 name: 'ostype',
110 inputValue: 'other'
111 }
112 ];
113
114 Ext.Array.each(me.column1, function(def) {
115 if (def.inputValue) {
116 def.boxLabel = PVE.Utils.render_kvm_ostype(def.inputValue);
117 }
118 });
119 Ext.Array.each(me.column2, function(def) {
120 if (def.inputValue) {
121 def.boxLabel = PVE.Utils.render_kvm_ostype(def.inputValue);
122 }
123 });
124
125 Ext.apply(me, {
126 useFieldContainer: {
127 xtype: 'radiogroup',
128 allowBlank: false
129 }
130 });
131
132 me.callParent();
133 }
134 });
135
136 Ext.define('PVE.qemu.OSTypeEdit', {
137 extend: 'PVE.window.Edit',
138
139 initComponent : function() {
140 var me = this;
141
142 Ext.apply(me, {
143 subject: 'OS Type',
144 items: Ext.create('PVE.qemu.OSTypeInputPanel')
145 });
146
147 me.callParent();
148
149 me.load({
150 success: function(response, options) {
151 var value = response.result.data.ostype || 'other';
152 me.setValues({ ostype: value});
153 }
154 });
155 }
156 });