您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

settingsSharedFolders.html 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <!--
  2. Shared Folders
  3. Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
  4. $Id: settingsSharedFolders.html 595 2015-04-17 09:50:36Z imoore76 $
  5. -->
  6. <table style='width: 100%' id='vboxSettingsSharedFoldersTable'>
  7. <tr style='vertical-align: middle'>
  8. <td style='width: 100%'>
  9. <table class='vboxSettingsHeadingLine' style='width:100%;border-spacing:0;border:0px;margin:0px;padding:0px;'><tr style='vertical-align:middle'><td style='white-space: nowrap; width: auto;'><span class='translate'>Folders List</span></td><td style='width: 100%'><hr style='width: 100%;' class='vboxSeparatorLine'/></td></tr></table>
  10. </td>
  11. </tr>
  12. <tr>
  13. <td style='width: 100%'>
  14. <table style='width: 100%'>
  15. <tr>
  16. <td style='width: 100%'>
  17. <div style='overflow: auto;' class='vboxBordered' id='vboxSettingsSharedFolders'>
  18. <table class='vboxHorizontal' id='vboxSettingsSharedFoldersList'>
  19. <thead>
  20. <tr id='vboxSettingsSharedFoldersHeading'>
  21. <th><span class='translate'>Name</span></th>
  22. <th style='width: 100%; white-space: nowrap;'><span class='translate'>Path</span></th>
  23. <th><span class='translate'>Auto-Mount</span></th>
  24. <th><span class='translate'>Access</span></th>
  25. </tr>
  26. </thead>
  27. </table>
  28. </div>
  29. </td>
  30. <td id='vboxSettingsSFButtons'></td>
  31. </tr>
  32. </table>
  33. </td>
  34. </tr>
  35. </table>
  36. <script type='text/javascript'>
  37. /*
  38. * Init Shared Folder buttons and toolbar
  39. */
  40. var sButtons = new Array(
  41. {
  42. 'name': 'addshared',
  43. 'label': 'Add Shared Folder',
  44. 'icon': 'sf_add',
  45. 'enabled': function (item) { return true; },
  46. 'click': function () {
  47. var dialog = vboxSettingsSFEditDialog();
  48. $('#vboxSettingsSFPath').val('');
  49. $('#vboxSettingsSFName').val('');
  50. $('#vboxSettingsSFAM').prop('checked',false);
  51. $('#vboxSettingsSFRO').prop('checked',false);
  52. $('#vboxSettingsSFPerm').prop('checked',false);
  53. var buttons = { };
  54. buttons[trans('OK','QIMessageBox')] = function() {
  55. if($('#vboxSettingsSFName').val() && $('#vboxSettingsSFPath').val()) {
  56. var f = {'name':$('#vboxSettingsSFName').val(),'hostPath':$('#vboxSettingsSFPath').val(),'autoMount':($('#vboxSettingsSFAM').prop('checked')),'writable':!($('#vboxSettingsSFRO').prop('checked'))};
  57. if($('#vboxSettingsSFPerm').length) {
  58. f['type'] = ($('#vboxSettingsSFPerm').prop('checked') ? 'machine' : '');
  59. } else {
  60. f['type'] = 'machine';
  61. }
  62. var row = vboxSettingsAddSharedFolder(f);
  63. $(row).children('td').last().trigger('click');
  64. }
  65. $(dialog).empty().remove();
  66. };
  67. buttons[trans('Cancel','QIMessageBox')] = function() { $(dialog).empty().remove(); };
  68. $(dialog).dialog({'buttons':buttons,'title':'<img src="images/vbox/sf_16px.png" class="vboxDialogTitleIcon" /> '+trans('Add Share','UIMachineSettingsSFDetails')}).dialog('open');
  69. }
  70. },
  71. {
  72. 'name': 'editshared',
  73. 'label': 'Edit Shared Folder',
  74. 'icon': 'sf_edit',
  75. 'enabled': function (item) { return $(item).hasClass('vboxListItemSelected'); },
  76. 'click': function () {
  77. var dialog = vboxSettingsSFEditDialog();
  78. var def = $('#vboxSettingsSharedFoldersList').find('tr.vboxListItemSelected').first();
  79. $('#vboxSettingsSFPath').val(($(def).data('hostPath')||''));
  80. $('#vboxSettingsSFName').val(($(def).data('name')||''));
  81. $('#vboxSettingsSFAM').prop('checked',($(def).data('autoMount') ? true : false));
  82. $('#vboxSettingsSFRO').prop('checked',($(def).data('writable') ? false : true));
  83. $('#vboxSettingsSFPerm').prop('checked',($(def).data('type') == 'machine' ? true : false));
  84. var buttons = { };
  85. buttons[trans('OK','QIMessageBox')] = function() {
  86. if($('#vboxSettingsSFName').val() && $('#vboxSettingsSFPath').val()) {
  87. var item = $('#vboxSettingsSharedFoldersList').find('tr.vboxListItemSelected').first();
  88. $(item).data({
  89. 'hostPath' : $('#vboxSettingsSFPath').val(),
  90. 'name' : $('#vboxSettingsSFName').val(),
  91. 'autoMount' : ($('#vboxSettingsSFAM').prop('checked')),
  92. 'writable' : !($('#vboxSettingsSFRO').prop('checked')),
  93. 'type' : ((!$('#vboxSettingsSFPerm').length || $('#vboxSettingsSFPerm').prop('checked')) ? 'machine' : '')
  94. }).trigger('refresh');
  95. }
  96. $(dialog).empty().remove();
  97. };
  98. buttons[trans('Cancel','QIMessageBox')] = function() { $(dialog).empty().remove(); };
  99. $(dialog).dialog({'buttons':buttons}).dialog('open');
  100. }
  101. },
  102. {
  103. 'name' : 'removeshared',
  104. 'label' : 'Remove Shared Folder',
  105. 'icon' : 'sf_remove',
  106. 'enabled' : function (item) { return $(item).hasClass('vboxListItemSelected'); },
  107. 'click' : function () {
  108. var item = $('#vboxSettingsSharedFoldersList').find('.vboxListItemSelected').first();
  109. var target = $(item).next();
  110. if(!$(target).hasClass('vboxListItemSelected')) target = $(item).prev();
  111. if(!$(target).hasClass('vboxListItemSelected')) target = $('#vboxSettingsSharedFoldersList').find('.vboxListItem').first();
  112. $('#vboxSettingsSharedFoldersList').find('tr.vboxListItemSelected').first().remove();
  113. if(!$(target).children().first().trigger('click').hasClass('vboxListItemSelected')) {
  114. $('#vboxSettingsSharedFoldersList').trigger('select',null);
  115. }
  116. }
  117. }
  118. );
  119. var sfToolbar = new vboxToolbarSmall({buttons: sButtons,
  120. language_context: 'UIMachineSettingsSF', renderTo: 'vboxSettingsSFButtons'});
  121. $('#vboxSettingsSharedFoldersList').on('select',function(e,el){sfToolbar.update(el);});
  122. /* Add Shared Folder to list */
  123. function vboxSettingsAddSharedFolder(f, noColor) {
  124. var tr = $('<tr />').attr({'class':'vboxListItem'}).addClass(f.type == 'machine' ? 'vboxSFMachine' : 'vboxSFTransient').on('refresh',function(){
  125. // bind refresh
  126. $(this).children('td.vboxSettingsSFNameCell').children('span').first().html($('<div/>').text($(this).data('name')).html());
  127. $(this).children('td.vboxSettingsSFPathCell').html($('<div/>').text($(this).data('hostPath')).html());
  128. $(this).children('td.vboxSettingsSFAMCell').html($(this).data('autoMount') ? trans('Yes','UIMachineSettingsSF') : '');
  129. $(this).children('td.vboxSettingsSFROCell').html($(this).data('writable') ? trans('Full','UIMachineSettingsSF') : trans('Read-only','UIMachineSettingsSF'));
  130. // Move from one type to another
  131. if($(this).data('type') == 'machine' && $(this).hasClass('vboxSFTransient')) {
  132. $(this).removeClass('vboxSFTransient').addClass('vboxSFMachine').detach().appendTo('#vboxSFMachineBody');
  133. vboxColorRows($('#vboxSFMachineBody'));
  134. vboxColorRows($('#vboxSFTransientBody'));
  135. } else if($(this).data('type') != 'machine' && $(this).hasClass('vboxSFMachine')) {
  136. $(this).removeClass('vboxSFMachine').addClass('vboxSFTransient').detach().appendTo('#vboxSFTransientBody');
  137. vboxColorRows($('#vboxSFMachineBody'));
  138. vboxColorRows($('#vboxSFTransientBody'));
  139. }
  140. }).hoverClass('vboxHover').disableSelection().data(f);
  141. // Name
  142. $('<td />').attr({'class':'vboxSettingsSFNameCell vboxHoverFirst'}).append($('<img />').attr({'src':'images/vbox/blank.gif','style':'height: 10px; width: 30px;'})).append($('<span />').html($('<div/>').text(f.name).html())).appendTo(tr);
  143. // Path
  144. $('<td />').attr({'class':'vboxSettingsSFPathCell vboxHoverMid'}).html($('<div/>').text(f.hostPath).html()).appendTo(tr);
  145. // auto-mount?
  146. $('<td />').attr({'class':'vboxSettingsSFAMCell vboxHoverMid'}).html(f.autoMount ? trans('Yes','UIMachineSettingsSF') : '').appendTo(tr);
  147. // Read only?
  148. $('<td />').attr({'class':'vboxSettingsSFROCell vboxHoverLast'}).html(f.writable ? trans('Full','UIMachineSettingsSF') : trans('Read-only','UIMachineSettingsSF')).appendTo(tr);
  149. $(tr).children().click(function(){
  150. $('#vboxSettingsSharedFoldersList').find('tr.vboxListItemSelected').removeClass('vboxListItemSelected').addClass('vboxListItem');
  151. $(this).parent().removeClass('vboxListItem').addClass('vboxListItemSelected');
  152. $('#vboxSettingsSharedFoldersList').trigger('select',$(this).parent());
  153. }).dblclick(function(e){
  154. sfToolbar.click('editshared');
  155. e.preventDefault();
  156. });
  157. if(f.type == 'machine') {
  158. $('#vboxSFMachineBody').append(tr);
  159. if(!noColor) vboxColorRows($('#vboxSFMachineBody'));
  160. } else {
  161. $('#vboxSFTransientBody').append(tr);
  162. if(!noColor) vboxColorRows($('#vboxSFTransientBody'));
  163. }
  164. return tr;
  165. }
  166. /*
  167. *
  168. *
  169. * Load SF data
  170. *
  171. */
  172. $('#vboxSettingsDialog').on('dataLoaded',function(){
  173. /* Shared Folders */
  174. var sfh = $('#vboxSettingsSharedFoldersList');
  175. sfh.children('tbody').empty().remove();
  176. /*
  177. *
  178. Add 'Machine Folder's
  179. *
  180. */
  181. var tb = $('<tbody />').attr({'id':'vboxSFMachineBody'}).addClass('vboxHover');
  182. var tr = $('<tr />').attr({'class':'vboxListItemDisabled'}).disableSelection();
  183. var td = $('<td />').attr({'class':'vboxSettingsSFNameCell'});
  184. $('<input />').attr({'type':'button','class':'vboxImgButton','style':'background-image: url(images/vbox/arrow_down_10px.png); width: 12px; height: 12px; margin-right: 4px;'}).click(function(){
  185. if(!$(this).data('toggleClicked')) {
  186. $(this).data('toggleClicked', true);
  187. $(this).css({'background-image':'url(images/vbox/arrow_right_10px.png)'});
  188. $('#vboxSettingsSharedFoldersList').trigger('select',null);
  189. $('#vboxSFMachineBody').children('tr.vboxSFMachine').css({'display':'none'}).removeClass('vboxListItemSelected').addClass('vboxListItem');
  190. } else {
  191. $(this).data('toggleClicked', false);
  192. $(this).css({'background-image':'url(images/vbox/arrow_down_10px.png)'});
  193. $('#vboxSettingsSharedFoldersList').trigger('select',null);
  194. $('#vboxSFMachineBody').children('tr.vboxSFMachine').css({'display':''});
  195. }
  196. }).appendTo(td);
  197. $(td).append($('<span />').html($('<div/>').text(trans(' Machine Folders','UIMachineSettingsSF')).html())).appendTo(tr);
  198. $(tb).append($(tr).append($('<td />').attr({'class':'vboxSettingsSFPathCell'})).append($('<td />').attr({'class':'vboxSettingsSFAMCell'})).append($('<td />').attr({'class':'vboxSettingsSFROCell'}))).appendTo(sfh);
  199. /*
  200. *
  201. * Add 'Transient Folders' if machine is running
  202. *
  203. */
  204. if(vboxVMStates.isRunning($('#vboxSettingsDialog').data('vboxMachineData')) || vboxVMStates.isSaved($('#vboxSettingsDialog').data('vboxMachineData')) || vboxVMStates.isPaused($('#vboxSettingsDialog').data('vboxMachineData'))) {
  205. var tb = $('<tbody />').attr({'id':'vboxSFTransientBody'}).addClass('vboxHover');
  206. var tr = $('<tr />').attr({'class':'vboxListItemDisabled'}).disableSelection();
  207. $('<td />').attr({'class':'vboxSettingsSFNameCell'}).append(
  208. $('<input />').attr({'type':'button','class':'vboxImgButton','style':'background-image: url(images/vbox/arrow_down_10px.png); width: 12px; height: 12px; margin-right: 4px;'}).click(function(){
  209. if(!$(this).data('toggleClicked')) {
  210. $(this).data('toggleClicked', true);
  211. $(this).css({'background-image':'url(images/vbox/arrow_right_10px.png)'});
  212. $('#vboxSettingsSharedFoldersList').trigger('select',null);
  213. $('#vboxSFTransientBody').children('tr.vboxSFTransient').css({'display':'none'}).removeClass('vboxListItemSelected').addClass('vboxListItem');
  214. } else {
  215. $(this).data('toggleClicked', false);
  216. $(this).css({'background-image':'url(images/vbox/arrow_down_10px.png)'});
  217. $('#vboxSettingsSharedFoldersList').trigger('select',null);
  218. $('#vboxSFTransientBody').children('tr.vboxSFTransient').css('display','');
  219. }
  220. })).append($('<span />').html($('<div/>').text(trans(' Transient Folders','UIMachineSettingsSF')).html())).appendTo(tr);
  221. $(tr).append($('<td />').attr({'class':'vboxSettingsSFPathCell'})).append($('<td />').attr({'class':'vboxSettingsSFAMCell'})).append($('<td />').attr({'class':'vboxSettingsSFROCell'}));
  222. $(tb).append(tr).appendTo(sfh);
  223. // add each transient folder
  224. for(var i = 0; i < $('#vboxSettingsDialog').data('vboxTransientSharedFolders').length; i++) {
  225. vboxSettingsAddSharedFolder($('#vboxSettingsDialog').data('vboxTransientSharedFolders')[i]);
  226. }
  227. }
  228. // add each machine folder
  229. for(var i = 0; i < $('#vboxSettingsDialog').data('vboxMachineData').sharedFolders.length; i++) {
  230. vboxSettingsAddSharedFolder($('#vboxSettingsDialog').data('vboxMachineData').sharedFolders[i]);
  231. }
  232. $('#vboxSettingsSharedFoldersList').trigger('select',null);
  233. });
  234. /* Update Shared Folder path and name. Callback for folder browser */
  235. function vboxSFBrowseFolder(btn) {
  236. vboxFileBrowser($('#vboxSettingsSFPath').val(),function(f) {
  237. if(!f) return;
  238. $('#vboxSettingsSFPath').val(f);
  239. if(!$('#vboxSettingsSFName').val()) {
  240. f = f.replace(/.*\//,'');
  241. f = f.replace(/.*\\/,'');
  242. if(f) $('#vboxSettingsSFName').val(f);
  243. }
  244. },true,trans('Folder Path:','UIMachineSettingsSFDetails').replace(':',''));
  245. }
  246. /*
  247. *
  248. *
  249. * Shared Folder Properties Screen
  250. *
  251. *
  252. */
  253. function vboxSettingsSFEditDialog() {
  254. var d = $('<div />').attr({'id':'vboxSettingsSFEdit','class':'vboxNonTabbed vboxDialogContent','style':'display: none;'});
  255. var tbl = $('<table />').attr({'style':'width: 100%','class':'vboxSettingsTable'});
  256. // Path
  257. $('<tr />').attr({'style':'vertical-align: middle'}).append($('<th />').attr({'style':'white-space: nowrap'}).html(trans('Folder Path:','UIMachineSettingsSFDetails'))).append(
  258. $('<td />').attr({'style':'white-space: nowrap'}).html('<table style="width: 100%"><tr><td style="width: 100%"><input type="text" class="vboxText" id="vboxSettingsSFPath" style="width: 100%"/></td><td style="width: auto" class="vboxFileFolderInput"><input type="button" class="vboxImgButton" style="background-image: url(images/vbox/select_file_16px.png)" onClick="vboxSFBrowseFolder(this)" /></td></tr></table>')
  259. ).appendTo(tbl);
  260. // Name
  261. $('<tr />').append($('<th />').html(trans('Folder Name:','UIMachineSettingsSFDetails'))).append($('<td />').html('<input type="text" class="vboxText" id="vboxSettingsSFName" style="width: 100%" />')).appendTo(tbl);
  262. // Read only
  263. $('<tr />').append($('<th />')).append($('<td />').html('<label><input type="checkbox" class="vboxCheckbox" id="vboxSettingsSFRO" /> ' + trans('Read-only','UIMachineSettingsSFDetails')+'</label>')).appendTo(tbl);
  264. // Auto mount
  265. $('<tr />').append($('<th />')).append($('<td />').html('<label><input type="checkbox" class="vboxCheckbox" id="vboxSettingsSFAM" /> ' + trans('Auto-mount','UIMachineSettingsSFDetails')+'</label>')).appendTo(tbl);
  266. // Add "Make Permanent"?
  267. if(vboxVMStates.isRunning($('#vboxSettingsDialog').data('vboxMachineData')) || vboxVMStates.isSaved($('#vboxSettingsDialog').data('vboxMachineData')) || vboxVMStates.isPaused($('#vboxSettingsDialog').data('vboxMachineData'))) {
  268. $('<tr />').append($('<th />')).append($('<td />').html('<label><input type="checkbox" class="vboxCheckbox" id="vboxSettingsSFPerm" /> ' + trans('Make Permanent','UIMachineSettingsSFDetails')+'</label>')).appendTo(tbl);
  269. }
  270. $(d).append(tbl).dialog({'width':800,'modal':true,'autoOpen':false,'dialogClass':'vboxDialogContent vboxNonTabbed','title':'<img src="images/vbox/sf_16px.png" class="vboxDialogTitleIcon" /> '+trans('Edit Share','UIMachineSettingsSFDetails')});
  271. return $('#vboxSettingsSFEdit');
  272. }
  273. /* Change settings onSave() */
  274. $('#vboxSettingsDialog').on('save',function(){
  275. $('#vboxSettingsDialog').data('vboxMachineData').sharedFolders = new Array();
  276. var folders = new Array();
  277. $('#vboxSettingsSharedFoldersList').find('tr').each(function(){
  278. // Skip headers and such
  279. if($(this).data('name')) {
  280. folders[folders.length] = {'name':$(this).data('name'),'hostPath':$(this).data('hostPath'),'autoMount':($(this).data('autoMount') ? true : false),'writable':($(this).data('writable') ? true : false),'type':$(this).data('type')};
  281. }
  282. });
  283. $('#vboxSettingsDialog').data('vboxMachineData').sharedFolders = folders;
  284. });
  285. </script>