]>
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)' ;
166 } else if ( value
=== 'lsi' ) {
167 return 'LSI 53C895A' ;
168 } else if ( value
=== 'megasas' ) {
169 return 'MegaRAID SAS 8708EM2' ;
170 } else if ( value
=== 'virtio-scsi-pci' ) {
177 // fixme: auto-generate this
178 // for now, please keep in sync with PVE::Tools::kvmkeymaps
183 'de-ch' : 'German (Swiss)' ,
184 'en-gb' : 'English (UK)' ,
185 'en-us' : 'English (USA' ,
189 //fo: 'Faroe Islands',
191 'fr-be' : 'French (Belgium)' ,
192 'fr-ca' : 'French (Canada)' ,
193 'fr-ch' : 'French (Swiss)' ,
203 //'nl-be': 'Dutch (Belgium)',
207 'pt-br' : 'Portuguese (Brazil)' ,
216 std
: gettext ( 'Standard VGA' ),
217 vmware
: gettext ( 'VMWare compatible' ),
218 cirrus
: 'Cirrus Logic GD5446' ,
220 qxl2
: 'SPICE dual monitor' ,
221 qxl3
: 'SPICE three monitors' ,
222 qxl4
: 'SPICE four monitors' ,
223 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
224 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
225 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
226 serial3
: gettext ( 'Serial terminal' ) + ' 3'
229 render_kvm_language : function ( value
) {
231 return PVE
. Utils
. defaultText
;
233 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
235 return text
+ ' (' + value
+ ')' ;
240 kvm_keymap_array : function () {
241 var data
= [[ '' , PVE
. Utils
. render_kvm_language ( '' )]];
242 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
243 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
259 nb
: 'Norwegian (Bokmal)' ,
260 nn
: 'Norwegian (Nynorsk)' ,
265 pt_BR
: 'Portuguese (Brazil)' ,
269 render_language : function ( value
) {
271 return PVE
. Utils
. defaultText
+ ' (English)' ;
273 var text
= PVE
. Utils
. language_map
[ value
];
275 return text
+ ' (' + value
+ ')' ;
280 language_array : function () {
281 var data
= [[ '' , PVE
. Utils
. render_language ( '' )]];
282 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
283 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
289 render_kvm_vga_driver : function ( value
) {
291 return PVE
. Utils
. defaultText
;
293 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
295 return text
+ ' (' + value
+ ')' ;
300 kvm_vga_driver_array : function () {
301 var data
= [[ '' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
302 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
303 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
309 render_kvm_startup : function ( value
) {
310 var startup
= PVE
. Parser
. parseStartup ( value
);
313 if ( startup
. order
=== undefined ) {
316 res
+= startup
. order
;
318 if ( startup
. up
!== undefined ) {
319 res
+= ',up=' + startup
. up
;
321 if ( startup
. down
!== undefined ) {
322 res
+= ',down=' + startup
. down
;
329 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
332 authClear : function () {
333 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
336 // fixme: remove - not needed?
337 gridLineHeigh : function () {
345 extractRequestError : function ( result
, verbose
) {
346 var msg
= gettext ( 'Successful' );
348 if (! result
. success
) {
349 msg
= gettext ( "Unknown error" );
350 if ( result
. message
) {
351 msg
= result
. message
;
353 msg
+= ' (' + result
. status
+ ')' ;
356 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
358 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
359 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
360 Ext
. htmlEncode ( desc
);
368 extractFormActionError : function ( action
) {
370 switch ( action
. failureType
) {
371 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
372 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
374 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
375 msg
= gettext ( 'Connection error' );
376 var resp
= action
. response
;
377 if ( resp
. status
&& resp
. statusText
) {
378 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
381 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
382 case Ext
. form
. action
. Action
. SERVER_INVALID
:
383 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
390 API2Request : function ( reqOpts
) {
392 var newopts
= Ext
. apply ({
393 waitMsg
: gettext ( 'Please wait...' )
396 if (! newopts
. url
. match ( /^\/api2/ )) {
397 newopts
. url
= '/api2/extjs' + newopts
. url
;
399 delete newopts
. callback
;
401 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
403 success : function ( response
, options
) {
404 if ( options
. waitMsgTarget
) {
405 options
. waitMsgTarget
. setLoading ( false );
407 var result
= Ext
. decode ( response
. responseText
);
408 response
. result
= result
;
409 if (! result
. success
) {
410 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
411 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
412 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
415 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
416 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
418 failure : function ( response
, options
) {
419 if ( options
. waitMsgTarget
) {
420 options
. waitMsgTarget
. setLoading ( false );
422 response
. result
= {};
424 response
. result
= Ext
. decode ( response
. responseText
);
426 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
427 if ( response
. aborted
) {
428 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
429 } else if ( response
. timedout
) {
430 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
431 } else if ( response
. status
&& response
. statusText
) {
432 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
434 response
. htmlStatus
= msg
;
435 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
436 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
441 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
443 var target
= newopts
. waitMsgTarget
;
445 // Note: ExtJS bug - this does not work when component is not rendered
446 target
. setLoading ( newopts
. waitMsg
);
448 Ext
. Ajax
. request ( newopts
);
451 assemble_field_data : function ( values
, data
) {
452 if ( Ext
. isObject ( data
)) {
453 Ext
. Object
. each ( data
, function ( name
, val
) {
454 if ( values
. hasOwnProperty ( name
)) {
455 var bucket
= values
[ name
];
456 if (! Ext
. isArray ( bucket
)) {
457 bucket
= values
[ name
] = [ bucket
];
459 if ( Ext
. isArray ( val
)) {
460 values
[ name
] = bucket
. concat ( val
);
471 checked_command : function ( orig_cmd
) {
472 PVE
. Utils
. API2Request ({
473 url
: '/nodes/localhost/subscription' ,
476 failure : function ( response
, opts
) {
477 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
479 success : function ( response
, opts
) {
480 var data
= response
. result
. data
;
482 if ( data
. status
!== 'Active' ) {
484 title
: gettext ( 'No valid subscription' ),
485 icon
: Ext
. Msg
. WARNING
,
486 msg
: PVE
. Utils
. noSubKeyHtml
,
488 callback : function ( btn
) {
503 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
504 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
505 vncshell
: [ '' , gettext ( 'Shell' ) ],
506 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
507 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
508 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
509 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
510 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
511 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
512 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
513 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
514 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
515 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
516 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
517 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
518 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
519 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
520 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
521 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
522 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
523 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
524 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
525 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
526 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
527 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
528 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
529 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
530 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
531 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
532 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
533 hastart
: [ 'HA' , gettext ( 'Start' ) ],
534 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
535 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
536 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
537 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
538 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
539 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
540 imgdel
: [ '' , gettext ( 'Erase data' ) ],
541 download
: [ '' , gettext ( 'Download' ) ],
542 vzdump
: [ '' , gettext ( 'Backup' ) ],
543 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
544 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
545 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ]
548 format_task_description : function ( type
, id
) {
549 var farray
= PVE
. Utils
. task_desc_table
[ type
];
553 var prefix
= farray
[ 0 ];
554 var text
= farray
[ 1 ];
556 return prefix
+ ' ' + id
+ ' - ' + text
;
561 parse_task_upid : function ( upid
) {
564 var res
= upid
. match ( /^UPID:(\S+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/ );
566 throw "unable to parse upid '" + upid
+ "'" ;
569 task
. pid
= parseInt ( res
[ 2 ], 16 );
570 task
. pstart
= parseInt ( res
[ 3 ], 16 );
571 task
. starttime
= parseInt ( res
[ 4 ], 16 );
576 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
581 format_size : function ( size
) {
582 /*jslint confusion: true */
588 var kb
= size
/ 1024 ;
591 return kb
. toFixed ( 0 ) + "KB" ;
594 var mb
= size
/ ( 1024 * 1024 );
597 return mb
. toFixed ( 0 ) + "MB" ;
603 return gb
. toFixed ( 2 ) + "GB" ;
608 return tb
. toFixed ( 2 ) + "TB" ;
612 format_html_bar : function ( per
, text
) {
614 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
615 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
620 format_cpu_bar : function ( per1
, per2
, text
) {
622 return "<div class='pve-bar-border'>" +
623 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
624 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
625 "<div class='pve-bar-text'>" + text
+ "</div>" +
629 format_large_bar : function ( per
, text
) {
632 text
= per
. toFixed ( 1 ) + "%" ;
635 return "<div class='pve-largebar-border'>" +
636 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
637 "<div class='pve-largebar-text'>" + text
+ "</div>" +
641 format_duration_long : function ( ut
) {
643 var days
= Math
. floor ( ut
/ 86400 );
645 var hours
= Math
. floor ( ut
/ 3600 );
647 var mins
= Math
. floor ( ut
/ 60 );
650 var hours_str
= '00' + hours
. toString ();
651 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
652 var mins_str
= "00" + mins
. toString ();
653 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
654 var ut_str
= "00" + ut
. toString ();
655 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
658 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
659 return days
. toString () + ' ' + ds
+ ' ' +
660 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
662 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
666 format_duration_short : function ( ut
) {
669 return ut
. toString () + 's' ;
674 return mins
. toFixed ( 0 ) + 'm' ;
678 var hours
= ut
/ 3600 ;
679 return hours
. toFixed ( 0 ) + 'h' ;
682 var days
= ut
/ 86400 ;
683 return days
. toFixed ( 0 ) + 'd' ;
686 yesText
: gettext ( 'Yes' ),
687 noText
: gettext ( 'No' ),
688 errorText
: gettext ( 'Error' ),
689 unknownText
: gettext ( 'Unknown' ),
690 defaultText
: gettext ( 'Default' ),
691 daysText
: gettext ( 'days' ),
692 dayText
: gettext ( 'day' ),
693 runningText
: gettext ( 'running' ),
694 stoppedText
: gettext ( 'stopped' ),
695 neverText
: gettext ( 'never' ),
696 totalText
: gettext ( 'Total' ),
697 usedText
: gettext ( 'Used' ),
699 format_expire : function ( date
) {
701 return PVE
. Utils
. neverText
;
703 return Ext
. Date
. format ( date
, "Y-m-d" );
706 format_storage_type : function ( value
) {
707 if ( value
=== 'dir' ) {
709 } else if ( value
=== 'nfs' ) {
711 } else if ( value
=== 'glusterfs' ) {
713 } else if ( value
=== 'lvm' ) {
715 } else if ( value
=== 'iscsi' ) {
717 } else if ( value
=== 'rbd' ) {
719 } else if ( value
=== 'sheepdog' ) {
721 } else if ( value
=== 'zfs' ) {
723 } else if ( value
=== 'iscsidirect' ) {
724 return 'iSCSIDirect' ;
726 return PVE
. Utils
. unknownText
;
730 format_boolean_with_default : function ( value
) {
731 if ( Ext
. isDefined ( value
) && value
!== '' ) {
732 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
734 return PVE
. Utils
. defaultText
;
737 format_boolean : function ( value
) {
738 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
741 format_neg_boolean : function ( value
) {
742 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
745 format_content_types : function ( value
) {
748 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
749 if ( ct
=== 'images' ) {
751 } else if ( ct
=== 'backup' ) {
753 } else if ( ct
=== 'vztmpl' ) {
754 cta
. push ( 'Templates' );
755 } else if ( ct
=== 'iso' ) {
757 } else if ( ct
=== 'rootdir' ) {
758 cta
. push ( 'Containers' );
762 return cta
. join ( ', ' );
765 render_storage_content : function ( value
, metaData
, record
) {
766 var data
= record
. data
;
767 if ( Ext
. isNumber ( data
. channel
) &&
768 Ext
. isNumber ( data
. id
) &&
769 Ext
. isNumber ( data
. lun
)) {
771 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
772 " ID " + data
. id
+ " LUN " + data
. lun
;
774 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
777 render_serverity : function ( value
) {
778 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
781 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
783 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
787 var maxcpu
= record
. data
. maxcpu
|| 1 ;
789 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
793 var per
= value
* 100 ;
795 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
798 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
799 /*jslint confusion: true */
801 if (! Ext
. isNumeric ( value
)) {
805 return PVE
. Utils
. format_size ( value
);
808 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
809 var servertime
= new Date ( value
* 1000 );
810 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
813 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
816 var maxmem
= record
. data
. maxmem
;
818 if (! record
. data
. uptime
) {
822 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
826 var per
= ( mem
* 100 ) / maxmem
;
828 return per
. toFixed ( 1 ) + '%' ;
831 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
834 var maxdisk
= record
. data
. maxdisk
;
836 if (!( Ext
. isNumeric ( disk
) && maxdisk
)) {
840 var per
= ( disk
* 100 ) / maxdisk
;
842 return per
. toFixed ( 1 ) + '%' ;
845 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
847 var cls
= 'pve-itype-icon-' + value
;
849 if ( record
. data
. running
) {
850 metaData
. tdCls
= cls
+ "-running" ;
851 } else if ( record
. data
. template
) {
852 metaData
. tdCls
= cls
+ "-template" ;
854 metaData
. tdCls
= cls
;
860 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
864 if ( uptime
=== undefined ) {
872 return PVE
. Utils
. format_duration_long ( uptime
);
875 render_support_level : function ( value
, metaData
, record
) {
876 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
879 render_upid : function ( value
, metaData
, record
) {
880 var type
= record
. data
. type
;
881 var id
= record
. data
. id
;
883 return PVE
. Utils
. format_task_description ( type
, id
);
886 dialog_title : function ( subject
, create
, isAdd
) {
889 return gettext ( 'Add' ) + ': ' + subject
;
891 return gettext ( 'Create' ) + ': ' + subject
;
894 return gettext ( 'Edit' ) + ': ' + subject
;
898 openConoleWindow : function ( vmtype
, vmid
, nodename
, vmname
) {
899 var url
= Ext
. urlEncode ({
900 console
: vmtype
, // kvm, openvz or shell
905 var nw
= window
. open ( "?" + url
, '_blank' ,
906 "innerWidth=745,innerheight=427" );
910 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
911 // use el.mask() instead
912 setErrorMask : function ( comp
, msg
) {
921 el
. mask ( gettext ( "Loading..." ));
928 monStoreErrors : function ( me
, store
) {
929 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
931 me
. loadCount
= 0 ; // make sure it is numeric
932 PVE
. Utils
. setErrorMask ( me
, true );
936 // only works with 'pve' proxy
937 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
941 PVE
. Utils
. setErrorMask ( me
, false );
946 var operation
= request
. operation
;
947 var error
= operation
. getError ();
948 if ( error
. statusText
) {
949 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
951 msg
= gettext ( 'Connection error' );
953 PVE
. Utils
. setErrorMask ( me
, msg
);