/**
* @fileOverview Dialog logic for various wizards and other dialogs
* @author Ian Moore (imoore76 at yahoo dot com)
* @version $Id: dialogs.js 599 2015-07-27 10:40:37Z imoore76 $
* @copyright Copyright (C) 2010-2015 Ian Moore (imoore76 at yahoo dot com)
*/
/**
* Run the import appliance wizard
*/
function vboxWizardImportApplianceDialog() {
// reference
var self = this;
// Extend vboxWizard
this.parentClass = vboxWizard;
this.parentClass();
/* Common settings */
this.name = 'wizardImportAppliance';
this.title = trans('Import Virtual Appliance','UIWizardImportApp');
this.bg = 'images/vbox/vmw_ovf_import_bg.png';
this.icon = 'import';
this.steps = 2;
this.height = 500;
this.finishText = trans('Import','UIWizardImportApp');
this.context = 'UIWizardImportApp';
/* Restore defaults is added to last step */
this.stepButtons = [
{
'name' : trans('Restore Defaults','UIWizardImportApp'),
'steps' : [-1],
'click' : function() {
wizardImportApplianceParsed();
}
}
];
/* Data to be loaded */
this.data = [
{'fn':'vboxGetEnumerationMap','args':{'class':'NetworkAdapterType'},'callback':function(d){$('#vboxPane').data('vboxNetworkAdapterTypes',d.responseData);}},
{'fn':'vboxGetEnumerationMap','args':{'class':'AudioControllerType'},'callback':function(d){$('#vboxPane').data('vboxAudioControllerTypes',d.responseData);}},
];
/* Perform action on finish */
this.onFinish = function() {
var file = $(self.form).find('[name=wizardImportApplianceLocation]').val();
var descriptions = $('#vboxImportProps').data('descriptions');
var reinitNetwork = $(self.form).find('[name=vboxImportReinitNetwork]').prop('checked');
// Check for descriptions
if(!descriptions) {
return;
}
/** Call Appliance import AJAX function */
var vboxImportApp = function() {
$(self.dialog).empty().remove();
var l = new vboxLoader();
l.add('applianceImport',function(d){
if(d.responseData.progress) {
vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(){
// Imported media must be refreshed
var ml = new vboxLoader();
ml.add('vboxGetMedia',function(d){$('#vboxPane').data('vboxMedia',d.responseData);});
ml.onLoad = function(){
self.completed.resolve();
};
ml.run();
},'progress_import_90px.png',trans('Import an appliance into VirtualBox','UIActionPool').replace(/\.+$/g,''),vboxBasename(file));
} else {
self.completed.reject();
}
},{'descriptions':descriptions,'file':file,'reinitNetwork':reinitNetwork});
l.run();
};
// license agreements
var licenses = [];
// Step through each VM and obtain value
for(var a = 0; a < descriptions.length; a++) {
var children = $('#vboxImportProps').children('tr.vboxChildOf'+a);
descriptions[a][5] = []; // enabled / disabled
var lic = null;
var vmname = null;
for(var b = 0; b < children.length; b++) {
descriptions[a][5][b] = !$(children[b]).data('propdisabled');
descriptions[a][3][$(children[b]).data('descOrder')] = $(children[b]).children('td:eq(1)').data('descValue');
// check for license
if(descriptions[a][0][b] == 'License') {
lic = descriptions[a][2][b];
} else if(descriptions[a][0][b] == 'Name') {
vmname = descriptions[a][2][b];
}
}
if(lic) {
if(!vmname) vmname = trans('Virtual System %1','UIApplianceEditorWidget').replace('%1',a);
licenses[licenses.length] = {'name':vmname,'license':lic};
}
}
if(licenses.length) {
var msg = trans('The virtual system "%1" requires that you agree to the terms and conditions of the software license agreement shown below.
Click Agree to continue or click Disagree to cancel the import.','UIImportLicenseViewer');
var a = 0;
var buttons = {};
buttons[trans('Agree','UIImportLicenseViewer')] = function() {
a++;
if(a >= licenses.length) {
$(this).remove();
vboxImportApp();
return;
}
$(this).dialog('close');
$('#vboxImportWizLicTitle').html(msg.replace('%1',licenses[a]['name']));
$('#vboxImportWizLicContent').val(licenses[a]['license']);
$(this).dialog('open');
};
buttons[trans('Disagree','UIImportLicenseViewer')] = function() {
$(this).empty().remove();
};
var dlg = $('
Cannot create the machine folder %1 in the parent folder
This folder already exists and possibly belongs to another machine.
','UIMessageCenter').replace('%1',vboxBasename(res.exists)).replace('%2',vboxDirname(res.exists))); } else if(res.success) { $(self.dialog).empty().remove(); var lm = new vboxLoader('machineCreate'); lm.add('vboxGetMedia',function(d){$('#vboxPane').data('vboxMedia',d.responseData);}); lm.onLoad = function() { self.completed.resolve(); }; lm.run(); } else { self.completed.reject(); } }); }; // Name must exist if(!jQuery.trim($(self.form).find('[name=newVMName]').val())) { $(self.form).find('[name=newVMName]').addClass('vboxRequired'); return; } $(self.form).find('[name=newVMName]').removeClass('vboxRequired'); // Make sure file does not exist var fnl = new vboxLoader(); fnl.add('vboxGetComposedMachineFilename',function(d){ loc = vboxDirname(d.responseData); var fileExists = false; var fe = new vboxLoader('fileExists'); fe.add('fileExists',function(d){ fileExists = d.responseData; },{'file':loc}); fe.onLoad = function() { if(fileExists) { vboxAlert(trans('Cannot create the machine folder %1 in the parent folder
This folder already exists and possibly belongs to another machine.
','UIMessageCenter').replace('%1',vboxBasename(loc)).replace('%2',vboxDirname(loc))); // Go back self.displayStep(1); return; } // Start new harddisk wizard if create new is selected if($(self.form).find('[name=newVMDisk]:checked').val() == 'create') { // Recommended size var size = newVMOSTypesObj[$(self.form).find('[name=newVMOSType]').val()].recommendedHDD; $.when(new vboxWizardNewHDDialog({'name':jQuery.trim($(self.form).find('[name=newVMName]').val()),'size':size,'group':vmgroup}).run()) .done(function(med){ $(self.form).find('[name=newVMDisk]').eq(2).trigger('click').prop('checked',true); // Add newly created disk as option and select it vmNewFillExistingDisks(med); vboxNewVMFinish(); }); return; } else if($(self.form).find('[name=newVMDisk]:checked').val() == 'none') { buttons = {}; buttons[trans('Continue','UIMessageCenter')] = function(){ $(this).empty().remove(); vboxNewVMFinish(); }; 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')); return; } vboxNewVMFinish(); }; fe.run(); },{'name':document.forms['frmwizardNewVM'].newVMName.value, 'group':vmgroup}); fnl.run(); }; } /** * Run the Clone Virtual Machine Wizard * @param {Object} args - wizard data - args.vm and args.snapshot should be populated * @returns {Object} deferred promise * @see vboxWizard() */ function vboxWizardCloneVMDialog(args) { // self reference var self = this; // Extend vboxWizard class this.parentClass = vboxWizard; this.parentClass(); /* Common options */ this.name = 'wizardCloneVM'; this.title = trans('Clone Virtual Machine','UIWizardCloneVM'); this.bg = 'images/vbox/vmw_clone_bg.png'; this.icon = 'vm_clone'; this.finishText = trans('Clone','UIWizardCloneVM'); this.context = 'UIWizardCloneVM'; this.widthAdvanced = 450; this.heightAdvanced = 350; /* Override run() because we need VM data */ this.parentRun = this.run; this.run = function() { var l = new vboxLoader('vboxWizardCloneVMInit'); l.showLoading(); $.when(vboxVMDataMediator.getVMDetails(args.vm.id)).always(function() { // Always remove loading screen l.removeLoading(); }).done(function(d){ self.steps = (d.snapshotCount > 0 ? 3 : 2); self.args = $.extend(true,args,{'vm':d}); self.parentRun(); }); return self.completed.promise(); }; /* Function to run when finished */ this.onFinish = function() { // Get parameters var name = jQuery.trim($(self.form).find('[name=machineCloneName]').val()); var src = self.args.vm.id; var snapshot = self.args.snapshot; var allNetcards = $(self.form).find('[name=vboxCloneReinitNetwork]').prop('checked'); if(!name) { $(self.form).find('[name=machineCloneName]').addClass('vboxRequired'); return; } // Only two steps? We can assume that state has no child states. // Force current state only var vmState = 'MachineState'; if(self.steps > 2 || self.mode == 'advanced') { vmState = $(self.form).find('[name=vmState]:checked').val(); } // Full / linked clone var cLink = $(self.form).find('[name=vboxCloneType]').eq(1).prop('checked'); // wrap function var vbClone = function(sn) { $.when(vboxAjaxRequest('machineClone', {'name':name,'vmState':vmState,'src':src,'snapshot':sn,'reinitNetwork':allNetcards,'link':cLink})) .done(function(d){ if(d.responseData.progress) { var registerVM = d.responseData.settingsFilePath; vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(ret) { $.when(vboxAjaxRequest('machineAdd',{'file':registerVM})).done(function(){ $.when(vboxAjaxRequest('vboxGetMedia')).done(function(dat){ $('#vboxPane').data('vboxMedia',dat.responseData); self.completed.resolve(); }).fail(function(){ self.completed.reject(); }); }).fail(function(){ self.completed.reject(); }); },'progress_clone_90px.png',trans('Clone selected virtual machine','UIActionPool'), self.args.vm.name + ' > ' + name); } else { self.completed.reject(); } }).fail(function(){ self.completed.reject(); }); }; // Check for linked clone, but not a snapshot if(cLink && !self.args.snapshot) { $.when(vboxAjaxRequest('snapshotTake', {'vm':src,'name':trans('Linked Base for %1 and %2','UIWizardCloneVM').replace('%1',self.args.vm.name).replace('%2',name),'description':''})) .done(function(d){ if(d.responseData.progress) { vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(){ $.when(vboxVMDataMediator.getVMDetails(src, true)).done(function(md){ vbClone(md.currentSnapshot); }); }, 'progress_snapshot_create_90px.png', trans('Take a snapshot of the current virtual machine state','UIActionPool'), self.args.vm.name); } else if(d && d.error) { self.completed.reject(); vboxAlert(d.error); } }).fail(function(){ self.completed.reject(); }); // Just clone } else { vbClone(snapshot); } $(self.dialog).empty().remove(); }; } /** * Run the VM Log Viewer dialog * @param {String} vm - uuid or name of virtual machine to obtain logs for */ function vboxShowLogsDialogInit(vm) { $('#vboxPane').append($('').attr({'id':'vboxVMLogsDialog'})); var l = new vboxLoader(); l.add('machineGetLogFilesList',function(r){ $('#vboxVMLogsDialog').data({'logs':r.responseData.logs,'logpath':r.responseData.path}); },{'vm':vm.id}); l.addFileToDOM('panes/vmlogs.html',$('#vboxVMLogsDialog')); l.onLoad = function(){ var buttons = {}; buttons[trans('Refresh','UIVMLogViewer')] = function() { l = new vboxLoader(); l.add('machineGetLogFilesList',function(r){ $('#vboxVMLogsDialog').data({'logs':r.responseData.logs,'logpath':r.responseData.path}); },{'vm':vm.id}); l.onLoad = function(){ vboxShowLogsInit(vm); }; l.run(); }; buttons[trans('Close','UIVMLogViewer')] = function(){$(this).trigger('close').empty().remove();}; $('#vboxVMLogsDialog').dialog({'closeOnEscape':true,'width':800,'height':500,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent','title':'The hard disk storage unit at location %1 already " + "exists. You cannot create a new virtual hard disk that uses this " + "location because it can be already used by another virtual hard " + "disk.
" + "Please specify a different location.
",'UIMessageCenter').replace('%1',file)); return; } var fsplit = $(self.form).find('[name=newHardDiskSplit]').prop('checked'); var size = vboxConvertMbytes($(self.form).find('[name=wizardNewHDSizeValue]').val()); var type = ($(self.form).find('[name=newHardDiskType]').eq(1).prop('checked') ? 'fixed' : 'dynamic'); var nl = new vboxLoader('mediumCreateBaseStorage'); nl.add('mediumCreateBaseStorage',function(d){ if(d.responseData.progress) { vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(ret) { var ml = new vboxLoader(); ml.add('vboxGetMedia',function(dat){$('#vboxPane').data('vboxMedia',dat.responseData);}); ml.onLoad = function() { var med = vboxMedia.getMediumByLocation(file); if(med) { vboxMedia.updateRecent(med); self.completed.resolve(med.id); } else { self.completed.reject(); } }; ml.run(); },'progress_media_create_90px.png',trans('Create a virtual hard disk now','UIWizardNewVM'), vboxBasename(file),true); } else { self.completed.reject(); } },{'file':file,'type':type,'size':size,'format':format,'split':fsplit}); nl.run(); $(self.dialog).empty().remove(); }; l.run(); }; } /** * Run the Copy Virtual Disk wizard * @param {Object} suggested - sugggested defaults such as hard disk name and path */ function vboxWizardCopyHDDialog(suggested) { // reference var self = this; /* Extend vboxWizard class */ this.parentClass = vboxWizard; this.parentClass(); /* Common options */ this.name = 'wizardCopyHD'; this.title = trans('Copy Virtual Hard Disk','UIWizardCloneVD'); this.bg = 'images/vbox/vmw_new_harddisk_bg.png'; this.icon = 'hd'; this.steps = 4; this.suggested = suggested; this.context = 'UIWizardCloneVD'; this.finishText = trans('Copy','UIWizardCloneVD'); this.height = 450; this.data = [ {'fn':'vboxSystemPropertiesGet','callback':function(d){$('#vboxPane').data('vboxSystemProperties',d.responseData);}}, {'fn':'vboxGetMedia','callback':function(d){$('#vboxPane').data('vboxMedia',d.responseData);}} ]; /* Function run when wizard completes */ this.onFinish = function() { var format = $(self.form)[0].elements['copyHDFileType']; var formatOpts = {}; for(var i = 0; i < format.length; i++) { if(format[i].checked) { formatOpts = $(format[i]).closest('tr').data('vboxFormat'); break; } } var src = $(self.form).find('[name=copyHDDiskSelect]').val(); var type = ($(self.form).find('[name=newHardDiskType]').eq(1).prop('checked') ? 'fixed' : 'dynamic'); var format = $(self.form)[0].elements['copyHDFileType']; for(var i = 0; i < format.length; i++) { if(format[i].checked) { format=format[i].value; break; } } var fsplit = $(self.form).find('[name=newHardDiskSplit]').prop('checked') && vboxMedia.formatSupportsSplit(format); var loc = jQuery.trim($(self.form).find('[name=wizardCopyHDLocation]').val()); if(!loc) { $(self.form).find('[name=wizardCopyHDLocation]').addClass('vboxRequired'); return; } $(self.form).find('[name=wizardCopyHDLocation]').removeClass('vboxRequired'); if(loc.search(/[\/|\\]/) < 0) { if($('#wizardCopyHDStep4').data('suggestedpath')) { loc = $('#wizardCopyHDStep4').data('suggestedpath') + loc; } else { loc = vboxDirname(vboxMedia.getMediumById(src).location) + $('#vboxPane').data('vboxConfig').DSEP + loc; } } // append ext? if(jQuery.inArray(loc.substring(loc.lastIndexOf('.')+1).toLowerCase(),formatOpts.extensions) < 0) { loc += '.'+formatOpts.extensions[0]; } /* Check to see if file exists */ var fileExists = false; var fe = new vboxLoader(); fe.add('fileExists',function(d){ fileExists = d.responseData; },{'file':loc}); fe.onLoad = function() { if(fileExists) { vboxAlert(trans("The hard disk storage unit at location %1 already " + "exists. You cannot create a new virtual hard disk that uses this " + "location because it can be already used by another virtual hard " + "disk.
" + "Please specify a different location.
",'UIMessageCenter').replace('%1',loc)); return; } $(self.dialog).empty().remove(); var l = new vboxLoader(); l.add('mediumCloneTo',function(d){ if(d.responseData.progress) { vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(ret,mid) { var ml = new vboxLoader(); ml.add('vboxGetMedia',function(dat){$('#vboxPane').data('vboxMedia',dat.responseData);}); ml.onLoad = function() { med = vboxMedia.getMediumByLocation(loc); vboxMedia.updateRecent(med); self.completed.resolve(mid); }; ml.run(); },'progress_media_create_90px.png',trans('Copy Virtual Hard Disk','UIWizardCloneVD'), vboxBasename(vboxMedia.getMediumById(src).location) + ' > ' + vboxBasename(loc)); } else { self.completed.reject(); } },{'src':vboxMedia.getMediumById(src).location,'type':type,'format':format,'location':loc,'split':fsplit}); l.run(); }; fe.run(); }; } /** * Display guest network adapters dialog * @param {String} vm - virtual machine uuid or name */ function vboxGuestNetworkAdaptersDialogInit(vm) { /* * Dialog */ $('#vboxPane').append($('').attr({'id':'vboxGuestNetworkDialog','style':'display: none'})); /* * Loader */ var l = new vboxLoader(); l.addFileToDOM('panes/guestNetAdapters.html',$('#vboxGuestNetworkDialog')); l.onLoad = function(){ var buttons = {}; buttons[trans('Close','UIVMLogViewer')] = function() {$('#vboxGuestNetworkDialog').trigger('close').empty().remove();}; $('#vboxGuestNetworkDialog').dialog({'closeOnEscape':true,'width':500,'height':250,'buttons':buttons,'modal':true,'autoOpen':true,'dialogClass':'vboxDialogContent','title':'The machine settings were changed while you were editing them. You currently have unsaved setting changes.
Would you like to reload the changed settings or to keep your own changes?
",'UIMessageCenter'), buttons, trans('Keep changes', 'UIMessageCenter'), function(){ reloadConfirmShowing = false; }); return; } } }; // Watch for changed VM settings $('#vboxPane').on('vboxEvents',machineSettingsChanged); $.when(vboxVMDataMediator.getVMDataCombined(vm.id)).done(function(vmData) { /* * Settings dialog data */ var dataList = new Array( {'fn':'vboxGetMedia','callback':function(d){ $('#vboxPane').data('vboxMedia',d.responseData); // data received from deferred object $('#vboxSettingsDialog').data('vboxMachineData',vmData); $('#vboxSettingsDialog').data('vboxFullEdit', (vboxVMStates.isPoweredOff(vmData) && !vboxVMStates.isSaved(vmData))); }}, {'fn':'getNetworking','callback':function(d){$('#vboxSettingsDialog').data('vboxNetworking',d.responseData);}}, {'fn':'hostGetDetails','callback':function(d){$('#vboxSettingsDialog').data('vboxHostDetails',d.responseData);}}, {'fn':'vboxGetEnumerationMap','callback':function(d){$('#vboxSettingsDialog').data('vboxNetworkAdapterTypes',d.responseData);},'args':{'class':'NetworkAdapterType'}}, {'fn':'vboxGetEnumerationMap','callback':function(d){$('#vboxSettingsDialog').data('vboxAudioControllerTypes',d.responseData);},'args':{'class':'AudioControllerType'}}, {'fn':'vboxRecentMediaGet','callback':function(d){$('#vboxPane').data('vboxRecentMedia',d.responseData);}}, {'fn':'consoleGetSharedFolders','callback':function(d){$('#vboxSettingsDialog').data('vboxTransientSharedFolders',d.responseData);},'args':{'vm':vm.id}} ); /* * Settings dialog panes */ var panes = new Array( {name:'General',label:'General',icon:'machine',tabbed:true,context:'UIMachineSettingsGeneral'}, {name:'System',label:'System',icon:'chipset',tabbed:true,context:'UIMachineSettingsSystem'}, {name:'Display',label:'Display',icon:'vrdp',tabbed:true,context:'UIMachineSettingsDisplay'}, {name:'Storage',label:'Storage',icon:'attachment',context:'UIMachineSettingsStorage'}, {name:'Audio',label:'Audio',icon:'sound',context:'UIMachineSettingsAudio'}, {name:'Network',label:'Network',icon:'nw',tabbed:true,context:'UIMachineSettingsNetwork'}, {name:'SerialPorts',label:'Serial Ports',icon:'serial_port',tabbed:true,context:'UIMachineSettingsSerial'}, {name:'ParallelPorts',label:'Parallel Ports',icon:'parallel_port',tabbed:true,disabled:(!$('#vboxPane').data('vboxConfig').enableLPTConfig),context:'UIMachineSettingsParallel'}, {name:'USB',label:'USB',icon:'usb',context:'UIMachineSettingsUSB'}, {name:'SharedFolders',label:'Shared Folders',icon:'sf',context:'UIMachineSettingsSF'} ); /* * Check for encryption settings change */ var presaveCallback = function() { if(!$('#vboxSettingsDialog').data('vboxEncSettingsChanged')) return true; var encMediaSettings = $.Deferred(); // Validate if(!vboxSettingsGeneralValidate()) { $('#vboxSettingsMenuList').children('li:eq(0)').first().click(); $('#vboxSettingsPane-General').tabs('option','active', 3); encMediaSettings.reject(); return encMediaSettings; } var vm = $('#vboxSettingsDialog').data('vboxMachineData'); var media = vboxStorage.getAttachedBaseMedia(vm); var encIds = vboxMedia.getEncryptedMediaIds(media); var encMedia = vboxMedia.getEncryptedMedia(media); var formCipher = $('#vboxSettingsDialog').data('vboxEncCipher'); var formPassword = $('#vboxSettingsDialog').data('vboxEncPw'); var formEncEnabled = $('#vboxSettingsDialog').data('vboxEncEnabled'); // If encryption is not enabled, cipher needs to be blank if(!formEncEnabled) { formCipher = ''; } // Get encryption password(s) $.when(vboxMediumEncryptionPasswordsDialog(vm.name, encIds)) .done(function(pwdata) { var runs = [] // Each medium attached for(var i = 0; i < media.length; i++) { // Only hard disks if(media[i].deviceType != 'HardDisk') continue; var id = vm.name; var oldpw = ""; var cipher = null; // Check for existing encryption setting for(var a = 0; a < encMedia.length; a++) { if(encMedia[a].medium == media[i].id) { cipher = media[i].encryptionSettings.cipher; // Look in passwords for id for(var b = 0; b < pwdata.length; b++) { if(pwdata[b].id == id) { oldpw = pwdata[b].password; break; } } break; } } runs.push({ medium: media[i].id, cipher: cipher, encId: id, password: oldpw }); } // No encrypted media changes if(!runs.length) { encMediaSettings.resolve(); return; } var l = new vboxLoader(); l.showLoading(); (function doruns(encMediaRuns){ if(!encMediaRuns.length) { l.removeLoading(); encMediaSettings.resolve(); return; } var run = encMediaRuns.shift(); // If encryption is enabled, and cypher is blank / "Leave Unchanged" // keep the original cipher var mcipher = formCipher; if(formEncEnabled && !mcipher) { mcipher = run.cipher; } var rdata = { medium: run.medium, id: run.encId, old_password: run.password, cipher: mcipher, password: formPassword }; $.when(vboxAjaxRequest('mediumChangeEncryption',rdata)).done(function(d){ if(d.responseData.progress) { var icon = 'progress_media_create_90px.png'; var title = trans('Encryption'); vboxProgress({'progress':d.responseData.progress,'persist':d.persist},function(){ // Loop doruns(encMediaRuns); },icon,title,vboxMedia.getMediumById(run.medium).name, true); } else { l.removeLoading(); encMediaSettings.reject(); return; } }); })(runs); }) .fail(function() { encMediaSettings.reject(); }); return encMediaSettings.promise(); } $.when(vboxSettingsDialog(vmData.name + ' - ' + trans('Settings','UISettingsDialog'),panes,dataList,pane,'vm_settings','UISettingsDialogMachine', presaveCallback)) // Always run this .always(function(){ // No longer watch for changed VM settings $('#vboxPane').unbind('vboxEvents',machineSettingsChanged); }) // Run this when "Save" is clicked .done(function() { var loader = new vboxLoader(); var sdata = $.extend($('#vboxSettingsDialog').data('vboxMachineData'),{'clientConfig':$('#vboxPane').data('vboxConfig')}); loader.add('machineSave',function(){return;},sdata); loader.onLoad = function() { // Refresh media var mload = new vboxLoader(); mload.add('vboxGetMedia',function(d){$('#vboxPane').data('vboxMedia',d.responseData);}); mload.onLoad = function() { results.resolve(); }; mload.run(); }; loader.run(); }); }); return results.promise(); } /** * Run the "First Run" wizard * @param {Object} vm - VM details object */ function vboxWizardFirstRunDialog(vm) { // ref var self = this; this.parentClass = vboxWizard; this.parentClass(); this.name = 'wizardFirstRun'; this.title = $('').text(vm.name).html(); this.bg = 'images/vbox/vmw_first_run_bg.png'; this.icon = vboxGuestOSTypeIcon(vm.OSTypeId); this.steps = 1; this.finishText = trans('Start','UIWizardFirstRun'); this.context = 'UIWizardFirstRun'; this.noAdvanced = true; this.args = vm; // This still resolves on cancel this.onCancel = function () { self.completed.resolve(); }; this.onFinish = function() { var med = vboxMedia.getMediumById($('#wizardFirstRunMedia').find(":selected").attr('value')); $(self.dialog).empty().remove(); if(med) { var port = null; var device = null; var bus = null; var controller = null; for(var i = 0; i < self.args.storageControllers.length; i++) { for(var a = 0; a < self.args.storageControllers[i].mediumAttachments.length; a++) { if(self.args.storageControllers[i].mediumAttachments[a].type == "DVD" && self.args.storageControllers[i].mediumAttachments[a].medium == null) { port = self.args.storageControllers[i].mediumAttachments[a].port; device = self.args.storageControllers[i].mediumAttachments[a].device; bus = self.args.storageControllers[i].bus; controller = self.args.storageControllers[i].name; break; } } } var args = {'vm':self.args.id, 'medium':med, 'port':port, 'device':device, 'bus':bus, 'controller':controller, 'noSave':true }; // Ajax request to mount medium var mount = new vboxLoader(); mount.add('mediumMount',function(ret){ var l = new vboxLoader(); l.add('vboxGetMedia',function(d){$('#vboxPane').data('vboxMedia',d.responseData);}); l.onLoad = function(){ self.completed.resolve(); }; l.run(); },args); mount.run(); } else { self.completed.resolve(); } }; } /** * Display a settings dialog (generic) called by dialog initializers * @param {String} title - title of dialog * @param {Array} panes - list of panes {Object} to load * @param {Object} data - list of data to load * @param {String} pane - optionally automatically select pane when dialog is shown * @param {String} icon - optional URL to icon for dialog * @param {String} langContext - language context to use for translations * @param {Function} presave - presave callback to run * @returns {Object} deferred promise * @see trans() */ function vboxSettingsDialog(title,panes,data,pane,icon,langContext,presave) { var results = $.Deferred(); var d = $('').attr({'id':'vboxSettingsDialog','style':'display: none;'}); var f = $('').attr({'name':'frmVboxSettings','style':'height: 100%'}); var t = $('