Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dialogs.js 60KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  1. /**
  2. * @fileOverview Dialog logic for various wizards and other dialogs
  3. * @author Ian Moore (imoore76 at yahoo dot com)
  4. * @version $Id: dialogs.js 599 2015-07-27 10:40:37Z imoore76 $
  5. * @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
  6. */
  7. /**
  8. * Run the import appliance wizard
  9. */
  10. function vboxWizardImportApplianceDialog() {
  11. // reference
  12. var self = this;
  13. // Extend vboxWizard
  14. this.parentClass = vboxWizard;
  15. this.parentClass();
  16. /* Common settings */
  17. this.name = 'wizardImportAppliance';
  18. this.title = trans('Import Virtual Appliance','UIWizardImportApp');
  19. this.bg = 'images/vbox/vmw_ovf_import_bg.png';
  20. this.icon = 'import';
  21. this.steps = 2;
  22. this.height = 500;
  23. this.finishText = trans('Import','UIWizardImportApp');
  24. this.context = 'UIWizardImportApp';
  25. /* Restore defaults is added to last step */
  26. this.stepButtons = [
  27. {
  28. 'name' : trans('Restore Defaults','UIWizardImportApp'),
  29. 'steps' : [-1],
  30. 'click' : function() {
  31. wizardImportApplianceParsed();
  32. }
  33. }
  34. ];
  35. /* Data to be loaded */
  36. this.data = [
  37. {'fn':'vboxGetEnumerationMap','args':{'class':'NetworkAdapterType'},'callback':function(d){$('#vboxPane').data('vboxNetworkAdapterTypes',d.responseData);}},
  38. {'fn':'vboxGetEnumerationMap','args':{'class':'AudioControllerType'},'callback':function(d){$('#vboxPane').data('vboxAudioControllerTypes',d.responseData);}},
  39. ];
  40. /* Perform action on finish */
  41. this.onFinish = function() {
  42. var file = $(self.form).find('[name=wizardImportApplianceLocation]').val();
  43. var descriptions = $('#vboxImportProps').data('descriptions');
  44. var reinitNetwork = $(self.form).find('[name=vboxImportReinitNetwork]').prop('checked');
  45. // Check for descriptions
  46. if(!descriptions) {
  47. return;
  48. }
  49. /** Call Appliance import AJAX function */
  50. var vboxImportApp = function() {
  51. $(self.dialog).empty().remove();
  52. var l = new vboxLoader();
  53. l.add('applianceImport',function(d){
  54. if(d.responseData.progress) {
  55. vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(){
  56. // Imported media must be refreshed
  57. var ml = new vboxLoader();
  58. ml.add('vboxGetMedia',function(d){$('#vboxPane').data('vboxMedia',d.responseData);});
  59. ml.onLoad = function(){
  60. self.completed.resolve();
  61. };
  62. ml.run();
  63. },'progress_import_90px.png',trans('Import an appliance into VirtualBox','UIActionPool').replace(/\.+$/g,''),vboxBasename(file));
  64. } else {
  65. self.completed.reject();
  66. }
  67. },{'descriptions':descriptions,'file':file,'reinitNetwork':reinitNetwork});
  68. l.run();
  69. };
  70. // license agreements
  71. var licenses = [];
  72. // Step through each VM and obtain value
  73. for(var a = 0; a < descriptions.length; a++) {
  74. var children = $('#vboxImportProps').children('tr.vboxChildOf'+a);
  75. descriptions[a][5] = []; // enabled / disabled
  76. var lic = null;
  77. var vmname = null;
  78. for(var b = 0; b < children.length; b++) {
  79. descriptions[a][5][b] = !$(children[b]).data('propdisabled');
  80. descriptions[a][3][$(children[b]).data('descOrder')] = $(children[b]).children('td:eq(1)').data('descValue');
  81. // check for license
  82. if(descriptions[a][0][b] == 'License') {
  83. lic = descriptions[a][2][b];
  84. } else if(descriptions[a][0][b] == 'Name') {
  85. vmname = descriptions[a][2][b];
  86. }
  87. }
  88. if(lic) {
  89. if(!vmname) vmname = trans('Virtual System %1','UIApplianceEditorWidget').replace('%1',a);
  90. licenses[licenses.length] = {'name':vmname,'license':lic};
  91. }
  92. }
  93. if(licenses.length) {
  94. var msg = trans('<b>The virtual system "%1" requires that you agree to the terms and conditions of the software license agreement shown below.</b><br /><br />Click <b>Agree</b> to continue or click <b>Disagree</b> to cancel the import.','UIImportLicenseViewer');
  95. var a = 0;
  96. var buttons = {};
  97. buttons[trans('Agree','UIImportLicenseViewer')] = function() {
  98. a++;
  99. if(a >= licenses.length) {
  100. $(this).remove();
  101. vboxImportApp();
  102. return;
  103. }
  104. $(this).dialog('close');
  105. $('#vboxImportWizLicTitle').html(msg.replace('%1',licenses[a]['name']));
  106. $('#vboxImportWizLicContent').val(licenses[a]['license']);
  107. $(this).dialog('open');
  108. };
  109. buttons[trans('Disagree','UIImportLicenseViewer')] = function() {
  110. $(this).empty().remove();
  111. };
  112. var dlg = $('<div />').dialog({'closeOnEscape':false,'width':600,'height':500,'buttons':buttons,'modal':true,'autoOpen':false,'dialogClass':'vboxDialogContent vboxWizard','title':'<img src="images/vbox/os_type_16px.png" class="vboxDialogTitleIcon" /> ' + trans('Software License Agreement','UIImportLicenseViewer')});
  113. $(dlg).html('<p id="vboxImportWizLicTitle" /><textarea rows="20" spellcheck="false" wrap="off" readonly="true"id="vboxImportWizLicContent" style="width:100%; margin:2px; padding:2px;"></textarea>');
  114. $('#vboxImportWizLicTitle').html(msg.replace('%1',licenses[a]['name']));
  115. $('#vboxImportWizLicContent').val(licenses[a]['license']);
  116. $(dlg).dialog('open');
  117. } else {
  118. vboxImportApp();
  119. }
  120. };
  121. }
  122. /**
  123. * Run the export appliance wizard
  124. */
  125. function vboxWizardExportApplianceDialog() {
  126. // reference
  127. var self = this;
  128. // Extend vboxWizard class
  129. this.parentClass = vboxWizard;
  130. this.parentClass();
  131. /* Common settings */
  132. this.name = 'wizardExportAppliance';
  133. this.title = trans('Export Virtual Appliance','UIWizardExportApp');
  134. this.bg = 'images/vbox/vmw_ovf_export_bg.png';
  135. this.icon = 'export';
  136. this.steps = 4;
  137. this.height = 500;
  138. this.context = 'UIWizardExportApp';
  139. this.finishText = trans('Export','UIWizardExportApp');
  140. /* Add restore defaults button to last step */
  141. this.stepButtons = [
  142. {
  143. 'name' : trans('Restore Defaults','UIWizardExportApp'),
  144. 'steps' : [-1],
  145. 'click' : function(e) {
  146. // Remove export VM properties
  147. $('#vboxExportProps').children().remove();
  148. // Re-trigger adding them
  149. if(self.mode == 'advanced')
  150. vboxWizardExportApplianceUpdateList();
  151. else
  152. $('#wizardExportApplianceStep4').trigger('show',e,self);
  153. }
  154. }
  155. ];
  156. /* Function run when wizard completes */
  157. this.onFinish = function() {
  158. // Actually export appliances
  159. function vboxExportApp(force) {
  160. // Each VM
  161. var vmid = null;
  162. var vms = {};
  163. var vmsAndProps = $('#vboxExportProps').children('tr');
  164. for(var a = 0; a < vmsAndProps.length; a++) {
  165. if($(vmsAndProps[a]).hasClass('vboxTableParent')) {
  166. vmid = $(vmsAndProps[a]).data('vm').id;
  167. vms[vmid] = {};
  168. vms[vmid]['id'] = vmid;
  169. continue;
  170. }
  171. var prop = $(vmsAndProps[a]).data('vmprop');
  172. vms[vmid][prop] = $(vmsAndProps[a]).children('td:eq(1)').children().first().text();
  173. }
  174. var file = $(self.form).find('[name=wizardExportApplianceLocation]').val();
  175. var format = $(self.form).find('[name=wizardExportApplianceFormat]').val();
  176. var manifest = $(self.form).find('[name=wizardExportApplianceManifest]').prop('checked');
  177. var overwrite = force;
  178. var l = new vboxLoader();
  179. l.add('applianceExport',function(d){
  180. if(d.responseData.progress) {
  181. vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(){
  182. self.completed.resolve();
  183. },'progress_export_90px.png',
  184. trans('Export one or more VirtualBox virtual machines as an appliance','UIActionPool').replace(/\.+$/g,''),
  185. vboxBasename(file));
  186. } else {
  187. self.completed.reject();
  188. }
  189. },{'format':format,'file':file,'vms':vms,'manifest':manifest,'overwrite':overwrite});
  190. l.run();
  191. $(self.dialog).empty().remove();
  192. }
  193. /* Remove required classes */
  194. $(self.form).find('[name=wizardExportApplianceLocation]').removeClass('vboxRequired');
  195. $('#vboxExportAppVMListContainer').removeClass('vboxRequired');
  196. /* Some vms must be selected */
  197. if($('#vboxExportProps').children('tr').length == 0) {
  198. $('#vboxExportAppVMListContainer').addClass('vboxRequired');
  199. return;
  200. }
  201. /* Check to see if file exists */
  202. var loc = $(self.form).find('[name=wizardExportApplianceLocation]').val();
  203. if(!loc) {
  204. $(self.form).find('[name=wizardExportApplianceLocation]').addClass('vboxRequired');
  205. return;
  206. }
  207. var fileExists = false;
  208. var fe = new vboxLoader();
  209. fe.add('fileExists',function(d){
  210. fileExists = d.responseData;
  211. },{'file':loc});
  212. fe.onLoad = function() {
  213. if(fileExists) {
  214. var buttons = {};
  215. buttons[trans('Yes','QIMessageBox')] = function() {
  216. vboxExportApp(1);
  217. $(this).empty().remove();
  218. };
  219. vboxConfirm(trans('A file named <b>%1</b> already exists. Are you sure you want to replace it?<br /><br />Replacing it will overwrite its contents.','UIMessageCenter').replace('%1',vboxBasename(loc)),buttons,trans('No','QIMessageBox'));
  220. return;
  221. }
  222. vboxExportApp(0);
  223. };
  224. fe.run();
  225. };
  226. }
  227. /**
  228. * Show the medium encryption dialog
  229. *
  230. * @param {String} context - used in dialog name
  231. * @param {Array} encIds - encryption ids
  232. *
  233. */
  234. function vboxMediumEncryptionPasswordsDialog(context, encIds, validIds) {
  235. if(!(encIds && encIds.length)) { return []; }
  236. var results = $.Deferred();
  237. var dialogTitle = trans("%1 - Disk Encryption").replace('%1', context);
  238. var l = new vboxLoader();
  239. l.addFileToDOM("panes/mediumEncryptionPasswords.html");
  240. l.onLoad = function() {
  241. for(var i = 0; i < encIds.length; i++) {
  242. vboxMediumEncryptionPasswordAdd(encIds[i].id, validIds && validIds.length && jQuery.inArray(encIds[i].id, validIds) > -1);
  243. }
  244. var buttons = {};
  245. buttons[trans('OK','QIMessageBox')] = function(){
  246. // Get passwords
  247. var pws = vboxMediumEncryptionPasswordsGet();
  248. if(pws === false)
  249. return;
  250. $(this).trigger('close').empty().remove();
  251. results.resolve(pws);
  252. };
  253. buttons[trans('Cancel','QIMessageBox')] = function(){
  254. results.reject();
  255. $(this).trigger('close').empty().remove();
  256. };
  257. $('#vboxMediumEncryptionPasswords').dialog({'closeOnEscape':true,'width':600,'height':400,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent','title':'<img src="images/vbox/nw_16px.png" class="vboxDialogTitleIcon" /> ' + dialogTitle}).on("dialogbeforeclose",function(){
  258. $(this).parent().find('span:contains("'+trans('Cancel','QIMessageBox')+'")').trigger('click');
  259. });
  260. };
  261. l.run()
  262. return results.promise();
  263. }
  264. /**
  265. * Show the port forwarding configuration dialog
  266. * @param {Array} rules - list of port forwarding rules to process
  267. * @returns {Object} deferred promise
  268. */
  269. function vboxPortForwardConfigDialog(rules) {
  270. var results = $.Deferred();
  271. var l = new vboxLoader();
  272. l.addFileToDOM("panes/settingsPortForwarding.html");
  273. l.onLoad = function(){
  274. vboxSettingsPortForwardingInit(rules);
  275. var resizeTable = function() {
  276. var h = $('#vboxSettingsPortForwarding').children('table').hide().parent().innerHeight() - 16;
  277. $('#vboxSettingsPortForwarding').children('table').css({'height':h+'px'}).show();
  278. $('#vboxSettingsPortForwardingListDiv').css({'height':(h-6)+'px','overflow':'auto'});
  279. };
  280. var buttons = {};
  281. buttons[trans('OK','QIMessageBox')] = function(){
  282. // Get rules
  283. var rules = $('#vboxSettingsPortForwardingList').children('tr');
  284. var rulesToPass = new Array();
  285. for(var i = 0; i < rules.length; i++) {
  286. if($(rules[i]).data('vboxRule')[3] == 0 || $(rules[i]).data('vboxRule')[5] == 0) {
  287. vboxAlert(trans("The current port forwarding rules are not valid. " +
  288. "None of the host or guest port values may be set to zero.",'UIMessageCenter'));
  289. return;
  290. }
  291. rulesToPass[i] = $(rules[i]).data('vboxRule');
  292. }
  293. $(this).trigger('close').empty().remove();
  294. results.resolve(rulesToPass);
  295. };
  296. buttons[trans('Cancel','QIMessageBox')] = function(){
  297. results.reject();
  298. $(this).trigger('close').empty().remove();
  299. };
  300. $('#vboxSettingsPortForwarding').dialog({'closeOnEscape':true,'width':600,'height':400,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent','title':'<img src="images/vbox/nw_16px.png" class="vboxDialogTitleIcon" /> ' + trans('Port Forwarding Rules','UIMachineSettingsPortForwardingDlg')}).on("dialogbeforeclose",function(){
  301. $(this).parent().find('span:contains("'+trans('Cancel','QIMessageBox')+'")').trigger('click');
  302. }).on('dialogresizestop',resizeTable);
  303. resizeTable();
  304. };
  305. l.run();
  306. return results.promise();
  307. }
  308. /**
  309. * Run the New Virtual Machine Wizard
  310. * @param {String} vmgroup - VM group to add machine to
  311. */
  312. function vboxWizardNewVMDialog(vmgroup) {
  313. // reference to self
  314. var self = this;
  315. // Extend vboxWizard class
  316. this.parentClass = vboxWizard;
  317. this.parentClass();
  318. /* Common settings */
  319. this.name = 'wizardNewVM';
  320. this.bg = 'images/vbox/vmw_new_welcome_bg.png';
  321. this.title = trans('Create Virtual Machine','UIWizardNewVM');
  322. this.icon = 'vm_new';
  323. this.steps = 3;
  324. this.vmgroup = vmgroup;
  325. this.context = 'UIWizardNewVM';
  326. this.finishText = trans('Create','UIWizardNewVM');
  327. this.data = [
  328. {'fn':'vboxGetMedia','callback':function(d){$('#vboxPane').data('vboxMedia',d.responseData);}}
  329. ];
  330. /* Function to run when wizard completes */
  331. this.onFinish = function() {
  332. // Callback to finish wizard
  333. var vboxNewVMFinish = function() {
  334. // Get parameters
  335. var disk = '';
  336. if($(self.form).find('[name=newVMDisk]:checked').val() == 'existing') {
  337. disk = $(self.form)[0].newVMDiskSelect.options[$(self.form)[0].newVMDiskSelect.selectedIndex].value;
  338. disk = vboxMedia.getMediumById(disk).location;
  339. }
  340. var name = jQuery.trim($(self.form).find('[name=newVMName]').val());
  341. var ostype = $(self.form).find('[name=newVMOSType]').val();
  342. var mem = parseInt($(self.form).find('[name=wizardNewVMSizeValue]').val());
  343. // Show loading screen
  344. var l = new vboxLoader('machineCreate');
  345. l.showLoading();
  346. $.when(vboxAjaxRequest('machineCreate',{'disk':disk,'ostype':ostype,'memory':mem,'name':name,'group':vmgroup}))
  347. .always(function() {
  348. l.removeLoading();
  349. }).done(function(res){
  350. if(res.responseData.exists) {
  351. vboxAlert(trans('<p>Cannot create the machine folder <b>%1</b> in the parent folder <nobr><b>%2</b>.</nobr></p><p>This folder already exists and possibly belongs to another machine.</p>','UIMessageCenter').replace('%1',vboxBasename(res.exists)).replace('%2',vboxDirname(res.exists)));
  352. } else if(res.success) {
  353. $(self.dialog).empty().remove();
  354. var lm = new vboxLoader('machineCreate');
  355. lm.add('vboxGetMedia',function(d){$('#vboxPane').data('vboxMedia',d.responseData);});
  356. lm.onLoad = function() {
  357. self.completed.resolve();
  358. };
  359. lm.run();
  360. } else {
  361. self.completed.reject();
  362. }
  363. });
  364. };
  365. // Name must exist
  366. if(!jQuery.trim($(self.form).find('[name=newVMName]').val())) {
  367. $(self.form).find('[name=newVMName]').addClass('vboxRequired');
  368. return;
  369. }
  370. $(self.form).find('[name=newVMName]').removeClass('vboxRequired');
  371. // Make sure file does not exist
  372. var fnl = new vboxLoader();
  373. fnl.add('vboxGetComposedMachineFilename',function(d){
  374. loc = vboxDirname(d.responseData);
  375. var fileExists = false;
  376. var fe = new vboxLoader('fileExists');
  377. fe.add('fileExists',function(d){
  378. fileExists = d.responseData;
  379. },{'file':loc});
  380. fe.onLoad = function() {
  381. if(fileExists) {
  382. vboxAlert(trans('<p>Cannot create the machine folder <b>%1</b> in the parent folder <nobr><b>%2</b>.</nobr></p><p>This folder already exists and possibly belongs to another machine.</p>','UIMessageCenter').replace('%1',vboxBasename(loc)).replace('%2',vboxDirname(loc)));
  383. // Go back
  384. self.displayStep(1);
  385. return;
  386. }
  387. // Start new harddisk wizard if create new is selected
  388. if($(self.form).find('[name=newVMDisk]:checked').val() == 'create') {
  389. // Recommended size
  390. var size = newVMOSTypesObj[$(self.form).find('[name=newVMOSType]').val()].recommendedHDD;
  391. $.when(new vboxWizardNewHDDialog({'name':jQuery.trim($(self.form).find('[name=newVMName]').val()),'size':size,'group':vmgroup}).run())
  392. .done(function(med){
  393. $(self.form).find('[name=newVMDisk]').eq(2).trigger('click').prop('checked',true);
  394. // Add newly created disk as option and select it
  395. vmNewFillExistingDisks(med);
  396. vboxNewVMFinish();
  397. });
  398. return;
  399. } else if($(self.form).find('[name=newVMDisk]:checked').val() == 'none') {
  400. buttons = {};
  401. buttons[trans('Continue','UIMessageCenter')] = function(){
  402. $(this).empty().remove();
  403. vboxNewVMFinish();
  404. };
  405. vboxConfirm(trans('You are about to create a new virtual machine without a hard disk. You will not be able to install an operating system on the machine until you add one. In the mean time you will only be able to start the machine using a virtual optical disk or from the network.','UIMessageCenter'), buttons, trans('Go Back','UIMessageCenter'));
  406. return;
  407. }
  408. vboxNewVMFinish();
  409. };
  410. fe.run();
  411. },{'name':document.forms['frmwizardNewVM'].newVMName.value, 'group':vmgroup});
  412. fnl.run();
  413. };
  414. }
  415. /**
  416. * Run the Clone Virtual Machine Wizard
  417. * @param {Object} args - wizard data - args.vm and args.snapshot should be populated
  418. * @returns {Object} deferred promise
  419. * @see vboxWizard()
  420. */
  421. function vboxWizardCloneVMDialog(args) {
  422. // self reference
  423. var self = this;
  424. // Extend vboxWizard class
  425. this.parentClass = vboxWizard;
  426. this.parentClass();
  427. /* Common options */
  428. this.name = 'wizardCloneVM';
  429. this.title = trans('Clone Virtual Machine','UIWizardCloneVM');
  430. this.bg = 'images/vbox/vmw_clone_bg.png';
  431. this.icon = 'vm_clone';
  432. this.finishText = trans('Clone','UIWizardCloneVM');
  433. this.context = 'UIWizardCloneVM';
  434. this.widthAdvanced = 450;
  435. this.heightAdvanced = 350;
  436. /* Override run() because we need VM data */
  437. this.parentRun = this.run;
  438. this.run = function() {
  439. var l = new vboxLoader('vboxWizardCloneVMInit');
  440. l.showLoading();
  441. $.when(vboxVMDataMediator.getVMDetails(args.vm.id)).always(function() {
  442. // Always remove loading screen
  443. l.removeLoading();
  444. }).done(function(d){
  445. self.steps = (d.snapshotCount > 0 ? 3 : 2);
  446. self.args = $.extend(true,args,{'vm':d});
  447. self.parentRun();
  448. });
  449. return self.completed.promise();
  450. };
  451. /* Function to run when finished */
  452. this.onFinish = function() {
  453. // Get parameters
  454. var name = jQuery.trim($(self.form).find('[name=machineCloneName]').val());
  455. var src = self.args.vm.id;
  456. var snapshot = self.args.snapshot;
  457. var allNetcards = $(self.form).find('[name=vboxCloneReinitNetwork]').prop('checked');
  458. if(!name) {
  459. $(self.form).find('[name=machineCloneName]').addClass('vboxRequired');
  460. return;
  461. }
  462. // Only two steps? We can assume that state has no child states.
  463. // Force current state only
  464. var vmState = 'MachineState';
  465. if(self.steps > 2 || self.mode == 'advanced') {
  466. vmState = $(self.form).find('[name=vmState]:checked').val();
  467. }
  468. // Full / linked clone
  469. var cLink = $(self.form).find('[name=vboxCloneType]').eq(1).prop('checked');
  470. // wrap function
  471. var vbClone = function(sn) {
  472. $.when(vboxAjaxRequest('machineClone', {'name':name,'vmState':vmState,'src':src,'snapshot':sn,'reinitNetwork':allNetcards,'link':cLink}))
  473. .done(function(d){
  474. if(d.responseData.progress) {
  475. var registerVM = d.responseData.settingsFilePath;
  476. vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(ret) {
  477. $.when(vboxAjaxRequest('machineAdd',{'file':registerVM})).done(function(){
  478. $.when(vboxAjaxRequest('vboxGetMedia')).done(function(dat){
  479. $('#vboxPane').data('vboxMedia',dat.responseData);
  480. self.completed.resolve();
  481. }).fail(function(){
  482. self.completed.reject();
  483. });
  484. }).fail(function(){
  485. self.completed.reject();
  486. });
  487. },'progress_clone_90px.png',trans('Clone selected virtual machine','UIActionPool'),
  488. self.args.vm.name + ' > ' + name);
  489. } else {
  490. self.completed.reject();
  491. }
  492. }).fail(function(){
  493. self.completed.reject();
  494. });
  495. };
  496. // Check for linked clone, but not a snapshot
  497. if(cLink && !self.args.snapshot) {
  498. $.when(vboxAjaxRequest('snapshotTake',
  499. {'vm':src,'name':trans('Linked Base for %1 and %2','UIWizardCloneVM').replace('%1',self.args.vm.name).replace('%2',name),'description':''}))
  500. .done(function(d){
  501. if(d.responseData.progress) {
  502. vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(){
  503. $.when(vboxVMDataMediator.getVMDetails(src, true)).done(function(md){
  504. vbClone(md.currentSnapshot);
  505. });
  506. },
  507. 'progress_snapshot_create_90px.png',
  508. trans('Take a snapshot of the current virtual machine state','UIActionPool'),
  509. self.args.vm.name);
  510. } else if(d && d.error) {
  511. self.completed.reject();
  512. vboxAlert(d.error);
  513. }
  514. }).fail(function(){
  515. self.completed.reject();
  516. });
  517. // Just clone
  518. } else {
  519. vbClone(snapshot);
  520. }
  521. $(self.dialog).empty().remove();
  522. };
  523. }
  524. /**
  525. * Run the VM Log Viewer dialog
  526. * @param {String} vm - uuid or name of virtual machine to obtain logs for
  527. */
  528. function vboxShowLogsDialogInit(vm) {
  529. $('#vboxPane').append($('<div />').attr({'id':'vboxVMLogsDialog'}));
  530. var l = new vboxLoader();
  531. l.add('machineGetLogFilesList',function(r){
  532. $('#vboxVMLogsDialog').data({'logs':r.responseData.logs,'logpath':r.responseData.path});
  533. },{'vm':vm.id});
  534. l.addFileToDOM('panes/vmlogs.html',$('#vboxVMLogsDialog'));
  535. l.onLoad = function(){
  536. var buttons = {};
  537. buttons[trans('Refresh','UIVMLogViewer')] = function() {
  538. l = new vboxLoader();
  539. l.add('machineGetLogFilesList',function(r){
  540. $('#vboxVMLogsDialog').data({'logs':r.responseData.logs,'logpath':r.responseData.path});
  541. },{'vm':vm.id});
  542. l.onLoad = function(){
  543. vboxShowLogsInit(vm);
  544. };
  545. l.run();
  546. };
  547. buttons[trans('Close','UIVMLogViewer')] = function(){$(this).trigger('close').empty().remove();};
  548. $('#vboxVMLogsDialog').dialog({'closeOnEscape':true,'width':800,'height':500,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent','title':'<img src="images/vbox/vm_show_logs_16px.png" class="vboxDialogTitleIcon" /> '+ trans('%1 - VirtualBox Log Viewer','UIVMLogViewer').replace('%1',vm.name)}).on("dialogbeforeclose",function(){
  549. $(this).parent().find('span:contains("'+trans('Close','UIVMLogViewer')+'")').trigger('click');
  550. });
  551. vboxShowLogsInit(vm);
  552. };
  553. l.run();
  554. }
  555. /**
  556. * Show the Virtual Media Manager Dialog
  557. * @param {Boolean} select - true to display "Select" button and resolve with selected medium
  558. * @param {String} type - optionally restrict media to media of this type
  559. * @param {Boolean} hideDiff - optionally hide differencing HardDisk media
  560. * @param {String} mPath - optional path to use when adding or creating media through the VMM dialog
  561. * @returns {Object} deferred promise
  562. */
  563. function vboxVMMDialog(select,type,hideDiff,mPath) {
  564. var results = $.Deferred();
  565. $('#vboxPane').append($('<div />').attr({'id':'vboxVMMDialog','class':'vboxVMMDialog'}));
  566. var l = new vboxLoader();
  567. l.add('getConfig',function(d){$('#vboxPane').data('vboxConfig',d.responseData);});
  568. l.add('vboxSystemPropertiesGet',function(d){$('#vboxPane').data('vboxSystemProperties',d.responseData);});
  569. l.add('vboxGetMedia',function(d){$('#vboxPane').data('vboxMedia',d.responseData);});
  570. l.addFileToDOM('panes/vmm.html',$('#vboxVMMDialog'));
  571. l.onLoad = function() {
  572. var buttons = {};
  573. if(select) {
  574. buttons[trans('Select','UIMediumManager')] = function() {
  575. var sel = null;
  576. switch($("#vboxVMMTabs").tabs('option','active')) {
  577. case 0: /* HardDisks */
  578. sel = $('#vboxVMMHDList').find('tr.vboxListItemSelected').first();
  579. break;
  580. case 1: /* DVD */
  581. sel = $('#vboxVMMCDList').find('tr.vboxListItemSelected').first();
  582. break;
  583. default:
  584. sel = $('#vboxVMMFDList').find('tr.vboxListItemSelected').first();
  585. }
  586. if($(sel).length) {
  587. vboxMedia.updateRecent(vboxMedia.getMediumById($(sel).data('medium')));
  588. results.resolve($(sel).data('medium'));
  589. }
  590. $('#vboxVMMDialog').trigger('close').empty().remove();
  591. };
  592. }
  593. buttons[trans('Close','UIMessageCenter')] = function() {
  594. $('#vboxVMMDialog').trigger('close').empty().remove();
  595. results.reject();
  596. };
  597. $("#vboxVMMDialog").dialog({'closeOnEscape':true,'width':800,'height':500,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent vboxVMMDialog','title':'<img src="images/vbox/diskimage_16px.png" class="vboxDialogTitleIcon" /> '+trans('Virtual Media Manager','VBoxMediaManagerDlg')}).on("dialogbeforeclose",function(){
  598. $(this).parent().find('span:contains("'+trans('Close','UIMessageCenter')+'")').trigger('click');
  599. });
  600. vboxVMMInit(hideDiff,mPath);
  601. if(type) {
  602. switch(type) {
  603. case 'HardDisk':
  604. $("#vboxVMMTabs").tabs('option','active',0);
  605. $("#vboxVMMTabs").tabs('disable',1);
  606. $("#vboxVMMTabs").tabs('disable',2);
  607. break;
  608. case 'DVD':
  609. $("#vboxVMMTabs").tabs('option','active',1);
  610. $("#vboxVMMTabs").tabs('disable',0);
  611. $("#vboxVMMTabs").tabs('disable',2);
  612. break;
  613. case 'Floppy':
  614. $("#vboxVMMTabs").tabs('option','active',2);
  615. $("#vboxVMMTabs").tabs('disable',0);
  616. $("#vboxVMMTabs").tabs('disable',1);
  617. break;
  618. default:
  619. $("#vboxVMMTabs").tabs('option','active',0);
  620. break;
  621. }
  622. }
  623. };
  624. l.run();
  625. return results.promise();
  626. }
  627. /**
  628. * Run the New Virtual Disk wizard
  629. * @param {Object} suggested - sugggested defaults such as hard disk name and path
  630. */
  631. function vboxWizardNewHDDialog(suggested) {
  632. // reference
  633. var self = this;
  634. // Extend vboxWizard class
  635. this.parentClass = vboxWizard;
  636. this.parentClass();
  637. /* Common options */
  638. this.name = 'wizardNewHD';
  639. this.title = trans('Create Virtual Hard Disk','UIWizardNewVD');
  640. this.bg = 'images/vbox/vmw_new_harddisk_bg.png';
  641. this.icon = 'hd';
  642. this.steps = 3;
  643. this.suggested = suggested;
  644. this.context = 'UIWizardNewVD';
  645. this.finishText = trans('Create','UIWizardNewVD');
  646. this.height = 450;
  647. this.data = [
  648. {'fn':'vboxSystemPropertiesGet','callback':function(d){$('#vboxPane').data('vboxSystemProperties',d.responseData);}},
  649. {'fn':'vboxGetMedia','callback':function(d){$('#vboxPane').data('vboxMedia',d.responseData);}}
  650. ];
  651. // Compose folder if suggested name exists
  652. if(this.suggested && this.suggested.name) {
  653. if(!this.suggested['group']) this.suggested.group = '';
  654. this.data.push(
  655. {'fn':'vboxGetComposedMachineFilename','callback':function(d){
  656. self.suggested.path = vboxDirname(d.responseData)+$('#vboxPane').data('vboxConfig').DSEP;
  657. },'args':{'name':this.suggested.name, 'group':this.suggested.group}});
  658. }
  659. /* Function to run when wizard completes */
  660. this.onFinish = function() {
  661. // Fix size if we need to
  662. var mbytes = vboxConvertMbytes($(self.form).find('[name=wizardNewHDSizeValue]').val());
  663. $(self.form).find('[name=wizardNewHDSizeValue]').val(vboxMbytesConvert(mbytes));
  664. $('#wizardNewHDSizeLabel').html(vboxMbytesConvert(mbytes) + ' ('+mbytes+' '+trans('MB','VBoxGlobal')+')');
  665. // Determine file location
  666. var file = $(self.form).find('[name=wizardNewHDLocation]').val();
  667. if(file.search(/[\/|\\]/) < 0) {
  668. // just a name
  669. if(self.suggested.path) {
  670. if($('#vboxPane').data('vboxConfig').enforceVMOwnership==true){
  671. file = self.suggested.path + $('#vboxPane').data('vboxConfig').DSEP + $('#vboxPane').data('vboxSession').user + "_" + file;
  672. } else {
  673. file = self.suggested.path + $('#vboxPane').data('vboxConfig').DSEP + file;
  674. }
  675. } else{
  676. if($('#vboxPane').data('vboxConfig').enforceVMOwnership==true){
  677. file = $('#vboxPane').data('vboxSystemProperties').homeFolder + $('#vboxPane').data('vboxConfig').DSEP + $('#vboxPane').data('vboxSession').user + "_" + file;
  678. } else {
  679. file = $('#vboxPane').data('vboxSystemProperties').homeFolder + $('#vboxPane').data('vboxConfig').DSEP + file;
  680. }
  681. }
  682. // Enforce VM ownership
  683. } else if($('#vboxPane').data('vboxConfig').enforceVMOwnership==true) {
  684. // has user ownership so use folderbased
  685. var nameIndex = file.lastIndexOf($('#vboxPane').data('vboxConfig').DSEP);
  686. var path = file.substr(0,nameIndex);
  687. var name = file.substr(nameIndex+1,file.length);
  688. file = path +$('#vboxPane').data('vboxConfig').DSEP + $('#vboxPane').data('vboxSession').user + "_" + name;
  689. }
  690. var format = $(self.form)[0].elements['newHardDiskFileType'];
  691. var formatOpts = {};
  692. for(var i = 0; i < format.length; i++) {
  693. if(format[i].checked) {
  694. formatOpts = $(format[i]).closest('tr').data('vboxFormat');
  695. format=format[i].value;
  696. break;
  697. }
  698. }
  699. // append filename ext?
  700. if(jQuery.inArray(file.substring(file.lastIndexOf('.')+1).toLowerCase(),formatOpts.extensions) < 0) {
  701. file += '.'+formatOpts.extensions[0];
  702. }
  703. // Normalize file
  704. file = file.replace($('#vboxPane').data('vboxConfig').DSEP+$('#vboxPane').data('vboxConfig').DSEP,$('#vboxPane').data('vboxConfig').DSEP);
  705. /* Check to see if file exists */
  706. var fileExists = false;
  707. var l = new vboxLoader('fileExists');
  708. l.add('fileExists',function(d){
  709. fileExists = d.responseData;
  710. },{'file':file});
  711. l.onLoad = function() {
  712. if(fileExists) {
  713. vboxAlert(trans("<p>The hard disk storage unit at location <b>%1</b> already " +
  714. "exists. You cannot create a new virtual hard disk that uses this " +
  715. "location because it can be already used by another virtual hard " +
  716. "disk.</p>" +
  717. "<p>Please specify a different location.</p>",'UIMessageCenter').replace('%1',file));
  718. return;
  719. }
  720. var fsplit = $(self.form).find('[name=newHardDiskSplit]').prop('checked');
  721. var size = vboxConvertMbytes($(self.form).find('[name=wizardNewHDSizeValue]').val());
  722. var type = ($(self.form).find('[name=newHardDiskType]').eq(1).prop('checked') ? 'fixed' : 'dynamic');
  723. var nl = new vboxLoader('mediumCreateBaseStorage');
  724. nl.add('mediumCreateBaseStorage',function(d){
  725. if(d.responseData.progress) {
  726. vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(ret) {
  727. var ml = new vboxLoader();
  728. ml.add('vboxGetMedia',function(dat){$('#vboxPane').data('vboxMedia',dat.responseData);});
  729. ml.onLoad = function() {
  730. var med = vboxMedia.getMediumByLocation(file);
  731. if(med) {
  732. vboxMedia.updateRecent(med);
  733. self.completed.resolve(med.id);
  734. } else {
  735. self.completed.reject();
  736. }
  737. };
  738. ml.run();
  739. },'progress_media_create_90px.png',trans('Create a virtual hard disk now','UIWizardNewVM'),
  740. vboxBasename(file),true);
  741. } else {
  742. self.completed.reject();
  743. }
  744. },{'file':file,'type':type,'size':size,'format':format,'split':fsplit});
  745. nl.run();
  746. $(self.dialog).empty().remove();
  747. };
  748. l.run();
  749. };
  750. }
  751. /**
  752. * Run the Copy Virtual Disk wizard
  753. * @param {Object} suggested - sugggested defaults such as hard disk name and path
  754. */
  755. function vboxWizardCopyHDDialog(suggested) {
  756. // reference
  757. var self = this;
  758. /* Extend vboxWizard class */
  759. this.parentClass = vboxWizard;
  760. this.parentClass();
  761. /* Common options */
  762. this.name = 'wizardCopyHD';
  763. this.title = trans('Copy Virtual Hard Disk','UIWizardCloneVD');
  764. this.bg = 'images/vbox/vmw_new_harddisk_bg.png';
  765. this.icon = 'hd';
  766. this.steps = 4;
  767. this.suggested = suggested;
  768. this.context = 'UIWizardCloneVD';
  769. this.finishText = trans('Copy','UIWizardCloneVD');
  770. this.height = 450;
  771. this.data = [
  772. {'fn':'vboxSystemPropertiesGet','callback':function(d){$('#vboxPane').data('vboxSystemProperties',d.responseData);}},
  773. {'fn':'vboxGetMedia','callback':function(d){$('#vboxPane').data('vboxMedia',d.responseData);}}
  774. ];
  775. /* Function run when wizard completes */
  776. this.onFinish = function() {
  777. var format = $(self.form)[0].elements['copyHDFileType'];
  778. var formatOpts = {};
  779. for(var i = 0; i < format.length; i++) {
  780. if(format[i].checked) {
  781. formatOpts = $(format[i]).closest('tr').data('vboxFormat');
  782. break;
  783. }
  784. }
  785. var src = $(self.form).find('[name=copyHDDiskSelect]').val();
  786. var type = ($(self.form).find('[name=newHardDiskType]').eq(1).prop('checked') ? 'fixed' : 'dynamic');
  787. var format = $(self.form)[0].elements['copyHDFileType'];
  788. for(var i = 0; i < format.length; i++) {
  789. if(format[i].checked) {
  790. format=format[i].value;
  791. break;
  792. }
  793. }
  794. var fsplit = $(self.form).find('[name=newHardDiskSplit]').prop('checked') && vboxMedia.formatSupportsSplit(format);
  795. var loc = jQuery.trim($(self.form).find('[name=wizardCopyHDLocation]').val());
  796. if(!loc) {
  797. $(self.form).find('[name=wizardCopyHDLocation]').addClass('vboxRequired');
  798. return;
  799. }
  800. $(self.form).find('[name=wizardCopyHDLocation]').removeClass('vboxRequired');
  801. if(loc.search(/[\/|\\]/) < 0) {
  802. if($('#wizardCopyHDStep4').data('suggestedpath')) {
  803. loc = $('#wizardCopyHDStep4').data('suggestedpath') + loc;
  804. } else {
  805. loc = vboxDirname(vboxMedia.getMediumById(src).location) + $('#vboxPane').data('vboxConfig').DSEP + loc;
  806. }
  807. }
  808. // append ext?
  809. if(jQuery.inArray(loc.substring(loc.lastIndexOf('.')+1).toLowerCase(),formatOpts.extensions) < 0) {
  810. loc += '.'+formatOpts.extensions[0];
  811. }
  812. /* Check to see if file exists */
  813. var fileExists = false;
  814. var fe = new vboxLoader();
  815. fe.add('fileExists',function(d){
  816. fileExists = d.responseData;
  817. },{'file':loc});
  818. fe.onLoad = function() {
  819. if(fileExists) {
  820. vboxAlert(trans("<p>The hard disk storage unit at location <b>%1</b> already " +
  821. "exists. You cannot create a new virtual hard disk that uses this " +
  822. "location because it can be already used by another virtual hard " +
  823. "disk.</p>" +
  824. "<p>Please specify a different location.</p>",'UIMessageCenter').replace('%1',loc));
  825. return;
  826. }
  827. $(self.dialog).empty().remove();
  828. var l = new vboxLoader();
  829. l.add('mediumCloneTo',function(d){
  830. if(d.responseData.progress) {
  831. vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(ret,mid) {
  832. var ml = new vboxLoader();
  833. ml.add('vboxGetMedia',function(dat){$('#vboxPane').data('vboxMedia',dat.responseData);});
  834. ml.onLoad = function() {
  835. med = vboxMedia.getMediumByLocation(loc);
  836. vboxMedia.updateRecent(med);
  837. self.completed.resolve(mid);
  838. };
  839. ml.run();
  840. },'progress_media_create_90px.png',trans('Copy Virtual Hard Disk','UIWizardCloneVD'),
  841. vboxBasename(vboxMedia.getMediumById(src).location) + ' > ' + vboxBasename(loc));
  842. } else {
  843. self.completed.reject();
  844. }
  845. },{'src':vboxMedia.getMediumById(src).location,'type':type,'format':format,'location':loc,'split':fsplit});
  846. l.run();
  847. };
  848. fe.run();
  849. };
  850. }
  851. /**
  852. * Display guest network adapters dialog
  853. * @param {String} vm - virtual machine uuid or name
  854. */
  855. function vboxGuestNetworkAdaptersDialogInit(vm) {
  856. /*
  857. * Dialog
  858. */
  859. $('#vboxPane').append($('<div />').attr({'id':'vboxGuestNetworkDialog','style':'display: none'}));
  860. /*
  861. * Loader
  862. */
  863. var l = new vboxLoader();
  864. l.addFileToDOM('panes/guestNetAdapters.html',$('#vboxGuestNetworkDialog'));
  865. l.onLoad = function(){
  866. var buttons = {};
  867. buttons[trans('Close','UIVMLogViewer')] = function() {$('#vboxGuestNetworkDialog').trigger('close').empty().remove();};
  868. $('#vboxGuestNetworkDialog').dialog({'closeOnEscape':true,'width':500,'height':250,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent','title':'<img src="images/vbox/nw_16px.png" class="vboxDialogTitleIcon" /> ' + trans('Guest Network Adapters','VBoxGlobal')}).on("dialogbeforeclose",function(){
  869. $(this).parent().find('span:contains("'+trans('Close','UIVMLogViewer')+'")').trigger('click');
  870. });
  871. // defined in pane
  872. vboxVMNetAdaptersInit(vm,nic);
  873. };
  874. l.run();
  875. }
  876. /**
  877. * Display Global Preferences dialog
  878. */
  879. function vboxGlobalPrefsDialog() {
  880. // Prefs
  881. var panes = new Array(
  882. {'name':'GlobalGeneral','label':'General','icon':'machine','context':'UIGlobalSettingsGeneral'},
  883. {'name':'GlobalLanguage','label':'Language','icon':'site','context':'UIGlobalSettingsLanguage'},
  884. {'name':'GlobalNetwork','label':'Network','icon':'nw','context':'UIGlobalSettingsNetwork','tabbed':true},
  885. {'name':'GlobalUsers','label':'Users','icon':'register','context':'UIUsers'}
  886. );
  887. var data = new Array(
  888. {'fn':'hostOnlyInterfacesGet','callback':function(d){$('#vboxSettingsDialog').data('vboxHostOnlyInterfaces',d.responseData);}},
  889. {'fn':'vboxSystemPropertiesGet','callback':function(d){$('#vboxSettingsDialog').data('vboxSystemProperties',d.responseData);}},
  890. {'fn':'vboxNATNetworksGet','callback':function(d){$('#vboxSettingsDialog').data('vboxNATNetworks',d.responseData);}},
  891. {'fn':'getUsers','callback':function(d){$('#vboxSettingsDialog').data('vboxUsers',d.responseData);}}
  892. );
  893. // Check for noAuth setting
  894. if($('#vboxPane').data('vboxConfig').noAuth || !$('#vboxPane').data('vboxSession').admin || !$('#vboxPane').data('vboxConfig').authCapabilities.canModifyUsers) {
  895. panes.pop();
  896. data.pop();
  897. }
  898. $.when(vboxSettingsDialog(trans('Preferences...','UIActionPool').replace(/\./g,''),
  899. panes,data,null,'global_settings','UISettingsDialogGlobal'))
  900. .done(function(){
  901. var l = new vboxLoader();
  902. // Language change?
  903. if($('#vboxSettingsDialog').data('language') && $('#vboxSettingsDialog').data('language') != __vboxLangName) {
  904. vboxSetCookie('vboxLanguage',$('#vboxSettingsDialog').data('language'));
  905. l.onLoad = function(){location.reload(true);};
  906. }
  907. l.add('vboxNATNetworksSave',function(){return;},{'networks':$('#vboxSettingsDialog').data('vboxNATNetworks')});
  908. l.add('hostOnlyInterfacesSave',function(){return;},{'networkInterfaces':$('#vboxSettingsDialog').data('vboxHostOnlyInterfaces').networkInterfaces});
  909. l.add('vboxSystemPropertiesSave',function(){return;},{'SystemProperties':$('#vboxSettingsDialog').data('vboxSystemProperties')});
  910. l.run();
  911. // Update system properties
  912. $('#vboxPane').data('vboxSystemProperties',$('#vboxSettingsDialog').data('vboxSystemProperties'));
  913. });
  914. }
  915. /**
  916. * Display a virtual machine settings dialog
  917. * @param {String} vm - uuid or name of virtual machine
  918. * @param {String} pane - optionally automatically select pane when dialog is displayed
  919. * @returns {Object} deferred promise
  920. */
  921. function vboxVMsettingsDialog(vm,pane) {
  922. var results = $.Deferred();
  923. if(typeof(vm) == 'string')
  924. vm = vboxVMDataMediator.getVMData(vm);
  925. // Only show these dialogs once per change
  926. var reloadConfirmShowing = false;
  927. // Handler for when VM settings have changed
  928. /////////////////////////////////////////////
  929. var machineSettingsChanged = function(e, eventList) {
  930. for(var i = 0; i < eventList.length; i++) {
  931. ////////////////////////////////
  932. //
  933. // Machine data changed..
  934. //
  935. ////////////////////////////////
  936. switch(eventList[i].eventType) {
  937. case 'OnMachineStateChanged':
  938. if(!eventList[i].machineId || eventList[i].machineId != vm.id) break;
  939. // Display loading screen
  940. var l = new vboxLoader();
  941. l.showLoading();
  942. $.when(vboxVMDataMediator.getVMDataCombined(vm.id)).done(function(vmData) {
  943. // data received from deferred object
  944. $('#vboxSettingsDialog').data('vboxMachineData',vmData);
  945. $('#vboxSettingsDialog').data('vboxFullEdit', (vboxVMStates.isPoweredOff(vmData) && !vboxVMStates.isSaved(vmData)));
  946. $('#vboxSettingsDialog').trigger('dataLoaded');
  947. l.removeLoading();
  948. if(vboxVMStates.isRunning(vmData)) {
  949. vboxAlert(trans('The virtual machine that you are changing has been started. Only certain settings can be changed while a machine is running. All other changes will be lost if you close this window now.','UIMessageCenter'));
  950. }
  951. });
  952. break;
  953. // Unregistered machine
  954. case 'OnMachineRegistered':
  955. if(!eventList[i].machineId || eventList[i].machineId != vm.id || eventList[i].registered) break;
  956. $('#vboxSettingsDialog').parent().find('span:contains("'+trans('Cancel','QIMessageBox')+'")').trigger('click');
  957. break;
  958. case 'OnMachineDataChanged':
  959. case 'OnNetworkAdapterChanged':
  960. case 'OnVRDEServerInfoChanged':
  961. case 'OnCPUChanged':
  962. case 'OnStorageControllerChanged':
  963. case 'OnMediumChanged':
  964. case 'OnVRDEServerChanged':
  965. case 'OnUSBControllerChanged':
  966. case 'OnSharedFolderChanged':
  967. case 'OnCPUExecutionCapChanged':
  968. case 'OnStorageDeviceChanged':
  969. case 'OnNATRedirect':
  970. if(!eventList[i].machineId || eventList[i].machineId != vm.id) break;
  971. // already showing reload confirmation
  972. if(reloadConfirmShowing) break;
  973. var buttons = {};
  974. buttons[trans('Reload settings','UIMessageCenter')] = function() {
  975. // Display loading screen
  976. var l = new vboxLoader();
  977. l.showLoading();
  978. $(this).empty().remove();
  979. /*
  980. * Data to be reloaded
  981. */
  982. var reload = [
  983. vboxAjaxRequest('vboxGetMedia',{}).done(function(d){$('#vboxPane').data('vboxMedia',d.responseData);}),
  984. vboxAjaxRequest('getNetworking',{}).done(function(d){$('#vboxSettingsDialog').data('vboxNetworking',d.responseData);}),
  985. vboxAjaxRequest('vboxRecentMediaGet',{}).done(function(d){$('#vboxPane').data('vboxRecentMedia',d.responseData);}),
  986. vboxAjaxRequest('consoleGetSharedFolders',{'vm':vm.id}).done(function(d){$('#vboxSettingsDialog').data('vboxTransientSharedFolders',d.responseData);}),
  987. $.when(vboxVMDataMediator.getVMDataCombined(vm.id)).done(function(vmData) {
  988. // data received from deferred object
  989. $('#vboxSettingsDialog').data('vboxMachineData',vmData);
  990. $('#vboxSettingsDialog').data('vboxFullEdit', (vboxVMStates.isPoweredOff(vmData) && !vboxVMStates.isSaved(vmData)));
  991. })
  992. ];
  993. // Only when all of these are done
  994. $.when.apply($, reload).done(function(){
  995. /* Change title and tell dialog that data is loaded */
  996. $('#vboxSettingsDialog').trigger('dataLoaded').dialog('option','title','<img src="images/vbox/vm_settings_16px.png" class="vboxDialogTitleIcon" /> ' +
  997. $('<div />').text($('#vboxSettingsDialog').data('vboxMachineData').name).text() + ' - ' + trans('Settings','UISettingsDialog'));
  998. l.removeLoading();
  999. reloadConfirmShowing = false;
  1000. });
  1001. };
  1002. reloadConfirmShowing = true;
  1003. vboxConfirm(trans("<p>The machine settings were changed while you were editing them. You currently have unsaved setting changes.</p><p>Would you like to reload the changed settings or to keep your own changes?</p>",'UIMessageCenter'),
  1004. buttons,
  1005. trans('Keep changes', 'UIMessageCenter'), function(){
  1006. reloadConfirmShowing = false;
  1007. });
  1008. return;
  1009. }
  1010. }
  1011. };
  1012. // Watch for changed VM settings
  1013. $('#vboxPane').on('vboxEvents',machineSettingsChanged);
  1014. $.when(vboxVMDataMediator.getVMDataCombined(vm.id)).done(function(vmData) {
  1015. /*
  1016. * Settings dialog data
  1017. */
  1018. var dataList = new Array(
  1019. {'fn':'vboxGetMedia','callback':function(d){
  1020. $('#vboxPane').data('vboxMedia',d.responseData);
  1021. // data received from deferred object
  1022. $('#vboxSettingsDialog').data('vboxMachineData',vmData);
  1023. $('#vboxSettingsDialog').data('vboxFullEdit', (vboxVMStates.isPoweredOff(vmData) && !vboxVMStates.isSaved(vmData)));
  1024. }},
  1025. {'fn':'getNetworking','callback':function(d){$('#vboxSettingsDialog').data('vboxNetworking',d.responseData);}},
  1026. {'fn':'hostGetDetails','callback':function(d){$('#vboxSettingsDialog').data('vboxHostDetails',d.responseData);}},
  1027. {'fn':'vboxGetEnumerationMap','callback':function(d){$('#vboxSettingsDialog').data('vboxNetworkAdapterTypes',d.responseData);},'args':{'class':'NetworkAdapterType'}},
  1028. {'fn':'vboxGetEnumerationMap','callback':function(d){$('#vboxSettingsDialog').data('vboxAudioControllerTypes',d.responseData);},'args':{'class':'AudioControllerType'}},
  1029. {'fn':'vboxRecentMediaGet','callback':function(d){$('#vboxPane').data('vboxRecentMedia',d.responseData);}},
  1030. {'fn':'consoleGetSharedFolders','callback':function(d){$('#vboxSettingsDialog').data('vboxTransientSharedFolders',d.responseData);},'args':{'vm':vm.id}}
  1031. );
  1032. /*
  1033. * Settings dialog panes
  1034. */
  1035. var panes = new Array(
  1036. {name:'General',label:'General',icon:'machine',tabbed:true,context:'UIMachineSettingsGeneral'},
  1037. {name:'System',label:'System',icon:'chipset',tabbed:true,context:'UIMachineSettingsSystem'},
  1038. {name:'Display',label:'Display',icon:'vrdp',tabbed:true,context:'UIMachineSettingsDisplay'},
  1039. {name:'Storage',label:'Storage',icon:'attachment',context:'UIMachineSettingsStorage'},
  1040. {name:'Audio',label:'Audio',icon:'sound',context:'UIMachineSettingsAudio'},
  1041. {name:'Network',label:'Network',icon:'nw',tabbed:true,context:'UIMachineSettingsNetwork'},
  1042. {name:'SerialPorts',label:'Serial Ports',icon:'serial_port',tabbed:true,context:'UIMachineSettingsSerial'},
  1043. {name:'ParallelPorts',label:'Parallel Ports',icon:'parallel_port',tabbed:true,disabled:(!$('#vboxPane').data('vboxConfig').enableLPTConfig),context:'UIMachineSettingsParallel'},
  1044. {name:'USB',label:'USB',icon:'usb',context:'UIMachineSettingsUSB'},
  1045. {name:'SharedFolders',label:'Shared Folders',icon:'sf',context:'UIMachineSettingsSF'}
  1046. );
  1047. /*
  1048. * Check for encryption settings change
  1049. */
  1050. var presaveCallback = function() {
  1051. if(!$('#vboxSettingsDialog').data('vboxEncSettingsChanged'))
  1052. return true;
  1053. var encMediaSettings = $.Deferred();
  1054. // Validate
  1055. if(!vboxSettingsGeneralValidate()) {
  1056. $('#vboxSettingsMenuList').children('li:eq(0)').first().click();
  1057. $('#vboxSettingsPane-General').tabs('option','active', 3);
  1058. encMediaSettings.reject();
  1059. return encMediaSettings;
  1060. }
  1061. var vm = $('#vboxSettingsDialog').data('vboxMachineData');
  1062. var media = vboxStorage.getAttachedBaseMedia(vm);
  1063. var encIds = vboxMedia.getEncryptedMediaIds(media);
  1064. var encMedia = vboxMedia.getEncryptedMedia(media);
  1065. var formCipher = $('#vboxSettingsDialog').data('vboxEncCipher');
  1066. var formPassword = $('#vboxSettingsDialog').data('vboxEncPw');
  1067. var formEncEnabled = $('#vboxSettingsDialog').data('vboxEncEnabled');
  1068. // If encryption is not enabled, cipher needs to be blank
  1069. if(!formEncEnabled) {
  1070. formCipher = '';
  1071. }
  1072. // Get encryption password(s)
  1073. $.when(vboxMediumEncryptionPasswordsDialog(vm.name, encIds))
  1074. .done(function(pwdata) {
  1075. var runs = []
  1076. // Each medium attached
  1077. for(var i = 0; i < media.length; i++) {
  1078. // Only hard disks
  1079. if(media[i].deviceType != 'HardDisk') continue;
  1080. var id = vm.name;
  1081. var oldpw = "";
  1082. var cipher = null;
  1083. // Check for existing encryption setting
  1084. for(var a = 0; a < encMedia.length; a++) {
  1085. if(encMedia[a].medium == media[i].id) {
  1086. cipher = media[i].encryptionSettings.cipher;
  1087. // Look in passwords for id
  1088. for(var b = 0; b < pwdata.length; b++) {
  1089. if(pwdata[b].id == id) {
  1090. oldpw = pwdata[b].password;
  1091. break;
  1092. }
  1093. }
  1094. break;
  1095. }
  1096. }
  1097. runs.push({
  1098. medium: media[i].id,
  1099. cipher: cipher,
  1100. encId: id,
  1101. password: oldpw
  1102. });
  1103. }
  1104. // No encrypted media changes
  1105. if(!runs.length) {
  1106. encMediaSettings.resolve();
  1107. return;
  1108. }
  1109. var l = new vboxLoader();
  1110. l.showLoading();
  1111. (function doruns(encMediaRuns){
  1112. if(!encMediaRuns.length) {
  1113. l.removeLoading();
  1114. encMediaSettings.resolve();
  1115. return;
  1116. }
  1117. var run = encMediaRuns.shift();
  1118. // If encryption is enabled, and cypher is blank / "Leave Unchanged"
  1119. // keep the original cipher
  1120. var mcipher = formCipher;
  1121. if(formEncEnabled && !mcipher) {
  1122. mcipher = run.cipher;
  1123. }
  1124. var rdata = {
  1125. medium: run.medium,
  1126. id: run.encId,
  1127. old_password: run.password,
  1128. cipher: mcipher,
  1129. password: formPassword
  1130. };
  1131. $.when(vboxAjaxRequest('mediumChangeEncryption',rdata)).done(function(d){
  1132. if(d.responseData.progress) {
  1133. var icon = 'progress_media_create_90px.png';
  1134. var title = trans('Encryption');
  1135. vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(){
  1136. // Loop
  1137. doruns(encMediaRuns);
  1138. },icon,title,vboxMedia.getMediumById(run.medium).name, true);
  1139. } else {
  1140. l.removeLoading();
  1141. encMediaSettings.reject();
  1142. return;
  1143. }
  1144. });
  1145. })(runs);
  1146. })
  1147. .fail(function() {
  1148. encMediaSettings.reject();
  1149. });
  1150. return encMediaSettings.promise();
  1151. }
  1152. $.when(vboxSettingsDialog(vmData.name + ' - ' + trans('Settings','UISettingsDialog'),panes,dataList,pane,'vm_settings','UISettingsDialogMachine', presaveCallback))
  1153. // Always run this
  1154. .always(function(){
  1155. // No longer watch for changed VM settings
  1156. $('#vboxPane').unbind('vboxEvents',machineSettingsChanged);
  1157. })
  1158. // Run this when "Save" is clicked
  1159. .done(function() {
  1160. var loader = new vboxLoader();
  1161. var sdata = $.extend($('#vboxSettingsDialog').data('vboxMachineData'),{'clientConfig':$('#vboxPane').data('vboxConfig')});
  1162. loader.add('machineSave',function(){return;},sdata);
  1163. loader.onLoad = function() {
  1164. // Refresh media
  1165. var mload = new vboxLoader();
  1166. mload.add('vboxGetMedia',function(d){$('#vboxPane').data('vboxMedia',d.responseData);});
  1167. mload.onLoad = function() {
  1168. results.resolve();
  1169. };
  1170. mload.run();
  1171. };
  1172. loader.run();
  1173. });
  1174. });
  1175. return results.promise();
  1176. }
  1177. /**
  1178. * Run the "First Run" wizard
  1179. * @param {Object} vm - VM details object
  1180. */
  1181. function vboxWizardFirstRunDialog(vm) {
  1182. // ref
  1183. var self = this;
  1184. this.parentClass = vboxWizard;
  1185. this.parentClass();
  1186. this.name = 'wizardFirstRun';
  1187. this.title = $('<div />').text(vm.name).html();
  1188. this.bg = 'images/vbox/vmw_first_run_bg.png';
  1189. this.icon = vboxGuestOSTypeIcon(vm.OSTypeId);
  1190. this.steps = 1;
  1191. this.finishText = trans('Start','UIWizardFirstRun');
  1192. this.context = 'UIWizardFirstRun';
  1193. this.noAdvanced = true;
  1194. this.args = vm;
  1195. // This still resolves on cancel
  1196. this.onCancel = function () {
  1197. self.completed.resolve();
  1198. };
  1199. this.onFinish = function() {
  1200. var med = vboxMedia.getMediumById($('#wizardFirstRunMedia').find(":selected").attr('value'));
  1201. $(self.dialog).empty().remove();
  1202. if(med) {
  1203. var port = null;
  1204. var device = null;
  1205. var bus = null;
  1206. var controller = null;
  1207. for(var i = 0; i < self.args.storageControllers.length; i++) {
  1208. for(var a = 0; a < self.args.storageControllers[i].mediumAttachments.length; a++) {
  1209. if(self.args.storageControllers[i].mediumAttachments[a].type == "DVD" &&
  1210. self.args.storageControllers[i].mediumAttachments[a].medium == null) {
  1211. port = self.args.storageControllers[i].mediumAttachments[a].port;
  1212. device = self.args.storageControllers[i].mediumAttachments[a].device;
  1213. bus = self.args.storageControllers[i].bus;
  1214. controller = self.args.storageControllers[i].name;
  1215. break;
  1216. }
  1217. }
  1218. }
  1219. var args = {'vm':self.args.id,
  1220. 'medium':med,
  1221. 'port':port,
  1222. 'device':device,
  1223. 'bus':bus,
  1224. 'controller':controller,
  1225. 'noSave':true
  1226. };
  1227. // Ajax request to mount medium
  1228. var mount = new vboxLoader();
  1229. mount.add('mediumMount',function(ret){
  1230. var l = new vboxLoader();
  1231. l.add('vboxGetMedia',function(d){$('#vboxPane').data('vboxMedia',d.responseData);});
  1232. l.onLoad = function(){
  1233. self.completed.resolve();
  1234. };
  1235. l.run();
  1236. },args);
  1237. mount.run();
  1238. } else {
  1239. self.completed.resolve();
  1240. }
  1241. };
  1242. }
  1243. /**
  1244. * Display a settings dialog (generic) called by dialog initializers
  1245. * @param {String} title - title of dialog
  1246. * @param {Array} panes - list of panes {Object} to load
  1247. * @param {Object} data - list of data to load
  1248. * @param {String} pane - optionally automatically select pane when dialog is shown
  1249. * @param {String} icon - optional URL to icon for dialog
  1250. * @param {String} langContext - language context to use for translations
  1251. * @param {Function} presave - presave callback to run
  1252. * @returns {Object} deferred promise
  1253. * @see trans()
  1254. */
  1255. function vboxSettingsDialog(title,panes,data,pane,icon,langContext,presave) {
  1256. var results = $.Deferred();
  1257. var d = $('<div />').attr({'id':'vboxSettingsDialog','style':'display: none;'});
  1258. var f = $('<form />').attr({'name':'frmVboxSettings','style':'height: 100%'});
  1259. var t = $('<table />').attr({'style':'height: 100%;','class':'vboxSettingsTable'});
  1260. var tr = $('<tr />');
  1261. $($('<td />').attr({'id':'vboxSettingsMenu','style': (panes.length == 1 ? 'display:none;' : '')})).append($('<ul />').attr({'id':'vboxSettingsMenuList','class':'vboxHover'})).appendTo(tr);
  1262. var td = $('<td />').attr({'id':'vboxSettingsPane'}).css({'height':'100%'});
  1263. // Settings table contains title and visible settings pane
  1264. var stbl = $('<table />').css({'height':'100%','width':'100%','padding':'0px','margin':'0px','border':'0px','border-spacing':'0px'});
  1265. // Title
  1266. var d1 = $('<div />').attr({'id':'vboxSettingsTitle'}).html('Padding').css({'display':(panes.length == 1 ? 'none' : '')});
  1267. $(stbl).append($('<tr />').append($('<td />').css({'height':'1%','padding':'0px','margin':'0px','border':'0px'}).append(d1)));
  1268. // Settings pane
  1269. var d1 = $('<div />').attr({'id':'vboxSettingsList'}).css({'width':'100%'});
  1270. $(stbl).append($('<tr />').append($('<td />').css({'padding':'0px','margin':'0px','border':'0px'}).append(d1)));
  1271. $(td).append(stbl).appendTo(tr);
  1272. $(d).append($(f).append($(t).append(tr))).appendTo('#vboxPane');
  1273. /* Load panes and data */
  1274. var loader = new vboxLoader();
  1275. /* Load Data */
  1276. for(var i = 0; i < data.length; i++) {
  1277. loader.add(data[i].fn,data[i].callback,(data[i].args ? data[i].args : undefined));
  1278. }
  1279. /* Load settings panes */
  1280. for(var i = 0; i < panes.length; i++) {
  1281. if(panes[i].disabled) continue;
  1282. // Menu item
  1283. $('<li />').html('<div><img src="images/vbox/'+panes[i].icon+'_16px.png" /></div> <div>'+trans(panes[i].label,langContext)+'</div>').data(panes[i]).click(function(){
  1284. $('#vboxSettingsTitle').html(trans($(this).data('label'),langContext));
  1285. $(this).addClass('vboxListItemSelected').siblings().addClass('vboxListItem').removeClass('vboxListItemSelected');
  1286. // jquery apply this css to everything with class .settingsPa..
  1287. $('#vboxSettingsDialog .vboxSettingsPaneSection').css({'display':'none'});
  1288. // Show selected pane
  1289. $('#vboxSettingsPane-' + $(this).data('name')).css({'display':''}).children().first().trigger('show');
  1290. }).on("mouseenter",function(){$(this).addClass('vboxHover');}).on("mouseleave",function(){$(this).removeClass('vboxHover');}).appendTo($('#vboxSettingsMenuList'));
  1291. // Settings pane
  1292. $('#vboxSettingsList').append($('<div />').attr({'id':'vboxSettingsPane-'+panes[i].name,'style':'display: none;','class':'vboxSettingsPaneSection ui-corner-all ' + (panes[i].tabbed ? 'vboxTabbed' : 'vboxNonTabbed')}));
  1293. loader.addFileToDOM('panes/settings'+panes[i].name+'.html',$('#vboxSettingsPane-'+panes[i].name));
  1294. }
  1295. loader.onLoad = function(){
  1296. /* Init UI Items */
  1297. for(var i = 0; i < panes.length; i++) {
  1298. vboxInitDisplay($('#vboxSettingsPane-'+panes[i].name),panes[i].context);
  1299. if(panes[i].tabbed) $('#vboxSettingsPane-'+panes[i].name).tabs();
  1300. }
  1301. /* Tell dialog that data is loaded */
  1302. $('#vboxSettingsDialog').trigger('dataLoaded');
  1303. var buttons = { };
  1304. buttons[trans('OK','QIMessageBox')] = function() {
  1305. $(this).trigger('save');
  1306. // Does some settings pane need to do some presave
  1307. // work? (ask questions, run wizard, some other asynch task)
  1308. var promise = true;
  1309. if(presave) {
  1310. promise = presave();
  1311. }
  1312. var dlg = this;
  1313. $.when(promise).done(function() {
  1314. results.resolve(true);
  1315. $(dlg).trigger('close').empty().remove();
  1316. $(document).trigger('click');
  1317. });
  1318. };
  1319. buttons[trans('Cancel','QIMessageBox')] = function() {
  1320. results.reject();
  1321. $(this).trigger('close').empty().remove();
  1322. $(document).trigger('click');
  1323. };
  1324. // Init with "nothing has changed yet"
  1325. $('#vboxSettingsDialog').data('formDataChanged', false);
  1326. // Show dialog
  1327. $('#vboxSettingsDialog').dialog({'closeOnEscape':true,'width':(panes.length > 1 ? 900 : 600),'height':(panes.length > 1 ? 500 : 450),'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxSettingsDialog vboxDialogContent','title':(icon ? '<img src="images/vbox/'+icon+'_16px.png" class="vboxDialogTitleIcon" /> ' : '') + title}).on("dialogbeforeclose",function(){
  1328. $(this).parent().find('span:contains("'+trans('Cancel','QIMessageBox')+'")').trigger('click');
  1329. });
  1330. // Resize pane
  1331. $('#vboxSettingsList').height($('#vboxSettingsList').parent().innerHeight()-8).css({'overflow':'auto','padding':'0px','margin-top':'8px','border':'0px','border-spacing':'0px'});
  1332. // Resizing dialog, resizes this too
  1333. $('#vboxSettingsDialog').on('dialogresizestop',function(){
  1334. var h = $('#vboxSettingsList').css({'display':'none'}).parent().innerHeight();
  1335. $('#vboxSettingsList').height(h-8).css({'display':''});
  1336. });
  1337. /* Select first or passed menu item */
  1338. var i = 0;
  1339. var offset = 0;
  1340. var tab = undefined;
  1341. if(typeof pane == "string") {
  1342. var section = pane.split(':');
  1343. if(section[1]) tab = section[1];
  1344. for(i = 0; i < panes.length; i++) {
  1345. if(panes[i].disabled) offset++;
  1346. if(panes[i].name == section[0]) break;
  1347. }
  1348. }
  1349. i-=offset;
  1350. if(i >= panes.length) i = 0;
  1351. $('#vboxSettingsMenuList').children('li:eq('+i+')').first().click().each(function(){
  1352. if(tab !== undefined) {
  1353. // Check for out of scope tab
  1354. tab = Math.min(($('#vboxSettingsPane-'+$(this).data('name')).children('ul').first().children().length-1), parseInt(tab));
  1355. $('#vboxSettingsPane-'+$(this).data('name')).tabs('option','active', tab);
  1356. }
  1357. });
  1358. /* Only 1 pane? */
  1359. if(panes.length == 1) {
  1360. $('#vboxSettingsDialog table.vboxSettingsTable').css('width','100%');
  1361. $('#vboxSettingsDialog').dialog('option','title',(icon ? '<img src="images/vbox/'+icon+'_16px.png" class="vboxDialogTitleIcon" /> ' : '') + trans(panes[0].label,langContext));
  1362. }
  1363. };
  1364. loader.run();
  1365. return results.promise();
  1366. }