package/ui/phpvirtualbox/js/utils.js
/**
 * Update progress dialog box or progress list row with % completed
 * 
 * @param {Object} prequest - progress operation data passed to ajax call
 * @param {Object} d - data returned from progressGet AJAX call
 * @param {Boolean} modal - true if updating modal dialog
 * @see vboxconnector::progressGet()
 */
Update progress dialog box or progress list row with % completed

@param {Object} prequest - progress operation data passed to ajax call
@param {Object} d - data returned from progressGet AJAX call
@param {Boolean} modal - true if updating modal dialog
@see vboxconnector::progressGet()
Update progress dialog box or progress list row with % completed @param { Object } prequest - progress operation data passed to ajax call @param { Object } d - data returned from progressGet AJAX call @param { Boolean } modal - true if updating modal dialog @see vboxconnector :: progressGet ()
function vboxProgressUpdate(prequest,d,modal) {
	var pid = prequest.progress;
	if(!d || !d.responseData || !d.responseData['progress'] || !d.responseData['info'] || d.responseData['info']['completed'] || d.responseData['info']['canceled']) {
		if(d && d.responseData['info'] && d.responseData['info']['canceled'])
			vboxAlert(trans('Operation Canceled','phpVirtualBox'),{'width':'300px','height':'auto'});
		var callback = $("#vboxProgress"+pid).data('vboxCallback');
		$("#vboxProgressBar"+pid).progressbar({ value: 100 });
		if(modal) {
			var icon = $("#vboxProgress"+pid).data('vboxIcon');
			var title = $("#vboxProgress"+pid).data('vboxTitle');
			var target = $("#vboxProgress"+pid).data('vboxTarget');
			$("#vboxProgress"+pid).empty().remove();
			if(callback) callback(d);
			vboxProgressCreateListElement(prequest,icon,title,target);
			vboxProgressUpdate(prequest);
		} else {
			var sdate = new Date();
			$("#vboxProgressText"+pid).html(sdate.toLocaleString());
			$('#vboxProgressCancel'+pid).remove();
			if(callback) callback(d);
		}
		$("#vboxProgress"+pid).addClass('vboxProgressComplete').removeClass('vboxProgressRunning');
		$("#vboxProgress"+pid).removeData([
			'vboxCallback',
			'vboxIcon',
			'vboxTitle',
			'vboxTarget'
		]);
		if($('#vboxPane').data('vboxConfig').maxProgressList) {
			var maxList = $('#vboxPane').data('vboxConfig').maxProgressList; 
	        try {
	        	maxList = Math.max(2,parseInt(maxList));
		    } catch (e) {
		        maxList = 5;
		    }
		    if(maxList > 0) $('#vboxProgressOps').children('div.vboxProgressComplete').slice(maxList).remove();
		}
		return;
	}
	$("#vboxProgressBar"+pid).progressbar({ value: d.responseData.info.percent });
	$("#vboxProgressText"+pid).html(d.responseData.info.percent+'%'+(modal ? '<br />' : ' ') + d.responseData.info.operationDescription);
	if(d.responseData.info.cancelable) {
		$('#vboxProgressCancel'+pid).show();
	}
	var def = $.Deferred();
	def.done(function(){
		$.when(prequest, vboxAjaxRequest('progressGet', prequest, {'persist': d.persist}))
			.done((modal ? vboxProgressUpdateModal : vboxProgressUpdate));
	});
	window.setTimeout(def.resolve, 2000);
}
function vboxProgressUpdate ( prequest , d , modal ) { var pid = prequest . progress ; if ( ! d || ! d . responseData || ! d . responseData [ 'progress' ] || ! d . responseData [ 'info' ] || d . responseData [ 'info' ] [ 'completed' ] || d . responseData [ 'info' ] [ 'canceled' ] ) { if ( d && d . responseData [ 'info' ] && d . responseData [ 'info' ] [ 'canceled' ] ) vboxAlert ( trans ( 'Operation Canceled' , 'phpVirtualBox' ) , { 'width' : '300px' , 'height' : 'auto' } ) ; var callback = $ ( "#vboxProgress" + pid ) . data ( 'vboxCallback' ) ; $ ( "#vboxProgressBar" + pid ) . progressbar ( { value : 100 } ) ; if ( modal ) { var icon = $ ( "#vboxProgress" + pid ) . data ( 'vboxIcon' ) ; var title = $ ( "#vboxProgress" + pid ) . data ( 'vboxTitle' ) ; var target = $ ( "#vboxProgress" + pid ) . data ( 'vboxTarget' ) ; $ ( "#vboxProgress" + pid ) . empty ( ) . remove ( ) ; if ( callback ) callback ( d ) ; vboxProgressCreateListElement ( prequest , icon , title , target ) ; vboxProgressUpdate ( prequest ) ; } else { var sdate = new Date ( ) ; $ ( "#vboxProgressText" + pid ) . html ( sdate . toLocaleString ( ) ) ; $ ( '#vboxProgressCancel' + pid ) . remove ( ) ; if ( callback ) callback ( d ) ; } $ ( "#vboxProgress" + pid ) . addClass ( 'vboxProgressComplete' ) . removeClass ( 'vboxProgressRunning' ) ; $ ( "#vboxProgress" + pid ) . removeData ( [ 'vboxCallback' , 'vboxIcon' , 'vboxTitle' , 'vboxTarget' ] ) ; if ( $ ( '#vboxPane' ) . data ( 'vboxConfig' ) . maxProgressList ) { var maxList = $ ( '#vboxPane' ) . data ( 'vboxConfig' ) . maxProgressList ; try { maxList = Math . max ( 2 , parseInt ( maxList ) ) ; } catch ( e ) { maxList = 5 ; } if ( maxList > 0 ) $ ( '#vboxProgressOps' ) . children ( 'div.vboxProgressComplete' ) . slice ( maxList ) . remove ( ) ; } return ; } $ ( "#vboxProgressBar" + pid ) . progressbar ( { value : d . responseData . info . percent } ) ; $ ( "#vboxProgressText" + pid ) . html ( d . responseData . info . percent + '%' + ( modal ? '<br />' : ' ' ) + d . responseData . info . operationDescription ) ; if ( d . responseData . info . cancelable ) { $ ( '#vboxProgressCancel' + pid ) . show ( ) ; } var def = $ . Deferred ( ) ; def . done ( function ( ) { $ . when ( prequest , vboxAjaxRequest ( 'progressGet' , prequest , { 'persist' : d . persist } ) ) . done ( ( modal ? vboxProgressUpdateModal : vboxProgressUpdate ) ) ; } ) ; window . setTimeout ( def . resolve , 2000 ) ; }
Update progress dialog box or progress list row with % completed
Update progress dialog box or progress list row with % completed
// Shorthand
 // check for completed progress
 // Now append to list
 // Remove data
 // Check for max elements
 // update percent
 // Cancelable?
 // Get request
