]>
Commit | Line | Data |
---|---|---|
b0a6d326 EK |
1 | Ext.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 |
6 | Ext.enableAria = false; |
7 | Ext.enableAriaButtons = false; | |
8 | Ext.enableAriaPanels = false; | |
9 | ||
b0a6d326 | 10 | // avoid errors when running without development tools |
0be88ae1 DC |
11 | if (!Ext.isDefined(Ext.global.console)) { |
12 | var console = { | |
0be88ae1 | 13 | log: function() {} |
b0a6d326 EK |
14 | }; |
15 | } | |
0be88ae1 | 16 | console.log("Starting PVE Manager"); |
b0a6d326 EK |
17 | |
18 | Ext.Ajax.defaultHeaders = { | |
19 | 'Accept': 'application/json' | |
20 | }; | |
21 | ||
89ae1bb1 | 22 | /*jslint confusion: true */ |
9fa2e36d | 23 | Ext.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 | ||
49 | 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.', | |
50 | ||
51 | kvm_ostypes: { | |
45d6c71a TL |
52 | 'Linux': [ |
53 | { desc: '4.X/3.X/2.6 Kernel', val: 'l26' }, | |
54 | { desc: '2.4 Kernel', val: 'l24' } | |
55 | ], | |
56 | 'Microsoft Windows': [ | |
57 | { desc: '10/2016', val: 'win10' }, | |
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; | |
aa240b29 DC |
86 | case 'old': |
87 | icon = 'warning fa-refresh'; | |
88 | break; | |
428bc4a2 DC |
89 | case 'warning': |
90 | icon = 'warning fa-exclamation'; | |
91 | break; | |
92 | case 'critical': | |
93 | icon = 'critical fa-times'; | |
94 | break; | |
95 | default: break; | |
96 | } | |
97 | ||
98 | if (circle) { | |
99 | icon += '-circle'; | |
100 | } | |
101 | ||
102 | return icon; | |
103 | }, | |
104 | ||
046e640c DC |
105 | map_ceph_health: { |
106 | 'HEALTH_OK':'good', | |
aa240b29 | 107 | 'HEALTH_OLD':'old', |
046e640c DC |
108 | 'HEALTH_WARN':'warning', |
109 | 'HEALTH_ERR':'critical' | |
110 | }, | |
111 | ||
dfe6d184 | 112 | render_ceph_health: function(healthObj) { |
046e640c DC |
113 | var state = { |
114 | iconCls: PVE.Utils.get_health_icon(), | |
115 | text: '' | |
116 | }; | |
117 | ||
dfe6d184 | 118 | if (!healthObj || !healthObj.status) { |
046e640c DC |
119 | return state; |
120 | } | |
121 | ||
dfe6d184 | 122 | var health = PVE.Utils.map_ceph_health[healthObj.status]; |
046e640c DC |
123 | |
124 | state.iconCls = PVE.Utils.get_health_icon(health, true); | |
dfe6d184 | 125 | state.text = healthObj.status; |
046e640c DC |
126 | |
127 | return state; | |
128 | }, | |
129 | ||
fee716d3 | 130 | render_zfs_health: function(value) { |
8c8604ba TM |
131 | if (typeof value == 'undefined'){ |
132 | return ""; | |
133 | } | |
fee716d3 DC |
134 | var iconCls = 'question-circle'; |
135 | switch (value) { | |
8c8604ba | 136 | case 'AVAIL': |
fee716d3 DC |
137 | case 'ONLINE': |
138 | iconCls = 'check-circle good'; | |
139 | break; | |
140 | case 'REMOVED': | |
141 | case 'DEGRADED': | |
142 | iconCls = 'exclamation-circle warning'; | |
143 | break; | |
144 | case 'UNAVAIL': | |
145 | case 'FAULTED': | |
146 | case 'OFFLINE': | |
147 | iconCls = 'times-circle critical'; | |
148 | break; | |
149 | default: //unknown | |
150 | } | |
151 | ||
152 | return '<i class="fa fa-' + iconCls + '"></i> ' + value; | |
8c8604ba | 153 | |
fee716d3 DC |
154 | }, |
155 | ||
45d6c71a TL |
156 | get_kvm_osinfo: function(value) { |
157 | var info = { base: 'Other' }; // default | |
158 | if (value) { | |
159 | Ext.each(Object.keys(PVE.Utils.kvm_ostypes), function(k) { | |
160 | Ext.each(PVE.Utils.kvm_ostypes[k], function(e) { | |
161 | if (e.val === value) { | |
162 | info = { desc: e.desc, base: k }; | |
163 | } | |
164 | }); | |
165 | }); | |
b0a6d326 | 166 | } |
45d6c71a TL |
167 | return info; |
168 | }, | |
169 | ||
170 | render_kvm_ostype: function (value) { | |
171 | var osinfo = PVE.Utils.get_kvm_osinfo(value); | |
172 | if (osinfo.desc && osinfo.desc !== '-') { | |
173 | return osinfo.base + ' ' + osinfo.desc; | |
174 | } else { | |
175 | return osinfo.base; | |
b0a6d326 | 176 | } |
b0a6d326 EK |
177 | }, |
178 | ||
179 | render_hotplug_features: function (value) { | |
23d3881a | 180 | var fa = []; |
b0a6d326 EK |
181 | |
182 | if (!value || (value === '0')) { | |
ec99b1c3 | 183 | return gettext('Disabled'); |
b0a6d326 EK |
184 | } |
185 | ||
4dcca8a4 DC |
186 | if (value === '1') { |
187 | value = 'disk,network,usb'; | |
188 | } | |
189 | ||
b0a6d326 EK |
190 | Ext.each(value.split(','), function(el) { |
191 | if (el === 'disk') { | |
192 | fa.push(gettext('Disk')); | |
193 | } else if (el === 'network') { | |
194 | fa.push(gettext('Network')); | |
195 | } else if (el === 'usb') { | |
b9628aa5 | 196 | fa.push('USB'); |
b0a6d326 EK |
197 | } else if (el === 'memory') { |
198 | fa.push(gettext('Memory')); | |
199 | } else if (el === 'cpu') { | |
200 | fa.push(gettext('CPU')); | |
201 | } else { | |
202 | fa.push(el); | |
203 | } | |
204 | }); | |
205 | ||
206 | return fa.join(', '); | |
207 | }, | |
208 | ||
1662ccdb SI |
209 | render_qga_features: function(value) { |
210 | if (!value) { | |
211 | return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText + ')'; | |
212 | } | |
213 | var props = PVE.Parser.parsePropertyString(value, 'enabled'); | |
214 | if (!PVE.Parser.parseBoolean(props.enabled)) { | |
215 | return Proxmox.Utils.disabledText; | |
216 | } | |
217 | ||
218 | delete props.enabled; | |
219 | var agentstring = Proxmox.Utils.enabledText; | |
220 | ||
221 | Ext.Object.each(props, function(key, value) { | |
222 | var keystring = '' ; | |
223 | agentstring += ', ' + key + ': '; | |
224 | ||
225 | if (PVE.Parser.parseBoolean(value)) { | |
226 | agentstring += Proxmox.Utils.enabledText; | |
227 | } else { | |
228 | agentstring += Proxmox.Utils.disabledText; | |
229 | } | |
230 | }); | |
231 | ||
232 | return agentstring; | |
233 | }, | |
234 | ||
a1ee14a2 DC |
235 | render_qemu_machine: function(value) { |
236 | return value || (Proxmox.Utils.defaultText + ' (i440fx)'); | |
237 | }, | |
238 | ||
17c71f27 DC |
239 | render_qemu_bios: function(value) { |
240 | if (!value) { | |
e7ade592 | 241 | return Proxmox.Utils.defaultText + ' (SeaBIOS)'; |
17c71f27 DC |
242 | } else if (value === 'seabios') { |
243 | return "SeaBIOS"; | |
244 | } else if (value === 'ovmf') { | |
245 | return "OVMF (UEFI)"; | |
246 | } else { | |
247 | return value; | |
248 | } | |
249 | }, | |
250 | ||
8f17b496 TL |
251 | render_dc_ha_opts: function(value) { |
252 | if (!value) { | |
41ca3465 | 253 | return Proxmox.Utils.defaultText; |
8f17b496 TL |
254 | } else { |
255 | return PVE.Parser.printPropertyString(value); | |
256 | } | |
257 | }, | |
bb469a11 TL |
258 | render_as_property_string: function(value) { |
259 | return (!value) ? Proxmox.Utils.defaultText | |
260 | : PVE.Parser.printPropertyString(value); | |
261 | }, | |
8f17b496 | 262 | |
b0a6d326 EK |
263 | render_scsihw: function(value) { |
264 | if (!value) { | |
e7ade592 | 265 | return Proxmox.Utils.defaultText + ' (LSI 53C895A)'; |
b0a6d326 EK |
266 | } else if (value === 'lsi') { |
267 | return 'LSI 53C895A'; | |
268 | } else if (value === 'lsi53c810') { | |
269 | return 'LSI 53C810'; | |
270 | } else if (value === 'megasas') { | |
271 | return 'MegaRAID SAS 8708EM2'; | |
272 | } else if (value === 'virtio-scsi-pci') { | |
49f5d1ab EK |
273 | return 'VirtIO SCSI'; |
274 | } else if (value === 'virtio-scsi-single') { | |
275 | return 'VirtIO SCSI single'; | |
b0a6d326 EK |
276 | } else if (value === 'pvscsi') { |
277 | return 'VMware PVSCSI'; | |
278 | } else { | |
279 | return value; | |
280 | } | |
281 | }, | |
282 | ||
283 | // fixme: auto-generate this | |
284 | // for now, please keep in sync with PVE::Tools::kvmkeymaps | |
285 | kvm_keymaps: { | |
286 | //ar: 'Arabic', | |
287 | da: 'Danish', | |
0be88ae1 DC |
288 | de: 'German', |
289 | 'de-ch': 'German (Swiss)', | |
290 | 'en-gb': 'English (UK)', | |
0a5b8747 | 291 | 'en-us': 'English (USA)', |
b0a6d326 EK |
292 | es: 'Spanish', |
293 | //et: 'Estonia', | |
294 | fi: 'Finnish', | |
0be88ae1 DC |
295 | //fo: 'Faroe Islands', |
296 | fr: 'French', | |
297 | 'fr-be': 'French (Belgium)', | |
b0a6d326 EK |
298 | 'fr-ca': 'French (Canada)', |
299 | 'fr-ch': 'French (Swiss)', | |
300 | //hr: 'Croatia', | |
301 | hu: 'Hungarian', | |
302 | is: 'Icelandic', | |
0be88ae1 | 303 | it: 'Italian', |
b0a6d326 EK |
304 | ja: 'Japanese', |
305 | lt: 'Lithuanian', | |
306 | //lv: 'Latvian', | |
0be88ae1 | 307 | mk: 'Macedonian', |
b0a6d326 EK |
308 | nl: 'Dutch', |
309 | //'nl-be': 'Dutch (Belgium)', | |
0be88ae1 | 310 | no: 'Norwegian', |
b0a6d326 EK |
311 | pl: 'Polish', |
312 | pt: 'Portuguese', | |
313 | 'pt-br': 'Portuguese (Brazil)', | |
314 | //ru: 'Russian', | |
315 | sl: 'Slovenian', | |
316 | sv: 'Swedish', | |
317 | //th: 'Thai', | |
318 | tr: 'Turkish' | |
319 | }, | |
320 | ||
321 | kvm_vga_drivers: { | |
322 | std: gettext('Standard VGA'), | |
5ca366f2 | 323 | vmware: gettext('VMware compatible'), |
b0a6d326 EK |
324 | qxl: 'SPICE', |
325 | qxl2: 'SPICE dual monitor', | |
326 | qxl3: 'SPICE three monitors', | |
327 | qxl4: 'SPICE four monitors', | |
328 | serial0: gettext('Serial terminal') + ' 0', | |
329 | serial1: gettext('Serial terminal') + ' 1', | |
330 | serial2: gettext('Serial terminal') + ' 2', | |
89ae1bb1 DC |
331 | serial3: gettext('Serial terminal') + ' 3', |
332 | virtio: 'VirtIO-GPU', | |
333 | none: Proxmox.Utils.noneText | |
b0a6d326 EK |
334 | }, |
335 | ||
336 | render_kvm_language: function (value) { | |
e7ade592 DC |
337 | if (!value || value === '__default__') { |
338 | return Proxmox.Utils.defaultText; | |
b0a6d326 EK |
339 | } |
340 | var text = PVE.Utils.kvm_keymaps[value]; | |
341 | if (text) { | |
342 | return text + ' (' + value + ')'; | |
343 | } | |
344 | return value; | |
345 | }, | |
346 | ||
347 | kvm_keymap_array: function() { | |
f2782813 | 348 | var data = [['__default__', PVE.Utils.render_kvm_language('')]]; |
b0a6d326 EK |
349 | Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) { |
350 | data.push([key, PVE.Utils.render_kvm_language(value)]); | |
351 | }); | |
352 | ||
353 | return data; | |
354 | }, | |
355 | ||
3438c27e DC |
356 | console_map: { |
357 | '__default__': Proxmox.Utils.defaultText + ' (HTML5)', | |
358 | 'vv': 'SPICE (remote-viewer)', | |
359 | 'html5': 'HTML5 (noVNC)', | |
4ace5c6f | 360 | 'xtermjs': 'xterm.js' |
3438c27e DC |
361 | }, |
362 | ||
b0a6d326 | 363 | render_console_viewer: function(value) { |
3438c27e DC |
364 | value = value || '__default__'; |
365 | if (PVE.Utils.console_map[value]) { | |
366 | return PVE.Utils.console_map[value]; | |
b0a6d326 | 367 | } |
3438c27e | 368 | return value; |
b0a6d326 EK |
369 | }, |
370 | ||
755b9083 | 371 | console_viewer_array: function() { |
3438c27e | 372 | return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) { |
755b9083 TL |
373 | return [v, PVE.Utils.render_console_viewer(v)]; |
374 | }); | |
375 | }, | |
376 | ||
b0a6d326 EK |
377 | render_kvm_vga_driver: function (value) { |
378 | if (!value) { | |
e7ade592 | 379 | return Proxmox.Utils.defaultText; |
b0a6d326 | 380 | } |
4f3e66d8 DC |
381 | var vga = PVE.Parser.parsePropertyString(value, 'type'); |
382 | var text = PVE.Utils.kvm_vga_drivers[vga.type]; | |
383 | if (!vga.type) { | |
384 | text = Proxmox.Utils.defaultText; | |
385 | } | |
0be88ae1 | 386 | if (text) { |
b0a6d326 EK |
387 | return text + ' (' + value + ')'; |
388 | } | |
389 | return value; | |
390 | }, | |
391 | ||
392 | kvm_vga_driver_array: function() { | |
f2782813 | 393 | var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]]; |
b0a6d326 EK |
394 | Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) { |
395 | data.push([key, PVE.Utils.render_kvm_vga_driver(value)]); | |
396 | }); | |
397 | ||
398 | return data; | |
399 | }, | |
400 | ||
401 | render_kvm_startup: function(value) { | |
402 | var startup = PVE.Parser.parseStartup(value); | |
403 | ||
404 | var res = 'order='; | |
405 | if (startup.order === undefined) { | |
406 | res += 'any'; | |
407 | } else { | |
408 | res += startup.order; | |
409 | } | |
410 | if (startup.up !== undefined) { | |
411 | res += ',up=' + startup.up; | |
412 | } | |
413 | if (startup.down !== undefined) { | |
414 | res += ',down=' + startup.down; | |
415 | } | |
416 | ||
417 | return res; | |
418 | }, | |
419 | ||
b0a6d326 EK |
420 | extractFormActionError: function(action) { |
421 | var msg; | |
422 | switch (action.failureType) { | |
423 | case Ext.form.action.Action.CLIENT_INVALID: | |
424 | msg = gettext('Form fields may not be submitted with invalid values'); | |
425 | break; | |
426 | case Ext.form.action.Action.CONNECT_FAILURE: | |
427 | msg = gettext('Connection error'); | |
428 | var resp = action.response; | |
429 | if (resp.status && resp.statusText) { | |
430 | msg += " " + resp.status + ": " + resp.statusText; | |
431 | } | |
432 | break; | |
433 | case Ext.form.action.Action.LOAD_FAILURE: | |
434 | case Ext.form.action.Action.SERVER_INVALID: | |
e7ade592 | 435 | msg = Proxmox.Utils.extractRequestError(action.result, true); |
b0a6d326 EK |
436 | break; |
437 | } | |
438 | return msg; | |
439 | }, | |
440 | ||
b0a6d326 | 441 | format_duration_short: function(ut) { |
0be88ae1 | 442 | |
b0a6d326 | 443 | if (ut < 60) { |
530ee6b7 | 444 | return ut.toFixed(1) + 's'; |
b0a6d326 EK |
445 | } |
446 | ||
447 | if (ut < 3600) { | |
448 | var mins = ut / 60; | |
530ee6b7 | 449 | return mins.toFixed(1) + 'm'; |
b0a6d326 EK |
450 | } |
451 | ||
452 | if (ut < 86400) { | |
453 | var hours = ut / 3600; | |
530ee6b7 | 454 | return hours.toFixed(1) + 'h'; |
b0a6d326 EK |
455 | } |
456 | ||
457 | var days = ut / 86400; | |
530ee6b7 | 458 | return days.toFixed(1) + 'd'; |
b0a6d326 EK |
459 | }, |
460 | ||
0e244a29 DC |
461 | contentTypes: { |
462 | 'images': gettext('Disk image'), | |
463 | 'backup': gettext('VZDump backup file'), | |
464 | 'vztmpl': gettext('Container template'), | |
465 | 'iso': gettext('ISO image'), | |
aef28e04 DC |
466 | 'rootdir': gettext('Container'), |
467 | 'snippets': gettext('Snippets') | |
0e244a29 | 468 | }, |
b0a6d326 | 469 | |
062a7f49 TL |
470 | storageSchema: { |
471 | dir: { | |
472 | name: Proxmox.Utils.directoryText, | |
473 | ipanel: 'DirInputPanel', | |
474 | faIcon: 'folder' | |
475 | }, | |
476 | lvm: { | |
477 | name: 'LVM', | |
478 | ipanel: 'LVMInputPanel', | |
479 | faIcon: 'folder' | |
480 | }, | |
481 | lvmthin: { | |
482 | name: 'LVM-Thin', | |
483 | ipanel: 'LvmThinInputPanel', | |
484 | faIcon: 'folder' | |
485 | }, | |
486 | nfs: { | |
487 | name: 'NFS', | |
488 | ipanel: 'NFSInputPanel', | |
489 | faIcon: 'building' | |
490 | }, | |
491 | cifs: { | |
492 | name: 'CIFS', | |
493 | ipanel: 'CIFSInputPanel', | |
494 | faIcon: 'building' | |
495 | }, | |
496 | glusterfs: { | |
497 | name: 'GlusterFS', | |
498 | ipanel: 'GlusterFsInputPanel', | |
499 | faIcon: 'building' | |
500 | }, | |
501 | iscsi: { | |
502 | name: 'iSCSI', | |
503 | ipanel: 'IScsiInputPanel', | |
504 | faIcon: 'building' | |
505 | }, | |
506 | sheepdog: { | |
507 | name: 'Sheepdog', | |
508 | ipanel: 'SheepdogInputPanel', | |
509 | hideAdd: true, | |
510 | faIcon: 'building' | |
511 | }, | |
4a4b2b6e TL |
512 | cephfs: { |
513 | name: 'CephFS', | |
514 | ipanel: 'CephFSInputPanel', | |
515 | faIcon: 'building' | |
516 | }, | |
517 | pvecephfs: { | |
518 | name: 'CephFS (PVE)', | |
519 | ipanel: 'CephFSInputPanel', | |
520 | hideAdd: true, | |
521 | faIcon: 'building' | |
522 | }, | |
062a7f49 TL |
523 | rbd: { |
524 | name: 'RBD', | |
525 | ipanel: 'RBDInputPanel', | |
062a7f49 TL |
526 | faIcon: 'building' |
527 | }, | |
528 | pveceph: { | |
529 | name: 'RBD (PVE)', | |
0d1ac958 TL |
530 | ipanel: 'RBDInputPanel', |
531 | hideAdd: true, | |
062a7f49 TL |
532 | faIcon: 'building' |
533 | }, | |
534 | zfs: { | |
535 | name: 'ZFS over iSCSI', | |
536 | ipanel: 'ZFSInputPanel', | |
537 | faIcon: 'building' | |
538 | }, | |
539 | zfspool: { | |
540 | name: 'ZFS', | |
541 | ipanel: 'ZFSPoolInputPanel', | |
542 | faIcon: 'folder' | |
543 | }, | |
544 | drbd: { | |
545 | name: 'DRBD', | |
546 | hideAdd: true | |
547 | } | |
548 | }, | |
549 | ||
3c23c025 | 550 | format_storage_type: function(value, md, record) { |
4a4b2b6e TL |
551 | if (value === 'rbd') { |
552 | value = (!record || record.get('monhost') ? 'rbd' : 'pveceph'); | |
553 | } else if (value === 'cephfs') { | |
554 | value = (!record || record.get('monhost') ? 'cephfs' : 'pvecephfs'); | |
3c23c025 | 555 | } |
062a7f49 TL |
556 | |
557 | var schema = PVE.Utils.storageSchema[value]; | |
558 | if (schema) { | |
559 | return schema.name; | |
b0a6d326 | 560 | } |
062a7f49 | 561 | return Proxmox.Utils.unknownText; |
a3b8efb4 EK |
562 | }, |
563 | ||
ced1677b | 564 | format_ha: function(value) { |
e7ade592 | 565 | var text = Proxmox.Utils.noneText; |
ced1677b TL |
566 | |
567 | if (value.managed) { | |
e7ade592 | 568 | text = value.state || Proxmox.Utils.noneText; |
ced1677b | 569 | |
e7ade592 DC |
570 | text += ', ' + Proxmox.Utils.groupText + ': '; |
571 | text += value.group || Proxmox.Utils.noneText; | |
ced1677b TL |
572 | } |
573 | ||
574 | return text; | |
575 | }, | |
576 | ||
b0a6d326 | 577 | format_content_types: function(value) { |
0e244a29 DC |
578 | return value.split(',').sort().map(function(ct) { |
579 | return PVE.Utils.contentTypes[ct] || ct; | |
580 | }).join(', '); | |
b0a6d326 EK |
581 | }, |
582 | ||
583 | render_storage_content: function(value, metaData, record) { | |
584 | var data = record.data; | |
585 | if (Ext.isNumber(data.channel) && | |
586 | Ext.isNumber(data.id) && | |
587 | Ext.isNumber(data.lun)) { | |
0be88ae1 DC |
588 | return "CH " + |
589 | Ext.String.leftPad(data.channel,2, '0') + | |
b0a6d326 EK |
590 | " ID " + data.id + " LUN " + data.lun; |
591 | } | |
592 | return data.volid.replace(/^.*:(.*\/)?/,''); | |
593 | }, | |
594 | ||
595 | render_serverity: function (value) { | |
596 | return PVE.Utils.log_severity_hash[value] || value; | |
597 | }, | |
598 | ||
599 | render_cpu: function(value, metaData, record, rowIndex, colIndex, store) { | |
600 | ||
601 | if (!(record.data.uptime && Ext.isNumeric(value))) { | |
602 | return ''; | |
603 | } | |
604 | ||
605 | var maxcpu = record.data.maxcpu || 1; | |
606 | ||
607 | if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) { | |
608 | return ''; | |
609 | } | |
0be88ae1 | 610 | |
b0a6d326 EK |
611 | var per = value * 100; |
612 | ||
613 | return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU'); | |
614 | }, | |
615 | ||
616 | render_size: function(value, metaData, record, rowIndex, colIndex, store) { | |
617 | /*jslint confusion: true */ | |
618 | ||
619 | if (!Ext.isNumeric(value)) { | |
620 | return ''; | |
621 | } | |
622 | ||
e7ade592 | 623 | return Proxmox.Utils.format_size(value); |
b0a6d326 EK |
624 | }, |
625 | ||
946730cd DC |
626 | render_bandwidth: function(value) { |
627 | if (!Ext.isNumeric(value)) { | |
628 | return ''; | |
629 | } | |
630 | ||
e7ade592 | 631 | return Proxmox.Utils.format_size(value) + '/s'; |
b0a6d326 EK |
632 | }, |
633 | ||
3f633655 EK |
634 | render_timestamp_human_readable: function(value) { |
635 | return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s'); | |
636 | }, | |
637 | ||
ddd26302 DC |
638 | render_duration: function(value) { |
639 | if (value === undefined) { | |
640 | return '-'; | |
641 | } | |
642 | return PVE.Utils.format_duration_short(value); | |
643 | }, | |
644 | ||
0bfc799f DC |
645 | calculate_mem_usage: function(data) { |
646 | if (!Ext.isNumeric(data.mem) || | |
647 | data.maxmem === 0 || | |
648 | data.uptime < 1) { | |
649 | return -1; | |
650 | } | |
651 | ||
652 | return (data.mem / data.maxmem); | |
653 | }, | |
654 | ||
655 | render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { | |
656 | if (!Ext.isNumeric(value) || value === -1) { | |
657 | return ''; | |
658 | } | |
659 | if (value > 1 ) { | |
660 | // we got no percentage but bytes | |
661 | var mem = value; | |
662 | var maxmem = record.data.maxmem; | |
663 | if (!record.data.uptime || | |
664 | maxmem === 0 || | |
665 | !Ext.isNumeric(mem)) { | |
666 | return ''; | |
667 | } | |
668 | ||
669 | return ((mem*100)/maxmem).toFixed(1) + " %"; | |
670 | } | |
671 | return (value*100).toFixed(1) + " %"; | |
672 | }, | |
673 | ||
b0a6d326 EK |
674 | render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
675 | ||
676 | var mem = value; | |
677 | var maxmem = record.data.maxmem; | |
0be88ae1 | 678 | |
b0a6d326 EK |
679 | if (!record.data.uptime) { |
680 | return ''; | |
681 | } | |
682 | ||
683 | if (!(Ext.isNumeric(mem) && maxmem)) { | |
684 | return ''; | |
685 | } | |
686 | ||
728f1b97 | 687 | return PVE.Utils.render_size(value); |
b0a6d326 EK |
688 | }, |
689 | ||
0bfc799f DC |
690 | calculate_disk_usage: function(data) { |
691 | ||
692 | if (!Ext.isNumeric(data.disk) || | |
693 | data.type === 'qemu' || | |
694 | (data.type === 'lxc' && data.uptime === 0) || | |
695 | data.maxdisk === 0) { | |
696 | return -1; | |
697 | } | |
698 | ||
699 | return (data.disk / data.maxdisk); | |
700 | }, | |
701 | ||
702 | render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) { | |
703 | if (!Ext.isNumeric(value) || value === -1) { | |
704 | return ''; | |
705 | } | |
706 | ||
707 | return (value * 100).toFixed(1) + " %"; | |
708 | }, | |
709 | ||
b0a6d326 EK |
710 | render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) { |
711 | ||
712 | var disk = value; | |
713 | var maxdisk = record.data.maxdisk; | |
728f1b97 | 714 | var type = record.data.type; |
b0a6d326 | 715 | |
728f1b97 DC |
716 | if (!Ext.isNumeric(disk) || |
717 | type === 'qemu' || | |
718 | maxdisk === 0 || | |
719 | (type === 'lxc' && record.data.uptime === 0)) { | |
b0a6d326 EK |
720 | return ''; |
721 | } | |
722 | ||
728f1b97 | 723 | return PVE.Utils.render_size(value); |
b0a6d326 EK |
724 | }, |
725 | ||
4dbc64a7 DC |
726 | get_object_icon_class: function(type, record) { |
727 | var status = ''; | |
728 | var objType = type; | |
729 | ||
730 | if (type === 'type') { | |
731 | // for folder view | |
732 | objType = record.groupbyid; | |
733 | } else if (record.template) { | |
734 | // templates | |
735 | objType = 'template'; | |
736 | status = type; | |
737 | } else { | |
738 | // everything else | |
739 | status = record.status + ' ha-' + record.hastate; | |
b1d8e73d DC |
740 | } |
741 | ||
4dbc64a7 DC |
742 | var defaults = PVE.tree.ResourceTree.typeDefaults[objType]; |
743 | if (defaults && defaults.iconCls) { | |
744 | var retVal = defaults.iconCls + ' ' + status; | |
745 | return retVal; | |
b0a6d326 EK |
746 | } |
747 | ||
4dbc64a7 DC |
748 | return ''; |
749 | }, | |
750 | ||
751 | render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) { | |
752 | ||
753 | var cls = PVE.Utils.get_object_icon_class(value,record.data); | |
2b2fe160 | 754 | |
4dbc64a7 | 755 | var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> '; |
b1d8e73d | 756 | return fa + value; |
b0a6d326 EK |
757 | }, |
758 | ||
b0a6d326 EK |
759 | render_support_level: function(value, metaData, record) { |
760 | return PVE.Utils.support_level_hash[value] || '-'; | |
761 | }, | |
762 | ||
0be88ae1 | 763 | render_upid: function(value, metaData, record) { |
b0a6d326 EK |
764 | var type = record.data.type; |
765 | var id = record.data.id; | |
766 | ||
e7ade592 | 767 | return Proxmox.Utils.format_task_description(type, id); |
b0a6d326 EK |
768 | }, |
769 | ||
054ac1b8 DC |
770 | /* render functions for new status panel */ |
771 | ||
772 | render_usage: function(val) { | |
773 | return (val*100).toFixed(2) + '%'; | |
774 | }, | |
775 | ||
776 | render_cpu_usage: function(val, max) { | |
777 | return Ext.String.format(gettext('{0}% of {1}') + | |
778 | ' ' + gettext('CPU(s)'), (val*100).toFixed(2), max); | |
779 | }, | |
780 | ||
781 | render_size_usage: function(val, max) { | |
bab64974 DC |
782 | if (max === 0) { |
783 | return gettext('N/A'); | |
784 | } | |
054ac1b8 DC |
785 | return (val*100/max).toFixed(2) + '% '+ '(' + |
786 | Ext.String.format(gettext('{0} of {1}'), | |
787 | PVE.Utils.render_size(val), PVE.Utils.render_size(max)) + ')'; | |
788 | }, | |
789 | ||
790 | /* this is different for nodes */ | |
791 | render_node_cpu_usage: function(value, record) { | |
792 | return PVE.Utils.render_cpu_usage(value, record.cpus); | |
793 | }, | |
794 | ||
795 | /* this is different for nodes */ | |
796 | render_node_size_usage: function(record) { | |
797 | return PVE.Utils.render_size_usage(record.used, record.total); | |
798 | }, | |
799 | ||
27809975 DC |
800 | render_optional_url: function(value) { |
801 | var match; | |
802 | if (value && (match = value.match(/^https?:\/\//)) !== null) { | |
cdd9b6c0 | 803 | return '<a target="_blank" href="' + value + '">' + value + '</a>'; |
27809975 DC |
804 | } |
805 | return value; | |
806 | }, | |
807 | ||
808 | render_san: function(value) { | |
809 | var names = []; | |
810 | if (Ext.isArray(value)) { | |
811 | value.forEach(function(val) { | |
812 | if (!Ext.isNumber(val)) { | |
813 | names.push(val); | |
814 | } | |
815 | }); | |
816 | return names.join('<br>'); | |
817 | } | |
818 | return value; | |
819 | }, | |
820 | ||
6ad4be69 DC |
821 | render_full_name: function(firstname, metaData, record) { |
822 | var first = firstname || ''; | |
823 | var last = record.data.lastname || ''; | |
824 | return Ext.htmlEncode(first + " " + last); | |
825 | }, | |
826 | ||
2d41c7e6 TL |
827 | render_u2f_error: function(error) { |
828 | var ErrorNames = { | |
829 | '1': gettext('Other Error'), | |
830 | '2': gettext('Bad Request'), | |
831 | '3': gettext('Configuration Unsupported'), | |
832 | '4': gettext('Device Ineligible'), | |
833 | '5': gettext('Timeout') | |
834 | }; | |
835 | return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText; | |
836 | }, | |
837 | ||
aa0819a8 | 838 | windowHostname: function() { |
e7ade592 | 839 | return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match, |
aa0819a8 WB |
840 | function(m, addr, offset, original) { return addr; }); |
841 | }, | |
0be88ae1 | 842 | |
8eccc68f | 843 | openDefaultConsoleWindow: function(consoles, vmtype, vmid, nodename, vmname, cmd) { |
3438c27e | 844 | var dv = PVE.Utils.defaultViewer(consoles); |
8eccc68f | 845 | PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname, cmd); |
b0a6d326 EK |
846 | }, |
847 | ||
8eccc68f | 848 | openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname, cmd) { |
9e361643 | 849 | // kvm, lxc, shell, upgrade |
b0a6d326 | 850 | |
9e361643 | 851 | if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) { |
b0a6d326 EK |
852 | throw "missing vmid"; |
853 | } | |
854 | ||
855 | if (!nodename) { | |
856 | throw "no nodename specified"; | |
857 | } | |
858 | ||
c7218ab3 | 859 | if (viewer === 'html5') { |
8eccc68f | 860 | PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname, cmd); |
c6b2336c | 861 | } else if (viewer === 'xtermjs') { |
8eccc68f | 862 | Proxmox.Utils.openXtermJsViewer(vmtype, vmid, nodename, vmname, cmd); |
b0a6d326 EK |
863 | } else if (viewer === 'vv') { |
864 | var url; | |
aa0819a8 | 865 | var params = { proxy: PVE.Utils.windowHostname() }; |
b0a6d326 EK |
866 | if (vmtype === 'kvm') { |
867 | url = '/nodes/' + nodename + '/qemu/' + vmid.toString() + '/spiceproxy'; | |
868 | PVE.Utils.openSpiceViewer(url, params); | |
9e361643 DM |
869 | } else if (vmtype === 'lxc') { |
870 | url = '/nodes/' + nodename + '/lxc/' + vmid.toString() + '/spiceproxy'; | |
b0a6d326 EK |
871 | PVE.Utils.openSpiceViewer(url, params); |
872 | } else if (vmtype === 'shell') { | |
873 | url = '/nodes/' + nodename + '/spiceshell'; | |
874 | PVE.Utils.openSpiceViewer(url, params); | |
875 | } else if (vmtype === 'upgrade') { | |
876 | url = '/nodes/' + nodename + '/spiceshell'; | |
877 | params.upgrade = 1; | |
878 | PVE.Utils.openSpiceViewer(url, params); | |
8eccc68f TM |
879 | } else if (vmtype === 'cmd') { |
880 | url = '/nodes/' + nodename + '/spiceshell'; | |
881 | params.cmd = cmd; | |
882 | PVE.Utils.openSpiceViewer(url, params); | |
b0a6d326 EK |
883 | } |
884 | } else { | |
885 | throw "unknown viewer type"; | |
886 | } | |
887 | }, | |
888 | ||
3438c27e DC |
889 | defaultViewer: function(consoles) { |
890 | ||
891 | var allowSpice, allowXtermjs; | |
892 | ||
893 | if (consoles === true) { | |
894 | allowSpice = true; | |
895 | allowXtermjs = true; | |
896 | } else if (typeof consoles === 'object') { | |
897 | allowSpice = consoles.spice; | |
4ace5c6f | 898 | allowXtermjs = !!consoles.xtermjs; |
3438c27e | 899 | } |
b0a6d326 EK |
900 | var vncdefault = 'html5'; |
901 | var dv = PVE.VersionInfo.console || vncdefault; | |
3438c27e | 902 | if ((dv === 'vv' && !allowSpice) || (dv === 'xtermjs' && !allowXtermjs)) { |
b0a6d326 EK |
903 | dv = vncdefault; |
904 | } | |
905 | ||
906 | return dv; | |
907 | }, | |
908 | ||
8eccc68f TM |
909 | openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) { |
910 | var url = Ext.Object.toQueryString({ | |
9e361643 | 911 | console: vmtype, // kvm, lxc, upgrade or shell |
c7218ab3 | 912 | novnc: 1, |
b0a6d326 EK |
913 | vmid: vmid, |
914 | vmname: vmname, | |
16e64c97 | 915 | node: nodename, |
8eccc68f TM |
916 | resize: 'off', |
917 | cmd: cmd | |
b0a6d326 EK |
918 | }); |
919 | var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427"); | |
7af1ab47 DC |
920 | if (nw) { |
921 | nw.focus(); | |
922 | } | |
b0a6d326 EK |
923 | }, |
924 | ||
925 | openSpiceViewer: function(url, params){ | |
926 | ||
927 | var downloadWithName = function(uri, name) { | |
928 | var link = Ext.DomHelper.append(document.body, { | |
929 | tag: 'a', | |
930 | href: uri, | |
931 | css : 'display:none;visibility:hidden;height:0px;' | |
932 | }); | |
933 | ||
934 | // Note: we need to tell android the correct file name extension | |
935 | // but we do not set 'download' tag for other environments, because | |
936 | // It can have strange side effects (additional user prompt on firefox) | |
937 | var andriod = navigator.userAgent.match(/Android/i) ? true : false; | |
938 | if (andriod) { | |
939 | link.download = name; | |
940 | } | |
941 | ||
942 | if (link.fireEvent) { | |
943 | link.fireEvent('onclick'); | |
944 | } else { | |
945 | var evt = document.createEvent("MouseEvents"); | |
946 | evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null); | |
947 | link.dispatchEvent(evt); | |
948 | } | |
949 | }; | |
950 | ||
e7ade592 | 951 | Proxmox.Utils.API2Request({ |
b0a6d326 EK |
952 | url: url, |
953 | params: params, | |
954 | method: 'POST', | |
955 | failure: function(response, opts){ | |
956 | Ext.Msg.alert('Error', response.htmlStatus); | |
957 | }, | |
958 | success: function(response, opts){ | |
959 | var raw = "[virt-viewer]\n"; | |
960 | Ext.Object.each(response.result.data, function(k, v) { | |
961 | raw += k + "=" + v + "\n"; | |
962 | }); | |
963 | var url = 'data:application/x-virt-viewer;charset=UTF-8,' + | |
964 | encodeURIComponent(raw); | |
0be88ae1 | 965 | |
b0a6d326 EK |
966 | downloadWithName(url, "pve-spice.vv"); |
967 | } | |
968 | }); | |
969 | }, | |
970 | ||
e3129443 DC |
971 | openTreeConsole: function(tree, record, item, index, e) { |
972 | e.stopEvent(); | |
973 | var nodename = record.data.node; | |
974 | var vmid = record.data.vmid; | |
975 | var vmname = record.data.name; | |
976 | if (record.data.type === 'qemu' && !record.data.template) { | |
e7ade592 | 977 | Proxmox.Utils.API2Request({ |
e3129443 DC |
978 | url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current', |
979 | failure: function(response, opts) { | |
980 | Ext.Msg.alert('Error', response.htmlStatus); | |
981 | }, | |
982 | success: function(response, opts) { | |
ab9f0fe1 | 983 | var allowSpice = !!response.result.data.spice; |
e3129443 DC |
984 | PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname); |
985 | } | |
986 | }); | |
987 | } else if (record.data.type === 'lxc' && !record.data.template) { | |
988 | PVE.Utils.openDefaultConsoleWindow(true, 'lxc', vmid, nodename, vmname); | |
989 | } | |
990 | }, | |
991 | ||
fbd60cfd DM |
992 | // test automation helper |
993 | call_menu_handler: function(menu, text) { | |
994 | ||
995 | var list = menu.query('menuitem'); | |
996 | ||
997 | Ext.Array.each(list, function(item) { | |
998 | if (item.text === text) { | |
999 | if (item.handler) { | |
1000 | item.handler(); | |
1001 | return 1; | |
1002 | } else { | |
1003 | return undefined; | |
1004 | } | |
1005 | } | |
1006 | }); | |
1007 | }, | |
1008 | ||
685b7aa4 DC |
1009 | createCmdMenu: function(v, record, item, index, event) { |
1010 | event.stopEvent(); | |
cc1a91be DC |
1011 | if (!(v instanceof Ext.tree.View)) { |
1012 | v.select(record); | |
1013 | } | |
685b7aa4 | 1014 | var menu; |
9bad05bd DC |
1015 | var template = !!record.data.template; |
1016 | var type = record.data.type; | |
685b7aa4 | 1017 | |
9bad05bd DC |
1018 | if (template) { |
1019 | if (type === 'qemu' || type == 'lxc') { | |
1020 | menu = Ext.create('PVE.menu.TemplateMenu', { | |
1021 | pveSelNode: record | |
1022 | }); | |
1023 | } | |
1024 | } else if (type === 'qemu' || | |
1025 | type === 'lxc' || | |
1026 | type === 'node') { | |
1027 | menu = Ext.create('PVE.' + type + '.CmdMenu', { | |
1028 | pveSelNode: record, | |
c11ab8cb DC |
1029 | nodename: record.data.node |
1030 | }); | |
685b7aa4 DC |
1031 | } else { |
1032 | return; | |
1033 | } | |
1034 | ||
1035 | menu.showAt(event.getXY()); | |
9f0b4e04 | 1036 | return menu; |
e7ade592 | 1037 | }, |
9fa2e36d | 1038 | |
fe4f00ad TL |
1039 | // helper for deleting field which are set to there default values |
1040 | delete_if_default: function(values, fieldname, default_val, create) { | |
1041 | if (values[fieldname] === '' || values[fieldname] === default_val) { | |
1042 | if (!create) { | |
1043 | if (values['delete']) { | |
1044 | values['delete'] += ',' + fieldname; | |
1045 | } else { | |
1046 | values['delete'] = fieldname; | |
1047 | } | |
1048 | } | |
1049 | ||
1050 | delete values[fieldname]; | |
1051 | } | |
857b97a7 TL |
1052 | }, |
1053 | ||
1054 | loadSSHKeyFromFile: function(file, callback) { | |
1055 | // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with | |
1056 | // a user@host comment, 1420 for 8192 bits; current max is 16kbit | |
1057 | // assume: 740*8 for max. 32kbit (5920 byte file) | |
1058 | // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space | |
1059 | if (file.size > 8192) { | |
1060 | Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size); | |
1061 | return; | |
1062 | } | |
1063 | /*global | |
1064 | FileReader | |
1065 | */ | |
1066 | var reader = new FileReader(); | |
1067 | reader.onload = function(evt) { | |
1068 | callback(evt.target.result); | |
1069 | }; | |
1070 | reader.readAsText(file); | |
abe824aa DC |
1071 | }, |
1072 | ||
1073 | bus_counts: { ide: 4, sata: 6, scsi: 16, virtio: 16 }, | |
1074 | ||
1075 | // types is either undefined (all busses), an array of busses, or a single bus | |
1076 | forEachBus: function(types, func) { | |
1077 | var busses = Object.keys(PVE.Utils.bus_counts); | |
1078 | var i, j, count, cont; | |
1079 | ||
1080 | if (Ext.isArray(types)) { | |
1081 | busses = types; | |
1082 | } else if (Ext.isDefined(types)) { | |
1083 | busses = [ types ]; | |
1084 | } | |
1085 | ||
1086 | // check if we only have valid busses | |
1087 | for (i = 0; i < busses.length; i++) { | |
1088 | if (!PVE.Utils.bus_counts[busses[i]]) { | |
1089 | throw "invalid bus: '" + busses[i] + "'"; | |
1090 | } | |
1091 | } | |
1092 | ||
1093 | for (i = 0; i < busses.length; i++) { | |
1094 | count = PVE.Utils.bus_counts[busses[i]]; | |
1095 | for (j = 0; j < count; j++) { | |
1096 | cont = func(busses[i], j); | |
1097 | if (!cont && cont !== undefined) { | |
1098 | return; | |
1099 | } | |
1100 | } | |
1101 | } | |
14a845bc DC |
1102 | }, |
1103 | ||
483bd394 | 1104 | mp_counts: { mps: 256, unused: 256 }, |
14a845bc DC |
1105 | |
1106 | forEachMP: function(func, includeUnused) { | |
1107 | var i, cont; | |
1108 | for (i = 0; i < PVE.Utils.mp_counts.mps; i++) { | |
1109 | cont = func('mp', i); | |
1110 | if (!cont && cont !== undefined) { | |
1111 | return; | |
1112 | } | |
1113 | } | |
1114 | ||
1115 | if (!includeUnused) { | |
1116 | return; | |
1117 | } | |
1118 | ||
1119 | for (i = 0; i < PVE.Utils.mp_counts.unused; i++) { | |
1120 | cont = func('unused', i); | |
1121 | if (!cont && cont !== undefined) { | |
1122 | return; | |
1123 | } | |
1124 | } | |
b945c7c1 TM |
1125 | }, |
1126 | ||
1127 | cleanEmptyObjectKeys: function (obj) { | |
1128 | var propName; | |
1129 | for (propName in obj) { | |
1130 | if (obj.hasOwnProperty(propName)) { | |
1131 | if (obj[propName] === null || obj[propName] === undefined) { | |
1132 | delete obj[propName]; | |
1133 | } | |
1134 | } | |
1135 | } | |
4616a55b TM |
1136 | }, |
1137 | ||
1138 | handleStoreErrorOrMask: function(me, store, regex, callback) { | |
1139 | ||
1140 | me.mon(store, 'load', function (proxy, response, success, operation) { | |
1141 | ||
1142 | if (success) { | |
1143 | Proxmox.Utils.setErrorMask(me, false); | |
1144 | return; | |
1145 | } | |
1146 | var msg; | |
1147 | ||
1148 | if (operation.error.statusText) { | |
1149 | if (operation.error.statusText.match(regex)) { | |
1150 | callback(me, operation.error); | |
1151 | return; | |
1152 | } else { | |
1153 | msg = operation.error.statusText + ' (' + operation.error.status + ')'; | |
1154 | } | |
1155 | } else { | |
1156 | msg = gettext('Connection error'); | |
1157 | } | |
1158 | Proxmox.Utils.setErrorMask(me, msg); | |
1159 | }); | |
1160 | }, | |
1161 | ||
1162 | showCephInstallOrMask: function(container, msg, nodename, callback){ | |
1163 | var regex = new RegExp("not (installed|initialized)", "i"); | |
1164 | if (msg.match(regex)) { | |
1165 | if (Proxmox.UserName === 'root@pam') { | |
1166 | container.el.mask(); | |
1167 | if (!container.down('pveCephInstallWindow')){ | |
f992ef80 | 1168 | var isInstalled = msg.match(/not initialized/i) ? true : false; |
4616a55b TM |
1169 | var win = Ext.create('PVE.ceph.Install', { |
1170 | nodename: nodename | |
1171 | }); | |
f992ef80 | 1172 | win.getViewModel().set('isInstalled', isInstalled); |
4616a55b TM |
1173 | container.add(win); |
1174 | win.show(); | |
1175 | callback(win); | |
1176 | } | |
1177 | } else { | |
a7e8b87b TL |
1178 | container.mask(Ext.String.format(gettext('{0} not installed.') + |
1179 | ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']); | |
4616a55b TM |
1180 | } |
1181 | return true; | |
1182 | } else { | |
1183 | return false; | |
1184 | } | |
e7ade592 DC |
1185 | } |
1186 | }, | |
fe4f00ad | 1187 | |
9fa2e36d EK |
1188 | singleton: true, |
1189 | constructor: function() { | |
1190 | var me = this; | |
1191 | Ext.apply(me, me.utilities); | |
685b7aa4 | 1192 | } |
e7ade592 | 1193 | |
9fa2e36d | 1194 | }); |
b0a6d326 | 1195 |