WIP: Simplify progress bar, remove upload.xajax.php

pull/2487/head
jmontoyaa 9 years ago
parent 7e3ff5b07e
commit f1bcb49dac
  1. 2
      main/admin/course_add.php
  2. 2
      main/admin/special_exports.php
  3. 2
      main/auth/profile.php
  4. 2
      main/coursecopy/copy_course.php
  5. 2
      main/coursecopy/create_backup.php
  6. 2
      main/coursecopy/import_backup.php
  7. 2
      main/create_course/add_course.php
  8. 2
      main/document/upload.php
  9. 2
      main/exercise/upload_exercise.php
  10. 2
      main/forum/forumfunction.inc.php
  11. 83
      main/inc/lib/formvalidator/FormValidator.class.php
  12. 75
      main/inc/lib/javascript/upload.js
  13. 33
      main/inc/lib/upload.xajax.php
  14. 2
      main/social/home.php
  15. 2
      main/upload/form.scorm.php
  16. 2
      main/upload/upload_ppt.php
  17. 14
      main/upload/upload_word.php
  18. 2
      main/work/upload_corrections.php
  19. 4
      main/work/work.lib.php
  20. 25
      tests/main/inc/lib/upload.xajax.test.php

@ -168,7 +168,7 @@ $(function() {
});
</script>';
$form->add_progress_bar();
$form->addProgress();
$form->addButtonCreate(get_lang('CreateCourse'));
// Set some default values.

