選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

toolbar.html 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <!--
  2. Top (main) phpVirtualBox tool bar
  3. Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
  4. $Id: toolbar.html 599 2015-07-27 10:40:37Z imoore76 $
  5. -->
  6. <script type='text/javascript'>
  7. /*
  8. * JS objects for actions that can be performed on a VM
  9. * from this toolbar
  10. */
  11. var tButtons = [
  12. vboxVMActions['new'],
  13. $.extend({},vboxVMActions['settings'],{click: function(){
  14. var vm = vboxChooser.getSingleSelected();
  15. if(!vm || vboxVMStates.isRunning(vm) || vboxVMStates.isPaused(vm)) return;
  16. vboxVMActions['settings'].click();
  17. }}),
  18. vboxVMActions['start'],
  19. {
  20. name: 'stop',
  21. icon: 'vm_poweroff',
  22. label: 'Stop',
  23. language_context: 'VBoxSelectorWnd',
  24. enabled: vboxVMActions['stop'].enabled,
  25. click : function() {return;}
  26. }
  27. ];
  28. /* Append Top Toolbar */
  29. var vboxChooserToolbarTop = new vboxToolbar({buttons: tButtons, size: 32,
  30. language_context: 'UIActionPool', renderTo: 'vboxPaneToolbar'});
  31. /* Stop button menu and actions */
  32. var stopMenuItems = [
  33. vboxVMActions['pause'],
  34. vboxVMActions['reset'],
  35. ];
  36. for(var i = 0; i < vboxVMActions.stop_actions.length; i++) {
  37. var n = $.extend({}, vboxVMActions[vboxVMActions.stop_actions[i]]);
  38. if(i==0) n.separator = true;
  39. stopMenuItems[stopMenuItems.length] = n;
  40. }
  41. stopMenu = new vboxMenu({name: 'stopContextMenu', menuItems: stopMenuItems, language_context: 'UIActionPool'});
  42. vboxChooserToolbarTop.getButtonElement('stop').contextMenu({
  43. menu: stopMenu.menuId(),
  44. button: 0,
  45. mode: 'menu'
  46. },function(a, el, pos) {
  47. for(var i in vboxVMActions) {
  48. if(typeof i == 'string' && vboxVMActions[i].name == a) {
  49. vboxVMActions[i].click();
  50. return;
  51. }
  52. }
  53. }
  54. );
  55. /* 'Settings' menu items / actions */
  56. var vboxChooserSettingsMenu = {
  57. 'settings' : {
  58. 'label' : vboxVMActions['settings'].label,
  59. 'icon' : vboxVMActions['settings'].icon
  60. },
  61. 'storage' : {
  62. 'icon' : 'hd'
  63. },
  64. 'USB' : {
  65. 'label' : 'USB',
  66. 'icon' : 'usb'
  67. },
  68. 'Network' : {
  69. 'label' : 'Network',
  70. 'icon' : 'nw'
  71. },
  72. 'SharedFolders' : {
  73. 'label' : 'Shared Folders',
  74. 'icon' : 'sf'
  75. },
  76. 'RemoteDisplay' : {
  77. 'label' : 'Remote Display',
  78. 'icon' : 'vrdp',
  79. 'separator' : true
  80. },
  81. 'GuestAdditions' : {
  82. 'label' : vboxVMActions['guestAdditionsInstall'].label,
  83. 'icon' : vboxVMActions['guestAdditionsInstall'].icon,
  84. 'separator' : true
  85. }
  86. };
  87. /* 'Settings' menu */
  88. var ul = $('<ul />').attr({'class':'contextMenu','style':'display: none','id':'vboxVMSettingsMenu'});
  89. for(var i in vboxChooserSettingsMenu) {
  90. // add name
  91. vboxChooserSettingsMenu[i].name = i;
  92. var label = trans(vboxChooserSettingsMenu[i].label, 'UIActionPool');
  93. var li = $('<li />').html("<span class='vboxMenuItemChecked' /><a href='#" + vboxChooserSettingsMenu[i].name + "' style='background-image: url(images/vbox/" + vboxChooserSettingsMenu[i].icon +"_16px.png);' >"+(label ? label : ' ')+"</a>");
  94. if(i == 'storage') { $(li).attr({'style':'display:none','id':'vboxVMSettingsToolbarStorageHolder'}); }
  95. if(i == 'USB') {
  96. /* 'USB' menu */
  97. $('<ul />').attr({'class':'vboxSettingsUSBAttachmentsMenu contextMenuNoBG','style':'display: none','id':'vboxVMSettingsUSBMenu'}).data({'callback':'vboxChooserToolbarUSBUpdate'}).appendTo(li);
  98. }
  99. if(vboxChooserSettingsMenu[i].separator) $(li).addClass('separator');
  100. $(ul).append(li);
  101. }
  102. /* Append 'Settings' button Menu */
  103. $('#vboxPane').append(ul);
  104. /* 'Settings' button menu initialization */
  105. vboxChooserToolbarTop.getButtonElement('settings').contextMenu({
  106. menu: 'vboxVMSettingsMenu',
  107. button: 0,
  108. mode: 'menu'
  109. },
  110. function(a, el, pos, srcEl) {
  111. var vm = vboxChooser.getSingleSelected();
  112. if(!vm) return;
  113. switch(a) {
  114. case 'Network':
  115. case 'SharedFolders':
  116. vboxVMsettingsDialog(vm, a);
  117. break;
  118. case 'GuestAdditions':
  119. vboxVMActions['guestAdditionsInstall'].click();
  120. break;
  121. // Don't do anything for dvd, fd, or USB devices main menu item click
  122. case 'dvdDevices':
  123. case 'fdDevices':
  124. case 'USB':
  125. break;
  126. case 'RemoteDisplay':
  127. var en = vboxVMDataMediator.getVMRuntimeData(vm.id).VRDEServer.enabled;
  128. vboxAjaxRequest('consoleVRDEServerSave',{'vm':vm.id,'enabled':(en ? 0 : 1)});
  129. break;
  130. case 'settings':
  131. vboxVMActions['settings'].click();
  132. break;
  133. default:
  134. // Assume it was a storage action
  135. if(vboxToolbarMediaLast) {
  136. if(vboxToolbarMediaLast.type == 'DVD') {
  137. vboxToolbarMediaMenuDVD.menuCallback(a,el,pos);
  138. } else {
  139. vboxToolbarMediaMenuFD.menuCallback(a,el,pos);
  140. }
  141. }
  142. } // </ switch / case >
  143. }
  144. );
  145. /*
  146. * Storage mount menu
  147. */
  148. var vboxToolbarMediaLast = null; // Used when context menu item is clicked to determine
  149. // which medium attachment to act upon.
  150. function vboxChooserToolbarMediumMount(medium) {
  151. var vmid = vboxChooser.getSingleSelectedId();
  152. var args = {'vm':vmid,'medium':medium,'port':vboxToolbarMediaLast.port,'device':vboxToolbarMediaLast.device,'bus':vboxToolbarMediaLast.bus,'controller':vboxToolbarMediaLast.controller};
  153. // Ajax request to mount medium
  154. var mount = new vboxLoader('mediumMount');
  155. mount.add('mediumMount',function(d){
  156. var l = new vboxLoader('getMedia');
  157. l.add('vboxGetMedia',function(d){$('#vboxPane').data('vboxMedia',d.responseData);});
  158. l.run();
  159. },args);
  160. mount.run();
  161. }
  162. var vboxToolbarMediaMenuDVD = new vboxMediaMenu('DVD',vboxChooserToolbarMediumMount,'');
  163. var vboxToolbarMediaMenuFD = new vboxMediaMenu('Floppy',vboxChooserToolbarMediumMount,'');
  164. function vboxChooserToolbarStorageUpdate(menu) {
  165. vboxToolbarMediaLast = $(menu).data('storage');
  166. var medium = null;
  167. if(vboxToolbarMediaLast && vboxToolbarMediaLast.medium && vboxToolbarMediaLast.medium.id)
  168. medium = vboxMedia.getMediumById(vboxToolbarMediaLast.medium.id);
  169. if(vboxToolbarMediaLast.type == 'DVD') {
  170. vboxToolbarMediaMenuDVD.menuUpdateMedia(medium);
  171. return vboxToolbarMediaMenuDVD.menuElement();
  172. }
  173. vboxToolbarMediaMenuFD.menuUpdateMedia(medium);
  174. return vboxToolbarMediaMenuFD.menuElement();
  175. }
  176. // Update host drives and recent media on host change.
  177. // Just recreate the menus
  178. $('#vboxPane').on('hostChanged',function(){
  179. vboxToolbarMediaMenuDVD = new vboxMediaMenu('DVD',vboxChooserToolbarMediumMount,'');
  180. vboxToolbarMediaMenuFD = new vboxMediaMenu('Floppy',vboxChooserToolbarMediumMount,'');
  181. });
  182. /*
  183. * Update USB device list
  184. */
  185. function vboxChooserToolbarUSBUpdate(menu) {
  186. $(menu).append($('<li />').html('<span><img src="images/jqueryFileTree/spinner.gif" /></span>').css({'width':'100px','text-align':'center'}));
  187. var vm = vboxChooser.getSingleSelected();
  188. var l = new vboxLoader();
  189. l.add('hostGetUSBDevices',function(d){
  190. $('#vboxPaneToolbar').data('hostUSB',d.responseData);
  191. },{});
  192. l.add('consoleGetUSBDevices',function(d){
  193. $('#vboxPaneToolbar').data('guestUSB',d.responseData);
  194. },{'vm':vm.id});
  195. l.noLoadingScreen = true;
  196. l.onLoad = function() {
  197. var hostUSB = $('#vboxPaneToolbar').data('hostUSB');
  198. var guestUSB = $('#vboxPaneToolbar').data('guestUSB');
  199. $(menu).children().remove();
  200. for(var i = 0; i < hostUSB.length; i++) {
  201. var dname = '';
  202. if(!hostUSB[i].product) {
  203. dname = trans('Unknown device %1:%2','UIActionPool').replace('%1',hostUSB[i].vendorId).replace('%2',hostUSB[i].productId);
  204. } else {
  205. dname = hostUSB[i].manufacturer + ' ' + hostUSB[i].product;
  206. }
  207. dname += ' [' + hostUSB[i].revision + ']';
  208. var capt = (hostUSB[i].state == 'Captured' && guestUSB[hostUSB[i].id]);
  209. var avail = (capt || (hostUSB[i].state != 'NotSupported' && hostUSB[i].state != 'Unavailable' && hostUSB[i].state != 'Captured'));
  210. var cbox = $('<input />').attr({'type':'checkbox','class':'vboxCheckbox'}).prop({'checked':(capt ? true : false),'disabled':(avail ? false : true)}).on('click',function(e){
  211. e.stopPropagation();
  212. if($(this).prop('disabled')) return;
  213. var cbox = $(this);
  214. // Detach
  215. if($(this).data('capt')) {
  216. $.when(vboxAjaxRequest('consoleUSBDeviceDetach',{'vm':vm.id,'id':$(this).data('usbDevice')})).done(function(d){
  217. if(d.success) {
  218. cbox.prop('checked',false);
  219. cbox.data('capt',false);
  220. } else {
  221. cbox.prop('checked',true);
  222. }
  223. });
  224. // Attach
  225. } else {
  226. $.when(vboxAjaxRequest('consoleUSBDeviceAttach',{'vm':vm.id,'id':$(this).data('usbDevice')})).done(function(d){
  227. if(d.success) {
  228. cbox.prop('checked',true);
  229. cbox.data('capt',true);
  230. } else {
  231. cbox.prop('checked',false);
  232. }
  233. });
  234. }
  235. }).data({'usbDevice':hostUSB[i].id,'capt':capt});
  236. $(menu).append($('<li />').append(
  237. $('<span />').addClass('vboxMenuAcceptClick')
  238. .click(function(){if(!$(this).parent().hasClass('disabled')){$(this).children('input').click();}return false;})
  239. .append(cbox).append(' '+dname)).attr({'class':(avail ? '' : 'disabled')}));
  240. }
  241. // No devices?
  242. if(hostUSB.length == 0) {
  243. $(menu).append($('<li />').html('<span>'+$('<div />').text(trans('<no devices available>','VBoxUSBMenu')).html()+'</span>'));
  244. }
  245. $(menu).trigger('menuLoaded');
  246. };
  247. l.run();
  248. }
  249. /*
  250. *
  251. * Update vboxSettingsMenu items. Called when
  252. * vboxChooser selection changes $('#vboxPane').onvmSelectionListChanged
  253. *
  254. */
  255. function vboxUpdateSettingsMenu(vm) {
  256. if(vboxVMStates.isRunning(vm) || vboxVMStates.isPaused(vm)) {
  257. vboxChooserToolbarTop.getButtonElement("settings").enableContextMenu();
  258. } else {
  259. vboxChooserToolbarTop.getButtonElement("settings").disableContextMenu();
  260. return;
  261. }
  262. // enable or disable USB
  263. var usbEnabled = false;
  264. if(vm['USBControllers'].length) {
  265. for(var i = 0; i < vm['USBControllers'].length; i++) {
  266. if(vm['USBControllers'][i].type == 'OHCI') {
  267. usbEnabled = true;
  268. break;
  269. }
  270. }
  271. }
  272. if(usbEnabled) {
  273. $('ul.vboxSettingsUSBAttachmentsMenu').children().remove();
  274. $('#vboxVMSettingsMenu').find('a[href=#USB]').closest('li').css('display','');
  275. } else {
  276. $('#vboxVMSettingsMenu').find('a[href=#USB]').closest('li').css('display','none');
  277. }
  278. // Enable or disable network
  279. var enabledS = false;
  280. if(vm && vm.networkAdapters && vm.networkAdapters.length) {
  281. for(var a = 0; a < vm.networkAdapters.length; a++) {
  282. if(vm.networkAdapters[a].enabled) {
  283. enabledS = true;
  284. break;
  285. }
  286. }
  287. }
  288. if(enabledS) {
  289. $('#vboxVMSettingsMenu').find('a[href=#Network]').closest('li').css('display','');
  290. } else {
  291. $('#vboxVMSettingsMenu').find('a[href=#Network]').closest('li').css('display','none');
  292. }
  293. // vboxVMSettingsToolbarStorageHolder
  294. var smenu = $('#vboxVMSettingsToolbarStorageHolder');
  295. smenu.siblings('li.vboxVMSettingsStorage').remove();
  296. $('ul.vboxVMSettingsStorage').remove();
  297. var enabledS = false;
  298. if(vm && vm.storageControllers && vm.storageControllers.length) {
  299. var dvdDevices = new Array();
  300. var fdDevices = new Array();
  301. for(var a = 0; a < vm.storageControllers.length; a++) {
  302. // See if this bus type supports removable media
  303. if(jQuery.inArray('dvd',vboxStorage[vm['storageControllers'][a].bus].driveTypes) == -1 &&
  304. jQuery.inArray('floppy',vboxStorage[vm['storageControllers'][a].bus].driveTypes) == -1)
  305. continue;
  306. var icon = vboxStorage.getBusIconName(vm['storageControllers'][a].bus);
  307. for(var b = 0; b < vm['storageControllers'][a]['mediumAttachments'].length; b++) {
  308. if(vm['storageControllers'][a]['mediumAttachments'][b].type == 'HardDisk') continue;
  309. vm['storageControllers'][a]['mediumAttachments'][b]['controller'] = vm['storageControllers'][a]['name'];
  310. var portName = vboxStorage[vm['storageControllers'][a].bus].slotName(vm['storageControllers'][a]['mediumAttachments'][b].port, vm['storageControllers'][a]['mediumAttachments'][b].device);
  311. var m = vm['storageControllers'][a]['mediumAttachments'][b].medium;
  312. m = vboxMedia.getMediumById((m && m.id ? m.id : null));
  313. var mName = vboxMedia.getName(m);
  314. mName = $('<div />').text(mName).html();
  315. var smid = vm.id+'-vboxVMSettingsStorage-'+a+'-'+b;
  316. $('#'+vm.id+'-vboxVMSettingsStorage-'+a+'-'+b).remove();
  317. var li = $('<li />').attr({'title':mName}).html("<a title='"+mName+"' href='#mount-"+vm['storageControllers'][a].bus+"-"+vm['storageControllers'][a]['mediumAttachments'][b].port+"-"+vm['storageControllers'][a]['mediumAttachments'][b].device+"' style='background-image:url(images/vbox/"+icon+"_16px.png);'>"+vm['storageControllers'][a]['name'] + ' ('+portName + ")</a>").addClass('vboxVMSettingsStorage');
  318. $(li).append($('<ul />').attr({'id':smid,'style':'display:none'}).data({'callback':'vboxChooserToolbarStorageUpdate','storage':vm['storageControllers'][a]['mediumAttachments'][b]}));
  319. if(vm['storageControllers'][a]['mediumAttachments'][b].type == 'DVD') {
  320. dvdDevices[dvdDevices.length] = li;
  321. } else {
  322. fdDevices[fdDevices.length] = li;
  323. }
  324. enabledS = true;
  325. }
  326. }
  327. if(dvdDevices.length) {
  328. var ul = null;
  329. var li = $('<li />').html("<a href='#dvdDevices' style='background-image:url(images/vbox/cd_16px.png);'>"+trans('Optical Drives','UIActionPool')+'</a>').addClass('vboxVMSettingsStorage');
  330. if(dvdDevices.length == 1) {
  331. ul = dvdDevices[0].children('ul').first();
  332. } else {
  333. ul = $('<ul />').attr({'style':'display:none'}).addClass('vboxVMSettingsStorage');
  334. for(var i = 0; i < dvdDevices.length; i++) {
  335. $(ul).append(dvdDevices[i]);
  336. }
  337. }
  338. $(li).append(ul).insertBefore(smenu);
  339. }
  340. if(fdDevices.length) {
  341. var ul = null;
  342. var li = $('<li />').html("<a href='#fdDevices' style='background-image:url(images/vbox/fd_16px.png);'>"+trans('Floppy Devices','UIActionPool')+'</a>').addClass('vboxVMSettingsStorage');
  343. if(fdDevices.length == 1) {
  344. ul = fdDevices[0].children('ul').first();
  345. } else {
  346. ul = $('<ul />').attr({'style':'display:none'}).addClass('vboxVMSettingsStorage');
  347. for(var i = 0; i < fdDevices.length; i++) {
  348. $(ul).append(fdDevices[i]);
  349. }
  350. }
  351. $(li).append(ul).insertBefore(smenu);
  352. }
  353. }
  354. if(enabledS) {
  355. $('#vboxVMSettingsMenu').find('a[href=#Network]').parent().addClass('separator');
  356. } else {
  357. $('#vboxVMSettingsMenu').find('a[href=#Network]').parent().removeClass('separator');
  358. }
  359. // Enable remote display?
  360. if(vm && vm.VRDEServer) {
  361. $('#vboxVMSettingsMenu').find('a[href=#RemoteDisplay]').css({'background-image':'url(images/vbox/vrdp' + (vm.VRDEServer.enabled ? '_on' : '') + '_16px.png)'}).parent().removeClass('disabled')
  362. .addClass((vm.VRDEServer.enabled ? 'vboxMenuItemChecked' : '')).removeClass((vm.VRDEServer.enabled ? '' : 'vboxMenuItemChecked'));
  363. } else {
  364. $('#vboxVMSettingsMenu').find('a[href=#RemoteDisplay]').css({'background-image':'url(images/vbox/vrdp_disabled_16px.png)'}).parent().addClass('disabled');
  365. }
  366. }
  367. /*
  368. Bind events...
  369. */
  370. // Selection list changed
  371. $('#vboxPane').on('vmSelectionListChanged',function(e) {
  372. vboxChooserToolbarTop.update(vboxChooser);
  373. vboxUpdateSettingsMenu();
  374. // Check for a single selected VM and
  375. // update settings menu based on its runtime data
  376. if(vboxChooser.selectedVMs.length == 1 && (vboxChooser.isSelectedInState('Running') || vboxChooser.isSelectedInState('Paused'))) {
  377. // Get data
  378. $.when(vboxVMDataMediator.getVMDataCombined(vboxChooser.selectedVMs[0]))
  379. .done(function(d) {
  380. vboxUpdateSettingsMenu(d);
  381. });
  382. }
  383. // Update menus on these events
  384. }).on('vboxEvents', function(e, eventList) {
  385. var updateToolbar = false;
  386. var updateSettingsMenu = false;
  387. var updateVRDE = false;
  388. for(var i = 0; i < eventList.length && !(updateToolbar && updateSettingsMenu); i++) {
  389. switch(eventList[i].eventType) {
  390. // Machine or session state change
  391. case 'OnMachineStateChanged':
  392. case 'OnSessionStateChanged':
  393. if(vboxChooser.isVMSelected(eventList[i].machineId)) {
  394. updateToolbar = true;
  395. }
  396. if(vboxChooser.getSingleSelectedId() == eventList[i].machineId) {
  397. updateSettingsMenu = true;
  398. }
  399. break;
  400. // Machine or medium data change
  401. case 'OnMachineDataChanged':
  402. case 'OnMediumChanged':
  403. if(vboxChooser.isVMSelected(eventList[i].machineId)) {
  404. updateToolbar = true;
  405. updateSettingsMenu = true;
  406. }
  407. break;
  408. // VRDE Server
  409. case 'OnVRDEServerChanged':
  410. case 'OnVRDEServerInfoChanged':
  411. if(!updateSettingsMenu && !updateVRDE && vboxChooser.isVMSelected(eventList[i].machineId)) {
  412. if(eventList[i].enrichmentData && eventList[i].enrichmentData.enabled) {
  413. updateVRDE = function(){
  414. $('#vboxVMSettingsMenu').find('a[href=#RemoteDisplay]').css({'background-image':'url(images/vbox/vrdp_on_16px.png)'}).parent().removeClass('disabled')
  415. .addClass('vboxMenuItemChecked');
  416. };
  417. } else {
  418. updateVRDE = function(){
  419. $('#vboxVMSettingsMenu').find('a[href=#RemoteDisplay]').css({'background-image':'url(images/vbox/vrdp_16px.png)'}).parent().removeClass('disabled')
  420. .removeClass('vboxMenuItemChecked');
  421. };
  422. }
  423. }
  424. break;
  425. } // </ switch event type >
  426. } // </ for each event >
  427. // Toolbar
  428. if(updateToolbar) {
  429. vboxChooserToolbarTop.update(vboxChooser);
  430. }
  431. // Entire settings menu or just VRDE
  432. if(updateSettingsMenu) {
  433. // Check for a single selected VM and
  434. // update settings menu based on its runtime data
  435. if(vboxChooser.selectedVMs.length == 1 && (vboxChooser.isSelectedInState('Running') || vboxChooser.isSelectedInState('Paused'))) {
  436. // Get data
  437. $.when(vboxVMDataMediator.getVMDataCombined(vboxChooser.selectedVMs[0]))
  438. .done(function(d) {
  439. vboxUpdateSettingsMenu(d);
  440. });
  441. } else {
  442. vboxUpdateSettingsMenu();
  443. }
  444. } else if(updateVRDE) {
  445. updateVRDE();
  446. }
  447. });
  448. $('#vboxVMSettingsMenu').disableContextMenu();
  449. </script>