]>
Commit | Line | Data |
---|---|---|
aff192e6 DM |
1 | Ext.ns('PVE'); |
2 | ||
3 | // avoid errors when running without development tools | |
4 | if (!Ext.isDefined(Ext.global.console)) { | |
5 | var console = { | |
6 | dir: function() {}, | |
7 | log: function() {} | |
8 | }; | |
9 | } | |
10 | console.log("Starting PVE Manager"); | |
11 | ||
12 | Ext.Ajax.defaultHeaders = { | |
13 | 'Accept': 'application/json' | |
14 | }; | |
15 | ||
16 | // do not send '_dc' parameter | |
17 | Ext.Ajax.disableCaching = false; | |
18 | ||
19 | Ext.Ajax.on('beforerequest', function(conn, options) { | |
20 | if (PVE.CSRFPreventionToken) { | |
21 | if (!options.headers) { | |
22 | options.headers = {}; | |
23 | } | |
24 | options.headers.CSRFPreventionToken = PVE.CSRFPreventionToken; | |
25 | } | |
26 | }); | |
27 | ||
10b4a988 | 28 | // custom Vtypes |
aff192e6 DM |
29 | Ext.apply(Ext.form.field.VTypes, { |
30 | IPAddress: function(v) { | |
31 | return (/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/).test(v); | |
32 | }, | |
33 | IPAddressText: 'Must be a numeric IP address', | |
34 | IPAddressMask: /[\d\.]/i, | |
35 | ||
36 | MacAddress: function(v) { | |
37 | return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v); | |
38 | }, | |
39 | MacAddressMask: /[a-fA-F0-9:]/, | |
40 | MacAddressText: 'Must be a valid MAC address (example: "01:23:45:67:89:ab")', | |
41 | ||
42 | BridgeName: function(v) { | |
43 | return (/^vmbr\d{1,4}$/).test(v); | |
44 | }, | |
45 | BridgeNameText: 'Allowable bridge names: vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999', | |
46 | ||
47 | BondName: function(v) { | |
48 | return (/^bond\d{1,4}$/).test(v); | |
49 | }, | |
50 | BondNameText: 'Allowable bond names: bond<b>N</b>, where 0 <= <b>N</b> <= 9999', | |
51 | ||
52 | QemuStartDate: function(v) { | |
53 | return (/^(now|\d{4}-\d{1,2}-\d{1,2}(T\d{1,2}:\d{1,2}:\d{1,2})?)$/).test(v); | |
54 | }, | |
55 | QemuStartDateText: 'Valid format for date are: "now" or "2006-06-17T16:01:21" or "2006-06-17"', | |
56 | ||
57 | StorageId: function(v) { | |
58 | return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v); | |
59 | }, | |
10b4a988 DM |
60 | StorageIdText: "ID contains illegal characters (allowed characters: 'a-z', '0-9', '-', '_' and '.')", |
61 | ||
62 | HttpProxy: function(v) { | |
63 | return (/^http:\/\/.*$/).test(v); | |
64 | }, | |
e7b95416 | 65 | HttpProxyText: "Must confirm to schema 'http://.*' (example: 'http://username:password@host:port/')" |
aff192e6 DM |
66 | }); |
67 | ||
68 | // we dont want that a displayfield set the form dirty flag! | |
69 | Ext.override(Ext.form.field.Display, { | |
70 | isDirty: function() { return false; } | |
71 | }); | |
72 | ||
73 | // hack: ExtJS does not display the correct value if we | |
74 | // call setValue while the store is loading, so we need | |
75 | // to call it again after loading | |
76 | Ext.override(Ext.form.field.ComboBox, { | |
77 | onLoad: function() { | |
78 | this.setValue(this.value, false); | |
79 | this.callOverridden(arguments); | |
80 | } | |
81 | }); | |
82 | ||
83 | Ext.define('PVE.Utils', { statics: { | |
84 | ||
85 | // this class only contains static functions | |
86 | ||
87 | log_severity_hash: { | |
88 | 0: "panic", | |
89 | 1: "alert", | |
90 | 2: "critical", | |
91 | 3: "error", | |
92 | 4: "warning", | |
93 | 5: "notice", | |
94 | 6: "info", | |
95 | 7: "debug" | |
96 | }, | |
97 | ||
98 | kvm_ostypes: { | |
99 | other: 'Other', | |
100 | wxp: 'Microsoft Windows XP/2003', | |
101 | w2k: 'Microsoft Windows 2000', | |
102 | w2k8: 'Microsoft Windows Vista/2008', | |
103 | win7: 'Microsoft Windows 7/2008r2', | |
104 | l24: 'Linux 2.4 Kernel', | |
1ea7a234 | 105 | l26: 'Linux 3.X/2.6 Kernel' |
aff192e6 DM |
106 | }, |
107 | ||
108 | render_kvm_ostype: function (value) { | |
109 | if (!value) { | |
110 | return 'Other'; | |
111 | } | |
112 | var text = PVE.Utils.kvm_ostypes[value]; | |
113 | if (text) { | |
114 | return text + ' (' + value + ')'; | |
115 | } | |
116 | return value; | |
117 | }, | |
118 | ||
119 | // fixme: auto-generate this | |
120 | // for now, please keep in sync with PVE::Tools::kvmkeymaps | |
121 | kvm_keymaps: { | |
122 | //ar: 'Arabic', | |
123 | dk: 'Danish', | |
124 | de: 'German', | |
125 | 'de-ch': 'German (Swiss)', | |
126 | 'en-gb': 'English (UK)', | |
127 | 'en-us': 'English (USA', | |
128 | es: 'Spanish', | |
129 | //et: 'Estonia', | |
130 | fi: 'Finnish', | |
131 | //fo: 'Faroe Islands', | |
132 | fr: 'French', | |
133 | 'fr-be': 'French (Belgium)', | |
134 | 'fr-ca': 'French (Canada)', | |
135 | 'fr-ch': 'French (Swiss)', | |
136 | //hr: 'Croatia', | |
137 | hu: 'Hungarian', | |
138 | is: 'Icelandic', | |
139 | it: 'Italian', | |
140 | ja: 'Japanese', | |
141 | lt: 'Lithuanian', | |
142 | //lv: 'Latvian', | |
143 | mk: 'Macedonian', | |
144 | nl: 'Dutch', | |
145 | //'nl-be': 'Dutch (Belgium)', | |
146 | no: 'Norwegian', | |
147 | pl: 'Polish', | |
148 | pt: 'Portuguese', | |
149 | 'pt-br': 'Portuguese (Brazil)', | |
150 | //ru: 'Russian', | |
151 | si: 'Slovenian' | |
152 | //sv: 'Swedish', | |
153 | //th: 'Thai', | |
154 | //tr: 'Turkish' | |
155 | }, | |
156 | ||
157 | kvm_vga_drivers: { | |
158 | std: 'Standard VGA', | |
159 | vmware: 'VMWare compatible', | |
160 | cirrus: 'Cirrus Logic GD5446' | |
161 | }, | |
162 | ||
163 | render_kvm_language: function (value) { | |
164 | if (!value) { | |
165 | return 'Default'; | |
166 | } | |
167 | var text = PVE.Utils.kvm_keymaps[value]; | |
168 | if (text) { | |
169 | return text + ' (' + value + ')'; | |
170 | } | |
171 | return value; | |
172 | }, | |
173 | ||
174 | kvm_keymap_array: function() { | |
175 | var data = [['', PVE.Utils.render_kvm_language('')]]; | |
176 | Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) { | |
177 | data.push([key, PVE.Utils.render_kvm_language(value)]); | |
178 | }); | |
179 | ||
180 | return data; | |
181 | }, | |
182 | ||
19fa0647 DM |
183 | language_map: { |
184 | en: 'English', | |
2198a479 DM |
185 | de: 'German', |
186 | fr: 'French' | |
19fa0647 DM |
187 | }, |
188 | ||
189 | render_language: function (value) { | |
190 | if (!value) { | |
191 | return 'Default (English)'; | |
192 | } | |
193 | var text = PVE.Utils.language_map[value]; | |
194 | if (text) { | |
195 | return text + ' (' + value + ')'; | |
196 | } | |
197 | return value; | |
198 | }, | |
199 | ||
200 | language_array: function() { | |
201 | var data = [['', PVE.Utils.render_language('')]]; | |
202 | Ext.Object.each(PVE.Utils.language_map, function(key, value) { | |
203 | data.push([key, PVE.Utils.render_language(value)]); | |
204 | }); | |
205 | ||
206 | return data; | |
207 | }, | |
208 | ||
aff192e6 DM |
209 | render_kvm_vga_driver: function (value) { |
210 | if (!value) { | |
133362ca | 211 | return 'OS default'; |
aff192e6 DM |
212 | } |
213 | var text = PVE.Utils.kvm_vga_drivers[value]; | |
214 | if (text) { | |
215 | return text + ' (' + value + ')'; | |
216 | } | |
217 | return value; | |
218 | }, | |
219 | ||
220 | kvm_vga_driver_array: function() { | |
221 | var data = [['', PVE.Utils.render_kvm_vga_driver('')]]; | |
222 | Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) { | |
223 | data.push([key, PVE.Utils.render_kvm_vga_driver(value)]); | |
224 | }); | |
225 | ||
226 | return data; | |
227 | }, | |
228 | ||
229 | authOK: function() { | |
230 | return Ext.util.Cookies.get('PVEAuthCookie'); | |
231 | }, | |
232 | ||
233 | authClear: function() { | |
234 | Ext.util.Cookies.clear("PVEAuthCookie"); | |
235 | }, | |
236 | ||
237 | // fixme: remove - not needed? | |
238 | gridLineHeigh: function() { | |
239 | return 21; | |
240 | ||
241 | //if (Ext.isGecko) | |
242 | //return 23; | |
243 | //return 21; | |
244 | }, | |
245 | ||
246 | extractRequestError: function(result, verbose) { | |
247 | var msg = 'Successful'; | |
248 | ||
249 | if (!result.success) { | |
250 | msg = "Unknown error"; | |
251 | if (result.message) { | |
252 | msg = result.message; | |
253 | if (result.status) { | |
254 | msg += ' (' + result.status + ')'; | |
255 | } | |
256 | } | |
257 | if (verbose && Ext.isObject(result.errors)) { | |
258 | msg += "<br>"; | |
259 | Ext.Object.each(result.errors, function(prop, desc) { | |
260 | msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " + | |
261 | Ext.htmlEncode(desc); | |
262 | }); | |
263 | } | |
264 | } | |
265 | ||
266 | return msg; | |
267 | }, | |
268 | ||
269 | extractFormActionError: function(action) { | |
270 | var msg; | |
271 | switch (action.failureType) { | |
272 | case Ext.form.action.Action.CLIENT_INVALID: | |
273 | msg = 'Form fields may not be submitted with invalid values'; | |
274 | break; | |
275 | case Ext.form.action.Action.CONNECT_FAILURE: | |
276 | msg = 'Connect failure'; | |
277 | var resp = action.response; | |
278 | if (resp.status && resp.statusText) { | |
279 | msg += " " + resp.status + ": " + resp.statusText; | |
280 | } | |
281 | break; | |
282 | case Ext.form.action.Action.LOAD_FAILURE: | |
283 | case Ext.form.action.Action.SERVER_INVALID: | |
284 | msg = PVE.Utils.extractRequestError(action.result, true); | |
285 | break; | |
286 | } | |
287 | return msg; | |
288 | }, | |
289 | ||
290 | // Ext.Ajax.request | |
291 | API2Request: function(reqOpts) { | |
292 | ||
293 | var newopts = Ext.apply({ | |
294 | waitMsg: 'Please wait...' | |
295 | }, reqOpts); | |
296 | ||
297 | if (!newopts.url.match(/^\/api2/)) { | |
298 | newopts.url = '/api2/extjs' + newopts.url; | |
299 | } | |
300 | delete newopts.callback; | |
301 | ||
302 | var createWrapper = function(successFn, callbackFn, failureFn) { | |
303 | Ext.apply(newopts, { | |
304 | success: function(response, options) { | |
305 | if (options.waitMsgTarget) { | |
306 | options.waitMsgTarget.setLoading(false); | |
307 | } | |
308 | var result = Ext.decode(response.responseText); | |
309 | response.result = result; | |
310 | if (!result.success) { | |
311 | response.htmlStatus = PVE.Utils.extractRequestError(result, true); | |
312 | Ext.callback(callbackFn, options.scope, [options, false, response]); | |
313 | Ext.callback(failureFn, options.scope, [response, options]); | |
314 | return; | |
315 | } | |
316 | Ext.callback(callbackFn, options.scope, [options, true, response]); | |
317 | Ext.callback(successFn, options.scope, [response, options]); | |
318 | }, | |
319 | failure: function(response, options) { | |
320 | if (options.waitMsgTarget) { | |
321 | options.waitMsgTarget.setLoading(false); | |
322 | } | |
52406c42 DM |
323 | response.result = {}; |
324 | try { | |
325 | response.result = Ext.decode(response.responseText); | |
db16032c | 326 | } catch(e) {} |
aff192e6 DM |
327 | var msg = "Connection error - server offline?"; |
328 | if (response.aborted) { | |
329 | msg = 'Transaction aborted.'; | |
330 | } else if (response.timedout) { | |
331 | msg = 'Communication failure: Timeout.'; | |
332 | } else if (response.status && response.statusText) { | |
333 | msg = 'Connection error ' + response.status + ': ' + response.statusText; | |
334 | } | |
335 | response.htmlStatus = msg; | |
336 | Ext.callback(callbackFn, options.scope, [options, false, response]); | |
337 | Ext.callback(failureFn, options.scope, [response, options]); | |
338 | } | |
339 | }); | |
340 | }; | |
341 | ||
342 | createWrapper(reqOpts.success, reqOpts.callback, reqOpts.failure); | |
343 | ||
344 | var target = newopts.waitMsgTarget; | |
345 | if (target) { | |
346 | // Note: ExtJS bug - this does not work when component is not rendered | |
347 | target.setLoading(newopts.waitMsg, true); | |
348 | } | |
349 | Ext.Ajax.request(newopts); | |
350 | }, | |
351 | ||
352 | assemble_field_data: function(values, data) { | |
353 | if (Ext.isObject(data)) { | |
354 | Ext.Object.each(data, function(name, val) { | |
355 | if (values.hasOwnProperty(name)) { | |
356 | var bucket = values[name]; | |
357 | if (!Ext.isArray(bucket)) { | |
358 | bucket = values[name] = [bucket]; | |
359 | } | |
360 | if (Ext.isArray(val)) { | |
361 | values[name] = bucket.concat(val); | |
362 | } else { | |
363 | bucket.push(val); | |
364 | } | |
365 | } else { | |
366 | values[name] = val; | |
367 | } | |
368 | }); | |
369 | } | |
370 | }, | |
371 | ||
acc0c13a DM |
372 | task_desc_table: { |
373 | vncproxy: 'VNC connection to VM/CT {0}', | |
374 | vncshell: 'VNC shell', | |
997b5dd6 DM |
375 | qmcreate: 'Create VM {0}', |
376 | qmrestore: 'Restore VM {0}', | |
377 | qmdestroy: 'Destroy VM {0}', | |
acc0c13a DM |
378 | qmigrate: 'Migrate VM {0}', |
379 | qmstart: 'Start VM {0}', | |
380 | qmstop: 'Stop VM {0}', | |
381 | qmreset: 'Reset VM {0}', | |
382 | qmshutdown: 'Shutdown VM {0}', | |
383 | qmsuspend: 'Suspend VM {0}', | |
384 | qmresume: 'Resume VM {0}', | |
385 | vzcreate: 'Create CT {0}', | |
aabf3add | 386 | vzrestore: 'Restore CT {0}', |
acc0c13a DM |
387 | vzdestroy: 'Destroy CT {0}', |
388 | vzstart: 'Start CT {0}', | |
389 | vzstop: 'Stop CT {0}', | |
390 | srvstart: 'Start service {0}', | |
391 | srvstop: 'Stop service {0}', | |
392 | srvrestart: 'Restart service {0}', | |
4a4051d8 DM |
393 | srvreload: 'Reload service {0}', |
394 | vzdump: 'Backup' | |
acc0c13a | 395 | }, |
d1233856 | 396 | |
acc0c13a DM |
397 | format_task_description: function(type, id) { |
398 | var format = PVE.Utils.task_desc_table[type]; | |
399 | if (format) { | |
400 | return Ext.String.format(format, id); | |
d1233856 | 401 | } |
aff192e6 DM |
402 | return type; |
403 | }, | |
404 | ||
aff192e6 DM |
405 | parse_task_upid: function(upid) { |
406 | var task = {}; | |
407 | ||
55d19d9b | 408 | var res = upid.match(/^UPID:(\S+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/); |
aff192e6 DM |
409 | if (!res) { |
410 | throw "unable to parse upid '" + upid + "'"; | |
411 | } | |
412 | task.node = res[1]; | |
413 | task.pid = parseInt(res[2], 16); | |
414 | task.pstart = parseInt(res[3], 16); | |
415 | task.starttime = parseInt(res[4], 16); | |
416 | task.type = res[5]; | |
417 | task.id = res[6]; | |
418 | task.user = res[7]; | |
419 | ||
420 | task.desc = PVE.Utils.format_task_description(task.type, task.id); | |
421 | ||
422 | return task; | |
423 | }, | |
424 | ||
425 | format_size: function(size) { | |
a2f57991 | 426 | /*jslint confusion: true */ |
aff192e6 | 427 | |
a1d849df DM |
428 | if (size < 1024) { |
429 | return size; | |
430 | } | |
431 | ||
aff192e6 DM |
432 | var kb = size / 1024; |
433 | ||
434 | if (kb < 1024) { | |
435 | return kb.toFixed(0) + "KB"; | |
436 | } | |
437 | ||
438 | var mb = size / (1024*1024); | |
439 | ||
440 | if (mb < 1024) { | |
441 | return mb.toFixed(0) + "MB"; | |
442 | } | |
443 | ||
444 | var gb = mb / 1024; | |
445 | ||
446 | if (gb < 1024) { | |
447 | return gb.toFixed(2) + "GB"; | |
448 | } | |
449 | ||
450 | var tb = gb / 1024; | |
451 | ||
452 | return tb.toFixed(2) + "TB"; | |
453 | ||
454 | }, | |
455 | ||
456 | format_html_bar: function(per, text) { | |
457 | ||
458 | return "<div class='pve-bar-wrap'>" + text + "<div class='pve-bar-border'>" + | |
459 | "<div class='pve-bar-inner' style='width:" + per + "%;'></div>" + | |
460 | "</div></div>"; | |
461 | ||
462 | }, | |
463 | ||
464 | format_cpu_bar: function(per1, per2, text) { | |
465 | ||
466 | return "<div class='pve-bar-border'>" + | |
467 | "<div class='pve-bar-inner' style='width:" + per1 + "%;'></div>" + | |
468 | "<div class='pve-bar-inner2' style='width:" + per2 + "%;'></div>" + | |
469 | "<div class='pve-bar-text'>" + text + "</div>" + | |
470 | "</div>"; | |
471 | }, | |
472 | ||
473 | format_large_bar: function(per, text) { | |
474 | ||
475 | if (!text) { | |
476 | text = per.toFixed(1) + "%"; | |
477 | } | |
478 | ||
479 | return "<div class='pve-largebar-border'>" + | |
480 | "<div class='pve-largebar-inner' style='width:" + per + "%;'></div>" + | |
481 | "<div class='pve-largebar-text'>" + text + "</div>" + | |
482 | "</div>"; | |
483 | }, | |
484 | ||
485 | format_duration_long: function(ut) { | |
486 | ||
487 | var days = Math.floor(ut / 86400); | |
488 | ut -= days*86400; | |
489 | var hours = Math.floor(ut / 3600); | |
490 | ut -= hours*3600; | |
491 | var mins = Math.floor(ut / 60); | |
492 | ut -= mins*60; | |
493 | ||
494 | var hours_str = '00' + hours.toString(); | |
495 | hours_str = hours_str.substr(hours_str.length - 2); | |
496 | var mins_str = "00" + mins.toString(); | |
497 | mins_str = mins_str.substr(mins_str.length - 2); | |
498 | var ut_str = "00" + ut.toString(); | |
499 | ut_str = ut_str.substr(ut_str.length - 2); | |
500 | ||
501 | if (days) { | |
502 | var ds = days > 1 ? 'days' : 'day'; | |
503 | return days.toString() + ' ' + ds + ' ' + | |
504 | hours_str + ':' + mins_str + ':' + ut_str; | |
505 | } else { | |
506 | return hours_str + ':' + mins_str + ':' + ut_str; | |
507 | } | |
508 | }, | |
509 | ||
510 | format_duration_short: function(ut) { | |
511 | ||
512 | if (ut < 60) { | |
513 | return ut.toString() + 's'; | |
514 | } | |
515 | ||
516 | if (ut < 3600) { | |
517 | var mins = ut / 60; | |
518 | return mins.toFixed(0) + 'm'; | |
519 | } | |
520 | ||
521 | if (ut < 86400) { | |
522 | var hours = ut / 3600; | |
523 | return hours.toFixed(0) + 'h'; | |
524 | } | |
525 | ||
526 | var days = ut / 86400; | |
527 | return days.toFixed(0) + 'd'; | |
528 | }, | |
529 | ||
530 | format_storage_type: function(value) { | |
531 | if (value === 'dir') { | |
532 | return 'Directory'; | |
533 | } else if (value === 'nfs') { | |
534 | return 'NFS'; | |
535 | } else if (value === 'lvm') { | |
536 | return 'LVM'; | |
537 | } else if (value === 'iscsi') { | |
538 | return 'iSCSI'; | |
539 | } else { | |
540 | return 'unknown'; | |
541 | } | |
542 | }, | |
543 | ||
544 | format_boolean_with_default: function(value) { | |
545 | if (Ext.isDefined(value) && value !== '') { | |
546 | return value ? 'Yes' : 'No'; | |
547 | } | |
548 | return 'Default'; | |
549 | }, | |
550 | ||
551 | format_boolean: function(value) { | |
552 | return value ? 'Yes' : 'No'; | |
553 | }, | |
554 | ||
555 | format_neg_boolean: function(value) { | |
556 | return !value ? 'Yes' : 'No'; | |
557 | }, | |
558 | ||
559 | format_content_types: function(value) { | |
560 | var cta = []; | |
561 | ||
f29297db | 562 | Ext.each(value.split(',').sort(), function(ct) { |
aff192e6 DM |
563 | if (ct === 'images') { |
564 | cta.push('Images'); | |
565 | } else if (ct === 'backup') { | |
566 | cta.push('Backups'); | |
567 | } else if (ct === 'vztmpl') { | |
568 | cta.push('Templates'); | |
569 | } else if (ct === 'iso') { | |
570 | cta.push('ISO'); | |
9f767883 DM |
571 | } else if (ct === 'rootdir') { |
572 | cta.push('Containers'); | |
aff192e6 DM |
573 | } |
574 | }); | |
575 | ||
576 | return cta.join(', '); | |
577 | }, | |
578 | ||
579 | render_storage_content: function(value, metaData, record) { | |
580 | var data = record.data; | |
581 | if (Ext.isNumber(data.channel) && | |
582 | Ext.isNumber(data.id) && | |
583 | Ext.isNumber(data.lun)) { | |
584 | return "CH " + | |
585 | Ext.String.leftPad(data.channel,2, '0') + | |
586 | " ID " + data.id + " LUN " + data.lun; | |
587 | } | |
588 | return data.volid.replace(/^.*:(.*\/)?/,''); | |
589 | }, | |
590 | ||
591 | render_serverity: function (value) { | |
592 | return PVE.Utils.log_severity_hash[value] || value; | |
593 | }, | |
594 | ||
595 | render_cpu: function(value, metaData, record, rowIndex, colIndex, store) { | |
596 | ||
105270d3 | 597 | if (!(record.data.uptime && Ext.isNumeric(value))) { |
aff192e6 DM |
598 | return ''; |
599 | } | |
600 | ||
105270d3 DM |
601 | var maxcpu = record.data.maxcpu || 1; |
602 | ||
603 | if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) { | |
aff192e6 DM |
604 | return ''; |
605 | } | |
105270d3 DM |
606 | |
607 | var per = value * 100; | |
aff192e6 DM |
608 | |
609 | return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU'); | |
610 | }, | |
611 | ||
612 | render_size: function(value, metaData, record, rowIndex, colIndex, store) { | |
a2f57991 | 613 | /*jslint confusion: true */ |
aff192e6 DM |
614 | |
615 | if (!Ext.isNumeric(value)) { | |
616 | return ''; | |
617 | } | |
618 | ||
619 | return PVE.Utils.format_size(value); | |
620 | }, | |
621 | ||
622 | render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) { | |
623 | var servertime = new Date(value * 1000); | |
624 | return Ext.Date.format(servertime, 'Y-m-d H:i:s'); | |
625 | }, | |
626 | ||
627 | render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) { | |
628 | ||
629 | var mem = value; | |
630 | var maxmem = record.data.maxmem; | |
631 | ||
632 | if (!record.data.uptime) { | |
633 | return ''; | |
634 | } | |
635 | ||
636 | if (!(Ext.isNumeric(mem) && maxmem)) { | |
637 | return ''; | |
638 | } | |
639 | ||
640 | var per = (mem * 100) / maxmem; | |
641 | ||
642 | return per.toFixed(1) + '%'; | |
643 | }, | |
644 | ||
645 | render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) { | |
646 | ||
647 | var disk = value; | |
648 | var maxdisk = record.data.maxdisk; | |
649 | ||
650 | if (!(Ext.isNumeric(disk) && maxdisk)) { | |
651 | return ''; | |
652 | } | |
653 | ||
654 | var per = (disk * 100) / maxdisk; | |
655 | ||
656 | return per.toFixed(1) + '%'; | |
657 | }, | |
658 | ||
659 | render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) { | |
660 | ||
661 | var cls = 'pve-itype-icon-' + value; | |
662 | ||
663 | if (record.data.running) { | |
664 | metaData.tdCls = cls + "-running"; | |
665 | } else { | |
666 | metaData.tdCls = cls; | |
667 | } | |
668 | ||
669 | return value; | |
670 | }, | |
671 | ||
672 | render_uptime: function(value, metaData, record, rowIndex, colIndex, store) { | |
673 | ||
674 | var uptime = value; | |
675 | ||
676 | if (uptime === undefined) { | |
677 | return ''; | |
678 | } | |
679 | ||
680 | if (uptime <= 0) { | |
681 | return '-'; | |
682 | } | |
683 | ||
684 | return PVE.Utils.format_duration_long(uptime); | |
685 | }, | |
686 | ||
687 | render_upid: function(value, metaData, record) { | |
688 | var type = record.data.type; | |
689 | var id = record.data.id; | |
690 | ||
691 | return PVE.Utils.format_task_description(type, id); | |
176eee4f DM |
692 | }, |
693 | ||
694 | openConoleWindow: function(vmtype, vmid, nodename) { | |
695 | var url = Ext.urlEncode({ | |
696 | console: vmtype, // kvm or openvz | |
697 | vmid: vmid, | |
698 | node: nodename | |
699 | }); | |
700 | var nw = window.open("?" + url, '_blank', | |
701 | "innerWidth=745,innerheight=427"); | |
702 | nw.focus(); | |
aff192e6 | 703 | } |
176eee4f | 704 | |
aff192e6 DM |
705 | }}); |
706 |