@ -173,7 +173,7 @@ function form_special_export() {
$form->addElement('radio', 'backup_option', '', get_lang('SpecialLetMeSelectItems'), 'select_items');
$form->addElement('html','<br />');
$form->addButtonExport(get_lang('CreateBackup'));
$form->add_progress_bar();
$form->addProgress();
$values['backup_option'] = 'full_backup';
$form->setDefaults($values);
$form->display();

@ -334,7 +334,7 @@ if (is_profile_editable() && api_get_setting('profile', 'picture') == 'true') {
array('id' => 'picture', 'class' => 'picture-form', 'crop_image' => true, 'crop_ratio' => '1 / 1')
);
$form->add_progress_bar();
$form->addProgress();
if (!empty($user_data['picture_uri'])) {
$form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
}

@ -122,7 +122,7 @@ if (Security::check_token('post') && (
$group[] = $form->createElement('radio', 'same_file_name_option', null, get_lang('SameFilenameRename'), FILE_RENAME);
$group[] = $form->createElement('radio', 'same_file_name_option', null, get_lang('SameFilenameOverwrite'), FILE_OVERWRITE);
$form->addGroup($group, '', get_lang('SameFilename'));
$form->add_progress_bar();
$form->addProgress();
$form->addButtonSave(get_lang('CopyCourse'));
$form->setDefaults(array('copy_option' =>'select_items','same_file_name_option' => FILE_OVERWRITE));

@ -102,7 +102,7 @@ if (Security::check_token('post') && (
$form->addElement('radio', 'backup_option', '', get_lang('CreateFullBackup'), 'full_backup');
$form->addElement('radio', 'backup_option', '', get_lang('LetMeSelectItems'), 'select_items');
$form->addButtonSave(get_lang('CreateBackup'));
$form->add_progress_bar();
$form->addProgress();
// When progress bar appears we have to hide the title "Please select a backup-option".
$form->updateAttributes(
array(

@ -268,7 +268,7 @@ if (Security::check_token('post') && (
$values['same_file_name_option'] = FILE_OVERWRITE;
$form->setDefaults($values);
$form->add_progress_bar();
$form->addProgress();
// When progress bar appears we have to hide the title "Select backup file".
$form->updateAttributes(array(
'onsubmit' => str_replace(

@ -242,7 +242,7 @@ $form->addElement('html', '</div>');
$form->addButtonCreate($course_validation_feature ? get_lang('CreateThisCourseRequest') : get_lang('CreateCourseArea'));
// The progress bar of this form.
$form->add_progress_bar();
$form->addProgress();
// Set default values.
if (isset($_user['language']) && $_user['language'] != '') {

@ -274,7 +274,7 @@ $form->addElement('html', '</div>');
// Button upload document
$form->addButtonSend(get_lang('SendDocument'), 'submitDocument');
$form->add_real_progress_bar('DocumentUpload', 'file');
$form->addProgress('DocumentUpload', 'file');
$fileExistsOption = api_get_setting('document_if_file_exists_option');

@ -127,7 +127,7 @@ function lp_upload_quiz_main()
$form->addRule('user_upload_quiz', get_lang('ThisFieldIsRequired'), 'required');
$form->add_progress_bar();
$form->addProgress();
$form->addButtonUpload(get_lang('Upload'), 'submit_upload_quiz');
// Display the upload field

@ -345,7 +345,7 @@ function show_add_forum_form($inputvalues = array(), $lp_id)
$form->addGroup($group, 'public_private_group_forum_group', get_lang('PublicPrivateGroupForum'));
// Forum image
$form->add_progress_bar();
$form->addProgress();
if (!empty($inputvalues['forum_image'])) {
$baseImagePath = api_get_course_path() . '/upload/forum/images/' . $inputvalues['forum_image'];
$image_path = api_get_path(WEB_COURSE_PATH) . $baseImagePath;

@ -893,88 +893,19 @@ EOT;
}
/**
* Adds a progress bar to the form.
* Adds a progress loading image to the form.
*
* Once the user submits the form, a progress bar (animated gif) is
* displayed. The progress bar will disappear once the page has been
* reloaded.
*
* @param int $delay (optional) The number of seconds between the moment the user
* @param string $label (optional) Custom label to be shown
*
* submits the form and the start of the progress bar.
* @deprecated ?
*/
public function add_progress_bar($delay = 2, $label = '')
public function addProgress($delay = 2, $label = '')
{
if (empty($label)) {
$label = get_lang('PleaseStandBy');
}
$this->with_progress_bar = true;
$this->updateAttributes("onsubmit=\"javascript: myUpload.start('dynamic_div','".Display::returnIconPath('progress_bar.gif')."','" . $label . "','" . $this->getAttribute('id') . "')\"");
$this->addElement('html', '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/upload.js" type="text/javascript"></script>');
$this->addElement('html', '<script type="text/javascript">var myUpload = new upload(' . (abs(intval($delay)) * 1000) . ');</script>');
}
/**
* Uses new functions (php 5.2) for displaying real upload progress.
* @param string $upload_id The value of the field UPLOAD_IDENTIFIER, the second parameter (XXX) of the $form->addElement('file', XXX) sentence
* @param string $element_after The first element of the form (to place at first UPLOAD_IDENTIFIER)
* @param int $delay (optional) The frequency of the xajax call
* @param bool $wait_after_upload (optional)
*/
public function add_real_progress_bar($upload_id, $element_after, $delay = 2, $wait_after_upload = false)
{
if (!function_exists('uploadprogress_get_info')) {
$this->add_progress_bar($delay);
return;
}
$xajax_upload = new xajax(api_get_path(WEB_LIBRARY_PATH) . 'upload.xajax.php');
$xajax_upload->registerFunction('updateProgress');
// IMPORTANT : must be the first element of the form
$el = $this->insertElementBefore(FormValidator::createElement('html', '<input type="hidden" name="UPLOAD_IDENTIFIER" value="' . $upload_id . '" />'), $element_after);
$this->addElement('html', '<br />');
// Add div-element where the progress bar is to be displayed
$this->addElement(
'html',
'<div id="dynamic_div_container" style="display:none">
<div id="dynamic_div_label">' . get_lang('UploadFile') . '</div>
<div id="dynamic_div_frame" style="width:214px; height:12px; border:1px solid grey; background-image:url(' . Display::returnIconPath('real_upload_frame.gif').');">
<div id="dynamic_div_filled" style="width:0%;height:100%;background-image:url(' . Display::returnIconPath('real_upload_step.gif').');background-repeat:repeat-x;background-position:center;"></div>
</div>
</div>'
);
if ($wait_after_upload) {
$this->addElement('html', '
<div id="dynamic_div_waiter_container" style="display:none">
<div id="dynamic_div_waiter_label">
' . get_lang('SlideshowConversion') . '
</div>
<div id="dynamic_div_waiter_frame">
'.Display::return_icon('real_upload_frame.gif').'
</div>
</div>
');
}
// Get the xajax code
$this->addElement('html', $xajax_upload->getJavascript(api_get_path(WEB_LIBRARY_PATH) . 'xajax'));
// Get the upload code
$this->addElement('html', '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/upload.js" type="text/javascript"></script>');
$this->addElement('html', '<script type="text/javascript">var myUpload = new upload(' . (abs(intval($delay)) * 1000) . ');</script>');
if (!$wait_after_upload) {
$wait_after_upload = 0;
}
$id = $this->getAttribute('id');
// Add the upload event
$this->updateAttributes("onsubmit=\"javascript: myUpload.startRealUpload('dynamic_div','" . $upload_id . "','" . $this->getAttribute('id') . "'," . $wait_after_upload . ")\"");
$this->updateAttributes("onsubmit=\"javascript: addProgress('" . $id . "')\"");
$this->addHtml('<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/upload.js" type="text/javascript"></script>');
}
/**
@ -1018,8 +949,10 @@ EOT;
$returnValue .= parent::toHtml();
// Add div-element which is to hold the progress bar
$id = $this->getAttribute('id');
if (isset($this->with_progress_bar) && $this->with_progress_bar) {
$returnValue .= '<div id="dynamic_div" style="display:block; margin-left:40%; margin-top:10px; height:50px;"></div>';
// @todo improve UI
$returnValue .= '<br /><div id="loading_div_'.$id.'" class="loading_div"><i class="fa fa-spinner fa-spin fa-3x fa-fw margin-bottom"></i></div>';
}
return $returnValue;

@ -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;
}

@ -33,7 +33,7 @@ if (api_get_setting('profile', 'picture') == 'true') {
// PICTURE
$form->addElement('file', 'picture', get_lang('AddImage'));
$form->add_progress_bar();
$form->addProgress();
if (!empty($user_data['picture_uri'])) {
$form->addElement(
'checkbox',

@ -67,7 +67,7 @@ $form->addLabel(null, Display::return_icon('scorm_logo.jpg', null, ['style' => '
$form->addElement('hidden', 'curdirpath', $path);
$form->addElement('hidden', 'tool', $my_tool);
$form->addElement('file', 'user_file', get_lang('FileToUpload'));
$form->add_real_progress_bar('uploadScorm', 'user_file');
$form->addProgress();
$form->addRule('user_file', get_lang('ThisFieldIsRequired'), 'required');
unset($content_origins[0]);

@ -93,7 +93,7 @@ if (api_get_setting('search_enabled') === 'true') {
$form->addButtonUpload(get_lang('ConvertToLP'), 'convert');
$form->addElement('hidden', 'ppt2lp', 'true');
$form->add_real_progress_bar(md5(rand(0, 10000)), 'user_file', 1, true);
$form->addProgress();
$size = api_get_setting('service_ppt2lp', 'size');
$defaults = array(
'take_slide_name'=>'checked="checked"',

@ -148,8 +148,8 @@ $user_file_template =
EOT;
$renderer->setCustomElementTemplate($user_file_template);
$form -> addElement ('file', 'user_file', Display::return_icon('word_big.gif'));
if (api_get_setting('search_enabled') == 'true') {
$form->addElement('file', 'user_file', Display::return_icon('word_big.gif'));
if (api_get_setting('search_enabled') === 'true') {
$form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument'));
$form->addElement('html', '<br />');
$form->addElement(
@ -162,7 +162,7 @@ if (api_get_setting('search_enabled') == 'true') {
foreach ($specific_fields as $specific_field) {
$form->addElement('text', $specific_field['code'], $specific_field['name'].' : ');
}
$form -> addElement ('html','</div>');
$form->addElement('html', '</div>');
}
/*
@ -170,10 +170,10 @@ if (api_get_setting('search_enabled') == 'true') {
* $form -> addElement ('radio', 'split_steps',null, get_lang('SplitStepsPerPage'),'per_page');
* $form -> addElement ('radio', 'split_steps',null, get_lang('SplitStepsPerChapter'),'per_chapter');
*/
$form -> addElement ('hidden', 'split_steps','per_page');
$form -> addElement ('submit', 'convert', get_lang('ConvertToLP'), 'class="convert_button"');
$form -> addElement ('hidden', 'woogie', 'true');
$form -> add_real_progress_bar(md5(rand(0,10000)), 'user_file', 1, true);
$form->addElement('hidden', 'split_steps', 'per_page');
$form->addElement('submit', 'convert', get_lang('ConvertToLP'), 'class="convert_button"');
$form->addElement('hidden', 'woogie', 'true');
$form->addProgress();
$defaults = array('split_steps'=>'per_page','index_document'=>'checked="checked"');
$form -> setDefaults($defaults);

@ -57,7 +57,7 @@ $form = new FormValidator(
);
$form->addElement('header', get_lang('UploadCorrections'));
$form->addElement('file', 'file', get_lang('UploadADocument'));
$form->add_real_progress_bar('uploadWork', 'file');
$form->addProgress();
$form->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('hidden', 'id', $workId);
$form->addButtonUpload(get_lang('Upload'));

@ -3298,7 +3298,7 @@ function setWorkUploadForm($form, $uploadFormType = 0)
case 0:
// File and text.
$form->addElement('file', 'file', get_lang('UploadADocument'), 'size="40" onchange="updateDocumentTitle(this.value)"');
$form->add_real_progress_bar('uploadWork', 'file');
$form->addProgress();
$form->addHtmlEditor('description', get_lang('Description'), false, false, getWorkDescriptionToolbar());
break;
case 1:
@ -3309,7 +3309,7 @@ function setWorkUploadForm($form, $uploadFormType = 0)
case 2:
// Only file.
$form->addElement('file', 'file', get_lang('UploadADocument'), 'size="40" onchange="updateDocumentTitle(this.value)"');
$form->add_real_progress_bar('uploadWork', 'file');
$form->addProgress();
$form->addRule('file', get_lang('ThisFieldIsRequired'), 'required');
break;
}

@ -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…
Cancel
Save