]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/Utils.js
ui: tfa selector code/spelling nit fix
[pve-manager.git] / www / manager6 / Utils.js
CommitLineData
b0a6d326
EK
1Ext.ns('PVE');
2
63b9faae
EK
3// avoid errors related to Accessible Rich Internet Applications
4// (access for people with disabilities)
0be88ae1 5// TODO reenable after all components are upgraded
63b9faae
EK
6Ext.enableAria = false;
7Ext.enableAriaButtons = false;
8Ext.enableAriaPanels = false;
9
b0a6d326 10// avoid errors when running without development tools
0be88ae1
DC
11if (!Ext.isDefined(Ext.global.console)) {
12 var console = {
0be88ae1 13 log: function() {}
b0a6d326
EK
14 };
15}
0be88ae1 16console.log("Starting PVE Manager");
b0a6d326
EK
17
18Ext.Ajax.defaultHeaders = {
19 'Accept': 'application/json'
20};
21
89ae1bb1 22/*jslint confusion: true */
9fa2e36d 23Ext.define('PVE.Utils', { utilities: {
b0a6d326 24
9fa2e36d 25 // this singleton contains miscellaneous utilities
b0a6d326 26
0be88ae1 27 toolkit: undefined, // (extjs|touch), set inside Toolkit.js
b0a6d326 28
98a01af2
EK
29 bus_match: /^(ide|sata|virtio|scsi)\d+$/,
30
b0a6d326
EK
31 log_severity_hash: {
32 0: "panic",
33 1: "alert",
34 2: "critical",
35 3: "error",
36 4: "warning",
37 5: "notice",
38 6: "info",
39 7: "debug"
40 },
41
42 support_level_hash: {
43 'c': gettext('Community'),
44 'b': gettext('Basic'),
45 's': gettext('Standard'),
46 'p': gettext('Premium')
47 },
48
8ec8af9c 49 noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.',
b0a6d326
EK
50
51 kvm_ostypes: {
45d6c71a 52 'Linux': [
ca71cd5d 53 { desc: '5.x - 2.6 Kernel', val: 'l26' },
45d6c71a
TL
54 { desc: '2.4 Kernel', val: 'l24' }
55 ],
56 'Microsoft Windows': [
beb3c8a4 57 { desc: '10/2016/2019', val: 'win10' },
45d6c71a
TL
58 { desc: '8.x/2012/2012r2', val: 'win8' },
59 { desc: '7/2008r2', val: 'win7' },
60 { desc: 'Vista/2008', val: 'w2k8' },
61 { desc: 'XP/2003', val: 'wxp' },
62 { desc: '2000', val: 'w2k' }
63 ],
64 'Solaris Kernel': [
65 { desc: '-', val: 'solaris'}
66 ],
67 'Other': [
68 { desc: '-', val: 'other'}
69 ]
b0a6d326
EK
70 },
71
428bc4a2
DC
72 get_health_icon: function(state, circle) {
73 if (circle === undefined) {
74 circle = false;
75 }
76
77 if (state === undefined) {
78 state = 'uknown';
79 }
80
81 var icon = 'faded fa-question';
82 switch(state) {
83 case 'good':
84 icon = 'good fa-check';
85 break;
23c83a3a
DC
86 case 'upgrade':
87 icon = 'warning fa-upload';
88 break;
aa240b29
DC
89 case 'old':
90 icon = 'warning fa-refresh';
91 break;
428bc4a2
DC
92 case 'warning':
93 icon = 'warning fa-exclamation';
94 break;
95 case 'critical':
96 icon = 'critical fa-times';
97 break;
98 default: break;
99 }
100
101 if (circle) {
102 icon += '-circle';
103 }
104
105 return icon;
106 },
107
95d0de89
DC
108 parse_ceph_version: function(service) {
109 if (service.ceph_version_short) {
110 return service.ceph_version_short;
111 }
112
113 if (service.ceph_version) {
35306f47 114 var match = service.ceph_version.match(/version (\d+(\.\d+)*)/);
95d0de89
DC
115 if (match) {
116 return match[1];
117 }
118 }
119
120 return undefined;
121 },
122
005e0a60 123 compare_ceph_versions: function(a, b) {
3a08795a
DC
124 let avers = [];
125 let bvers = [];
126
005e0a60
DC
127 if (a === b) {
128 return 0;
129 }
3a08795a
DC
130
131 if (Ext.isArray(a)) {
132 avers = a.slice(); // copy array
133 } else {
134 avers = a.toString().split('.');
135 }
136
137 if (Ext.isArray(b)) {
138 bvers = b.slice(); // copy array
139 } else {
140 bvers = b.toString().split('.');
141 }
35306f47
TL
142
143 while (true) {
144 let av = avers.shift();
145 let bv = bvers.shift();
146
147 if (av === undefined && bv === undefined) {
148 return 0;
149 } else if (av === undefined) {
150 return -1;
151 } else if (bv === undefined) {
152 return 1;
153 } else {
154 let diff = parseInt(av, 10) - parseInt(bv, 10);
155 if (diff != 0) return diff;
156 // else we need to look at the next parts
005e0a60
DC
157 }
158 }
159
005e0a60
DC
160 },
161
2f5b82ae
DC
162 get_ceph_icon_html: function(health, fw) {
163 var state = PVE.Utils.map_ceph_health[health];
164 var cls = PVE.Utils.get_health_icon(state);
165 if (fw) {
166 cls += ' fa-fw';
167 }
168 return "<i class='fa " + cls + "'></i> ";
169 },
170
046e640c
DC
171 map_ceph_health: {
172 'HEALTH_OK':'good',
23c83a3a 173 'HEALTH_UPGRADE':'upgrade',
aa240b29 174 'HEALTH_OLD':'old',
046e640c
DC
175 'HEALTH_WARN':'warning',
176 'HEALTH_ERR':'critical'
177 },
178
dfe6d184 179 render_ceph_health: function(healthObj) {
046e640c
DC
180 var state = {
181 iconCls: PVE.Utils.get_health_icon(),
182 text: ''
183 };
184
dfe6d184 185 if (!healthObj || !healthObj.status) {
046e640c
DC
186 return state;
187 }
188
dfe6d184 189 var health = PVE.Utils.map_ceph_health[healthObj.status];
046e640c
DC
190
191 state.iconCls = PVE.Utils.get_health_icon(health, true);
dfe6d184 192 state.text = healthObj.status;
046e640c
DC
193
194 return state;
195 },
196
fee716d3 197 render_zfs_health: function(value) {
8c8604ba
TM
198 if (typeof value == 'undefined'){
199 return "";
200 }
fee716d3
DC
201 var iconCls = 'question-circle';
202 switch (value) {
8c8604ba 203 case 'AVAIL':
fee716d3
DC
204 case 'ONLINE':
205 iconCls = 'check-circle good';
206 break;
207 case 'REMOVED':
208 case 'DEGRADED':
209 iconCls = 'exclamation-circle warning';
210 break;
211 case 'UNAVAIL':
212 case 'FAULTED':
213 case 'OFFLINE':
214 iconCls = 'times-circle critical';
215 break;
216 default: //unknown
217 }
218
219 return '<i class="fa fa-' + iconCls + '"></i> ' + value;
8c8604ba 220
fee716d3
DC
221 },
222
45d6c71a
TL
223 get_kvm_osinfo: function(value) {
224 var info = { base: 'Other' }; // default
225 if (value) {
226 Ext.each(Object.keys(PVE.Utils.kvm_ostypes), function(k) {
227 Ext.each(PVE.Utils.kvm_ostypes[k], function(e) {
228 if (e.val === value) {
229 info = { desc: e.desc, base: k };
230 }
231 });
232 });
b0a6d326 233 }
45d6c71a
TL
234 return info;
235 },
236
237 render_kvm_ostype: function (value) {
238 var osinfo = PVE.Utils.get_kvm_osinfo(value);
239 if (osinfo.desc && osinfo.desc !== '-') {
240 return osinfo.base + ' ' + osinfo.desc;
241 } else {
242 return osinfo.base;
b0a6d326 243 }
b0a6d326
EK
244 },
245
246 render_hotplug_features: function (value) {
23d3881a 247 var fa = [];
b0a6d326
EK
248
249 if (!value || (value === '0')) {
ec99b1c3 250 return gettext('Disabled');
b0a6d326
EK
251 }
252
4dcca8a4
DC
253 if (value === '1') {
254 value = 'disk,network,usb';
255 }
256
b0a6d326
EK
257 Ext.each(value.split(','), function(el) {
258 if (el === 'disk') {
259 fa.push(gettext('Disk'));
260 } else if (el === 'network') {
261 fa.push(gettext('Network'));
262 } else if (el === 'usb') {
b9628aa5 263 fa.push('USB');
b0a6d326
EK
264 } else if (el === 'memory') {
265 fa.push(gettext('Memory'));
266 } else if (el === 'cpu') {
267 fa.push(gettext('CPU'));
268 } else {
269 fa.push(el);
270 }
271 });
272
273 return fa.join(', ');
274 },
275
1662ccdb
SI
276 render_qga_features: function(value) {
277 if (!value) {
278 return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText + ')';
279 }
280 var props = PVE.Parser.parsePropertyString(value, 'enabled');
281 if (!PVE.Parser.parseBoolean(props.enabled)) {
282 return Proxmox.Utils.disabledText;
283 }
284
285 delete props.enabled;
286 var agentstring = Proxmox.Utils.enabledText;
287
288 Ext.Object.each(props, function(key, value) {
289 var keystring = '' ;
290 agentstring += ', ' + key + ': ';
291
5a6c563c
MD
292 if (key === 'type') {
293 let map = {
294 isa: "ISA",
176a62d3 295 virtio: "VirtIO",
5a6c563c
MD
296 };
297 agentstring += map[value] || Proxmox.Utils.unknownText;
1662ccdb 298 } else {
5a6c563c
MD
299 if (PVE.Parser.parseBoolean(value)) {
300 agentstring += Proxmox.Utils.enabledText;
301 } else {
302 agentstring += Proxmox.Utils.disabledText;
303 }
1662ccdb
SI
304 }
305 });
306
307 return agentstring;
308 },
309
a1ee14a2
DC
310 render_qemu_machine: function(value) {
311 return value || (Proxmox.Utils.defaultText + ' (i440fx)');
312 },
313
17c71f27
DC
314 render_qemu_bios: function(value) {
315 if (!value) {
e7ade592 316 return Proxmox.Utils.defaultText + ' (SeaBIOS)';
17c71f27
DC
317 } else if (value === 'seabios') {
318 return "SeaBIOS";
319 } else if (value === 'ovmf') {
320 return "OVMF (UEFI)";
321 } else {
322 return value;
323 }
324 },
325
8f17b496
TL
326 render_dc_ha_opts: function(value) {
327 if (!value) {
41ca3465 328 return Proxmox.Utils.defaultText;
8f17b496
TL
329 } else {
330 return PVE.Parser.printPropertyString(value);
331 }
332 },
bb469a11
TL
333 render_as_property_string: function(value) {
334 return (!value) ? Proxmox.Utils.defaultText
335 : PVE.Parser.printPropertyString(value);
336 },
8f17b496 337
b0a6d326
EK
338 render_scsihw: function(value) {
339 if (!value) {
e7ade592 340 return Proxmox.Utils.defaultText + ' (LSI 53C895A)';
b0a6d326
EK
341 } else if (value === 'lsi') {
342 return 'LSI 53C895A';
343 } else if (value === 'lsi53c810') {
344 return 'LSI 53C810';
345 } else if (value === 'megasas') {
346 return 'MegaRAID SAS 8708EM2';
347 } else if (value === 'virtio-scsi-pci') {
49f5d1ab
EK
348 return 'VirtIO SCSI';
349 } else if (value === 'virtio-scsi-single') {
350 return 'VirtIO SCSI single';
b0a6d326
EK
351 } else if (value === 'pvscsi') {
352 return 'VMware PVSCSI';
353 } else {
354 return value;
355 }
356 },
357
9c22da32 358 render_spice_enhancements: function(values) {
9c22da32
AL
359 let props = PVE.Parser.parsePropertyString(values);
360 if (Ext.Object.isEmpty(props)) {
3b0facc9 361 return Proxmox.Utils.noneText;
9c22da32
AL
362 }
363
364 let output = [];
365 if (PVE.Parser.parseBoolean(props.foldersharing)) {
366 output.push('Folder Sharing: ' + gettext('Enabled'));
367 }
368 if (props.videostreaming === 'all' || props.videostreaming === 'filter') {
369 output.push('Video Streaming: ' + props.videostreaming);
370 }
371 return output.join(', ');
372 },
373
b0a6d326
EK
374 // fixme: auto-generate this
375 // for now, please keep in sync with PVE::Tools::kvmkeymaps
376 kvm_keymaps: {
377 //ar: 'Arabic',
378 da: 'Danish',
0be88ae1
DC
379 de: 'German',
380 'de-ch': 'German (Swiss)',
381 'en-gb': 'English (UK)',
0a5b8747 382 'en-us': 'English (USA)',
b0a6d326
EK
383 es: 'Spanish',
384 //et: 'Estonia',
385 fi: 'Finnish',
0be88ae1
DC
386 //fo: 'Faroe Islands',
387 fr: 'French',
388 'fr-be': 'French (Belgium)',
b0a6d326
EK
389 'fr-ca': 'French (Canada)',
390 'fr-ch': 'French (Swiss)',
391 //hr: 'Croatia',
392 hu: 'Hungarian',
393 is: 'Icelandic',
0be88ae1 394 it: 'Italian',
b0a6d326
EK
395 ja: 'Japanese',
396 lt: 'Lithuanian',
397 //lv: 'Latvian',
0be88ae1 398 mk: 'Macedonian',
b0a6d326
EK
399 nl: 'Dutch',
400 //'nl-be': 'Dutch (Belgium)',
0be88ae1 401 no: 'Norwegian',
b0a6d326
EK
402 pl: 'Polish',
403 pt: 'Portuguese',
404 'pt-br': 'Portuguese (Brazil)',
405 //ru: 'Russian',
406 sl: 'Slovenian',
407 sv: 'Swedish',
408 //th: 'Thai',
409 tr: 'Turkish'
410 },
411
412 kvm_vga_drivers: {
413 std: gettext('Standard VGA'),
5ca366f2 414 vmware: gettext('VMware compatible'),
b0a6d326
EK
415 qxl: 'SPICE',
416 qxl2: 'SPICE dual monitor',
417 qxl3: 'SPICE three monitors',
418 qxl4: 'SPICE four monitors',
419 serial0: gettext('Serial terminal') + ' 0',
420 serial1: gettext('Serial terminal') + ' 1',
421 serial2: gettext('Serial terminal') + ' 2',
89ae1bb1
DC
422 serial3: gettext('Serial terminal') + ' 3',
423 virtio: 'VirtIO-GPU',
424 none: Proxmox.Utils.noneText
b0a6d326
EK
425 },
426
427 render_kvm_language: function (value) {
e7ade592
DC
428 if (!value || value === '__default__') {
429 return Proxmox.Utils.defaultText;
b0a6d326
EK
430 }
431 var text = PVE.Utils.kvm_keymaps[value];
432 if (text) {
433 return text + ' (' + value + ')';
434 }
435 return value;
436 },
437
438 kvm_keymap_array: function() {
f2782813 439 var data = [['__default__', PVE.Utils.render_kvm_language('')]];
b0a6d326
EK
440 Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) {
441 data.push([key, PVE.Utils.render_kvm_language(value)]);
442 });
443
444 return data;
445 },
446
3438c27e 447 console_map: {
da9d14cd 448 '__default__': Proxmox.Utils.defaultText + ' (xterm.js)',
3438c27e
DC
449 'vv': 'SPICE (remote-viewer)',
450 'html5': 'HTML5 (noVNC)',
4ace5c6f 451 'xtermjs': 'xterm.js'
3438c27e
DC
452 },
453
b0a6d326 454 render_console_viewer: function(value) {
3438c27e
DC
455 value = value || '__default__';
456 if (PVE.Utils.console_map[value]) {
457 return PVE.Utils.console_map[value];
b0a6d326 458 }
3438c27e 459 return value;
b0a6d326
EK
460 },
461
755b9083 462 console_viewer_array: function() {
3438c27e 463 return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) {
755b9083
TL
464 return [v, PVE.Utils.render_console_viewer(v)];
465 });
466 },
467
b0a6d326
EK
468 render_kvm_vga_driver: function (value) {
469 if (!value) {
e7ade592 470 return Proxmox.Utils.defaultText;
b0a6d326 471 }
4f3e66d8
DC
472 var vga = PVE.Parser.parsePropertyString(value, 'type');
473 var text = PVE.Utils.kvm_vga_drivers[vga.type];
474 if (!vga.type) {
475 text = Proxmox.Utils.defaultText;
476 }
0be88ae1 477 if (text) {
b0a6d326
EK
478 return text + ' (' + value + ')';
479 }
480 return value;
481 },
482
483 kvm_vga_driver_array: function() {
f2782813 484 var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]];
b0a6d326
EK
485 Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) {
486 data.push([key, PVE.Utils.render_kvm_vga_driver(value)]);
487 });
488
489 return data;
490 },
491
492 render_kvm_startup: function(value) {
493 var startup = PVE.Parser.parseStartup(value);
494
495 var res = 'order=';
496 if (startup.order === undefined) {
497 res += 'any';
498 } else {
499 res += startup.order;
500 }
501 if (startup.up !== undefined) {
502 res += ',up=' + startup.up;
503 }
504 if (startup.down !== undefined) {
505 res += ',down=' + startup.down;
506 }
507
508 return res;
509 },
510
b0a6d326
EK
511 extractFormActionError: function(action) {
512 var msg;
513 switch (action.failureType) {
514 case Ext.form.action.Action.CLIENT_INVALID:
515 msg = gettext('Form fields may not be submitted with invalid values');
516 break;
517 case Ext.form.action.Action.CONNECT_FAILURE:
518 msg = gettext('Connection error');
519 var resp = action.response;
520 if (resp.status && resp.statusText) {
521 msg += " " + resp.status + ": " + resp.statusText;
522 }
523 break;
524 case Ext.form.action.Action.LOAD_FAILURE:
525 case Ext.form.action.Action.SERVER_INVALID:
e7ade592 526 msg = Proxmox.Utils.extractRequestError(action.result, true);
b0a6d326
EK
527 break;
528 }
529 return msg;
530 },
531
b0a6d326 532 format_duration_short: function(ut) {
0be88ae1 533
b0a6d326 534 if (ut < 60) {
530ee6b7 535 return ut.toFixed(1) + 's';
b0a6d326
EK
536 }
537
538 if (ut < 3600) {
539 var mins = ut / 60;
530ee6b7 540 return mins.toFixed(1) + 'm';
b0a6d326
EK
541 }
542
543 if (ut < 86400) {
544 var hours = ut / 3600;
530ee6b7 545 return hours.toFixed(1) + 'h';
b0a6d326
EK
546 }
547
548 var days = ut / 86400;
530ee6b7 549 return days.toFixed(1) + 'd';
b0a6d326
EK
550 },
551
0e244a29
DC
552 contentTypes: {
553 'images': gettext('Disk image'),
554 'backup': gettext('VZDump backup file'),
555 'vztmpl': gettext('Container template'),
556 'iso': gettext('ISO image'),
aef28e04
DC
557 'rootdir': gettext('Container'),
558 'snippets': gettext('Snippets')
0e244a29 559 },
b0a6d326 560
3b8f599b
DM
561 volume_is_qemu_backup: function(volid, format) {
562 return format === 'pbs-vm' || volid.match(':backup/vzdump-qemu-');
563 },
564
565 volume_is_lxc_backup: function(volid, format) {
566 return format === 'pbs-ct' || volid.match(':backup/vzdump-(lxc|openvz)-');
567 },
568
062a7f49
TL
569 storageSchema: {
570 dir: {
571 name: Proxmox.Utils.directoryText,
572 ipanel: 'DirInputPanel',
573 faIcon: 'folder'
574 },
575 lvm: {
576 name: 'LVM',
577 ipanel: 'LVMInputPanel',
578 faIcon: 'folder'
579 },
580 lvmthin: {
581 name: 'LVM-Thin',
582 ipanel: 'LvmThinInputPanel',
583 faIcon: 'folder'
584 },
585 nfs: {
586 name: 'NFS',
587 ipanel: 'NFSInputPanel',
588 faIcon: 'building'
589 },
590 cifs: {
591 name: 'CIFS',
592 ipanel: 'CIFSInputPanel',
593 faIcon: 'building'
594 },
595 glusterfs: {
596 name: 'GlusterFS',
597 ipanel: 'GlusterFsInputPanel',
598 faIcon: 'building'
599 },
600 iscsi: {
601 name: 'iSCSI',
602 ipanel: 'IScsiInputPanel',
603 faIcon: 'building'
604 },
4a4b2b6e
TL
605 cephfs: {
606 name: 'CephFS',
607 ipanel: 'CephFSInputPanel',
608 faIcon: 'building'
609 },
610 pvecephfs: {
611 name: 'CephFS (PVE)',
612 ipanel: 'CephFSInputPanel',
613 hideAdd: true,
614 faIcon: 'building'
615 },
062a7f49
TL
616 rbd: {
617 name: 'RBD',
618 ipanel: 'RBDInputPanel',
062a7f49
TL
619 faIcon: 'building'
620 },
621 pveceph: {
622 name: 'RBD (PVE)',
0d1ac958
TL
623 ipanel: 'RBDInputPanel',
624 hideAdd: true,
062a7f49
TL
625 faIcon: 'building'
626 },
627 zfs: {
628 name: 'ZFS over iSCSI',
629 ipanel: 'ZFSInputPanel',
630 faIcon: 'building'
631 },
632 zfspool: {
633 name: 'ZFS',
634 ipanel: 'ZFSPoolInputPanel',
635 faIcon: 'folder'
636 },
637 drbd: {
638 name: 'DRBD',
639 hideAdd: true
640 }
641 },
642
9233148b
AD
643 sdnvnetSchema: {
644 vnet: {
645 name: 'vnet',
646 faIcon: 'folder'
647 },
648 },
649
650 sdnzoneSchema: {
651 zone: {
652 name: 'zone',
653 hideAdd: true
654 },
655 vlan: {
656 name: 'vlan',
657 ipanel: 'VlanInputPanel',
658 faIcon: 'folder'
659 },
660 qinq: {
661 name: 'qinq',
662 ipanel: 'QinQInputPanel',
663 faIcon: 'folder'
664 },
665 vxlan: {
666 name: 'vxlan',
667 ipanel: 'VxlanInputPanel',
668 faIcon: 'folder'
669 },
670 evpn: {
671 name: 'evpn',
672 ipanel: 'EvpnInputPanel',
673 faIcon: 'folder'
674 },
675 },
676
677 sdncontrollerSchema: {
678 controller: {
679 name: 'controller',
680 hideAdd: true
681 },
682 evpn: {
683 name: 'evpn',
684 ipanel: 'EvpnInputPanel',
685 faIcon: 'folder'
686 },
687 },
688
689 format_sdnvnet_type: function(value, md, record) {
690 var schema = PVE.Utils.sdnvnetSchema[value];
691 if (schema) {
692 return schema.name;
693 }
694 return Proxmox.Utils.unknownText;
695 },
696
697 format_sdnzone_type: function(value, md, record) {
698 var schema = PVE.Utils.sdnzoneSchema[value];
699 if (schema) {
34d0acbd 700 return schema.name.toUpperCase();
9233148b
AD
701 }
702 return Proxmox.Utils.unknownText;
703 },
704
705 format_sdncontroller_type: function(value, md, record) {
706 var schema = PVE.Utils.sdncontrollerSchema[value];
707 if (schema) {
708 return schema.name;
709 }
710 return Proxmox.Utils.unknownText;
711 },
712
3c23c025 713 format_storage_type: function(value, md, record) {
4a4b2b6e
TL
714 if (value === 'rbd') {
715 value = (!record || record.get('monhost') ? 'rbd' : 'pveceph');
716 } else if (value === 'cephfs') {
717 value = (!record || record.get('monhost') ? 'cephfs' : 'pvecephfs');
3c23c025 718 }
062a7f49
TL
719
720 var schema = PVE.Utils.storageSchema[value];
721 if (schema) {
722 return schema.name;
b0a6d326 723 }
062a7f49 724 return Proxmox.Utils.unknownText;
a3b8efb4
EK
725 },
726
ced1677b 727 format_ha: function(value) {
e7ade592 728 var text = Proxmox.Utils.noneText;
ced1677b
TL
729
730 if (value.managed) {
e7ade592 731 text = value.state || Proxmox.Utils.noneText;
ced1677b 732
e7ade592
DC
733 text += ', ' + Proxmox.Utils.groupText + ': ';
734 text += value.group || Proxmox.Utils.noneText;
ced1677b
TL
735 }
736
737 return text;
738 },
739
b0a6d326 740 format_content_types: function(value) {
0e244a29
DC
741 return value.split(',').sort().map(function(ct) {
742 return PVE.Utils.contentTypes[ct] || ct;
743 }).join(', ');
b0a6d326
EK
744 },
745
746 render_storage_content: function(value, metaData, record) {
747 var data = record.data;
748 if (Ext.isNumber(data.channel) &&
749 Ext.isNumber(data.id) &&
750 Ext.isNumber(data.lun)) {
0be88ae1
DC
751 return "CH " +
752 Ext.String.leftPad(data.channel,2, '0') +
b0a6d326
EK
753 " ID " + data.id + " LUN " + data.lun;
754 }
3b8f599b 755 return data.volid.replace(/^.*?:(.*?\/)?/,'');
b0a6d326
EK
756 },
757
758 render_serverity: function (value) {
759 return PVE.Utils.log_severity_hash[value] || value;
760 },
761
762 render_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
763
764 if (!(record.data.uptime && Ext.isNumeric(value))) {
765 return '';
766 }
767
768 var maxcpu = record.data.maxcpu || 1;
769
770 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
771 return '';
772 }
0be88ae1 773
b0a6d326
EK
774 var per = value * 100;
775
776 return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
777 },
778
779 render_size: function(value, metaData, record, rowIndex, colIndex, store) {
780 /*jslint confusion: true */
781
782 if (!Ext.isNumeric(value)) {
783 return '';
784 }
785
e7ade592 786 return Proxmox.Utils.format_size(value);
b0a6d326
EK
787 },
788
946730cd
DC
789 render_bandwidth: function(value) {
790 if (!Ext.isNumeric(value)) {
791 return '';
792 }
793
e7ade592 794 return Proxmox.Utils.format_size(value) + '/s';
b0a6d326
EK
795 },
796
3f633655
EK
797 render_timestamp_human_readable: function(value) {
798 return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s');
799 },
800
ddd26302
DC
801 render_duration: function(value) {
802 if (value === undefined) {
803 return '-';
804 }
805 return PVE.Utils.format_duration_short(value);
806 },
807
0bfc799f
DC
808 calculate_mem_usage: function(data) {
809 if (!Ext.isNumeric(data.mem) ||
810 data.maxmem === 0 ||
811 data.uptime < 1) {
812 return -1;
813 }
814
815 return (data.mem / data.maxmem);
816 },
817
818 render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
819 if (!Ext.isNumeric(value) || value === -1) {
820 return '';
821 }
822 if (value > 1 ) {
823 // we got no percentage but bytes
824 var mem = value;
825 var maxmem = record.data.maxmem;
826 if (!record.data.uptime ||
827 maxmem === 0 ||
828 !Ext.isNumeric(mem)) {
829 return '';
830 }
831
832 return ((mem*100)/maxmem).toFixed(1) + " %";
833 }
834 return (value*100).toFixed(1) + " %";
835 },
836
b0a6d326
EK
837 render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
838
839 var mem = value;
840 var maxmem = record.data.maxmem;
0be88ae1 841
b0a6d326
EK
842 if (!record.data.uptime) {
843 return '';
844 }
845
846 if (!(Ext.isNumeric(mem) && maxmem)) {
847 return '';
848 }
849
728f1b97 850 return PVE.Utils.render_size(value);
b0a6d326
EK
851 },
852
0bfc799f
DC
853 calculate_disk_usage: function(data) {
854
855 if (!Ext.isNumeric(data.disk) ||
856 data.type === 'qemu' ||
857 (data.type === 'lxc' && data.uptime === 0) ||
858 data.maxdisk === 0) {
859 return -1;
860 }
861
862 return (data.disk / data.maxdisk);
863 },
864
865 render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
866 if (!Ext.isNumeric(value) || value === -1) {
867 return '';
868 }
869
870 return (value * 100).toFixed(1) + " %";
871 },
872
b0a6d326
EK
873 render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
874
875 var disk = value;
876 var maxdisk = record.data.maxdisk;
728f1b97 877 var type = record.data.type;
b0a6d326 878
728f1b97
DC
879 if (!Ext.isNumeric(disk) ||
880 type === 'qemu' ||
881 maxdisk === 0 ||
882 (type === 'lxc' && record.data.uptime === 0)) {
b0a6d326
EK
883 return '';
884 }
885
728f1b97 886 return PVE.Utils.render_size(value);
b0a6d326
EK
887 },
888
4dbc64a7
DC
889 get_object_icon_class: function(type, record) {
890 var status = '';
891 var objType = type;
892
893 if (type === 'type') {
894 // for folder view
895 objType = record.groupbyid;
896 } else if (record.template) {
897 // templates
898 objType = 'template';
899 status = type;
900 } else {
901 // everything else
902 status = record.status + ' ha-' + record.hastate;
b1d8e73d
DC
903 }
904
6284a48a
DC
905 if (record.lock) {
906 status += ' locked lock-' + record.lock;
907 }
908
4dbc64a7
DC
909 var defaults = PVE.tree.ResourceTree.typeDefaults[objType];
910 if (defaults && defaults.iconCls) {
911 var retVal = defaults.iconCls + ' ' + status;
912 return retVal;
b0a6d326
EK
913 }
914
4dbc64a7
DC
915 return '';
916 },
917
918 render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
919
920 var cls = PVE.Utils.get_object_icon_class(value,record.data);
2b2fe160 921
4dbc64a7 922 var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> ';
b1d8e73d 923 return fa + value;
b0a6d326
EK
924 },
925
b0a6d326
EK
926 render_support_level: function(value, metaData, record) {
927 return PVE.Utils.support_level_hash[value] || '-';
928 },
929
0be88ae1 930 render_upid: function(value, metaData, record) {
b0a6d326
EK
931 var type = record.data.type;
932 var id = record.data.id;
933
e7ade592 934 return Proxmox.Utils.format_task_description(type, id);
b0a6d326
EK
935 },
936
054ac1b8
DC
937 /* render functions for new status panel */
938
939 render_usage: function(val) {
940 return (val*100).toFixed(2) + '%';
941 },
942
943 render_cpu_usage: function(val, max) {
944 return Ext.String.format(gettext('{0}% of {1}') +
945 ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max);
946 },
947
948 render_size_usage: function(val, max) {
bab64974
DC
949 if (max === 0) {
950 return gettext('N/A');
951 }
054ac1b8
DC
952 return (val*100/max).toFixed(2) + '% '+ '(' +
953 Ext.String.format(gettext('{0} of {1}'),
954 PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')';
955 },
956
957 /* this is different for nodes */
958 render_node_cpu_usage: function(value, record) {
959 return PVE.Utils.render_cpu_usage(value, record.cpus);
960 },
961
962 /* this is different for nodes */
963 render_node_size_usage: function(record) {
964 return PVE.Utils.render_size_usage(record.used, record.total);
965 },
966
27809975
DC
967 render_optional_url: function(value) {
968 var match;
969 if (value && (match = value.match(/^https?:\/\//)) !== null) {
cdd9b6c0 970 return '<a target="_blank" href="' + value + '">' + value + '</a>';
27809975
DC
971 }
972 return value;
973 },
974
975 render_san: function(value) {
976 var names = [];
977 if (Ext.isArray(value)) {
978 value.forEach(function(val) {
979 if (!Ext.isNumber(val)) {
980 names.push(val);
981 }
982 });
983 return names.join('<br>');
984 }
985 return value;
986 },
987
6ad4be69
DC
988 render_full_name: function(firstname, metaData, record) {
989 var first = firstname || '';
990 var last = record.data.lastname || '';
991 return Ext.htmlEncode(first + " " + last);
992 },
993
2d41c7e6
TL
994 render_u2f_error: function(error) {
995 var ErrorNames = {
996 '1': gettext('Other Error'),
997 '2': gettext('Bad Request'),
998 '3': gettext('Configuration Unsupported'),
999 '4': gettext('Device Ineligible'),
1000 '5': gettext('Timeout')
1001 };
1002 return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText;
1003 },
1004
aa0819a8 1005 windowHostname: function() {
e7ade592 1006 return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
aa0819a8
WB
1007 function(m, addr, offset, original) { return addr; });
1008 },
0be88ae1 1009
8eccc68f 1010 openDefaultConsoleWindow: function(consoles, vmtype, vmid, nodename, vmname, cmd) {
3438c27e 1011 var dv = PVE.Utils.defaultViewer(consoles);
8eccc68f 1012 PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname, cmd);
b0a6d326
EK
1013 },
1014
8eccc68f 1015 openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname, cmd) {
9e361643 1016 // kvm, lxc, shell, upgrade
b0a6d326 1017
9e361643 1018 if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) {
b0a6d326
EK
1019 throw "missing vmid";
1020 }
1021
1022 if (!nodename) {
1023 throw "no nodename specified";
1024 }
1025
c7218ab3 1026 if (viewer === 'html5') {
8eccc68f 1027 PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname, cmd);
c6b2336c 1028 } else if (viewer === 'xtermjs') {
8eccc68f 1029 Proxmox.Utils.openXtermJsViewer(vmtype, vmid, nodename, vmname, cmd);
b0a6d326
EK
1030 } else if (viewer === 'vv') {
1031 var url;
aa0819a8 1032 var params = { proxy: PVE.Utils.windowHostname() };
b0a6d326
EK
1033 if (vmtype === 'kvm') {
1034 url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
1035 PVE.Utils.openSpiceViewer(url, params);
9e361643
DM
1036 } else if (vmtype === 'lxc') {
1037 url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy';
b0a6d326
EK
1038 PVE.Utils.openSpiceViewer(url, params);
1039 } else if (vmtype === 'shell') {
1040 url = '/nodes/' + nodename + '/spiceshell';
1041 PVE.Utils.openSpiceViewer(url, params);
1042 } else if (vmtype === 'upgrade') {
1043 url = '/nodes/' + nodename + '/spiceshell';
1044 params.upgrade = 1;
1045 PVE.Utils.openSpiceViewer(url, params);
8eccc68f
TM
1046 } else if (vmtype === 'cmd') {
1047 url = '/nodes/' + nodename + '/spiceshell';
1048 params.cmd = cmd;
1049 PVE.Utils.openSpiceViewer(url, params);
b0a6d326
EK
1050 }
1051 } else {
1052 throw "unknown viewer type";
1053 }
1054 },
1055
3438c27e
DC
1056 defaultViewer: function(consoles) {
1057
1058 var allowSpice, allowXtermjs;
1059
1060 if (consoles === true) {
1061 allowSpice = true;
1062 allowXtermjs = true;
1063 } else if (typeof consoles === 'object') {
1064 allowSpice = consoles.spice;
4ace5c6f 1065 allowXtermjs = !!consoles.xtermjs;
3438c27e 1066 }
da9d14cd 1067 var dv = PVE.VersionInfo.console || 'xtermjs';
f932cffa
DC
1068 if (dv === 'vv' && !allowSpice) {
1069 dv = (allowXtermjs) ? 'xtermjs' : 'html5';
1070 } else if (dv === 'xtermjs' && !allowXtermjs) {
1071 dv = (allowSpice) ? 'vv' : 'html5';
b0a6d326
EK
1072 }
1073
1074 return dv;
1075 },
1076
8eccc68f 1077 openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) {
af89f682
TL
1078 let scaling = 'off';
1079 if (Proxmox.Utils.toolkit !== 'touch') {
1080 var sp = Ext.state.Manager.getProvider();
1081 scaling = sp.get('novnc-scaling', 'off');
1082 }
8eccc68f 1083 var url = Ext.Object.toQueryString({
9e361643 1084 console: vmtype, // kvm, lxc, upgrade or shell
c7218ab3 1085 novnc: 1,
b0a6d326
EK
1086 vmid: vmid,
1087 vmname: vmname,
16e64c97 1088 node: nodename,
af89f682 1089 resize: scaling,
8eccc68f 1090 cmd: cmd
b0a6d326
EK
1091 });
1092 var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
7af1ab47
DC
1093 if (nw) {
1094 nw.focus();
1095 }
b0a6d326
EK
1096 },
1097
1098 openSpiceViewer: function(url, params){
1099
1100 var downloadWithName = function(uri, name) {
1101 var link = Ext.DomHelper.append(document.body, {
1102 tag: 'a',
1103 href: uri,
1104 css : 'display:none;visibility:hidden;height:0px;'
1105 });
1106
1107 // Note: we need to tell android the correct file name extension
1108 // but we do not set 'download' tag for other environments, because
1109 // It can have strange side effects (additional user prompt on firefox)
1110 var andriod = navigator.userAgent.match(/Android/i) ? true : false;
1111 if (andriod) {
1112 link.download = name;
1113 }
1114
1115 if (link.fireEvent) {
1116 link.fireEvent('onclick');
1117 } else {
1118 var evt = document.createEvent("MouseEvents");
1119 evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
1120 link.dispatchEvent(evt);
1121 }
1122 };
1123
e7ade592 1124 Proxmox.Utils.API2Request({
b0a6d326
EK
1125 url: url,
1126 params: params,
1127 method: 'POST',
1128 failure: function(response, opts){
1129 Ext.Msg.alert('Error', response.htmlStatus);
1130 },
1131 success: function(response, opts){
1132 var raw = "[virt-viewer]\n";
1133 Ext.Object.each(response.result.data, function(k, v) {
1134 raw += k + "=" + v + "\n";
1135 });
1136 var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
1137 encodeURIComponent(raw);
0be88ae1 1138
b0a6d326
EK
1139 downloadWithName(url, "pve-spice.vv");
1140 }
1141 });
1142 },
1143
e3129443
DC
1144 openTreeConsole: function(tree, record, item, index, e) {
1145 e.stopEvent();
1146 var nodename = record.data.node;
1147 var vmid = record.data.vmid;
1148 var vmname = record.data.name;
1149 if (record.data.type === 'qemu' && !record.data.template) {
e7ade592 1150 Proxmox.Utils.API2Request({
e3129443
DC
1151 url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
1152 failure: function(response, opts) {
1153 Ext.Msg.alert('Error', response.htmlStatus);
1154 },
1155 success: function(response, opts) {
bd9537d7 1156 let conf = response.result.data;
54453c38 1157 var consoles = {
bd9537d7
TL
1158 spice: !!conf.spice,
1159 xtermjs: !!conf.serial,
54453c38
DC
1160 };
1161 PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
e3129443
DC
1162 }
1163 });
1164 } else if (record.data.type === 'lxc' && !record.data.template) {
1165 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
1166 }
1167 },
1168
fbd60cfd
DM
1169 // test automation helper
1170 call_menu_handler: function(menu, text) {
1171
1172 var list = menu.query('menuitem');
1173
1174 Ext.Array.each(list, function(item) {
1175 if (item.text === text) {
1176 if (item.handler) {
1177 item.handler();
1178 return 1;
1179 } else {
1180 return undefined;
1181 }
1182 }
1183 });
1184 },
1185
685b7aa4
DC
1186 createCmdMenu: function(v, record, item, index, event) {
1187 event.stopEvent();
cc1a91be
DC
1188 if (!(v instanceof Ext.tree.View)) {
1189 v.select(record);
1190 }
685b7aa4 1191 var menu;
9bad05bd
DC
1192 var template = !!record.data.template;
1193 var type = record.data.type;
685b7aa4 1194
9bad05bd
DC
1195 if (template) {
1196 if (type === 'qemu' || type == 'lxc') {
1197 menu = Ext.create('PVE.menu.TemplateMenu', {
1198 pveSelNode: record
1199 });
1200 }
1201 } else if (type === 'qemu' ||
1202 type === 'lxc' ||
1203 type === 'node') {
1204 menu = Ext.create('PVE.' + type + '.CmdMenu', {
1205 pveSelNode: record,
c11ab8cb
DC
1206 nodename: record.data.node
1207 });
685b7aa4
DC
1208 } else {
1209 return;
1210 }
1211
1212 menu.showAt(event.getXY());
9f0b4e04 1213 return menu;
e7ade592 1214 },
9fa2e36d 1215
fe4f00ad
TL
1216 // helper for deleting field which are set to there default values
1217 delete_if_default: function(values, fieldname, default_val, create) {
1218 if (values[fieldname] === '' || values[fieldname] === default_val) {
1219 if (!create) {
1220 if (values['delete']) {
1221 values['delete'] += ',' + fieldname;
1222 } else {
1223 values['delete'] = fieldname;
1224 }
1225 }
1226
1227 delete values[fieldname];
1228 }
857b97a7
TL
1229 },
1230
1231 loadSSHKeyFromFile: function(file, callback) {
1232 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1233 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1234 // assume: 740*8 for max. 32kbit (5920 byte file)
1235 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1236 if (file.size > 8192) {
1237 Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
1238 return;
1239 }
1240 /*global
1241 FileReader
1242 */
1243 var reader = new FileReader();
1244 reader.onload = function(evt) {
1245 callback(evt.target.result);
1246 };
1247 reader.readAsText(file);
abe824aa
DC
1248 },
1249
8c4ec8c7
TL
1250 diskControllerMaxIDs: {
1251 ide: 4,
1252 sata: 6,
cf0d139e 1253 scsi: 31,
8c4ec8c7
TL
1254 virtio: 16,
1255 },
abe824aa
DC
1256
1257 // types is either undefined (all busses), an array of busses, or a single bus
1258 forEachBus: function(types, func) {
8c4ec8c7 1259 var busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
abe824aa
DC
1260 var i, j, count, cont;
1261
1262 if (Ext.isArray(types)) {
1263 busses = types;
1264 } else if (Ext.isDefined(types)) {
1265 busses = [ types ];
1266 }
1267
1268 // check if we only have valid busses
1269 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1270 if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) {
abe824aa
DC
1271 throw "invalid bus: '" + busses[i] + "'";
1272 }
1273 }
1274
1275 for (i = 0; i < busses.length; i++) {
8c4ec8c7 1276 count = PVE.Utils.diskControllerMaxIDs[busses[i]];
abe824aa
DC
1277 for (j = 0; j < count; j++) {
1278 cont = func(busses[i], j);
1279 if (!cont && cont !== undefined) {
1280 return;
1281 }
1282 }
1283 }
14a845bc
DC
1284 },
1285
483bd394 1286 mp_counts: { mps: 256, unused: 256 },
14a845bc
DC
1287
1288 forEachMP: function(func, includeUnused) {
1289 var i, cont;
1290 for (i = 0; i < PVE.Utils.mp_counts.mps; i++) {
1291 cont = func('mp', i);
1292 if (!cont && cont !== undefined) {
1293 return;
1294 }
1295 }
1296
1297 if (!includeUnused) {
1298 return;
1299 }
1300
1301 for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
1302 cont = func('unused', i);
1303 if (!cont && cont !== undefined) {
1304 return;
1305 }
1306 }
b945c7c1
TM
1307 },
1308
6c1d8ead 1309 hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1 },
9d855398 1310
b945c7c1
TM
1311 cleanEmptyObjectKeys: function (obj) {
1312 var propName;
1313 for (propName in obj) {
1314 if (obj.hasOwnProperty(propName)) {
1315 if (obj[propName] === null || obj[propName] === undefined) {
1316 delete obj[propName];
1317 }
1318 }
1319 }
4616a55b
TM
1320 },
1321
1322 handleStoreErrorOrMask: function(me, store, regex, callback) {
1323
1324 me.mon(store, 'load', function (proxy, response, success, operation) {
1325
1326 if (success) {
1327 Proxmox.Utils.setErrorMask(me, false);
1328 return;
1329 }
1330 var msg;
1331
1332 if (operation.error.statusText) {
1333 if (operation.error.statusText.match(regex)) {
1334 callback(me, operation.error);
1335 return;
1336 } else {
1337 msg = operation.error.statusText + ' (' + operation.error.status + ')';
1338 }
1339 } else {
1340 msg = gettext('Connection error');
1341 }
1342 Proxmox.Utils.setErrorMask(me, msg);
1343 });
1344 },
1345
1346 showCephInstallOrMask: function(container, msg, nodename, callback){
1347 var regex = new RegExp("not (installed|initialized)", "i");
1348 if (msg.match(regex)) {
1349 if (Proxmox.UserName === 'root@pam') {
1350 container.el.mask();
1351 if (!container.down('pveCephInstallWindow')){
f992ef80 1352 var isInstalled = msg.match(/not initialized/i) ? true : false;
4616a55b
TM
1353 var win = Ext.create('PVE.ceph.Install', {
1354 nodename: nodename
1355 });
f992ef80 1356 win.getViewModel().set('isInstalled', isInstalled);
4616a55b
TM
1357 container.add(win);
1358 win.show();
1359 callback(win);
1360 }
1361 } else {
a7e8b87b
TL
1362 container.mask(Ext.String.format(gettext('{0} not installed.') +
1363 ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']);
4616a55b
TM
1364 }
1365 return true;
1366 } else {
1367 return false;
1368 }
49dfba72
DC
1369 },
1370
1371 propertyStringSet: function(target, source, name, value) {
1372 if (source) {
1373 if (value === undefined) {
1374 target[name] = source;
1375 } else {
1376 target[name] = value;
1377 }
1378 } else {
1379 delete target[name];
1380 }
bbc83309
DC
1381 },
1382
1383 updateColumns: function(container) {
f973c5b2
DC
1384 let mode = Ext.state.Manager.get('summarycolumns') || 'auto';
1385 let factor;
1386 if (mode !== 'auto') {
1387 factor = parseInt(mode, 10);
1388 if (Number.isNaN(factor)) {
1389 factor = 1;
1390 }
1391 } else {
1392 factor = container.getSize().width < 1400 ? 1 : 2;
1393 }
bbc83309
DC
1394
1395 if (container.oldFactor === factor) {
1396 return;
1397 }
1398
1399 let items = container.query('>'); // direct childs
1400 factor = Math.min(factor, items.length);
1401 container.oldFactor = factor;
1402
1403 items.forEach((item) => {
1404 item.columnWidth = 1 / factor;
1405 });
1406
1407 // we have to update the layout twice, since the first layout change
1408 // can trigger the scrollbar which reduces the amount of space left
1409 container.updateLayout();
1410 container.updateLayout();
1411 },
e65817a1
SR
1412
1413 forEachCorosyncLink: function(nodeinfo, cb) {
1414 let re = /(?:ring|link)(\d+)_addr/;
1415 Ext.iterate(nodeinfo, (prop, val) => {
1416 let match = re.exec(prop);
1417 if (match) {
1418 cb(Number(match[1]), val);
1419 }
1420 });
1421 },
e7ade592 1422},
fe4f00ad 1423
9fa2e36d
EK
1424 singleton: true,
1425 constructor: function() {
1426 var me = this;
1427 Ext.apply(me, me.utilities);
685b7aa4 1428 }
e7ade592 1429
9fa2e36d 1430});