]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/form/ControllerSelector.js
1 Ext
.define('PVE.form.ControllerSelector', {
2 extend
: 'Ext.form.FieldContainer',
3 alias
: 'widget.pveControllerSelector',
18 vmconfig
: {}, // used to check for existing devices
20 sortByPreviousUsage: function(vmconfig
, controllerList
) {
23 var usedControllers
= Ext
.clone(PVE
.form
.ControllerSelector
.maxIds
);
26 for (type
in usedControllers
) {
27 if(usedControllers
.hasOwnProperty(type
)) {
28 usedControllers
[type
] = 0;
33 for (property
in vmconfig
) {
34 if (vmconfig
.hasOwnProperty(property
)) {
35 if (property
.match(PVE
.Utils
.bus_match
) && !vmconfig
[property
].match(/media=cdrom/)) {
36 var foundController
= property
.match(PVE
.Utils
.bus_match
)[1];
37 usedControllers
[foundController
]++;
42 var vmDefaults
= PVE
.qemu
.OSDefaults
[vmconfig
.ostype
];
44 var sortPriority
= vmDefaults
&& vmDefaults
.busPriority
45 ? vmDefaults
.busPriority
: PVE
.qemu
.OSDefaults
.generic
;
47 var sortedList
= Ext
.clone(controllerList
);
48 sortedList
.sort(function(a
,b
) {
49 if (usedControllers
[b
] == usedControllers
[a
]) {
50 return sortPriority
[b
] - sortPriority
[a
];
52 return usedControllers
[b
] - usedControllers
[a
];
58 setVMConfig: function(vmconfig
, autoSelect
) {
61 me
.vmconfig
= Ext
.apply({}, vmconfig
);
63 var clist
= ['ide', 'virtio', 'scsi', 'sata'];
64 if (autoSelect
=== 'cdrom') {
65 clist
= ['ide', 'scsi', 'sata'];
66 if (!Ext
.isDefined(me
.vmconfig
.ide2
)) {
67 me
.down('field[name=controller]').setValue('ide');
68 me
.down('field[name=deviceid]').setValue(2);
72 // in most cases we want to add a disk to the same controller
74 clist
= me
.sortByPreviousUsage(me
.vmconfig
, clist
);
77 Ext
.Array
.each(clist
, function(controller
) {
79 if ((controller
=== 'virtio' && me
.noVirtIO
) ||
80 (controller
=== 'scsi' && me
.noScsi
)) {
83 me
.down('field[name=controller]').setValue(controller
);
84 for (i
= 0; i
<= PVE
.form
.ControllerSelector
.maxIds
[controller
]; i
++) {
85 confid
= controller
+ i
.toString();
86 if (!Ext
.isDefined(me
.vmconfig
[confid
])) {
87 me
.down('field[name=deviceid]').setValue(i
);
88 return false; // break
93 me
.down('field[name=deviceid]').validate();
96 initComponent: function() {
100 fieldLabel
: gettext('Bus/Device'),
108 xtype
: 'pveBusSelector',
110 value
: PVE
.qemu
.OSDefaults
.generic
.busType
,
111 noVirtIO
: me
.noVirtIO
,
115 change: function(t
, value
) {
116 if (!me
.rendered
|| !value
) {
119 var field
= me
.down('field[name=deviceid]');
120 field
.setMaxValue(PVE
.form
.ControllerSelector
.maxIds
[value
]);
126 xtype
: 'numberfield',
129 maxValue
: PVE
.form
.ControllerSelector
.maxIds
.ide
,
131 validator: function(value
) {
132 /*jslint confusion: true */
136 var field
= me
.down('field[name=controller]');
137 var controller
= field
.getValue();
138 var confid
= controller
+ value
;
139 if (Ext
.isDefined(me
.vmconfig
[confid
])) {
140 return "This device is already in use.";