parent
7e3ff5b07e
commit
f1bcb49dac
@ -1,66 +1,9 @@ |
||||
/** |
||||
* JavaScript library to deal with file uploads |
||||
* @author Yannick Warnier <yannick.warnier@dokeos.com> |
||||
*/ |
||||
/** |
||||
* Upload class. Used to pack functions into one practical object. |
||||
* Call like this: var myUpload = new upload(5); |
||||
*/ |
||||
function upload(latency){ |
||||
/** |
||||
* Starts the timer |
||||
* Call like this: |
||||
* @param string Name of the DOM element we need to update |
||||
* @param string Loading image to display |
||||
* @return true |
||||
*/ |
||||
function start(domid,img,text,formid){ |
||||
__progress_bar_domid = domid; |
||||
__progress_bar_img = img; |
||||
__progress_bar_text = text; |
||||
__progress_bar_interval = setTimeout(__display_progress_bar,latency,__progress_bar_text); |
||||
__upload_form_domid = formid; |
||||
} |
||||
|
||||
/** |
||||
* Starts the timer of the real upload progress |
||||
*/ |
||||
function startRealUpload(domid, upload_id, formid, waitAfterUpload){ |
||||
__progress_bar_domid = domid; |
||||
__progress_bar_uploadid = upload_id; |
||||
__progress_bar_waitAfterUpload = waitAfterUpload; |
||||
__upload_form_domid = formid; |
||||
__progress_bar_interval = setInterval(__refreshUpload,latency); |
||||
document.getElementById(domid+'_container').style.display = 'block'; |
||||
if(waitAfterUpload){ |
||||
document.getElementById(domid+'_waiter_container').style.display = 'block'; |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
/** |
||||
* Function called by a timer to update every x seconds the progress bar |
||||
*/ |
||||
function __refreshUpload(){ |
||||
xajax_updateProgress(__progress_bar_domid, __progress_bar_uploadid, __progress_bar_waitAfterUpload); |
||||
} |
||||
|
||||
/** |
||||
* Displays the progress bar in the given DOM element |
||||
*/ |
||||
function __display_progress_bar(){ |
||||
var my_html ='<span style="font-style:italic;">'+ __progress_bar_text+'</span><br/><img src="'+__progress_bar_img+'" alt="'+__progress_bar_text+'" title="'+__progress_bar_text+'"/>'; |
||||
document.getElementById(__progress_bar_domid).innerHTML = my_html; |
||||
if(__upload_form_domid != ''){ |
||||
document.getElementById(__upload_form_domid).style.display = 'none'; |
||||
} |
||||
} |
||||
this.start = start; |
||||
this.startRealUpload = startRealUpload; |
||||
var __progress_bar_domid = ''; |
||||
var __progress_bar_img = '../img/progress_bar.gif'; |
||||
var __progress_bar_text = 'Uploading... Please wait'; |
||||
var __progress_bar_interval = 1; |
||||
var __upload_form_domid = ''; |
||||
} |
||||
$(document).ready(function() { |
||||
$('.loading_div').hide(); |
||||
}) |
||||
|
||||
function addProgress(id) |
||||
{ |
||||
$('#loading_div_'+id).show(); |
||||
$('#'+id).hide(); |
||||
} |
||||
|
@ -1,33 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* @package chamilo.library |
||||
*/ |
||||
/** |
||||
* Code |
||||
*/ |
||||
include(dirname(__FILE__).'/../global.inc.php'); |
||||
$xajax_upload = new Xajax(); |
||||
$xajax_upload -> registerFunction ('updateProgress'); |
||||
$xajax_upload -> processRequests(); |
||||
|
||||
/** |
||||
* This function updates the progress bar |
||||
* @param div_id where the progress bar is displayed |
||||
* @param upload_id the identifier given in the field UPLOAD_IDENTIFIER |
||||
*/ |
||||
function updateProgress($div_id, $upload_id, $waitAfterupload = false) { |
||||
|
||||
$objResponse = new xajaxResponse(); |
||||
$ul_info = uploadprogress_get_info($upload_id); |
||||
$percent = intval($ul_info['bytes_uploaded']*100/$ul_info['bytes_total']); |
||||
if($waitAfterupload && $ul_info['est_sec']<2) { |
||||
$percent = 100; |
||||
$objResponse->addAssign($div_id.'_label' , 'innerHTML', get_lang('UploadFile').' : '.$percent.' %'); |
||||
$objResponse->addAssign($div_id.'_waiter_frame','innerHTML', Display::return_icon('progress_bar.gif')); |
||||
$objResponse->addScript('clearInterval("myUpload.__progress_bar_interval")'); |
||||
} |
||||
$objResponse->addAssign($div_id.'_label', 'innerHTML', get_lang('UploadFile').' : '.$percent.' %'); |
||||
$objResponse->addAssign($div_id.'_filled', 'style.width', $percent.'%'); |
||||
|
||||
return $objResponse; |
||||
} |
@ -1,25 +0,0 @@ |
||||
<?php |
||||
/** To can run this test you need change the line 17 in upload.xajax.php by: |
||||
* $ul_info = array(); |
||||
* if(function_exists('uploadprogress_get_info')) |
||||
* { |
||||
* $ul_info = uploadprogress_get_info($upload_id); |
||||
* } |
||||
*/ |
||||
|
||||
require_once(api_get_path(LIBRARY_PATH).'upload.xajax.php'); |
||||
require_once(api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php'); |
||||
require_once(api_get_path(LIBRARY_PATH).'xajax/xajaxResponse.inc.php'); |
||||
|
||||
|
||||
|
||||
class TestUpdateXajax extends UnitTestCase { |
||||
/* |
||||
function testUpdateProgress(){ |
||||
$div_id=''; |
||||
$upload_id=''; |
||||
$res = updateProgress($div_id, $upload_id, $waitAfterupload=false); |
||||
$this->assertTrue($res); |
||||
}*/ |
||||
} |
||||
?> |
Loading…
Reference in new issue