Author: sevein
Date: Fri Oct 9 13:39:05 2009
New Revision: 3709
Log:
Added more verbosity and detection of errors in multi-file upload. Added
'cancel' by the progress bar button to stop uploads before they finish. Some
cosmetic changes.
Modified:
trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php
trunk/apps/qubit/modules/digitalobject/templates/multiFileUploadSuccess.php
trunk/web/js/multiFileUpload.js
Modified: trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php
Fri Oct 9 13:36:43 2009 (r3708)
+++ trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php
Fri Oct 9 13:39:05 2009 (r3709)
@@ -53,7 +53,12 @@
$thumbPath = $tmpDir.'/'.$thumbName;
// Move file to web/uploads/tmp directory
- move_uploaded_file($file['tmp_name'], $tmpFilePath);
+ if (!move_uploaded_file($file['tmp_name'], $tmpFilePath))
+ {
+ $errorMessage = $this->getContext()->getI18N()->__('File %1% could not
be moved to %2%', array('%1%' => $file['name'], '%2%' => $tmpDir));
+ $uploadFiles[] = array('error' => $errorMessage);
+ continue;
+ }
$tmpFileMd5sum = md5_file($tmpFilePath);
$tmpFileMimeType = QubitDigitalObject::deriveMimeType($tmpFileName);
@@ -76,6 +81,12 @@
file_put_contents($thumbPath, $resizedObject);
chmod($thumbPath, 0644);
}
+
+ // Show a warning message if object couldn't be thumbnailed when it is
supposed to be possible
+ if (!file_exists($thumbPath) && 0 >= filesize($thumbPath))
+ {
+ $warning = $this->getContext()->getI18N()->__('File %1% could not be
thumbnailed', array('%1%' => $file['name']));
+ }
}
else
{
@@ -88,7 +99,8 @@
'md5sum' => $tmpFileMd5sum,
'thumb' => $thumbName,
'size' => hr_filesize($file['size']),
- 'canThumbnail' => $canThumbnail
+ 'canThumbnail' => $canThumbnail,
+ 'warning' => $warning
);
}
Modified:
trunk/apps/qubit/modules/digitalobject/templates/multiFileUploadSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/digitalobject/templates/multiFileUploadSuccess.php
Fri Oct 9 13:36:43 2009 (r3708)
+++ trunk/apps/qubit/modules/digitalobject/templates/multiFileUploadSuccess.php
Fri Oct 9 13:39:05 2009 (r3709)
@@ -67,6 +67,7 @@
var i18nFilename = "'.__('file name').'";
var i18nFilesize = "'.__('file size').'";
var i18nDelete = "'.__('Delete').'";
+ var i18nCancel = "'.__('Cancel').'";
var i18nOversizedFileListMessage = "'.__('These files couldn\'t be uploaded
because of file size upload limits').'";
'); ?>
Modified: trunk/web/js/multiFileUpload.js
==============================================================================
--- trunk/web/js/multiFileUpload.js Fri Oct 9 13:36:43 2009 (r3708)
+++ trunk/web/js/multiFileUpload.js Fri Oct 9 13:39:05 2009 (r3709)
@@ -80,7 +80,7 @@
{
// Create an upload block for this digital object
var uploadBlock = '<div id="upload-' + fileHash + '"
class="multiFileUpload warning">';
- uploadBlock += '<ul class=\"validation_error\"><li>Warning, ' +
fileName + ' exceeds maximum upload size.</li></ul>';
+ uploadBlock += '<ul class=\"validation_error\"><li>Warning, ' +
fileName + ' exceeds maximum upload size</li></ul>';
uploadBlock += '</div>';
$('#uploads').append(uploadBlock);
@@ -95,7 +95,8 @@
$('#uploads').append(uploadBlock);
// Insert placeholder for thumbnail ("upload text + progress bar div")
- var progress = '<span style="color: #999; text-align: left">' +
i18nUploading + '</span><br />';
+ var progress = '<span style="color: #999; text-align: left">' +
i18nUploading + '</span>';
+ progress += ' <a href="#" class="cancel"
onclick="cancelUpload(\'' + fileHash + '\'); return false;">' + i18nCancel +
'</a><br />';
progress += '<div class="progress-bar" style="width=: ' +
thumbWidth + 'px;"></div>';
$('#thumbnail-' + fileHash).html(progress)
@@ -151,6 +152,19 @@
for (i in uploadFiles)
{
+ // Ignore this event if upload was cancel
+ if (!$('div#upload-' + event['id']).length)
+ {
+ break;
+ }
+
+ if (uploadFiles[i].error)
+ {
+ var warningMessage = '<ul class="validation_error"><li>' +
uploadFiles[i].error + '</li></ul>';
+ $('#upload-' + event['id']).html(warningMessage).addClass('warning');
+ break;
+ }
+
var thumbnail = '<img src="' + uploadTmpDir + '/' + uploadFiles[i].thumb +
'"/>';
$('#thumbnail-' + event['id']).html(thumbnail);
@@ -192,7 +206,14 @@
uploadData += '<input type="hidden" class="md5sum" value="' +
uploadFiles[i].md5sum + '" />';
uploadData += '<input type="hidden" class="filename" value="' +
uploadFiles[i].name + '" />';
+ // Show warning message if exists
uploadData += '<div class="toolbar" style="text-align: right;">';
+
+ if (uploadFiles[i].warning)
+ {
+ uploadData += '<span style="color: Red;">' + uploadFiles[i].warning +
'</span> | ';
+ }
+
uploadData += '<a href="#" onclick="deleteUpload(\'' + event['id'] + '\');
return false;">' + i18nDelete + '</a>';
uploadData += '</div>';
@@ -272,7 +293,7 @@
{
var fileName = $('input.md5sum[value=' + md5sum +
']:first').parent().find("input.filename").val();
$(this).find('ul.validation_error').remove();
- $(this).addClass('repeated').prepend('<ul
class=\"validation_error\"><li>Warning: duplicate of image ' + fileName +
'</li></ul>');
+ $(this).addClass('repeated').prepend('<ul
class=\"validation_error\"><li>Warning: duplicate of ' + fileName +
'</li></ul>');
}
else
{
@@ -282,6 +303,15 @@
});
}
+function cancelUpload(id)
+{
+ uploader.cancel(id);
+ $('div#upload-' + id).slideUp('fast', function()
+ {
+ $(this).remove();
+ });
+}
+
function deleteUpload(id)
{
// Get the file index from the id passed by YUI
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---