Author: sevein
Date: Sat Sep 19 12:47:58 2009
New Revision: 3428
Log:
Show a warning when same object is being uploaded more than once. Some fixes in
numbering objects and CSS style for digital object blocks.
Modified:
trunk/web/css/graphic.css
trunk/web/js/multiFileUpload.js
Modified: trunk/web/css/graphic.css
==============================================================================
--- trunk/web/css/graphic.css Sat Sep 19 00:52:34 2009 (r3427)
+++ trunk/web/css/graphic.css Sat Sep 19 12:47:58 2009 (r3428)
@@ -862,7 +862,7 @@
{
border: 1px solid #bbb;
padding: 2px;
- margin: 2px;
+ margin: 2px 2px 12px 2px;
overflow: auto;
}
@@ -998,4 +998,4 @@
bottom: 7px;
right: 10px;
z-index: 90;
-}
+}
\ No newline at end of file
Modified: trunk/web/js/multiFileUpload.js
==============================================================================
--- trunk/web/js/multiFileUpload.js Sat Sep 19 00:52:34 2009 (r3427)
+++ trunk/web/js/multiFileUpload.js Sat Sep 19 12:47:58 2009 (r3428)
@@ -69,6 +69,8 @@
var fileName = fileList[i].name;
var fileSize = fileList[i].size; // bytes
+ // TODO: Look for a way for blocking repeated files before upload them.
+ // Unfortunately, YUI generates different ids for same file opening
browser two times.
if (-1 < jQuery.inArray(fileHash, uploadedList))
{
break;
@@ -77,7 +79,7 @@
if (fileSize > maxUploadSize)
{
// Create an upload block for this digital object
- var uploadBlock = '<div id="upload-' + fileHash + '"
class="multiFileUpload">';
+ var uploadBlock = '<div id="upload-' + fileHash + '"
class="multiFileUpload warning">';
uploadBlock += '<ul class=\"validation_error\"><li>Warning, ' +
fileName + ' exceeds maximum upload size.</li></ul>';
uploadBlock += '</div>';
$('#uploads').append(uploadBlock);
@@ -174,12 +176,14 @@
var uploadData = '<div class="form-item"><label>' + i18nInfoObjectTitle +
'</label><input type="text" name="files[' + fileIndex + '][infoObjectTitle]"
value="" style="width: 250px"/></div>';
uploadData += '<div class="form-item"><label>' + i18nFilename + '</label>'
+ uploadFiles[i].name + '</div>';
uploadData += '<div class="form-item"><label>' + i18nFilesize + '</label>'
+ uploadFiles[i].size + '</div>';
+ uploadData += '<input type="hidden" class="md5sum" value="' +
uploadFiles[i].md5sum + '" />';
+ uploadData += '<input type="hidden" class="filename" value="' +
uploadFiles[i].name + '" />';
- uploadData += '<div style="text-align: right;">';
- uploadData += '<a href="#" onclick="deleteUpload(\'' + fileIndex + '\');
return false;">' + i18nDelete + '</a>';
+ uploadData += '<div class="toolbar" style="text-align: right;">';
+ uploadData += '<a href="#" onclick="deleteUpload(\'' + event['id'] + '\');
return false;">' + i18nDelete + '</a>';
uploadData += '</div>';
- $('#upload-' + event['id']).append(uploadData);
+ $('#upload-' + event['id']).append(uploadData).addClass('ready');
hilightRepeatedFiles();
renumerateUploads();
@@ -218,27 +222,72 @@
function renumerateUploads()
{
- $('div.multiFileUpload').each(function(i) {
+ $('div.multiFileUpload:not(.warning)').each(function(i) {
var newValue =
replacePlaceHolder(document.getElementById('uploadForm')['title'].value, i + 1);
$(this).find('input[type=text]').val(newValue); });
}
-function hilightRepeatedFiles()
+function hilightRepeatedFiles(force)
{
- // TODO: iterates over all div.multiFileUploads hilighting ones with same
md5sum (ignore first ocurrence)
+ // Count of selected files by YUI browser
+ var fileCount = 0;
+ for (var i in fileList)
+ {
+ fileCount++;
+ }
+
+ // Count of uploaded files successfully
+ var fileReadyCount = $('div.multiFileUpload.ready').length;
+
+ // Count of files which couldn't be uploaded
+ var fileWarningCount = $('div.multiFileUpload.warning').length;
+
+ // If there is any upload in progress stop function
+ if (!force && (fileReadyCount < fileCount - fileWarningCount))
+ {
+ return;
+ }
+
+ var memMd5 = Array();
+
+ // Iterates over all div.multiFileUploads hilighting ones with same md5sum
(ignore first ocurrence)
+ $('div.multiFileUpload:not(.warning)').each(function() {
+ var md5sum = $(this).find("input.md5sum").val();
+
+ // If file already exists
+ if (-1 < jQuery.inArray(md5sum, memMd5))
+ {
+ 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>');
+ }
+ else
+ {
+ $(this).removeClass('repeated').find('ul.validation_error').remove();
+ memMd5[memMd5.length] = md5sum;
+ }
+ });
}
function deleteUpload(id)
{
- $('div#upload-file' + id).slideUp('fast', function() {
+ // Get the file index from the id passed by YUI
+ var fileIndex = id.match(/([0-9]+)$/).shift();
+ if (null == fileIndex || isNaN(parseInt(fileIndex)))
+ {
+ return;
+ }
+
+ $('div#upload-file' + fileIndex).slideUp('fast', function() {
// Remove the HTML block
$(this).remove();
// Remove hidden fields
- $('input[type=hidden][name*=\[' + id + '\]]').remove();
+ $('input[type=hidden][name*=\[' + fileIndex + '\]]').remove();
- hilightRepeatedFiles();
- renumerateUploads(); });
+ hilightRepeatedFiles(1);
+ renumerateUploads();
+ });
// TODO: Ajax call to remove temporary file
}
\ No newline at end of file
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---