package/ui/phpvirtualbox/js/dialogs.js
/**
 * Run the New Virtual Machine Wizard
 * @param {String} vmgroup - VM group to add machine to
 */
Run the New Virtual Machine Wizard
@param {String} vmgroup - VM group to add machine to
Run the New Virtual Machine Wizard @param { String } vmgroup - VM group to add machine to
function vboxWizardNewVMDialog(vmgroup) {
	var self = this;
	this.parentClass = vboxWizard;
	this.parentClass();
	this.name = 'wizardNewVM';
	this.bg = 'images/vbox/vmw_new_welcome_bg.png';
	this.title = trans('Create Virtual Machine','UIWizardNewVM');
	this.icon = 'vm_new';
	this.steps = 3;
	this.vmgroup = vmgroup;
	this.context = 'UIWizardNewVM';
	this.finishText = trans('Create','UIWizardNewVM');
	this.data = [
	   {'fn':'vboxGetMedia','callback':function(d){$('#vboxPane').data('vboxMedia',d.responseData);}}
	];
	this.onFinish = function() {
		var vboxNewVMFinish = function() {
			var disk = '';
			if($(self.form).find('[name=newVMDisk]:checked').val() == 'existing') {
				disk = $(self.form)[0].newVMDiskSelect.options[$(self.form)[0].newVMDiskSelect.selectedIndex].value;
				disk = vboxMedia.getMediumById(disk).location;
			}
			var name = jQuery.trim($(self.form).find('[name=newVMName]').val());
			var ostype = $(self.form).find('[name=newVMOSType]').val();
			var mem = parseInt($(self.form).find('[name=wizardNewVMSizeValue]').val());
			var l = new vboxLoader('machineCreate');
			l.showLoading();
			$.when(vboxAjaxRequest('machineCreate',{'disk':disk,'ostype':ostype,'memory':mem,'name':name,'group':vmgroup}))
			.always(function() {
				l.removeLoading();
			}).done(function(res){
				if(res.responseData.exists) {
					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)));
				} 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();
				}
			});
		};
		if(!jQuery.trim($(self.form).find('[name=newVMName]').val())) {
			$(self.form).find('[name=newVMName]').addClass('vboxRequired');
			return;
		}
		$(self.form).find('[name=newVMName]').removeClass('vboxRequired');
		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('<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)));
					self.displayStep(1);
					return;
				}
				if($(self.form).find('[name=newVMDisk]:checked').val() == 'create') {
					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);
								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();
	};
}
function vboxWizardNewVMDialog ( vmgroup ) { var self = this ; this . parentClass = vboxWizard ; this . parentClass ( ) ; this . name = 'wizardNewVM' ; this . bg = 'images/vbox/vmw_new_welcome_bg.png' ; this . title = trans ( 'Create Virtual Machine' , 'UIWizardNewVM' ) ; this . icon = 'vm_new' ; this . steps = 3 ; this . vmgroup = vmgroup ; this . context = 'UIWizardNewVM' ; this . finishText = trans ( 'Create' , 'UIWizardNewVM' ) ; this . data = [ { 'fn' : 'vboxGetMedia' , 'callback' : function ( d ) { $ ( '#vboxPane' ) . data ( 'vboxMedia' , d . responseData ) ; } } ] ; this . onFinish = function ( ) { var vboxNewVMFinish = function ( ) { var disk = '' ; if ( $ ( self . form ) . find ( '[name=newVMDisk]:checked' ) . val ( ) == 'existing' ) { disk = $ ( self . form ) [ 0 ] . newVMDiskSelect . options [ $ ( self . form ) [ 0 ] . newVMDiskSelect . selectedIndex ] . value ; disk = vboxMedia . getMediumById ( disk ) . location ; } var name = jQuery . trim ( $ ( self . form ) . find ( '[name=newVMName]' ) . val ( ) ) ; var ostype = $ ( self . form ) . find ( '[name=newVMOSType]' ) . val ( ) ; var mem = parseInt ( $ ( self . form ) . find ( '[name=wizardNewVMSizeValue]' ) . val ( ) ) ; var l = new vboxLoader ( 'machineCreate' ) ; l . showLoading ( ) ; $ . when ( vboxAjaxRequest ( 'machineCreate' , { 'disk' : disk , 'ostype' : ostype , 'memory' : mem , 'name' : name , 'group' : vmgroup } ) ) . always ( function ( ) { l . removeLoading ( ) ; } ) . done ( function ( res ) { if ( res . responseData . exists ) { 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 ) ) ) ; } 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 ( ) ; } } ) ; } ; if ( ! jQuery . trim ( $ ( self . form ) . find ( '[name=newVMName]' ) . val ( ) ) ) { $ ( self . form ) . find ( '[name=newVMName]' ) . addClass ( 'vboxRequired' ) ; return ; } $ ( self . form ) . find ( '[name=newVMName]' ) . removeClass ( 'vboxRequired' ) ; 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 ( '<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 ) ) ) ; self . displayStep ( 1 ) ; return ; } if ( $ ( self . form ) . find ( '[name=newVMDisk]:checked' ) . val ( ) == 'create' ) { 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 ) ; 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 New Virtual Machine Wizard
 @param {String} vmgroup - VM group to add machine to
Run the New Virtual Machine Wizard @param { String } vmgroup - VM group to add machine to
// reference to self
 // Extend vboxWizard class
 /* Common settings */ /* Function to run when wizard completes */ // Callback to finish wizard
 // Get parameters
 // Show loading screen
 // Name must exist
 // Make sure file does not exist
 // Go back
 // Start new harddisk wizard if create new is selected
 // Recommended size
 // Add newly created disk as option and select it
