Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!--
  2. VM Console tab
  3. Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
  4. $Id: tabVMConsoleVNC.html 595 2015-04-17 09:50:36Z imoore76 $
  5. -->
  6. <form name="vboxVNCForm" id="vboxVNCForm">
  7. <span class='translate'>Requested desktop size</span>:
  8. <select id='vboxVNCSize' name='vboxVNCSizeSelect'>
  9. <option value='800x600'>800x600</option>
  10. <option value='1024x768'>1024x768</option>
  11. <option value='1280x1024'>1280x1024</option>
  12. </select>
  13. <input id='vboxVNCDetachBtn' name='detach' type='button' value='Detach' onClick="vboxVNCDetach();" />
  14. </form>
  15. <div id='vboxVNCAppletContainer'>
  16. </div>
  17. <script type='text/javascript'>
  18. //Custom resolutions
  19. if($("#vboxPane").data('vboxConfig').consoleResolutions) {
  20. var res = $("#vboxPane").data('vboxConfig').consoleResolutions;
  21. // first one must be valid
  22. if(res[0].split('x').length == 2) {
  23. document.vboxVNCForm.vboxVNCSizeSelect.options.length = 0;
  24. $(document.vboxVNCForm.vboxVNCSizeSelect).children().remove();
  25. for(var i = 0; i < res.length; i++) {
  26. document.vboxVNCForm.vboxVNCSizeSelect.options[i] = new Option(res[i],res[i]);
  27. }
  28. }
  29. $(document.vboxVNCForm.vboxVNCSizeSelect).on('change',function(){
  30. var wh = $(this).val().split('x');
  31. var width = wh[0];
  32. var height = wh[1];
  33. $('#vboxVNCAppletContainer').children().first().attr({'height':height,'width':width});
  34. vboxSetLocalDataItem('vbox'+vboxChooser.getSingleSelectedId()+'ConsoleSize',$(this).val(),true);
  35. });
  36. }
  37. // Translate
  38. $(document.vboxVNCForm.vboxVNCDetachBtn).val(trans("Detach",'VBoxConsoleWgt'));
  39. //Disable / enable tab on selection list changes
  40. $('#vboxPane').on('vmSelectionListChanged', function(){
  41. var vm = vboxChooser.getSingleSelected();
  42. // Initially disable tab
  43. $('#vboxTabVMConsole').parent().trigger('disableTab', ['vboxTabVMConsole']);
  44. if(vm && vboxVMStates.isRunning(vm)) {
  45. // VM is running, get runtime data
  46. $.when(vboxVMDataMediator.getVMDataCombined(vm.id)).done(function(info) {
  47. if(info.VRDEServerInfo && info.VRDEServerInfo.port > 0) {
  48. $('#vboxTabVMConsole').parent().trigger('enableTab', ['vboxTabVMConsole']);
  49. }
  50. });
  51. }
  52. // Update on console info change
  53. }).on('vboxOnVRDEServerInfoChanged',function(e,eventData) {
  54. // Shorthand
  55. var vmid = eventData.machineId;
  56. var VRDEServerInfo = eventData.enrichmentData;
  57. var selVM = vboxChooser.getSingleSelected();
  58. var enabled = (selVM && selVM.id == vmid && vboxVMStates.isRunning(selVM) && VRDEServerInfo && VRDEServerInfo.port > 0);
  59. if(enabled) {
  60. $.when(vboxVMDataMediator.getVMDataCombined(vmid)).done(function(info) {
  61. enabled = (info.VRDEServerInfo && info.VRDEServerInfo.port > 0);
  62. if(enabled) {
  63. $('#vboxTabVMConsole').parent().trigger('enableTab', ['vboxTabVMConsole']);
  64. var chost = vboxGetVRDEHost(selVM);
  65. chost+=':'+VRDEServerInfo.port;
  66. } else {
  67. $('#vboxTabVMConsole').parent().trigger('disableTab', ['vboxTabVMConsole']);
  68. }
  69. });
  70. } else {
  71. $('#vboxTabVMConsole').parent().trigger('disableTab', ['vboxTabVMConsole']);
  72. }
  73. // Update tab on machine state change
  74. }).on('vboxOnMachineStateChanged', function(e, eventData){
  75. var selVMId = vboxChooser.getSingleSelectedId();
  76. var enabled = (selVMId == eventData.machineId && vboxVMStates.isRunning({'state':eventData.state}));
  77. $('#vboxTabVMConsole').parent().trigger('disableTab', ['vboxTabVMConsole']);
  78. if(enabled) {
  79. // VM is running, get runtime data
  80. $.when(vboxVMDataMediator.getVMRuntimeData(eventData.machineId)).done(function(vm) {
  81. if(vm.VRDEServerInfo && vm.VRDEServerInfo.port > 0) {
  82. $('#vboxTabVMConsole').parent().trigger('enableTab', ['vboxTabVMConsole']);
  83. }
  84. });
  85. }
  86. // Clean up local data storage when a machine is unregistered
  87. }).on('vboxMachineRegistered', function(e, eventData) {
  88. if(!eventData.registered) {
  89. vboxSetLocalDataItem('vbox'+eventData.machineId+'ConsoleSize','',true);
  90. vboxSetLocalDataItem('vbox'+eventData.machineId+'ConsoleConnected','',true);
  91. }
  92. });
  93. /*
  94. * Populate console info values when this tab is shown
  95. */
  96. $('#vboxTabVMConsole').on('show',function(){
  97. var vm = vboxChooser.getSingleSelected();
  98. /* Load runtime data. This will tell us if the VRDE server is actually active */
  99. /* And details. This will give us info about the VRDEServer configuration */
  100. $.when(vboxVMDataMediator.getVMRuntimeData(vm.id),vboxVMDataMediator.getVMDetails(vm.id))
  101. .done(function(runtimeData, detailsData) {
  102. /* Not active */
  103. if(!(runtimeData.VRDEServerInfo && runtimeData.VRDEServerInfo.port > 0)) {
  104. $('#vboxTabVMConsole').parent().trigger('disableTab',['vboxTabVMConsole']);
  105. return;
  106. }
  107. // Set default console size for this VM?
  108. var cs = vboxGetLocalDataItem('vbox'+detailsData.id+'ConsoleSize');
  109. if(cs) {
  110. $(document.vboxVNCForm.vboxVNCSizeSelect).children('[value='+cs+']').first().prop('selected',true);
  111. }
  112. var wh = $(document.vboxVNCForm.vboxVNCSizeSelect).val().split('x');
  113. var width = wh[0];
  114. var height = wh[1];
  115. var chost = vboxGetVRDEHost(runtimeData);
  116. $('#vboxVNCAppletContainer').empty().html('<APPLET CODE="VncViewer.class" ARCHIVE="tightvnc/VncViewer.jar" width="'+width+'" height="'+height+'"><PARAM NAME="PORT" VALUE="'+runtimeData.VRDEServerInfo.port+'"><PARAM NAME="HOST" VALUE="'+chost+'"></APPLET>');
  117. });
  118. });
  119. function vboxVNCDetach() {
  120. var vmname = vboxChooser.getSingleSelected().name;
  121. var wh = $('#vboxVNCSize').val().split('x');
  122. var newwin = window.open('about:blank','vboxConsoleDetachedWin'+vmname.replace(/[^a-zA-Z0-9]/g,'_'),'toolbar=0,menubar=0,location=0,directories=0,status=true,resize=true,width='+(parseInt(wh[0])+20)+',height='+(parseInt(wh[1])+20)+'');
  123. newwin.document.open();
  124. newwin.document.write('<html><head><title>'+vmname + ' - ' + trans('Console','UIVMDesktop')+'</title></head><body style="margin: 0px; border: 0px; padding: 0px; overflow: hidden;"><div style="margin: 0px; border: 0px; padding: 0px" id="vboxPane">'+$('#vboxVNCAppletContainer').html()+'</div></body></html>');
  125. newwin.document.close();
  126. newwin.trans = function(t) { return t; };
  127. }
  128. </script>