]>
git.proxmox.com Git - pve-manager.git/blob - www/manager/Utils.js
3 // avoid errors when running without development tools
4 if (! Ext
. isDefined ( Ext
. global
. console
)) {
10 console
. log ( "Starting PVE Manager" );
12 Ext
. Ajax
. defaultHeaders
= {
13 'Accept' : 'application/json'
16 // do not send '_dc' parameter
17 Ext
. Ajax
. disableCaching
= false ;
19 Ext
. Ajax
. on ( 'beforerequest' , function ( conn
, options
) {
20 if ( PVE
. CSRFPreventionToken
) {
21 if (! options
. headers
) {
24 options
. headers
. CSRFPreventionToken
= PVE
. CSRFPreventionToken
;
28 var IPV4_OCTET
= "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])" ;
29 var IPV4_REGEXP
= "(?:(?:" + IPV4_OCTET
+ " \\ .){3}" + IPV4_OCTET
+ ")" ;
30 var IPV6_H16
= "(?:[0-9a-fA-F]{1,4})" ;
31 var IPV6_LS32
= "(?:(?:" + IPV6_H16
+ ":" + IPV6_H16
+ ")|" + IPV4_REGEXP
+ ")" ;
34 var IP4_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")$" );
36 var IPV6_REGEXP
= "(?:" +
37 "(?:(?:" + "(?:" + IPV6_H16
+ ":){6})" + IPV6_LS32
+ ")|" +
38 "(?:(?:" + "::" + "(?:" + IPV6_H16
+ ":){5})" + IPV6_LS32
+ ")|" +
39 "(?:(?:(?:" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){4})" + IPV6_LS32
+ ")|" +
40 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,1}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){3})" + IPV6_LS32
+ ")|" +
41 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,2}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){2})" + IPV6_LS32
+ ")|" +
42 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,3}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){1})" + IPV6_LS32
+ ")|" +
43 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,4}" + IPV6_H16
+ ")?::" + ")" + IPV6_LS32
+ ")|" +
44 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,5}" + IPV6_H16
+ ")?::" + ")" + IPV6_H16
+ ")|" +
45 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,7}" + IPV6_H16
+ ")?::" + ")" + ")" +
48 var IP64_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ ")$" );
51 Ext
. apply ( Ext
. form
. field
. VTypes
, {
52 IPAddress : function ( v
) {
53 return IP4_match
. test ( v
);
55 IPAddressText
: gettext ( 'Example' ) + ': 192.168.1.1' ,
56 IPAddressMask
: /[\d\.]/i ,
58 IP64Address : function ( v
) {
59 return IP64_match
. test ( v
);
61 IP64AddressText
: gettext ( 'Example' ) + ': 192.168.1.1 2001:DB8::42' ,
62 IP64AddressMask
: /[A-Fa-f0-9\.:]/ ,
64 MacAddress : function ( v
) {
65 return ( /^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/ ). test ( v
);
67 MacAddressMask
: /[a-fA-F0-9:]/ ,
68 MacAddressText
: gettext ( 'Example' ) + ': 01:23:45:67:89:ab' ,
70 BridgeName : function ( v
) {
71 return ( /^vmbr\d{1,4}$/ ). test ( v
);
73 BridgeNameText
: gettext ( 'Format' ) + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999' ,
75 BondName : function ( v
) {
76 return ( /^bond\d{1,4}$/ ). test ( v
);
78 BondNameText
: gettext ( 'Format' ) + ': bond<b>N</b>, where 0 <= <b>N</b> <= 9999' ,
80 QemuStartDate : function ( v
) {
81 return ( /^(now|\d{4}-\d{1,2}-\d{1,2}(T\d{1,2}:\d{1,2}:\d{1,2})?)$/ ). test ( v
);
83 QemuStartDateText
: gettext ( 'Format' ) + ': "now" or "2006-06-17T16:01:21" or "2006-06-17"' ,
85 StorageId : function ( v
) {
86 return ( /^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i ). test ( v
);
88 StorageIdText
: gettext ( "Allowed characters" ) + ": 'a-z', '0-9', '-', '_', '.'" ,
90 HttpProxy : function ( v
) {
91 return ( /^http:\/\/.*$/ ). test ( v
);
93 HttpProxyText
: gettext ( 'Example' ) + ": http://username:password@host:port/" ,
95 DnsName : function ( v
) {
96 return ( /^(([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)\.)*([A-Za-z0-9]([A-Za-z0-9\-]*[A-Za-z0-9])?)$/ ). test ( v
);
98 DnsNameText
: gettext ( 'This is not a valid DNS name' )
101 // we dont want that a displayfield set the form dirty flag!
102 Ext
. override ( Ext
. form
. field
. Display
, {
103 isDirty : function () { return false ; }
106 // hack: ExtJS does not display the correct value if we
107 // call setValue while the store is loading, so we need
108 // to call it again after loading
109 Ext
. override ( Ext
. form
. field
. ComboBox
, {
111 this . setValue ( this . value
, false );
112 this . callOverridden ( arguments
);
116 Ext
. define ( 'PVE.Utils' , { statics
: {
118 // this class only contains static functions
131 support_level_hash
: {
132 'c' : gettext ( 'Community' ),
133 'b' : gettext ( 'Basic' ),
134 's' : gettext ( 'Standard' ),
135 'p' : gettext ( 'Premium' )
138 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.' ,
141 other
: gettext ( 'Other OS types' ),
142 wxp
: 'Microsoft Windows XP/2003' ,
143 w2k
: 'Microsoft Windows 2000' ,
144 w2k8
: 'Microsoft Windows Vista/2008' ,
145 win7
: 'Microsoft Windows 7/2008r2' ,
146 win8
: 'Microsoft Windows 8/2012' ,
147 l24
: 'Linux 2.4 Kernel' ,
148 l26
: 'Linux 3.X/2.6 Kernel' ,
149 solaris
: 'Solaris Kernel'
152 render_kvm_ostype : function ( value
) {
154 return gettext ( 'Other OS types' );
156 var text
= PVE
. Utils
. kvm_ostypes
[ value
];
158 return text
+ ' (' + value
+ ')' ;
163 render_scsihw : function ( value
) {
165 return PVE
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
166 } else if ( value
=== 'lsi' ) {
167 return 'LSI 53C895A' ;
168 } else if ( value
=== 'lsi53c810' ) {
170 } else if ( value
=== 'megasas' ) {
171 return 'MegaRAID SAS 8708EM2' ;
172 } else if ( value
=== 'virtio-scsi-pci' ) {
174 } else if ( value
=== 'pvscsi' ) {
175 return 'VMware PVSCSI' ;
181 // fixme: auto-generate this
182 // for now, please keep in sync with PVE::Tools::kvmkeymaps
187 'de-ch' : 'German (Swiss)' ,
188 'en-gb' : 'English (UK)' ,
189 'en-us' : 'English (USA' ,
193 //fo: 'Faroe Islands',
195 'fr-be' : 'French (Belgium)' ,
196 'fr-ca' : 'French (Canada)' ,
197 'fr-ch' : 'French (Swiss)' ,
207 //'nl-be': 'Dutch (Belgium)',
211 'pt-br' : 'Portuguese (Brazil)' ,
220 std
: gettext ( 'Standard VGA' ),
221 vmware
: gettext ( 'VMWare compatible' ),
222 cirrus
: 'Cirrus Logic GD5446' ,
224 qxl2
: 'SPICE dual monitor' ,
225 qxl3
: 'SPICE three monitors' ,
226 qxl4
: 'SPICE four monitors' ,
227 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
228 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
229 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
230 serial3
: gettext ( 'Serial terminal' ) + ' 3'
233 render_kvm_language : function ( value
) {
235 return PVE
. Utils
. defaultText
;
237 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
239 return text
+ ' (' + value
+ ')' ;
244 kvm_keymap_array : function () {
245 var data
= [[ '' , PVE
. Utils
. render_kvm_language ( '' )]];
246 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
247 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
253 render_console_viewer : function ( value
) {
255 return PVE
. Utils
. defaultText
+ ' (Java VNC Applet)' ;
256 } else if ( value
=== 'applet' ) {
257 return 'Java VNC Applet' ;
258 } else if ( value
=== 'vv' ) {
259 return 'SPICE (remote-viewer)' ;
275 nb
: 'Norwegian (Bokmal)' ,
276 nn
: 'Norwegian (Nynorsk)' ,
281 pt_BR
: 'Portuguese (Brazil)' ,
285 render_language : function ( value
) {
287 return PVE
. Utils
. defaultText
+ ' (English)' ;
289 var text
= PVE
. Utils
. language_map
[ value
];
291 return text
+ ' (' + value
+ ')' ;
296 language_array : function () {
297 var data
= [[ '' , PVE
. Utils
. render_language ( '' )]];
298 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
299 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
305 render_kvm_vga_driver : function ( value
) {
307 return PVE
. Utils
. defaultText
;
309 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
311 return text
+ ' (' + value
+ ')' ;
316 kvm_vga_driver_array : function () {
317 var data
= [[ '' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
318 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
319 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
325 render_kvm_startup : function ( value
) {
326 var startup
= PVE
. Parser
. parseStartup ( value
);
329 if ( startup
. order
=== undefined ) {
332 res
+= startup
. order
;
334 if ( startup
. up
!== undefined ) {
335 res
+= ',up=' + startup
. up
;
337 if ( startup
. down
!== undefined ) {
338 res
+= ',down=' + startup
. down
;
345 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
348 authClear : function () {
349 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
352 // fixme: remove - not needed?
353 gridLineHeigh : function () {
361 extractRequestError : function ( result
, verbose
) {
362 var msg
= gettext ( 'Successful' );
364 if (! result
. success
) {
365 msg
= gettext ( "Unknown error" );
366 if ( result
. message
) {
367 msg
= result
. message
;
369 msg
+= ' (' + result
. status
+ ')' ;
372 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
374 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
375 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
376 Ext
. htmlEncode ( desc
);
384 extractFormActionError : function ( action
) {
386 switch ( action
. failureType
) {
387 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
388 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
390 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
391 msg
= gettext ( 'Connection error' );
392 var resp
= action
. response
;
393 if ( resp
. status
&& resp
. statusText
) {
394 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
397 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
398 case Ext
. form
. action
. Action
. SERVER_INVALID
:
399 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
406 API2Request : function ( reqOpts
) {
408 var newopts
= Ext
. apply ({
409 waitMsg
: gettext ( 'Please wait...' )
412 if (! newopts
. url
. match ( /^\/api2/ )) {
413 newopts
. url
= '/api2/extjs' + newopts
. url
;
415 delete newopts
. callback
;
417 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
419 success : function ( response
, options
) {
420 if ( options
. waitMsgTarget
) {
421 options
. waitMsgTarget
. setLoading ( false );
423 var result
= Ext
. decode ( response
. responseText
);
424 response
. result
= result
;
425 if (! result
. success
) {
426 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
427 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
428 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
431 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
432 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
434 failure : function ( response
, options
) {
435 if ( options
. waitMsgTarget
) {
436 options
. waitMsgTarget
. setLoading ( false );
438 response
. result
= {};
440 response
. result
= Ext
. decode ( response
. responseText
);
442 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
443 if ( response
. aborted
) {
444 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
445 } else if ( response
. timedout
) {
446 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
447 } else if ( response
. status
&& response
. statusText
) {
448 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
450 response
. htmlStatus
= msg
;
451 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
452 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
457 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
459 var target
= newopts
. waitMsgTarget
;
461 // Note: ExtJS bug - this does not work when component is not rendered
462 target
. setLoading ( newopts
. waitMsg
);
464 Ext
. Ajax
. request ( newopts
);
467 assemble_field_data : function ( values
, data
) {
468 if ( Ext
. isObject ( data
)) {
469 Ext
. Object
. each ( data
, function ( name
, val
) {
470 if ( values
. hasOwnProperty ( name
)) {
471 var bucket
= values
[ name
];
472 if (! Ext
. isArray ( bucket
)) {
473 bucket
= values
[ name
] = [ bucket
];
475 if ( Ext
. isArray ( val
)) {
476 values
[ name
] = bucket
. concat ( val
);
487 checked_command : function ( orig_cmd
) {
488 PVE
. Utils
. API2Request ({
489 url
: '/nodes/localhost/subscription' ,
492 failure : function ( response
, opts
) {
493 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
495 success : function ( response
, opts
) {
496 var data
= response
. result
. data
;
498 if ( data
. status
!== 'Active' ) {
500 title
: gettext ( 'No valid subscription' ),
501 icon
: Ext
. Msg
. WARNING
,
502 msg
: PVE
. Utils
. noSubKeyHtml
,
504 callback : function ( btn
) {
519 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
520 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
521 vncshell
: [ '' , gettext ( 'Shell' ) ],
522 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
523 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
524 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
525 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
526 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
527 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
528 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
529 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
530 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
531 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
532 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
533 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
534 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
535 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
536 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
537 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
538 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
539 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
540 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
541 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
542 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
543 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
544 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
545 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
546 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
547 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
548 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
549 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
550 hastart
: [ 'HA' , gettext ( 'Start' ) ],
551 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
552 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
553 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
554 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
555 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
556 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
557 imgdel
: [ '' , gettext ( 'Erase data' ) ],
558 download
: [ '' , gettext ( 'Download' ) ],
559 vzdump
: [ '' , gettext ( 'Backup' ) ],
560 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
561 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
562 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ]
565 format_task_description : function ( type
, id
) {
566 var farray
= PVE
. Utils
. task_desc_table
[ type
];
570 var prefix
= farray
[ 0 ];
571 var text
= farray
[ 1 ];
573 return prefix
+ ' ' + id
+ ' - ' + text
;
578 parse_task_upid : function ( upid
) {
581 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]+):$/ );
583 throw "unable to parse upid '" + upid
+ "'" ;
586 task
. pid
= parseInt ( res
[ 2 ], 16 );
587 task
. pstart
= parseInt ( res
[ 3 ], 16 );
588 task
. starttime
= parseInt ( res
[ 4 ], 16 );
593 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
598 format_size : function ( size
) {
599 /*jslint confusion: true */
605 var kb
= size
/ 1024 ;
608 return kb
. toFixed ( 0 ) + "KB" ;
611 var mb
= size
/ ( 1024 * 1024 );
614 return mb
. toFixed ( 0 ) + "MB" ;
620 return gb
. toFixed ( 2 ) + "GB" ;
625 return tb
. toFixed ( 2 ) + "TB" ;
629 format_html_bar : function ( per
, text
) {
631 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
632 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
637 format_cpu_bar : function ( per1
, per2
, text
) {
639 return "<div class='pve-bar-border'>" +
640 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
641 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
642 "<div class='pve-bar-text'>" + text
+ "</div>" +
646 format_large_bar : function ( per
, text
) {
649 text
= per
. toFixed ( 1 ) + "%" ;
652 return "<div class='pve-largebar-border'>" +
653 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
654 "<div class='pve-largebar-text'>" + text
+ "</div>" +
658 format_duration_long : function ( ut
) {
660 var days
= Math
. floor ( ut
/ 86400 );
662 var hours
= Math
. floor ( ut
/ 3600 );
664 var mins
= Math
. floor ( ut
/ 60 );
667 var hours_str
= '00' + hours
. toString ();
668 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
669 var mins_str
= "00" + mins
. toString ();
670 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
671 var ut_str
= "00" + ut
. toString ();
672 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
675 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
676 return days
. toString () + ' ' + ds
+ ' ' +
677 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
679 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
683 format_duration_short : function ( ut
) {
686 return ut
. toString () + 's' ;
691 return mins
. toFixed ( 0 ) + 'm' ;
695 var hours
= ut
/ 3600 ;
696 return hours
. toFixed ( 0 ) + 'h' ;
699 var days
= ut
/ 86400 ;
700 return days
. toFixed ( 0 ) + 'd' ;
703 yesText
: gettext ( 'Yes' ),
704 noText
: gettext ( 'No' ),
705 errorText
: gettext ( 'Error' ),
706 unknownText
: gettext ( 'Unknown' ),
707 defaultText
: gettext ( 'Default' ),
708 daysText
: gettext ( 'days' ),
709 dayText
: gettext ( 'day' ),
710 runningText
: gettext ( 'running' ),
711 stoppedText
: gettext ( 'stopped' ),
712 neverText
: gettext ( 'never' ),
713 totalText
: gettext ( 'Total' ),
714 usedText
: gettext ( 'Used' ),
716 format_expire : function ( date
) {
718 return PVE
. Utils
. neverText
;
720 return Ext
. Date
. format ( date
, "Y-m-d" );
723 format_storage_type : function ( value
) {
724 if ( value
=== 'dir' ) {
726 } else if ( value
=== 'nfs' ) {
728 } else if ( value
=== 'glusterfs' ) {
730 } else if ( value
=== 'lvm' ) {
732 } else if ( value
=== 'iscsi' ) {
734 } else if ( value
=== 'rbd' ) {
736 } else if ( value
=== 'sheepdog' ) {
738 } else if ( value
=== 'zfs' ) {
740 } else if ( value
=== 'iscsidirect' ) {
741 return 'iSCSIDirect' ;
743 return PVE
. Utils
. unknownText
;
747 format_boolean_with_default : function ( value
) {
748 if ( Ext
. isDefined ( value
) && value
!== '' ) {
749 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
751 return PVE
. Utils
. defaultText
;
754 format_boolean : function ( value
) {
755 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
758 format_neg_boolean : function ( value
) {
759 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
762 format_content_types : function ( value
) {
765 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
766 if ( ct
=== 'images' ) {
768 } else if ( ct
=== 'backup' ) {
770 } else if ( ct
=== 'vztmpl' ) {
771 cta
. push ( 'Templates' );
772 } else if ( ct
=== 'iso' ) {
774 } else if ( ct
=== 'rootdir' ) {
775 cta
. push ( 'Containers' );
779 return cta
. join ( ', ' );
782 render_storage_content : function ( value
, metaData
, record
) {
783 var data
= record
. data
;
784 if ( Ext
. isNumber ( data
. channel
) &&
785 Ext
. isNumber ( data
. id
) &&
786 Ext
. isNumber ( data
. lun
)) {
788 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
789 " ID " + data
. id
+ " LUN " + data
. lun
;
791 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
794 render_serverity : function ( value
) {
795 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
798 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
800 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
804 var maxcpu
= record
. data
. maxcpu
|| 1 ;
806 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
810 var per
= value
* 100 ;
812 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
815 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
816 /*jslint confusion: true */
818 if (! Ext
. isNumeric ( value
)) {
822 return PVE
. Utils
. format_size ( value
);
825 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
826 var servertime
= new Date ( value
* 1000 );
827 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
830 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
833 var maxmem
= record
. data
. maxmem
;
835 if (! record
. data
. uptime
) {
839 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
843 var per
= ( mem
* 100 ) / maxmem
;
845 return per
. toFixed ( 1 ) + '%' ;
848 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
851 var maxdisk
= record
. data
. maxdisk
;
853 if (!( Ext
. isNumeric ( disk
) && maxdisk
)) {
857 var per
= ( disk
* 100 ) / maxdisk
;
859 return per
. toFixed ( 1 ) + '%' ;
862 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
864 var cls
= 'pve-itype-icon-' + value
;
866 if ( record
. data
. running
) {
867 metaData
. tdCls
= cls
+ "-running" ;
868 } else if ( record
. data
. template
) {
869 metaData
. tdCls
= cls
+ "-template" ;
871 metaData
. tdCls
= cls
;
877 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
881 if ( uptime
=== undefined ) {
889 return PVE
. Utils
. format_duration_long ( uptime
);
892 render_support_level : function ( value
, metaData
, record
) {
893 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
896 render_upid : function ( value
, metaData
, record
) {
897 var type
= record
. data
. type
;
898 var id
= record
. data
. id
;
900 return PVE
. Utils
. format_task_description ( type
, id
);
903 dialog_title : function ( subject
, create
, isAdd
) {
906 return gettext ( 'Add' ) + ': ' + subject
;
908 return gettext ( 'Create' ) + ': ' + subject
;
911 return gettext ( 'Edit' ) + ': ' + subject
;
915 openConsoleWindow : function ( vmtype
, vmid
, nodename
, vmname
) {
916 var url
= Ext
. urlEncode ({
917 console
: vmtype
, // kvm, openvz or shell
922 var nw
= window
. open ( "?" + url
, '_blank' ,
923 "innerWidth=745,innerheight=427" );
927 defaultViewer : function (){
928 return PVE
. VersionInfo
. console
|| 'applet' ;
931 openSpiceViewer : function ( url
, params
){
932 PVE
. Utils
. API2Request ({
936 failure : function ( response
, opts
){
937 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
939 success : function ( response
, opts
){
940 var raw
= "[virt-viewer] \n " ;
941 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
942 raw
+= k
+ "=" + v
+ " \n " ;
944 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
945 encodeURIComponent ( raw
);
947 window
. open ( url
, "_top" );
952 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
953 // use el.mask() instead
954 setErrorMask : function ( comp
, msg
) {
963 el
. mask ( gettext ( "Loading..." ));
970 monStoreErrors : function ( me
, store
) {
971 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
973 me
. loadCount
= 0 ; // make sure it is numeric
974 PVE
. Utils
. setErrorMask ( me
, true );
978 // only works with 'pve' proxy
979 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
983 PVE
. Utils
. setErrorMask ( me
, false );
988 var operation
= request
. operation
;
989 var error
= operation
. getError ();
990 if ( error
. statusText
) {
991 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
993 msg
= gettext ( 'Connection error' );
995 PVE
. Utils
. setErrorMask ( me
, msg
);