package/ui/phpvirtualbox/js/dialogs.js
/**
 * Run the Copy Virtual Disk wizard
 * @param {Object} suggested - sugggested defaults such as hard disk name and path
 */
Run the Copy Virtual Disk wizard
@param {Object} suggested - sugggested defaults such as hard disk name and path
Run the Copy Virtual Disk wizard @param { Object } suggested - sugggested defaults such as hard disk name and path
function vboxWizardCopyHDDialog(suggested) {
	var self = this;
	this.parentClass = vboxWizard;
	this.parentClass();
	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);}}
	];
	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;
			}
		}
		if(jQuery.inArray(loc.substring(loc.lastIndexOf('.')+1).toLowerCase(),formatOpts.extensions) < 0) {
			loc += '.'+formatOpts.extensions[0];
		}
		var fileExists = false;
		var fe = new vboxLoader();
		fe.add('fileExists',function(d){
			fileExists = d.responseData;
		},{'file':loc});
		fe.onLoad = function() { 
			if(fileExists) {
				vboxAlert(trans("<p>The hard disk storage unit at location <b>%1</b> 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.</p>" +
				           "<p>Please specify a different location.</p>",'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();
	};
}
function vboxWizardCopyHDDialog ( suggested ) { var self = this ; this . parentClass = vboxWizard ; this . parentClass ( ) ; 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 ) ; } } ] ; 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 ; } } if ( jQuery . inArray ( loc . substring ( loc . lastIndexOf ( '.' ) + 1 ) . toLowerCase ( ) , formatOpts . extensions ) < 0 ) { loc += '.' + formatOpts . extensions [ 0 ] ; } var fileExists = false ; var fe = new vboxLoader ( ) ; fe . add ( 'fileExists' , function ( d ) { fileExists = d . responseData ; } , { 'file' : loc } ) ; fe . onLoad = function ( ) { if ( fileExists ) { vboxAlert ( trans ( "<p>The hard disk storage unit at location <b>%1</b> 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.</p>" + "<p>Please specify a different location.</p>" , '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 ( ) ; } ; }
Run the Copy Virtual Disk wizard
 @param {Object} suggested - sugggested defaults such as hard disk name and path
Run the Copy Virtual Disk wizard @param { Object } suggested - sugggested defaults such as hard disk name and path
// reference
 /* Extend vboxWizard class */ /* Common options */ /* Function run when wizard completes */ // append ext?
 /* Check to see if file exists */