]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/Utils.js
remove debugging code from postrm
[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 = {
13 dir: function() {},
14 log: function() {}
b0a6d326
EK
15 };
16}
0be88ae1 17console.log("Starting PVE Manager");
b0a6d326
EK
18
19Ext.Ajax.defaultHeaders = {
20 'Accept': 'application/json'
21};
22
23Ext.Ajax.on('beforerequest', function(conn, options) {
24 if (PVE.CSRFPreventionToken) {
0be88ae1 25 if (!options.headers) {
b0a6d326
EK
26 options.headers = {};
27 }
28 options.headers.CSRFPreventionToken = PVE.CSRFPreventionToken;
29 }
30});
31
32var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
33var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
34var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
35var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
36
37
38var IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
368df92e 39var IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
b0a6d326
EK
40
41var IPV6_REGEXP = "(?:" +
42 "(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
43 "(?:(?:" + "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" +
44 "(?:(?:(?:" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" +
45 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" +
46 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" +
47 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" +
48 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" + ")" + IPV6_LS32 + ")|" +
49 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" + ")" + IPV6_H16 + ")|" +
50 "(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" + ")" + ")" +
51 ")";
52
8a52defd 53var IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
368df92e 54var IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
aa0819a8 55var IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
8a52defd 56
b0a6d326
EK
57var IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
58
7b58d7b2
DC
59var DnsName_REGEXP = "(?:(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*([A-Za-z0-9]([A-Za-z0-9\\-]*[A-Za-z0-9])?))";
60var DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
61
70e779e4
DC
62var HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
63var HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
64var IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
65
a50de124
DC
66var DocsPages = {
67 'pve-admin-guide.html':'Proxmox VE Administration Guide',
68 'chapter-sysadmin.html':'Host System Administration',
69 'chapter-pvecm.html':'Cluster Manager',
70 'chapter-pmxcfs.html':'Proxmox Cluster File System (pmxcfs)',
71 'chapter-pvesm.html':'Proxmox VE Storage',
72 'chapter-qm.html': 'Qemu/KVM Virtual Machines',
73 'chapter-pve-firewall.html': 'Proxmox VE Firewall',
74 'chapter-pveum.html': 'User Management',
75 'chapter-pct.html': 'Proxmox Container Toolkit',
76 'chapter-ha-manager.html': 'High Availability',
77 'chapter-vzdump.html': 'Backup and Restore',
78 'chapter-pve-faq.html': 'Frequently Asked Questions',
79 'chapter-pve-bibliography.html': 'Bibliography',
80 'qm.1.html': 'Qemu/KVM Virtual Machine Manager',
81 'qmrestore.1.html': 'Restore QemuServer vzdump Backups',
82 'pct.1.html': 'Tool to manage Linux Containers (LXC) on Proxmox VE',
83 'pveam.1.html': 'Proxmox VE Appliance Manager',
84 'pveceph.1.html': 'Manage CEPH Services on Proxmox VE Nodes',
85 'pvecm.1.html': 'Proxmox VE Cluster Manager',
86 'pveum.1.html': 'Proxmox VE User Manager',
87 'pvesm.1.html': 'Proxmox VE Storage Manager',
88 'pvesubscription.1.html': 'Proxmox VE Subscription Manager',
89 'vzdump.1.html': 'Backup Utility for VMs and Containers',
90 'ha-manager.1.html': 'Proxmox VE HA Manager',
91 'index.html':'',
92 'datacenter.cfg.5.html':'Proxmox VE Datacenter Configuration'
93};
94
95var DocsSubTitles = {
96 '_vm_container_configuration':'VM/Container configuration',
97 '_ip_aliases':'IP Aliases',
98 '_ip_sets':'IP Sets'
99};
b0a6d326
EK
100Ext.define('PVE.Utils', { statics: {
101
102 // this class only contains static functions
103
0be88ae1 104 toolkit: undefined, // (extjs|touch), set inside Toolkit.js
b0a6d326
EK
105
106 log_severity_hash: {
107 0: "panic",
108 1: "alert",
109 2: "critical",
110 3: "error",
111 4: "warning",
112 5: "notice",
113 6: "info",
114 7: "debug"
115 },
116
117 support_level_hash: {
118 'c': gettext('Community'),
119 'b': gettext('Basic'),
120 's': gettext('Standard'),
121 'p': gettext('Premium')
122 },
123
124 noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="http://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.',
125
126 kvm_ostypes: {
127 other: gettext('Other OS types'),
128 wxp: 'Microsoft Windows XP/2003',
129 w2k: 'Microsoft Windows 2000',
130 w2k8: 'Microsoft Windows Vista/2008',
131 win7: 'Microsoft Windows 7/2008r2',
d481d825 132 win8: 'Microsoft Windows 8.x/10/2012/r2',
b0a6d326 133 l24: 'Linux 2.4 Kernel',
5a4ba3c2 134 l26: 'Linux 4.X/3.X/2.6 Kernel',
b0a6d326
EK
135 solaris: 'Solaris Kernel'
136 },
137
138 render_kvm_ostype: function (value) {
139 if (!value) {
140 return gettext('Other OS types');
141 }
142 var text = PVE.Utils.kvm_ostypes[value];
143 if (text) {
b7159d8b 144 return text;
b0a6d326
EK
145 }
146 return value;
147 },
148
149 render_hotplug_features: function (value) {
23d3881a 150 var fa = [];
b0a6d326
EK
151
152 if (!value || (value === '0')) {
153 return gettext('disabled');
154 }
155
4dcca8a4
DC
156 if (value === '1') {
157 value = 'disk,network,usb';
158 }
159
b0a6d326
EK
160 Ext.each(value.split(','), function(el) {
161 if (el === 'disk') {
162 fa.push(gettext('Disk'));
163 } else if (el === 'network') {
164 fa.push(gettext('Network'));
165 } else if (el === 'usb') {
166 fa.push(gettext('USB'));
167 } else if (el === 'memory') {
168 fa.push(gettext('Memory'));
169 } else if (el === 'cpu') {
170 fa.push(gettext('CPU'));
171 } else {
172 fa.push(el);
173 }
174 });
175
176 return fa.join(', ');
177 },
178
179 network_iface_types: {
180 eth: gettext("Network Device"),
181 bridge: 'Linux Bridge',
182 bond: 'Linux Bond',
183 OVSBridge: 'OVS Bridge',
184 OVSBond: 'OVS Bond',
185 OVSPort: 'OVS Port',
186 OVSIntPort: 'OVS IntPort'
187 },
188
189 render_network_iface_type: function(value) {
0be88ae1 190 return PVE.Utils.network_iface_types[value] ||
b0a6d326
EK
191 PVE.Utils.unknownText;
192 },
193
17c71f27
DC
194 render_qemu_bios: function(value) {
195 if (!value) {
196 return PVE.Utils.defaultText + ' (SeaBIOS)';
197 } else if (value === 'seabios') {
198 return "SeaBIOS";
199 } else if (value === 'ovmf') {
200 return "OVMF (UEFI)";
201 } else {
202 return value;
203 }
204 },
205
b0a6d326
EK
206 render_scsihw: function(value) {
207 if (!value) {
208 return PVE.Utils.defaultText + ' (LSI 53C895A)';
209 } else if (value === 'lsi') {
210 return 'LSI 53C895A';
211 } else if (value === 'lsi53c810') {
212 return 'LSI 53C810';
213 } else if (value === 'megasas') {
214 return 'MegaRAID SAS 8708EM2';
215 } else if (value === 'virtio-scsi-pci') {
49f5d1ab
EK
216 return 'VirtIO SCSI';
217 } else if (value === 'virtio-scsi-single') {
218 return 'VirtIO SCSI single';
b0a6d326
EK
219 } else if (value === 'pvscsi') {
220 return 'VMware PVSCSI';
221 } else {
222 return value;
223 }
224 },
225
226 // fixme: auto-generate this
227 // for now, please keep in sync with PVE::Tools::kvmkeymaps
228 kvm_keymaps: {
229 //ar: 'Arabic',
230 da: 'Danish',
0be88ae1
DC
231 de: 'German',
232 'de-ch': 'German (Swiss)',
233 'en-gb': 'English (UK)',
0a5b8747 234 'en-us': 'English (USA)',
b0a6d326
EK
235 es: 'Spanish',
236 //et: 'Estonia',
237 fi: 'Finnish',
0be88ae1
DC
238 //fo: 'Faroe Islands',
239 fr: 'French',
240 'fr-be': 'French (Belgium)',
b0a6d326
EK
241 'fr-ca': 'French (Canada)',
242 'fr-ch': 'French (Swiss)',
243 //hr: 'Croatia',
244 hu: 'Hungarian',
245 is: 'Icelandic',
0be88ae1 246 it: 'Italian',
b0a6d326
EK
247 ja: 'Japanese',
248 lt: 'Lithuanian',
249 //lv: 'Latvian',
0be88ae1 250 mk: 'Macedonian',
b0a6d326
EK
251 nl: 'Dutch',
252 //'nl-be': 'Dutch (Belgium)',
0be88ae1 253 no: 'Norwegian',
b0a6d326
EK
254 pl: 'Polish',
255 pt: 'Portuguese',
256 'pt-br': 'Portuguese (Brazil)',
257 //ru: 'Russian',
258 sl: 'Slovenian',
259 sv: 'Swedish',
260 //th: 'Thai',
261 tr: 'Turkish'
262 },
263
264 kvm_vga_drivers: {
265 std: gettext('Standard VGA'),
5ca366f2 266 vmware: gettext('VMware compatible'),
b0a6d326
EK
267 cirrus: 'Cirrus Logic GD5446',
268 qxl: 'SPICE',
269 qxl2: 'SPICE dual monitor',
270 qxl3: 'SPICE three monitors',
271 qxl4: 'SPICE four monitors',
272 serial0: gettext('Serial terminal') + ' 0',
273 serial1: gettext('Serial terminal') + ' 1',
274 serial2: gettext('Serial terminal') + ' 2',
275 serial3: gettext('Serial terminal') + ' 3'
276 },
277
278 render_kvm_language: function (value) {
279 if (!value) {
280 return PVE.Utils.defaultText;
281 }
282 var text = PVE.Utils.kvm_keymaps[value];
283 if (text) {
284 return text + ' (' + value + ')';
285 }
286 return value;
287 },
288
289 kvm_keymap_array: function() {
f2782813 290 var data = [['__default__', PVE.Utils.render_kvm_language('')]];
b0a6d326
EK
291 Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) {
292 data.push([key, PVE.Utils.render_kvm_language(value)]);
293 });
294
295 return data;
296 },
297
298 render_console_viewer: function(value) {
f2782813 299 if (!value || value === '__default__') {
b0a6d326 300 return PVE.Utils.defaultText + ' (HTML5)';
b0a6d326
EK
301 } else if (value === 'vv') {
302 return 'SPICE (remote-viewer)';
303 } else if (value === 'html5') {
304 return 'HTML5 (noVNC)';
305 } else {
306 return value;
307 }
308 },
309
310 language_map: {
311 zh_CN: 'Chinese',
312 ca: 'Catalan',
313 da: 'Danish',
314 en: 'English',
315 eu: 'Euskera (Basque)',
316 fr: 'French',
317 de: 'German',
318 it: 'Italian',
319 ja: 'Japanese',
320 nb: 'Norwegian (Bokmal)',
321 nn: 'Norwegian (Nynorsk)',
322 fa: 'Persian (Farsi)',
323 pl: 'Polish',
324 pt_BR: 'Portuguese (Brazil)',
325 ru: 'Russian',
326 sl: 'Slovenian',
327 es: 'Spanish',
328 sv: 'Swedish',
329 tr: 'Turkish'
330 },
331
332 render_language: function (value) {
333 if (!value) {
334 return PVE.Utils.defaultText + ' (English)';
335 }
336 var text = PVE.Utils.language_map[value];
337 if (text) {
338 return text + ' (' + value + ')';
339 }
340 return value;
341 },
342
343 language_array: function() {
d98a2c3c 344 var data = [['__default__', PVE.Utils.render_language('')]];
b0a6d326
EK
345 Ext.Object.each(PVE.Utils.language_map, function(key, value) {
346 data.push([key, PVE.Utils.render_language(value)]);
347 });
348
349 return data;
350 },
351
352 render_kvm_vga_driver: function (value) {
353 if (!value) {
354 return PVE.Utils.defaultText;
355 }
356 var text = PVE.Utils.kvm_vga_drivers[value];
0be88ae1 357 if (text) {
b0a6d326
EK
358 return text + ' (' + value + ')';
359 }
360 return value;
361 },
362
363 kvm_vga_driver_array: function() {
f2782813 364 var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]];
b0a6d326
EK
365 Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) {
366 data.push([key, PVE.Utils.render_kvm_vga_driver(value)]);
367 });
368
369 return data;
370 },
371
372 render_kvm_startup: function(value) {
373 var startup = PVE.Parser.parseStartup(value);
374
375 var res = 'order=';
376 if (startup.order === undefined) {
377 res += 'any';
378 } else {
379 res += startup.order;
380 }
381 if (startup.up !== undefined) {
382 res += ',up=' + startup.up;
383 }
384 if (startup.down !== undefined) {
385 res += ',down=' + startup.down;
386 }
387
388 return res;
389 },
390
391 authOK: function() {
392 return Ext.util.Cookies.get('PVEAuthCookie');
393 },
394
395 authClear: function() {
396 Ext.util.Cookies.clear("PVEAuthCookie");
397 },
398
399 // fixme: remove - not needed?
400 gridLineHeigh: function() {
401 return 21;
0be88ae1 402
b0a6d326
EK
403 //if (Ext.isGecko)
404 //return 23;
405 //return 21;
406 },
407
408 extractRequestError: function(result, verbose) {
409 var msg = gettext('Successful');
410
411 if (!result.success) {
412 msg = gettext("Unknown error");
413 if (result.message) {
414 msg = result.message;
415 if (result.status) {
416 msg += ' (' + result.status + ')';
417 }
418 }
419 if (verbose && Ext.isObject(result.errors)) {
420 msg += "<br>";
421 Ext.Object.each(result.errors, function(prop, desc) {
0be88ae1 422 msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " +
b0a6d326
EK
423 Ext.htmlEncode(desc);
424 });
0be88ae1 425 }
b0a6d326
EK
426 }
427
428 return msg;
429 },
430
431 extractFormActionError: function(action) {
432 var msg;
433 switch (action.failureType) {
434 case Ext.form.action.Action.CLIENT_INVALID:
435 msg = gettext('Form fields may not be submitted with invalid values');
436 break;
437 case Ext.form.action.Action.CONNECT_FAILURE:
438 msg = gettext('Connection error');
439 var resp = action.response;
440 if (resp.status && resp.statusText) {
441 msg += " " + resp.status + ": " + resp.statusText;
442 }
443 break;
444 case Ext.form.action.Action.LOAD_FAILURE:
445 case Ext.form.action.Action.SERVER_INVALID:
446 msg = PVE.Utils.extractRequestError(action.result, true);
447 break;
448 }
449 return msg;
450 },
451
452 // Ext.Ajax.request
453 API2Request: function(reqOpts) {
454
455 var newopts = Ext.apply({
456 waitMsg: gettext('Please wait...')
457 }, reqOpts);
458
459 if (!newopts.url.match(/^\/api2/)) {
460 newopts.url = '/api2/extjs' + newopts.url;
461 }
462 delete newopts.callback;
463
464 var createWrapper = function(successFn, callbackFn, failureFn) {
465 Ext.apply(newopts, {
466 success: function(response, options) {
467 if (options.waitMsgTarget) {
468 if (PVE.Utils.toolkit === 'touch') {
469 options.waitMsgTarget.setMasked(false);
470 } else {
471 options.waitMsgTarget.setLoading(false);
472 }
473 }
474 var result = Ext.decode(response.responseText);
475 response.result = result;
476 if (!result.success) {
477 response.htmlStatus = PVE.Utils.extractRequestError(result, true);
478 Ext.callback(callbackFn, options.scope, [options, false, response]);
479 Ext.callback(failureFn, options.scope, [response, options]);
480 return;
481 }
482 Ext.callback(callbackFn, options.scope, [options, true, response]);
483 Ext.callback(successFn, options.scope, [response, options]);
484 },
485 failure: function(response, options) {
486 if (options.waitMsgTarget) {
487 if (PVE.Utils.toolkit === 'touch') {
488 options.waitMsgTarget.setMasked(false);
489 } else {
490 options.waitMsgTarget.setLoading(false);
491 }
492 }
493 response.result = {};
494 try {
495 response.result = Ext.decode(response.responseText);
496 } catch(e) {}
497 var msg = gettext('Connection error') + ' - server offline?';
498 if (response.aborted) {
499 msg = gettext('Connection error') + ' - aborted.';
500 } else if (response.timedout) {
501 msg = gettext('Connection error') + ' - Timeout.';
502 } else if (response.status && response.statusText) {
503 msg = gettext('Connection error') + ' ' + response.status + ': ' + response.statusText;
504 }
505 response.htmlStatus = msg;
506 Ext.callback(callbackFn, options.scope, [options, false, response]);
507 Ext.callback(failureFn, options.scope, [response, options]);
508 }
509 });
510 };
511
512 createWrapper(reqOpts.success, reqOpts.callback, reqOpts.failure);
513
514 var target = newopts.waitMsgTarget;
515 if (target) {
516 if (PVE.Utils.toolkit === 'touch') {
517 target.setMasked({ xtype: 'loadmask', message: newopts.waitMsg} );
518 } else {
519 // Note: ExtJS bug - this does not work when component is not rendered
520 target.setLoading(newopts.waitMsg);
521 }
522 }
523 Ext.Ajax.request(newopts);
524 },
525
526 assemble_field_data: function(values, data) {
527 if (Ext.isObject(data)) {
528 Ext.Object.each(data, function(name, val) {
529 if (values.hasOwnProperty(name)) {
530 var bucket = values[name];
531 if (!Ext.isArray(bucket)) {
532 bucket = values[name] = [bucket];
533 }
534 if (Ext.isArray(val)) {
535 values[name] = bucket.concat(val);
536 } else {
537 bucket.push(val);
538 }
539 } else {
540 values[name] = val;
541 }
542 });
543 }
544 },
545
546 checked_command: function(orig_cmd) {
547 PVE.Utils.API2Request({
548 url: '/nodes/localhost/subscription',
549 method: 'GET',
550 //waitMsgTarget: me,
551 failure: function(response, opts) {
552 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
553 },
554 success: function(response, opts) {
555 var data = response.result.data;
556
557 if (data.status !== 'Active') {
558 Ext.Msg.show({
559 title: gettext('No valid subscription'),
560 icon: Ext.Msg.WARNING,
561 msg: PVE.Utils.noSubKeyHtml,
562 buttons: Ext.Msg.OK,
563 callback: function(btn) {
564 if (btn !== 'ok') {
565 return;
566 }
567 orig_cmd();
568 }
569 });
570 } else {
571 orig_cmd();
572 }
573 }
574 });
575 },
576
577 task_desc_table: {
a36deac4 578 diskinit: [ 'Disk', gettext('Initialize GPT') ],
b0a6d326
EK
579 vncproxy: [ 'VM/CT', gettext('Console') ],
580 spiceproxy: [ 'VM/CT', gettext('Console') + ' (Spice)' ],
581 vncshell: [ '', gettext('Shell') ],
582 spiceshell: [ '', gettext('Shell') + ' (Spice)' ],
583 qmsnapshot: [ 'VM', gettext('Snapshot') ],
584 qmrollback: [ 'VM', gettext('Rollback') ],
585 qmdelsnapshot: [ 'VM', gettext('Delete Snapshot') ],
586 qmcreate: [ 'VM', gettext('Create') ],
587 qmrestore: [ 'VM', gettext('Restore') ],
588 qmdestroy: [ 'VM', gettext('Destroy') ],
589 qmigrate: [ 'VM', gettext('Migrate') ],
590 qmclone: [ 'VM', gettext('Clone') ],
591 qmmove: [ 'VM', gettext('Move disk') ],
592 qmtemplate: [ 'VM', gettext('Convert to template') ],
593 qmstart: [ 'VM', gettext('Start') ],
594 qmstop: [ 'VM', gettext('Stop') ],
595 qmreset: [ 'VM', gettext('Reset') ],
596 qmshutdown: [ 'VM', gettext('Shutdown') ],
597 qmsuspend: [ 'VM', gettext('Suspend') ],
598 qmresume: [ 'VM', gettext('Resume') ],
599 qmconfig: [ 'VM', gettext('Configure') ],
16152937
DM
600 vzsnapshot: [ 'CT', gettext('Snapshot') ],
601 vzrollback: [ 'CT', gettext('Rollback') ],
602 vzdelsnapshot: [ 'CT', gettext('Delete Snapshot') ],
b0a6d326
EK
603 vzcreate: ['CT', gettext('Create') ],
604 vzrestore: ['CT', gettext('Restore') ],
605 vzdestroy: ['CT', gettext('Destroy') ],
606 vzmigrate: [ 'CT', gettext('Migrate') ],
bfade4b4
DM
607 vzclone: [ 'CT', gettext('Clone') ],
608 vztemplate: [ 'CT', gettext('Convert to template') ],
b0a6d326
EK
609 vzstart: ['CT', gettext('Start') ],
610 vzstop: ['CT', gettext('Stop') ],
611 vzmount: ['CT', gettext('Mount') ],
612 vzumount: ['CT', gettext('Unmount') ],
613 vzshutdown: ['CT', gettext('Shutdown') ],
614 vzsuspend: [ 'CT', gettext('Suspend') ],
615 vzresume: [ 'CT', gettext('Resume') ],
616 hamigrate: [ 'HA', gettext('Migrate') ],
617 hastart: [ 'HA', gettext('Start') ],
618 hastop: [ 'HA', gettext('Stop') ],
619 srvstart: ['SRV', gettext('Start') ],
620 srvstop: ['SRV', gettext('Stop') ],
621 srvrestart: ['SRV', gettext('Restart') ],
622 srvreload: ['SRV', gettext('Reload') ],
623 cephcreatemon: ['Ceph Monitor', gettext('Create') ],
624 cephdestroymon: ['Ceph Monitor', gettext('Destroy') ],
625 cephcreateosd: ['Ceph OSD', gettext('Create') ],
626 cephdestroyosd: ['Ceph OSD', gettext('Destroy') ],
627 imgcopy: ['', gettext('Copy data') ],
628 imgdel: ['', gettext('Erase data') ],
629 download: ['', gettext('Download') ],
630 vzdump: ['', gettext('Backup') ],
631 aptupdate: ['', gettext('Update package database') ],
632 startall: [ '', gettext('Start all VMs and Containers') ],
633 stopall: [ '', gettext('Stop all VMs and Containers') ],
634 migrateall: [ '', gettext('Migrate all VMs and Containers') ]
635 },
636
0be88ae1 637 format_task_description: function(type, id) {
b0a6d326
EK
638 var farray = PVE.Utils.task_desc_table[type];
639 if (!farray) {
640 return type;
641 }
642 var prefix = farray[0];
643 var text = farray[1];
644 if (prefix) {
0be88ae1 645 return prefix + ' ' + id + ' - ' + text;
b0a6d326
EK
646 }
647 return text;
648 },
649
650 parse_task_upid: function(upid) {
651 var task = {};
652
653 var res = upid.match(/^UPID:(\S+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/);
654 if (!res) {
655 throw "unable to parse upid '" + upid + "'";
656 }
657 task.node = res[1];
658 task.pid = parseInt(res[2], 16);
659 task.pstart = parseInt(res[3], 16);
660 task.starttime = parseInt(res[4], 16);
661 task.type = res[5];
662 task.id = res[6];
663 task.user = res[7];
664
665 task.desc = PVE.Utils.format_task_description(task.type, task.id);
666
667 return task;
668 },
669
670 format_size: function(size) {
671 /*jslint confusion: true */
672
02f47fe8
DC
673 var units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'];
674 var num = 0;
b0a6d326 675
02f47fe8
DC
676 while (size >= 1024 && ((num++)+1) < units.length) {
677 size = size / 1024;
b0a6d326
EK
678 }
679
02f47fe8 680 return size.toFixed((num > 0)?2:0) + " " + units[num] + "B";
b0a6d326
EK
681 },
682
683 format_html_bar: function(per, text) {
684
685 return "<div class='pve-bar-wrap'>" + text + "<div class='pve-bar-border'>" +
686 "<div class='pve-bar-inner' style='width:" + per + "%;'></div>" +
687 "</div></div>";
0be88ae1 688
b0a6d326
EK
689 },
690
691 format_cpu_bar: function(per1, per2, text) {
692
693 return "<div class='pve-bar-border'>" +
694 "<div class='pve-bar-inner' style='width:" + per1 + "%;'></div>" +
695 "<div class='pve-bar-inner2' style='width:" + per2 + "%;'></div>" +
0be88ae1 696 "<div class='pve-bar-text'>" + text + "</div>" +
b0a6d326
EK
697 "</div>";
698 },
699
700 format_large_bar: function(per, text) {
701
702 if (!text) {
703 text = per.toFixed(1) + "%";
704 }
705
706 return "<div class='pve-largebar-border'>" +
707 "<div class='pve-largebar-inner' style='width:" + per + "%;'></div>" +
0be88ae1 708 "<div class='pve-largebar-text'>" + text + "</div>" +
b0a6d326
EK
709 "</div>";
710 },
711
712 format_duration_long: function(ut) {
713
714 var days = Math.floor(ut / 86400);
715 ut -= days*86400;
716 var hours = Math.floor(ut / 3600);
717 ut -= hours*3600;
718 var mins = Math.floor(ut / 60);
719 ut -= mins*60;
720
721 var hours_str = '00' + hours.toString();
722 hours_str = hours_str.substr(hours_str.length - 2);
723 var mins_str = "00" + mins.toString();
724 mins_str = mins_str.substr(mins_str.length - 2);
725 var ut_str = "00" + ut.toString();
726 ut_str = ut_str.substr(ut_str.length - 2);
727
728 if (days) {
729 var ds = days > 1 ? PVE.Utils.daysText : PVE.Utils.dayText;
0be88ae1 730 return days.toString() + ' ' + ds + ' ' +
b0a6d326
EK
731 hours_str + ':' + mins_str + ':' + ut_str;
732 } else {
733 return hours_str + ':' + mins_str + ':' + ut_str;
734 }
735 },
736
737 format_duration_short: function(ut) {
0be88ae1 738
b0a6d326
EK
739 if (ut < 60) {
740 return ut.toString() + 's';
741 }
742
743 if (ut < 3600) {
744 var mins = ut / 60;
745 return mins.toFixed(0) + 'm';
746 }
747
748 if (ut < 86400) {
749 var hours = ut / 3600;
750 return hours.toFixed(0) + 'h';
751 }
752
753 var days = ut / 86400;
0be88ae1 754 return days.toFixed(0) + 'd';
b0a6d326
EK
755 },
756
757 yesText: gettext('Yes'),
758 noText: gettext('No'),
759 noneText: gettext('none'),
760 errorText: gettext('Error'),
761 unknownText: gettext('Unknown'),
762 defaultText: gettext('Default'),
763 daysText: gettext('days'),
764 dayText: gettext('day'),
765 runningText: gettext('running'),
766 stoppedText: gettext('stopped'),
767 neverText: gettext('never'),
768 totalText: gettext('Total'),
769 usedText: gettext('Used'),
770 directoryText: gettext('Directory'),
771 imagesText: gettext('Disk image'),
772 backupFileText: gettext('VZDump backup file'),
2c554952 773 vztmplText: gettext('Container template'),
b0a6d326 774 isoImageText: gettext('ISO image'),
2c554952 775 containersText: gettext('Container'),
45ab85bb
DM
776 stateText: gettext('State'),
777 groupText: gettext('Group'),
b0a6d326
EK
778
779 format_expire: function(date) {
780 if (!date) {
781 return PVE.Utils.neverText;
782 }
783 return Ext.Date.format(date, "Y-m-d");
784 },
785
786 format_storage_type: function(value) {
787 if (value === 'dir') {
788 return PVE.Utils.directoryText;
789 } else if (value === 'nfs') {
790 return 'NFS';
791 } else if (value === 'glusterfs') {
792 return 'GlusterFS';
793 } else if (value === 'lvm') {
794 return 'LVM';
ffd96a3b
DM
795 } else if (value === 'lvmthin') {
796 return 'LVM-Thin';
b0a6d326
EK
797 } else if (value === 'iscsi') {
798 return 'iSCSI';
799 } else if (value === 'rbd') {
800 return 'RBD';
801 } else if (value === 'sheepdog') {
802 return 'Sheepdog';
803 } else if (value === 'zfs') {
804 return 'ZFS over iSCSI';
805 } else if (value === 'zfspool') {
806 return 'ZFS';
807 } else if (value === 'iscsidirect') {
808 return 'iSCSIDirect';
ffd96a3b
DM
809 } else if (value === 'drbd') {
810 return 'DRBD';
b0a6d326
EK
811 } else {
812 return PVE.Utils.unknownText;
813 }
814 },
815
816 format_boolean_with_default: function(value) {
f2782813 817 if (Ext.isDefined(value) && value !== '__default__') {
b0a6d326
EK
818 return value ? PVE.Utils.yesText : PVE.Utils.noText;
819 }
820 return PVE.Utils.defaultText;
821 },
822
823 format_boolean: function(value) {
824 return value ? PVE.Utils.yesText : PVE.Utils.noText;
825 },
826
827 format_neg_boolean: function(value) {
828 return !value ? PVE.Utils.yesText : PVE.Utils.noText;
829 },
830
ced1677b
TL
831 format_ha: function(value) {
832 var text = PVE.Utils.format_boolean(value.managed);
833
834 if (value.managed) {
45ab85bb 835 text += ', ' + PVE.Utils.stateText + ': ';
f25d7c4a 836 text += value.state || PVE.Utils.noneText;
ced1677b 837
45ab85bb 838 text += ', ' + PVE.Utils.groupText + ': ';
f25d7c4a 839 text += value.group || PVE.Utils.noneText;
ced1677b
TL
840 }
841
842 return text;
843 },
844
b0a6d326
EK
845 format_content_types: function(value) {
846 var cta = [];
847
848 Ext.each(value.split(',').sort(), function(ct) {
849 if (ct === 'images') {
850 cta.push(PVE.Utils.imagesText);
851 } else if (ct === 'backup') {
852 cta.push(PVE.Utils.backupFileText);
853 } else if (ct === 'vztmpl') {
854 cta.push(PVE.Utils.vztmplText);
855 } else if (ct === 'iso') {
856 cta.push(PVE.Utils.isoImageText);
857 } else if (ct === 'rootdir') {
858 cta.push(PVE.Utils.containersText);
859 }
860 });
861
862 return cta.join(', ');
863 },
864
865 render_storage_content: function(value, metaData, record) {
866 var data = record.data;
867 if (Ext.isNumber(data.channel) &&
868 Ext.isNumber(data.id) &&
869 Ext.isNumber(data.lun)) {
0be88ae1
DC
870 return "CH " +
871 Ext.String.leftPad(data.channel,2, '0') +
b0a6d326
EK
872 " ID " + data.id + " LUN " + data.lun;
873 }
874 return data.volid.replace(/^.*:(.*\/)?/,'');
875 },
876
877 render_serverity: function (value) {
878 return PVE.Utils.log_severity_hash[value] || value;
879 },
880
881 render_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
882
883 if (!(record.data.uptime && Ext.isNumeric(value))) {
884 return '';
885 }
886
887 var maxcpu = record.data.maxcpu || 1;
888
889 if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
890 return '';
891 }
0be88ae1 892
b0a6d326
EK
893 var per = value * 100;
894
895 return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
896 },
897
898 render_size: function(value, metaData, record, rowIndex, colIndex, store) {
899 /*jslint confusion: true */
900
901 if (!Ext.isNumeric(value)) {
902 return '';
903 }
904
905 return PVE.Utils.format_size(value);
906 },
907
908 render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) {
909 var servertime = new Date(value * 1000);
910 return Ext.Date.format(servertime, 'Y-m-d H:i:s');
911 },
912
0bfc799f
DC
913 calculate_mem_usage: function(data) {
914 if (!Ext.isNumeric(data.mem) ||
915 data.maxmem === 0 ||
916 data.uptime < 1) {
917 return -1;
918 }
919
920 return (data.mem / data.maxmem);
921 },
922
923 render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
924 if (!Ext.isNumeric(value) || value === -1) {
925 return '';
926 }
927 if (value > 1 ) {
928 // we got no percentage but bytes
929 var mem = value;
930 var maxmem = record.data.maxmem;
931 if (!record.data.uptime ||
932 maxmem === 0 ||
933 !Ext.isNumeric(mem)) {
934 return '';
935 }
936
937 return ((mem*100)/maxmem).toFixed(1) + " %";
938 }
939 return (value*100).toFixed(1) + " %";
940 },
941
b0a6d326
EK
942 render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
943
944 var mem = value;
945 var maxmem = record.data.maxmem;
0be88ae1 946
b0a6d326
EK
947 if (!record.data.uptime) {
948 return '';
949 }
950
951 if (!(Ext.isNumeric(mem) && maxmem)) {
952 return '';
953 }
954
728f1b97 955 return PVE.Utils.render_size(value);
b0a6d326
EK
956 },
957
0bfc799f
DC
958 calculate_disk_usage: function(data) {
959
960 if (!Ext.isNumeric(data.disk) ||
961 data.type === 'qemu' ||
962 (data.type === 'lxc' && data.uptime === 0) ||
963 data.maxdisk === 0) {
964 return -1;
965 }
966
967 return (data.disk / data.maxdisk);
968 },
969
970 render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
971 if (!Ext.isNumeric(value) || value === -1) {
972 return '';
973 }
974
975 return (value * 100).toFixed(1) + " %";
976 },
977
b0a6d326
EK
978 render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
979
980 var disk = value;
981 var maxdisk = record.data.maxdisk;
728f1b97 982 var type = record.data.type;
b0a6d326 983
728f1b97
DC
984 if (!Ext.isNumeric(disk) ||
985 type === 'qemu' ||
986 maxdisk === 0 ||
987 (type === 'lxc' && record.data.uptime === 0)) {
b0a6d326
EK
988 return '';
989 }
990
728f1b97 991 return PVE.Utils.render_size(value);
b0a6d326
EK
992 },
993
994 render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
995
b1d8e73d
DC
996 var icon = '';
997 var gridcls = '';
998
999 switch (value) {
1000 case 'lxc': icon = 'cube';
1001 gridcls = '-stopped';
1002 break;
1003 case 'qemu': icon = 'desktop';
1004 gridcls = '-stopped';
1005 break;
1006 case 'node': icon = 'building';
1007 gridcls = '-offline';
1008 break;
1009 case 'storage': icon = 'database'; break;
1010 case 'pool': icon = 'tags'; break;
1011 default: icon = 'file';
1012 }
1013
1014 if (value === 'lxc' || value === 'qemu') {
1015 if (record.data.running && record.data.status !== 'paused') {
1016 gridcls = '-running';
1017 } else if (record.data.running) {
1018 gridcls = '-paused';
1019 }
1020 if (record.data.template) {
1021 icon = 'file-o';
1022 gridcls = '-template-' + value;
1023 }
1024 } else if (value === 'node') {
1025 if (record.data.running) {
a764c5f7 1026 gridcls = '-online';
b1d8e73d 1027 }
b0a6d326
EK
1028 }
1029
a764c5f7 1030 var fa = '<i class="fa fa-fw x-fa-grid' + gridcls + ' fa-' + icon + '"></i> ';
b1d8e73d 1031 return fa + value;
b0a6d326
EK
1032 },
1033
1034 render_uptime: function(value, metaData, record, rowIndex, colIndex, store) {
1035
1036 var uptime = value;
1037
1038 if (uptime === undefined) {
1039 return '';
1040 }
0be88ae1 1041
b0a6d326
EK
1042 if (uptime <= 0) {
1043 return '-';
1044 }
1045
1046 return PVE.Utils.format_duration_long(uptime);
1047 },
1048
1049 render_support_level: function(value, metaData, record) {
1050 return PVE.Utils.support_level_hash[value] || '-';
1051 },
1052
0be88ae1 1053 render_upid: function(value, metaData, record) {
b0a6d326
EK
1054 var type = record.data.type;
1055 var id = record.data.id;
1056
1057 return PVE.Utils.format_task_description(type, id);
1058 },
1059
054ac1b8
DC
1060 /* render functions for new status panel */
1061
1062 render_usage: function(val) {
1063 return (val*100).toFixed(2) + '%';
1064 },
1065
1066 render_cpu_usage: function(val, max) {
1067 return Ext.String.format(gettext('{0}% of {1}') +
1068 ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max);
1069 },
1070
1071 render_size_usage: function(val, max) {
1072 return (val*100/max).toFixed(2) + '% '+ '(' +
1073 Ext.String.format(gettext('{0} of {1}'),
1074 PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')';
1075 },
1076
1077 /* this is different for nodes */
1078 render_node_cpu_usage: function(value, record) {
1079 return PVE.Utils.render_cpu_usage(value, record.cpus);
1080 },
1081
1082 /* this is different for nodes */
1083 render_node_size_usage: function(record) {
1084 return PVE.Utils.render_size_usage(record.used, record.total);
1085 },
1086
b0a6d326
EK
1087 dialog_title: function(subject, create, isAdd) {
1088 if (create) {
1089 if (isAdd) {
1090 return gettext('Add') + ': ' + subject;
1091 } else {
1092 return gettext('Create') + ': ' + subject;
1093 }
1094 } else {
1095 return gettext('Edit') + ': ' + subject;
1096 }
1097 },
aa0819a8
WB
1098
1099 windowHostname: function() {
1100 return window.location.hostname.replace(IP6_bracket_match,
1101 function(m, addr, offset, original) { return addr; });
1102 },
0be88ae1 1103
b0a6d326
EK
1104 openDefaultConsoleWindow: function(allowSpice, vmtype, vmid, nodename, vmname) {
1105 var dv = PVE.Utils.defaultViewer(allowSpice);
1106 PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname);
1107 },
1108
1109 openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname) {
9e361643 1110 // kvm, lxc, shell, upgrade
b0a6d326 1111
9e361643 1112 if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) {
b0a6d326
EK
1113 throw "missing vmid";
1114 }
1115
1116 if (!nodename) {
1117 throw "no nodename specified";
1118 }
1119
c7218ab3
DC
1120 if (viewer === 'html5') {
1121 PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname);
b0a6d326
EK
1122 } else if (viewer === 'vv') {
1123 var url;
aa0819a8 1124 var params = { proxy: PVE.Utils.windowHostname() };
b0a6d326
EK
1125 if (vmtype === 'kvm') {
1126 url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy';
1127 PVE.Utils.openSpiceViewer(url, params);
9e361643
DM
1128 } else if (vmtype === 'lxc') {
1129 url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy';
b0a6d326
EK
1130 PVE.Utils.openSpiceViewer(url, params);
1131 } else if (vmtype === 'shell') {
1132 url = '/nodes/' + nodename + '/spiceshell';
1133 PVE.Utils.openSpiceViewer(url, params);
1134 } else if (vmtype === 'upgrade') {
1135 url = '/nodes/' + nodename + '/spiceshell';
1136 params.upgrade = 1;
1137 PVE.Utils.openSpiceViewer(url, params);
1138 }
1139 } else {
1140 throw "unknown viewer type";
1141 }
1142 },
1143
1144 defaultViewer: function(allowSpice) {
1145 var vncdefault = 'html5';
1146 var dv = PVE.VersionInfo.console || vncdefault;
1147 if (dv === 'vv' && !allowSpice) {
1148 dv = vncdefault;
1149 }
1150
1151 return dv;
1152 },
1153
c7218ab3 1154 openVNCViewer: function(vmtype, vmid, nodename, vmname) {
b0a6d326 1155 var url = Ext.urlEncode({
9e361643 1156 console: vmtype, // kvm, lxc, upgrade or shell
c7218ab3 1157 novnc: 1,
b0a6d326
EK
1158 vmid: vmid,
1159 vmname: vmname,
1160 node: nodename
1161 });
1162 var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
1163 nw.focus();
1164 },
1165
1166 openSpiceViewer: function(url, params){
1167
1168 var downloadWithName = function(uri, name) {
1169 var link = Ext.DomHelper.append(document.body, {
1170 tag: 'a',
1171 href: uri,
1172 css : 'display:none;visibility:hidden;height:0px;'
1173 });
1174
1175 // Note: we need to tell android the correct file name extension
1176 // but we do not set 'download' tag for other environments, because
1177 // It can have strange side effects (additional user prompt on firefox)
1178 var andriod = navigator.userAgent.match(/Android/i) ? true : false;
1179 if (andriod) {
1180 link.download = name;
1181 }
1182
1183 if (link.fireEvent) {
1184 link.fireEvent('onclick');
1185 } else {
1186 var evt = document.createEvent("MouseEvents");
1187 evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
1188 link.dispatchEvent(evt);
1189 }
1190 };
1191
1192 PVE.Utils.API2Request({
1193 url: url,
1194 params: params,
1195 method: 'POST',
1196 failure: function(response, opts){
1197 Ext.Msg.alert('Error', response.htmlStatus);
1198 },
1199 success: function(response, opts){
1200 var raw = "[virt-viewer]\n";
1201 Ext.Object.each(response.result.data, function(k, v) {
1202 raw += k + "=" + v + "\n";
1203 });
1204 var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
1205 encodeURIComponent(raw);
0be88ae1 1206
b0a6d326
EK
1207 downloadWithName(url, "pve-spice.vv");
1208 }
1209 });
1210 },
1211
0be88ae1 1212 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
b0a6d326
EK
1213 // use el.mask() instead
1214 setErrorMask: function(comp, msg) {
1215 var el = comp.el;
1216 if (!el) {
1217 return;
1218 }
1219 if (!msg) {
1220 el.unmask();
1221 } else {
1222 if (msg === true) {
1223 el.mask(gettext("Loading..."));
1224 } else {
1225 el.mask(msg);
1226 }
1227 }
1228 },
1229
1230 monStoreErrors: function(me, store) {
1231 me.mon(store, 'beforeload', function(s, operation, eOpts) {
1232 if (!me.loadCount) {
1233 me.loadCount = 0; // make sure it is numeric
1234 PVE.Utils.setErrorMask(me, true);
1235 }
1236 });
1237
1238 // only works with 'pve' proxy
1239 me.mon(store.proxy, 'afterload', function(proxy, request, success) {
1240 me.loadCount++;
1241
1242 if (success) {
1243 PVE.Utils.setErrorMask(me, false);
1244 return;
1245 }
1246
1247 var msg;
23d3881a 1248 /*jslint nomen: true */
86826854 1249 var operation = request._operation;
b0a6d326
EK
1250 var error = operation.getError();
1251 if (error.statusText) {
1252 msg = error.statusText + ' (' + error.status + ')';
1253 } else {
1254 msg = gettext('Connection error');
1255 }
1256 PVE.Utils.setErrorMask(me, msg);
1257 });
685b7aa4 1258 },
b0a6d326 1259
e3129443
DC
1260 openTreeConsole: function(tree, record, item, index, e) {
1261 e.stopEvent();
1262 var nodename = record.data.node;
1263 var vmid = record.data.vmid;
1264 var vmname = record.data.name;
1265 if (record.data.type === 'qemu' && !record.data.template) {
1266 PVE.Utils.API2Request({
1267 url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
1268 failure: function(response, opts) {
1269 Ext.Msg.alert('Error', response.htmlStatus);
1270 },
1271 success: function(response, opts) {
1272 var allowSpice = response.result.data.spice;
1273 PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname);
1274 }
1275 });
1276 } else if (record.data.type === 'lxc' && !record.data.template) {
1277 PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname);
1278 }
1279 },
1280
685b7aa4
DC
1281 createCmdMenu: function(v, record, item, index, event) {
1282 event.stopEvent();
cc1a91be
DC
1283 if (!(v instanceof Ext.tree.View)) {
1284 v.select(record);
1285 }
685b7aa4
DC
1286 var menu;
1287
1288 if (record.data.type === 'qemu' && !record.data.template) {
1289 menu = Ext.create('PVE.qemu.CmdMenu', {
1290 pveSelNode: record
1291 });
1292 } else if (record.data.type === 'qemu' && record.data.template) {
1293 menu = Ext.create('PVE.qemu.TemplateMenu', {
1294 pveSelNode: record
1295 });
1296 } else if (record.data.type === 'lxc' && !record.data.template) {
1297 menu = Ext.create('PVE.lxc.CmdMenu', {
1298 pveSelNode: record
1299 });
1300 } else if (record.data.type === 'lxc' && record.data.template) {
1301 /* since clone does not work reliably, disable for now
1302 menu = Ext.create('PVE.lxc.TemplateMenu', {
1303 pveSelNode: record
1304 });
1305 */
1306 return;
1307 } else {
1308 return;
1309 }
1310
1311 menu.showAt(event.getXY());
a50de124
DC
1312 },
1313
1314 mapDocsUrlToTitle: function(url) {
1315 var title, subtitle;
1316 // if there is a subtitle
1317 if (url.indexOf('#') !== -1) {
1318 title = DocsPages[url.split('#')[0]] || '';
1319 subtitle = DocsSubTitles[url.split('#')[1]];
1320
1321 // if we do not find the subtitle,
1322 // capitalize the beginning of every word
1323 // and replace '_' with ' '
1324 // e.g.:
1325 // '_my_text' -> 'My Text'
1326 if (!subtitle) {
1327 subtitle = url.split('#')[1].replace(/_(\w)/gi, function(match,p1){
1328 return ' ' + p1.toUpperCase();
1329 }).slice(1);
1330 }
1331
1332 if (title !== '') {
1333 title += ' - ';
1334 }
1335
1336 title += subtitle;
1337 } else {
1338 title = DocsPages[url] || '';
1339 }
1340
1341 return title;
685b7aa4 1342 }
b0a6d326
EK
1343}});
1344