I'm playing around with using the theme's script.js to invoke the Upload buttons and get the progress bars to work (cuz they only work when Upload button is used, not when Save or Add another item are). This might be useful in that it doesn't involve hacking CCK or Filefield. I have it almost working but need some help.
Again, I'm using FF for large files, and when someone's uploading ten 1GB files and they bypass the individual Upload buttons by clicking Save or Add another, then progress bars are missing and that becomes an issue.
This code binds the Save button to Drupal.cckSaveFilefield which searches for input fields with id -upload and non-empty value and asks the user what to do for each. If the user confirms Yes then the upload button is pressed. Note: return false; is there just so I can watch what happens without drupal saving the node and loosing the errors that are shown on the edit form.
This almost works - the script pops up a confirm alert for each populated field, but then the uploads get crushed by the script exiting too quickly. I need to find a way to make the script wait for each upload to finish BUT not keep the next upload from starting and have all uploads running simultaneously. It it could exit without stopping the uploads then it could just return false if any non-empty -upload's were found, fire off the uploads, and then assume the user will notice when their all finished and re-click Save. But detecting when all uploads are finished and saving the form would be nice. Perhaps that requires some fancy function layouts with callbacks, etc.
Just want to mention that I can manually click all the buttons ~4-5 seconds apart and successfully get all progress bars working with ten 400mb files. If I click the first two too quickly (less than 3-4 seconds apart) then each upload still works but the progress bars sit at "Starting upload..." through the whole upload of each file.
I suppose I could get by with replacing the confirm with a simple alert asking the user to Upload each file before saving. I wrote a similar script for the Add another item button, and see similar behavior.
Drupal.cckSaveFilefield = { uploadFF: function(event) {
//find any populated file uploads fields and bark if not yet uploaded.
$('.form-file').each(function(){
if ( jQuery(this).val() ) {
var file = $(this).val();
if (confirm("Do you want to upload " + file + "?")) {
// click the Upload button
var dfId = $(this).attr("id");
var dfIdUpload = dfId.replace(/-upload/,'-filefield-upload');
$('#'+dfIdUpload).mousedown();
}else{
// clear the field and move on
$(this).val("");
}
}
});
//return false;
} }
Drupal.behaviors.uploadFilefield = function(context) {
$('#edit-submit').bind('click', Drupal.cckSaveFilefield.uploadFF); }
Comments
Comment #1
quicksketchI'm interested in this functionality but I do not have the time to dedicate to writing it. If you can get this working by modifying the FileField JavaScript files, please provide a patch and I'll look over it.
Comment #2
djdevinAlso interested in this - I have some time to work on this in the near future, the progress bar should always happen on submit. Having a separate upload button is out of the ordinary for most web users.
Comment #3
quicksketchI thought there was an existing issue for this. Let's merge with #435746: Progress bar not shown when Save or Add-another are clicked.