]>
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 | }, | |
a2dca26b | 33 | IPAddressText: gettext('Example') + ': 192.168.1.1', |
aff192e6 DM |
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:]/, | |
a2dca26b | 40 | MacAddressText: gettext('Example') + ': 01:23:45:67:89:ab', |
aff192e6 DM |
41 | |
42 | BridgeName: function(v) { | |
43 | return (/^vmbr\d{1,4}$/).test(v); | |
44 | }, | |
a2dca26b | 45 | BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999', |
aff192e6 DM |
46 | |
47 | BondName: function(v) { | |
48 | return (/^bond\d{1,4}$/).test(v); | |
49 | }, | |
a2dca26b | 50 | BondNameText: gettext('Format') + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999', |
aff192e6 DM |
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 | }, | |
a2dca26b | 55 | QemuStartDateText: gettext('Format') + ': "now" or "2006-06-17T16:01:21" or "2006-06-17"', |
aff192e6 DM |
56 | |
57 | StorageId: function(v) { | |
58 | return (/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i).test(v); | |
59 | }, | |
a2dca26b | 60 | StorageIdText: gettext("Allowed characters") + ": 'a-z', '0-9', '-', '_', '.'", |
10b4a988 DM |
61 | |
62 | HttpProxy: function(v) { | |
63 | return (/^http:\/\/.*$/).test(v); | |
64 | }, | |
a2dca26b | 65 | HttpProxyText: gettext('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: { | |
2ed04b3c | 99 | other: gettext('Other OS types'), |
aff192e6 DM |
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) { | |
2ed04b3c | 110 | return gettext('Other OS types'); |
aff192e6 DM |
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) { | |
2ed04b3c | 165 | return PVE.Utils.defaultText; |
aff192e6 DM |
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 | 183 | language_map: { |
22217294 | 184 | ja: 'Japanese', |
19fa0647 | 185 | en: 'English', |
2198a479 DM |
186 | de: 'German', |
187 | fr: 'French' | |
19fa0647 DM |
188 | }, |
189 | ||
190 | render_language: function (value) { | |
191 | if (!value) { | |
7e6b14a8 | 192 | return PVE.Utils.defaultText + ' (English)'; |
19fa0647 DM |
193 | } |
194 | var text = PVE.Utils.language_map[value]; | |
195 | if (text) { | |
196 | return text + ' (' + value + ')'; | |
197 | } | |
198 | return value; | |
199 | }, | |
200 | ||
201 | language_array: function() { | |
202 | var data = [['', PVE.Utils.render_language('')]]; | |
203 | Ext.Object.each(PVE.Utils.language_map, function(key, value) { | |
204 | data.push([key, PVE.Utils.render_language(value)]); | |
205 | }); | |
206 | ||
207 | return data; | |
208 | }, | |
209 | ||
aff192e6 DM |
210 | render_kvm_vga_driver: function (value) { |
211 | if (!value) { | |
2ed04b3c | 212 | return PVE.Utils.defaultText; |
aff192e6 DM |
213 | } |
214 | var text = PVE.Utils.kvm_vga_drivers[value]; | |
215 | if (text) { | |
216 | return text + ' (' + value + ')'; | |
217 | } | |
218 | return value; | |
219 | }, | |
220 | ||
221 | kvm_vga_driver_array: function() { | |
222 | var data = [['', PVE.Utils.render_kvm_vga_driver('')]]; | |
223 | Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) { | |
224 | data.push([key, PVE.Utils.render_kvm_vga_driver(value)]); | |
225 | }); | |
226 | ||
227 | return data; | |
228 | }, | |
229 | ||
230 | authOK: function() { | |
231 | return Ext.util.Cookies.get('PVEAuthCookie'); | |
232 | }, | |
233 | ||
234 | authClear: function() { | |
235 | Ext.util.Cookies.clear("PVEAuthCookie"); | |
236 | }, | |
237 | ||
238 | // fixme: remove - not needed? | |
239 | gridLineHeigh: function() { | |
240 | return 21; | |
241 | ||
242 | //if (Ext.isGecko) | |
243 | //return 23; | |
244 | //return 21; | |
245 | }, | |
246 | ||
247 | extractRequestError: function(result, verbose) { | |
a2dca26b | 248 | var msg = gettext('Successful'); |
aff192e6 DM |
249 | |
250 | if (!result.success) { | |
a2dca26b | 251 | msg = gettext("Unknown error"); |
aff192e6 DM |
252 | if (result.message) { |
253 | msg = result.message; | |
254 | if (result.status) { | |
255 | msg += ' (' + result.status + ')'; | |
256 | } | |
257 | } | |
258 | if (verbose && Ext.isObject(result.errors)) { | |
259 | msg += "<br>"; | |
260 | Ext.Object.each(result.errors, function(prop, desc) { | |
261 | msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " + | |
262 | Ext.htmlEncode(desc); | |
263 | }); | |
264 | } | |
265 | } | |
266 | ||
267 | return msg; | |
268 | }, | |
269 | ||
270 | extractFormActionError: function(action) { | |
271 | var msg; | |
272 | switch (action.failureType) { | |
273 | case Ext.form.action.Action.CLIENT_INVALID: | |
a2dca26b | 274 | msg = gettext('Form fields may not be submitted with invalid values'); |
aff192e6 DM |
275 | break; |
276 | case Ext.form.action.Action.CONNECT_FAILURE: | |
a2dca26b | 277 | msg = gettext('Connection error'); |
aff192e6 DM |
278 | var resp = action.response; |
279 | if (resp.status && resp.statusText) { | |
280 | msg += " " + resp.status + ": " + resp.statusText; | |
281 | } | |
282 | break; | |
283 | case Ext.form.action.Action.LOAD_FAILURE: | |
284 | case Ext.form.action.Action.SERVER_INVALID: | |
285 | msg = PVE.Utils.extractRequestError(action.result, true); | |
286 | break; | |
287 | } | |
288 | return msg; | |
289 | }, | |
290 | ||
291 | // Ext.Ajax.request | |
292 | API2Request: function(reqOpts) { | |
293 | ||
294 | var newopts = Ext.apply({ | |
a2dca26b | 295 | waitMsg: gettext('Please wait...') |
aff192e6 DM |
296 | }, reqOpts); |
297 | ||
298 | if (!newopts.url.match(/^\/api2/)) { | |
299 | newopts.url = '/api2/extjs' + newopts.url; | |
300 | } | |
301 | delete newopts.callback; | |
302 | ||
303 | var createWrapper = function(successFn, callbackFn, failureFn) { | |
304 | Ext.apply(newopts, { | |
305 | success: function(response, options) { | |
306 | if (options.waitMsgTarget) { | |
307 | options.waitMsgTarget.setLoading(false); | |
308 | } | |
309 | var result = Ext.decode(response.responseText); | |
310 | response.result = result; | |
311 | if (!result.success) { | |
312 | response.htmlStatus = PVE.Utils.extractRequestError(result, true); | |
313 | Ext.callback(callbackFn, options.scope, [options, false, response]); | |
314 | Ext.callback(failureFn, options.scope, [response, options]); | |
315 | return; | |
316 | } | |
317 | Ext.callback(callbackFn, options.scope, [options, true, response]); | |
318 | Ext.callback(successFn, options.scope, [response, options]); | |
319 | }, | |
320 | failure: function(response, options) { | |
321 | if (options.waitMsgTarget) { | |
322 | options.waitMsgTarget.setLoading(false); | |
323 | } | |
52406c42 DM |
324 | response.result = {}; |
325 | try { | |
326 | response.result = Ext.decode(response.responseText); | |
db16032c | 327 | } catch(e) {} |
a2dca26b | 328 | var msg = gettext('Connection error') + ' - server offline?'; |
aff192e6 | 329 | if (response.aborted) { |
a2dca26b | 330 | msg = gettext('Connection error') + ' - aborted.'; |
aff192e6 | 331 | } else if (response.timedout) { |
a2dca26b | 332 | msg = gettext('Connection error') + ' - Timeout.'; |
aff192e6 | 333 | } else if (response.status && response.statusText) { |
a2dca26b | 334 | msg = gettext('Connection error') + ' ' + response.status + ': ' + response.statusText; |
aff192e6 DM |
335 | } |
336 | response.htmlStatus = msg; | |
337 | Ext.callback(callbackFn, options.scope, [options, false, response]); | |
338 | Ext.callback(failureFn, options.scope, [response, options]); | |
339 | } | |
340 | }); | |
341 | }; | |
342 | ||
343 | createWrapper(reqOpts.success, reqOpts.callback, reqOpts.failure); | |
344 | ||
345 | var target = newopts.waitMsgTarget; | |
346 | if (target) { | |
347 | // Note: ExtJS bug - this does not work when component is not rendered | |
348 | target.setLoading(newopts.waitMsg, true); | |
349 | } | |
350 | Ext.Ajax.request(newopts); | |
351 | }, | |
352 | ||
353 | assemble_field_data: function(values, data) { | |
354 | if (Ext.isObject(data)) { | |
355 | Ext.Object.each(data, function(name, val) { | |
356 | if (values.hasOwnProperty(name)) { | |
357 | var bucket = values[name]; | |
358 | if (!Ext.isArray(bucket)) { | |
359 | bucket = values[name] = [bucket]; | |
360 | } | |
361 | if (Ext.isArray(val)) { | |
362 | values[name] = bucket.concat(val); | |
363 | } else { | |
364 | bucket.push(val); | |
365 | } | |
366 | } else { | |
367 | values[name] = val; | |
368 | } | |
369 | }); | |
370 | } | |
371 | }, | |
372 | ||
acc0c13a | 373 | task_desc_table: { |
c25f9d30 | 374 | vncproxy: [ 'VM/CT', gettext('Console') ], |
2ed04b3c | 375 | vncshell: [ '', gettext('Shell') ], |
c25f9d30 DM |
376 | qmcreate: [ 'VM', gettext('Create') ], |
377 | qmrestore: [ 'VM', gettext('Restore') ], | |
378 | qmdestroy: [ 'VM', gettext('Destroy') ], | |
379 | qmigrate: [ 'VM', gettext('Migrate') ], | |
380 | qmstart: [ 'VM', gettext('Start') ], | |
381 | qmstop: [ 'VM', gettext('Stop') ], | |
382 | qmreset: [ 'VM', gettext('Reset') ], | |
383 | qmshutdown: [ 'VM', gettext('Shutdown') ], | |
384 | qmsuspend: [ 'VM', gettext('Suspend') ], | |
385 | qmresume: [ 'VM', gettext('Resume') ], | |
386 | vzcreate: ['CT', gettext('Create') ], | |
387 | vzrestore: ['CT', gettext('Restore') ], | |
388 | vzdestroy: ['CT', gettext('Destroy') ], | |
389 | vzmigrate: [ 'CT', gettext('Migrate') ], | |
390 | vzstart: ['CT', gettext('Start') ], | |
391 | vzstop: ['CT', gettext('Stop') ], | |
392 | srvstart: ['SRV', gettext('Start') ], | |
393 | srvstop: ['SRV', gettext('Stop') ], | |
394 | srvrestart: ['SRV', gettext('Restart') ], | |
395 | srvreload: ['SRV', gettext('Reload') ], | |
2ed04b3c | 396 | vzdump: ['', gettext('Backup') ] |
acc0c13a | 397 | }, |
d1233856 | 398 | |
acc0c13a | 399 | format_task_description: function(type, id) { |
2ed04b3c DM |
400 | var farray = PVE.Utils.task_desc_table[type]; |
401 | if (!farray) { | |
402 | return type; | |
d1233856 | 403 | } |
2ed04b3c | 404 | var prefix = farray[0]; |
c25f9d30 | 405 | var text = farray[1]; |
2ed04b3c | 406 | if (prefix) { |
c25f9d30 | 407 | return prefix + ' ' + id + ' - ' + text; |
2ed04b3c | 408 | } |
81e94b6d | 409 | return text; |
aff192e6 DM |
410 | }, |
411 | ||
aff192e6 DM |
412 | parse_task_upid: function(upid) { |
413 | var task = {}; | |
414 | ||
55d19d9b | 415 | 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 |
416 | if (!res) { |
417 | throw "unable to parse upid '" + upid + "'"; | |
418 | } | |
419 | task.node = res[1]; | |
420 | task.pid = parseInt(res[2], 16); | |
421 | task.pstart = parseInt(res[3], 16); | |
422 | task.starttime = parseInt(res[4], 16); | |
423 | task.type = res[5]; | |
424 | task.id = res[6]; | |
425 | task.user = res[7]; | |
426 | ||
427 | task.desc = PVE.Utils.format_task_description(task.type, task.id); | |
428 | ||
429 | return task; | |
430 | }, | |
431 | ||
432 | format_size: function(size) { | |
a2f57991 | 433 | /*jslint confusion: true */ |
aff192e6 | 434 | |
a1d849df DM |
435 | if (size < 1024) { |
436 | return size; | |
437 | } | |
438 | ||
aff192e6 DM |
439 | var kb = size / 1024; |
440 | ||
441 | if (kb < 1024) { | |
442 | return kb.toFixed(0) + "KB"; | |
443 | } | |
444 | ||
445 | var mb = size / (1024*1024); | |
446 | ||
447 | if (mb < 1024) { | |
448 | return mb.toFixed(0) + "MB"; | |
449 | } | |
450 | ||
451 | var gb = mb / 1024; | |
452 | ||
453 | if (gb < 1024) { | |
454 | return gb.toFixed(2) + "GB"; | |
455 | } | |
456 | ||
457 | var tb = gb / 1024; | |
458 | ||
459 | return tb.toFixed(2) + "TB"; | |
460 | ||
461 | }, | |
462 | ||
463 | format_html_bar: function(per, text) { | |
464 | ||
465 | return "<div class='pve-bar-wrap'>" + text + "<div class='pve-bar-border'>" + | |
466 | "<div class='pve-bar-inner' style='width:" + per + "%;'></div>" + | |
467 | "</div></div>"; | |
468 | ||
469 | }, | |
470 | ||
471 | format_cpu_bar: function(per1, per2, text) { | |
472 | ||
473 | return "<div class='pve-bar-border'>" + | |
474 | "<div class='pve-bar-inner' style='width:" + per1 + "%;'></div>" + | |
475 | "<div class='pve-bar-inner2' style='width:" + per2 + "%;'></div>" + | |
476 | "<div class='pve-bar-text'>" + text + "</div>" + | |
477 | "</div>"; | |
478 | }, | |
479 | ||
480 | format_large_bar: function(per, text) { | |
481 | ||
482 | if (!text) { | |
483 | text = per.toFixed(1) + "%"; | |
484 | } | |
485 | ||
486 | return "<div class='pve-largebar-border'>" + | |
487 | "<div class='pve-largebar-inner' style='width:" + per + "%;'></div>" + | |
488 | "<div class='pve-largebar-text'>" + text + "</div>" + | |
489 | "</div>"; | |
490 | }, | |
491 | ||
492 | format_duration_long: function(ut) { | |
493 | ||
494 | var days = Math.floor(ut / 86400); | |
495 | ut -= days*86400; | |
496 | var hours = Math.floor(ut / 3600); | |
497 | ut -= hours*3600; | |
498 | var mins = Math.floor(ut / 60); | |
499 | ut -= mins*60; | |
500 | ||
501 | var hours_str = '00' + hours.toString(); | |
502 | hours_str = hours_str.substr(hours_str.length - 2); | |
503 | var mins_str = "00" + mins.toString(); | |
504 | mins_str = mins_str.substr(mins_str.length - 2); | |
505 | var ut_str = "00" + ut.toString(); | |
506 | ut_str = ut_str.substr(ut_str.length - 2); | |
507 | ||
508 | if (days) { | |
7e6b14a8 | 509 | var ds = days > 1 ? PVE.Utils.daysText : PVE.Utils.dayText; |
aff192e6 DM |
510 | return days.toString() + ' ' + ds + ' ' + |
511 | hours_str + ':' + mins_str + ':' + ut_str; | |
512 | } else { | |
513 | return hours_str + ':' + mins_str + ':' + ut_str; | |
514 | } | |
515 | }, | |
516 | ||
517 | format_duration_short: function(ut) { | |
518 | ||
519 | if (ut < 60) { | |
520 | return ut.toString() + 's'; | |
521 | } | |
522 | ||
523 | if (ut < 3600) { | |
524 | var mins = ut / 60; | |
525 | return mins.toFixed(0) + 'm'; | |
526 | } | |
527 | ||
528 | if (ut < 86400) { | |
529 | var hours = ut / 3600; | |
530 | return hours.toFixed(0) + 'h'; | |
531 | } | |
532 | ||
533 | var days = ut / 86400; | |
534 | return days.toFixed(0) + 'd'; | |
535 | }, | |
536 | ||
7e6b14a8 DM |
537 | yesText: gettext('Yes'), |
538 | noText: gettext('No'), | |
32314691 | 539 | errorText: gettext('Error'), |
7e6b14a8 DM |
540 | unknownText: gettext('Unknown'), |
541 | defaultText: gettext('Default'), | |
542 | daysText: gettext('days'), | |
543 | dayText: gettext('day'), | |
32314691 DM |
544 | runningText: gettext('running'), |
545 | stoppedText: gettext('stopped'), | |
7e6b14a8 | 546 | |
aff192e6 DM |
547 | format_storage_type: function(value) { |
548 | if (value === 'dir') { | |
549 | return 'Directory'; | |
550 | } else if (value === 'nfs') { | |
551 | return 'NFS'; | |
552 | } else if (value === 'lvm') { | |
553 | return 'LVM'; | |
554 | } else if (value === 'iscsi') { | |
555 | return 'iSCSI'; | |
556 | } else { | |
7e6b14a8 | 557 | return PVE.Utils.unknownText; |
aff192e6 DM |
558 | } |
559 | }, | |
560 | ||
561 | format_boolean_with_default: function(value) { | |
562 | if (Ext.isDefined(value) && value !== '') { | |
a2dca26b | 563 | return value ? PVE.Utils.yesText : PVE.Utils.noText; |
aff192e6 | 564 | } |
a2dca26b | 565 | return PVE.Utils.defaultText; |
aff192e6 DM |
566 | }, |
567 | ||
568 | format_boolean: function(value) { | |
a2dca26b | 569 | return value ? PVE.Utils.yesText : PVE.Utils.noText; |
aff192e6 DM |
570 | }, |
571 | ||
572 | format_neg_boolean: function(value) { | |
a2dca26b | 573 | return !value ? PVE.Utils.yesText : PVE.Utils.noText; |
aff192e6 DM |
574 | }, |
575 | ||
576 | format_content_types: function(value) { | |
577 | var cta = []; | |
578 | ||
f29297db | 579 | Ext.each(value.split(',').sort(), function(ct) { |
aff192e6 DM |
580 | if (ct === 'images') { |
581 | cta.push('Images'); | |
582 | } else if (ct === 'backup') { | |
583 | cta.push('Backups'); | |
584 | } else if (ct === 'vztmpl') { | |
585 | cta.push('Templates'); | |
586 | } else if (ct === 'iso') { | |
587 | cta.push('ISO'); | |
9f767883 DM |
588 | } else if (ct === 'rootdir') { |
589 | cta.push('Containers'); | |
aff192e6 DM |
590 | } |
591 | }); | |
592 | ||
593 | return cta.join(', '); | |
594 | }, | |
595 | ||
596 | render_storage_content: function(value, metaData, record) { | |
597 | var data = record.data; | |
598 | if (Ext.isNumber(data.channel) && | |
599 | Ext.isNumber(data.id) && | |
600 | Ext.isNumber(data.lun)) { | |
601 | return "CH " + | |
602 | Ext.String.leftPad(data.channel,2, '0') + | |
603 | " ID " + data.id + " LUN " + data.lun; | |
604 | } | |
605 | return data.volid.replace(/^.*:(.*\/)?/,''); | |
606 | }, | |
607 | ||
608 | render_serverity: function (value) { | |
609 | return PVE.Utils.log_severity_hash[value] || value; | |
610 | }, | |
611 | ||
612 | render_cpu: function(value, metaData, record, rowIndex, colIndex, store) { | |
613 | ||
105270d3 | 614 | if (!(record.data.uptime && Ext.isNumeric(value))) { |
aff192e6 DM |
615 | return ''; |
616 | } | |
617 | ||
105270d3 DM |
618 | var maxcpu = record.data.maxcpu || 1; |
619 | ||
620 | if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) { | |
aff192e6 DM |
621 | return ''; |
622 | } | |
105270d3 DM |
623 | |
624 | var per = value * 100; | |
aff192e6 DM |
625 | |
626 | return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU'); | |
627 | }, | |
628 | ||
629 | render_size: function(value, metaData, record, rowIndex, colIndex, store) { | |
a2f57991 | 630 | /*jslint confusion: true */ |
aff192e6 DM |
631 | |
632 | if (!Ext.isNumeric(value)) { | |
633 | return ''; | |
634 | } | |
635 | ||
636 | return PVE.Utils.format_size(value); | |
637 | }, | |
638 | ||
639 | render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) { | |
640 | var servertime = new Date(value * 1000); | |
641 | return Ext.Date.format(servertime, 'Y-m-d H:i:s'); | |
642 | }, | |
643 | ||
644 | render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) { | |
645 | ||
646 | var mem = value; | |
647 | var maxmem = record.data.maxmem; | |
648 | ||
649 | if (!record.data.uptime) { | |
650 | return ''; | |
651 | } | |
652 | ||
653 | if (!(Ext.isNumeric(mem) && maxmem)) { | |
654 | return ''; | |
655 | } | |
656 | ||
657 | var per = (mem * 100) / maxmem; | |
658 | ||
659 | return per.toFixed(1) + '%'; | |
660 | }, | |
661 | ||
662 | render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) { | |
663 | ||
664 | var disk = value; | |
665 | var maxdisk = record.data.maxdisk; | |
666 | ||
667 | if (!(Ext.isNumeric(disk) && maxdisk)) { | |
668 | return ''; | |
669 | } | |
670 | ||
671 | var per = (disk * 100) / maxdisk; | |
672 | ||
673 | return per.toFixed(1) + '%'; | |
674 | }, | |
675 | ||
676 | render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) { | |
677 | ||
678 | var cls = 'pve-itype-icon-' + value; | |
679 | ||
680 | if (record.data.running) { | |
681 | metaData.tdCls = cls + "-running"; | |
682 | } else { | |
683 | metaData.tdCls = cls; | |
684 | } | |
685 | ||
686 | return value; | |
687 | }, | |
688 | ||
689 | render_uptime: function(value, metaData, record, rowIndex, colIndex, store) { | |
690 | ||
691 | var uptime = value; | |
692 | ||
693 | if (uptime === undefined) { | |
694 | return ''; | |
695 | } | |
696 | ||
697 | if (uptime <= 0) { | |
698 | return '-'; | |
699 | } | |
700 | ||
701 | return PVE.Utils.format_duration_long(uptime); | |
702 | }, | |
703 | ||
704 | render_upid: function(value, metaData, record) { | |
705 | var type = record.data.type; | |
706 | var id = record.data.id; | |
707 | ||
708 | return PVE.Utils.format_task_description(type, id); | |
176eee4f DM |
709 | }, |
710 | ||
fb3feb55 | 711 | openConoleWindow: function(vmtype, vmid, nodename, vmname) { |
176eee4f | 712 | var url = Ext.urlEncode({ |
fb3feb55 | 713 | console: vmtype, // kvm, openvz or shell |
176eee4f | 714 | vmid: vmid, |
fb3feb55 | 715 | vmname: vmname, |
176eee4f DM |
716 | node: nodename |
717 | }); | |
718 | var nw = window.open("?" + url, '_blank', | |
719 | "innerWidth=745,innerheight=427"); | |
720 | nw.focus(); | |
aff192e6 | 721 | } |
176eee4f | 722 | |
aff192e6 DM |
723 | }}); |
724 |