Skip to content
Snippets Groups Projects
Commit 23bd2c00 authored by Steven Wittens's avatar Steven Wittens
Browse files

#60532: multiple file upload broken in some browsers

parent 00f8037e
No related branches found
No related tags found
No related merge requests found
......@@ -113,7 +113,7 @@ function HTTPPost(uri, callbackFunction, callbackParameter, object) {
* window.parent.iframeHandler() after submission.
*/
function redirectFormButton(uri, button, handler) {
// Make sure we have an iframe to target
// (Re)create an iframe to target.
createIframe();
// Trap the button
......@@ -140,8 +140,8 @@ function redirectFormButton(uri, button, handler) {
// Get response from iframe body
try {
response = (iframe.contentWindow || iframe.contentDocument || iframe).document.body.innerHTML;
// Firefox 1.0.x hack: Replace control characters
response = response.replace(/[\f\n\r\t\v]/g, ' ');
// Firefox 1.0.x hack: Remove (corrupted) control characters
response = response.replace(/[\f\n\r\t]/g, ' ');
if (window.opera) {
// Opera-hack: it returns innerHTML sanitized.
response = response.replace(/"/g, '"');
......@@ -151,8 +151,8 @@ function redirectFormButton(uri, button, handler) {
response = null;
}
// Recreate the iframe: re-using an old iframe can sometimes cause browser bugs.
createIframe();
$('redirect-target').onload = null;
$('redirect-target').src = 'about:blank';
response = parseJson(response);
// Check response code
......@@ -353,7 +353,7 @@ function createIframe() {
*/
function deleteIframe() {
var holder = $('redirect-holder');
if (typeof holder != 'undefined') {
if (holder != null) {
removeNode(holder);
}
}
......
......@@ -235,6 +235,7 @@ function upload_form_alter($form_id, &$form) {
drupal_add_js('misc/progress.js');
drupal_add_js('misc/upload.js');
// Attachments fieldset
$form['attachments'] = array(
'#type' => 'fieldset',
'#title' => t('File attachments'),
......@@ -245,7 +246,13 @@ function upload_form_alter($form_id, &$form) {
'#suffix' => '</div>',
'#weight' => 30,
);
$form['attachments'] += _upload_form($node);
// Wrapper for fieldset contents (used by upload JS).
$form['attachments']['wrapper'] = array(
'#prefix' => '<div id="attach-wrapper">',
'#suffix' => '</div>',
);
$form['attachments']['wrapper'] += _upload_form($node);
$form['#attributes']['enctype'] = 'multipart/form-data';
}
}
......@@ -268,7 +275,7 @@ function _upload_validate(&$node) {
// Bypass validation for uid = 1.
if ($user->uid != 1) {
//Update filesize accumulator.
// Update filesize accumulator.
$filesize += $file->filesize;
// Validate file against all users roles.
......@@ -545,6 +552,7 @@ function upload_delete_revision($node) {
function _upload_form($node) {
$form['#theme'] = 'upload_form_new';
if (is_array($node->files) && count($node->files)) {
$form['files']['#theme'] = 'upload_form_current';
$form['files']['#tree'] = TRUE;
......@@ -568,10 +576,15 @@ function _upload_form($node) {
}
if (user_access('upload files')) {
// This div is hidden when the user uploads through JS.
$form['new'] = array(
'#prefix' => '<div id="attach-hide">',
'#suffix' => '</div>',
);
$form['new']['upload'] = array('#type' => 'file', '#title' => t('Attach new file'), '#size' => 40);
$form['new']['fileop'] = array('#type' => 'button', '#value' => t('Attach'), '#name'=> 'fileop', '#attributes' => array('id' => 'fileop'));
$form['new']['attach'] = array('#type' => 'button', '#value' => t('Attach'), '#name'=> 'attach', '#attributes' => array('id' => 'attach'));
// The class triggers the js upload behaviour.
$form['fileop'] = array('#type' => 'hidden', '#value' => url('upload/js', NULL, NULL, TRUE), '#attributes' => array('class' => 'upload'));
$form['attach'] = array('#type' => 'hidden', '#value' => url('upload/js', NULL, NULL, TRUE), '#attributes' => array('class' => 'upload'));
}
// Needed for JS
......@@ -579,15 +592,6 @@ function _upload_form($node) {
return $form;
}
function theme_upload_form_new($form) {
$output .= '<div id="fileop-wrapper">' . "\n";
$output .= '<div id="fileop-hide">' . "\n";
$output .= form_render($form) . "\n";
$output .= "</div>\n";
$output .= "</div>\n";
return $output;
}
function theme_upload_form_current(&$form) {
$header = array(t('Delete'), t('List'), t('Description'), t('Size'));
......@@ -659,7 +663,6 @@ function upload_js() {
}
$form = form_builder('upload_js', $form);
$output = theme('status_messages') . form_render($form);
// We send the updated file attachments form.
print drupal_to_js(array('status' => TRUE, 'data' => $output));
exit;
......
......@@ -235,6 +235,7 @@ function upload_form_alter($form_id, &$form) {
drupal_add_js('misc/progress.js');
drupal_add_js('misc/upload.js');
// Attachments fieldset
$form['attachments'] = array(
'#type' => 'fieldset',
'#title' => t('File attachments'),
......@@ -245,7 +246,13 @@ function upload_form_alter($form_id, &$form) {
'#suffix' => '</div>',
'#weight' => 30,
);
$form['attachments'] += _upload_form($node);
// Wrapper for fieldset contents (used by upload JS).
$form['attachments']['wrapper'] = array(
'#prefix' => '<div id="attach-wrapper">',
'#suffix' => '</div>',
);
$form['attachments']['wrapper'] += _upload_form($node);
$form['#attributes']['enctype'] = 'multipart/form-data';
}
}
......@@ -268,7 +275,7 @@ function _upload_validate(&$node) {
// Bypass validation for uid = 1.
if ($user->uid != 1) {
//Update filesize accumulator.
// Update filesize accumulator.
$filesize += $file->filesize;
// Validate file against all users roles.
......@@ -545,6 +552,7 @@ function upload_delete_revision($node) {
function _upload_form($node) {
$form['#theme'] = 'upload_form_new';
if (is_array($node->files) && count($node->files)) {
$form['files']['#theme'] = 'upload_form_current';
$form['files']['#tree'] = TRUE;
......@@ -568,10 +576,15 @@ function _upload_form($node) {
}
if (user_access('upload files')) {
// This div is hidden when the user uploads through JS.
$form['new'] = array(
'#prefix' => '<div id="attach-hide">',
'#suffix' => '</div>',
);
$form['new']['upload'] = array('#type' => 'file', '#title' => t('Attach new file'), '#size' => 40);
$form['new']['fileop'] = array('#type' => 'button', '#value' => t('Attach'), '#name'=> 'fileop', '#attributes' => array('id' => 'fileop'));
$form['new']['attach'] = array('#type' => 'button', '#value' => t('Attach'), '#name'=> 'attach', '#attributes' => array('id' => 'attach'));
// The class triggers the js upload behaviour.
$form['fileop'] = array('#type' => 'hidden', '#value' => url('upload/js', NULL, NULL, TRUE), '#attributes' => array('class' => 'upload'));
$form['attach'] = array('#type' => 'hidden', '#value' => url('upload/js', NULL, NULL, TRUE), '#attributes' => array('class' => 'upload'));
}
// Needed for JS
......@@ -579,15 +592,6 @@ function _upload_form($node) {
return $form;
}
function theme_upload_form_new($form) {
$output .= '<div id="fileop-wrapper">' . "\n";
$output .= '<div id="fileop-hide">' . "\n";
$output .= form_render($form) . "\n";
$output .= "</div>\n";
$output .= "</div>\n";
return $output;
}
function theme_upload_form_current(&$form) {
$header = array(t('Delete'), t('List'), t('Description'), t('Size'));
......@@ -659,7 +663,6 @@ function upload_js() {
}
$form = form_builder('upload_js', $form);
$output = theme('status_messages') . form_render($form);
// We send the updated file attachments form.
print drupal_to_js(array('status' => TRUE, 'data' => $output));
exit;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment