Skip to content

Commit

Permalink
dev: fixed various issues with file upload, upgraded ajaxupload.js to…
Browse files Browse the repository at this point in the history
… latest version to eliminate errors. should be completely localised now and no more javascript errors

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey@10301 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
mennodekker committed Jun 20, 2011
1 parent a104099 commit a5b823b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
10 changes: 5 additions & 5 deletions index.php
Expand Up @@ -1707,7 +1707,7 @@ function checkconditionalmandatorys($move, $backok=null)

function checkUploadedFileValidity($move, $backok=null)
{
global $connect, $thisstep;
global $connect, $thisstep, $clang;
if (!isset($backok) || $backok != "Y")
{
global $dbprefix;
Expand Down Expand Up @@ -1756,7 +1756,7 @@ function checkUploadedFileValidity($move, $backok=null)
if ($file['size'] > $validation['max_filesize'] * 1000)
{
$filenotvalidated = array();
$filenotvalidated[$field."_file_".$i] = "Sorry, the uploaded file (".$file['size'].") is larger than the allowed filesize of ".$validation['max_filesize']." KB.";
$filenotvalidated[$field."_file_".$i] = sprintf($clang->gT("Sorry, the uploaded file (%s) is larger than the allowed filesize of %s KB."), $file['size'], $validation['max_filesize']);
$append = true;
}

Expand All @@ -1769,13 +1769,13 @@ function checkUploadedFileValidity($move, $backok=null)
{
if (isset($append) && $append)
{
$filenotvalidated[$field."_file_".$i] .= "Sorry, only ".$validation['allowed_filetypes']." extensions are allowed ! ";
$filenotvalidated[$field."_file_".$i] .= sprintf($clang->gT("Sorry, only %s extensions are allowed !"),$validation['allowed_filetypes']);
unset($append);
}
else
{
$filenotvalidated = array();
$filenotvalidated[$field."_file_".$i] = "Sorry, only ".$validation['allowed_filetypes']." extensions are allowed ! ";
$filenotvalidated[$field."_file_".$i] .= sprintf($clang->gT("Sorry, only %s extensions are allowed !"),$validation['allowed_filetypes']);
}
}
}
Expand All @@ -1787,7 +1787,7 @@ function checkUploadedFileValidity($move, $backok=null)
if ($filecount < $validation['min_num_of_files'])
{
$filenotvalidated = array();
$filenotvalidated[$field] = "The minimum number of files have not been uploaded";
$filenotvalidated[$field] = $clang->gT("The minimum number of files have not been uploaded");
}
}
}
Expand Down
65 changes: 37 additions & 28 deletions scripts/ajaxupload.js
@@ -1,23 +1,9 @@
/**
* AJAX Upload ( http://valums.com/ajax-upload/ )
* Copyright (c) Andris Valums
* Licensed under the MIT license ( http://valums.com/mit-license/ )
* Thanks to Gary Haran, David Mark, Corey Burns and others for contributions
* Copyright (c) Andrew Valums
* Licensed under the MIT license
*/
(function () {
/* global window */
/* jslint browser: true, devel: true, undef: true, nomen: true, bitwise: true, regexp: true, newcap: true, immed: true */

/**
* Wrapper for FireBug's console.log
*/
function log(){
if (typeof(console) != 'undefined' && typeof(console.log) == 'function'){
Array.prototype.unshift.call(arguments, '[Ajax Upload]');
console.log( Array.prototype.join.call(arguments, ' '));
}
}

/**
* Attaches event to a dom element.
* @param {Element} el
Expand Down Expand Up @@ -236,6 +222,8 @@
action: 'upload.php',
// File upload name
name: 'userfile',
// Select & upload multiple files at once FF3.6+, Chrome 4+
multiple: false,
// Additional data to send
data: {},
// Submit file as soon as it's selected
Expand All @@ -247,6 +235,8 @@
responseType: false,
// Class applied to button when mouse is hovered
hoverClass: 'hover',
// Class applied to button when button is focused
focusClass: 'focus',
// Class applied to button when AU is disabled
disabledClass: 'disabled',
// When user selects a file, useful with autoSubmit disabled
Expand Down Expand Up @@ -328,10 +318,12 @@

// hide input
if (this._input){
// We use visibility instead of display to fix problem with Safari 4
// The problem is that the value of input doesn't change if it
// has display none when user selects a file
this._input.parentNode.style.visibility = 'hidden';
if (this._input.parentNode) {
// We use visibility instead of display to fix problem with Safari 4
// The problem is that the value of input doesn't change if it
// has display none when user selects a file
this._input.parentNode.style.visibility = 'hidden';
}
}
},
enable: function(){
Expand All @@ -351,6 +343,7 @@
var input = document.createElement("input");
input.setAttribute('type', 'file');
input.setAttribute('name', this._settings.name);
if(this._settings.multiple) input.setAttribute('multiple', 'multiple');

addStyles(input, {
'position' : 'absolute',
Expand All @@ -360,7 +353,10 @@
'right' : 0,
'margin' : 0,
'padding' : 0,
'fontSize' : '480px',
'fontSize' : '480px',
// in Firefox if font-family is set to
// 'inherit' the input doesn't work
'fontFamily' : 'sans-serif',
'cursor' : 'pointer'
});

Expand Down Expand Up @@ -415,14 +411,24 @@

addEvent(input, 'mouseout', function(){
removeClass(self._button, self._settings.hoverClass);
removeClass(self._button, self._settings.focusClass);

// We use visibility instead of display to fix problem with Safari 4
// The problem is that the value of input doesn't change if it
// has display none when user selects a file
input.parentNode.style.visibility = 'hidden';

if (input.parentNode) {
// We use visibility instead of display to fix problem with Safari 4
// The problem is that the value of input doesn't change if it
// has display none when user selects a file
input.parentNode.style.visibility = 'hidden';
}
});

addEvent(input, 'focus', function(){
addClass(self._button, self._settings.focusClass);
});

addEvent(input, 'blur', function(){
removeClass(self._button, self._settings.focusClass);
});

div.appendChild(input);
document.body.appendChild(div);

Expand All @@ -439,6 +445,7 @@
this._createInput();

removeClass(this._button, this._settings.hoverClass);
removeClass(this._button, this._settings.focusClass);
},
/**
* Function makes sure that when user clicks upload button,
Expand Down Expand Up @@ -603,6 +610,7 @@
// nodeValue property to retrieve the unmangled content.
// Note that IE6 only understands text/html
if (doc.body.firstChild && doc.body.firstChild.nodeName.toUpperCase() == 'PRE') {
doc.normalize();
response = doc.body.firstChild.firstChild.nodeValue;
}

Expand Down Expand Up @@ -654,14 +662,15 @@
// div -> input type='file'
removeNode(this._input.parentNode);
removeClass(self._button, self._settings.hoverClass);
removeClass(self._button, self._settings.focusClass);

form.appendChild(this._input);

form.submit();

// request set, clean up
removeNode(form); form = null;
removeNode(this._input); this._input = null;
removeNode(this._input); this._input = null;

// Get response from iframe and fire onComplete event when ready
this._getResponse(iframe, file);
Expand All @@ -670,4 +679,4 @@
this._createInput();
}
};
})();
})();
6 changes: 3 additions & 3 deletions scripts/uploader.js
Expand Up @@ -22,7 +22,7 @@ $(document).ready(function(){
"<td align='center' width='50%' padding='20px' >";

if (isValueInArray(image_extensions, json[i-1].ext))
previewblock += "<img src='uploader.php?filegetcontents="+json[i-1].filename+"' height='60px' />"+decodeURIComponent(json[i].name);
previewblock += "<img src='uploader.php?filegetcontents="+json[i-1].filename+"' height='60px' />"+decodeURIComponent(json[i-1].name);
else
previewblock += "<img src='images/placeholder.png' height='60px' /><br />"+decodeURIComponent(json[i-1].name);

Expand Down Expand Up @@ -167,7 +167,7 @@ $(document).ready(function(){
if (filecount < minfiles)
$('#uploadstatus').html(translt.errorNeedMore.replace('%s',(minfiles - filecount)));
else if (filecount < maxfiles)
$('#uploadstatus').html(translt.errorMoreAllowed.replace('%s',(minfiles - filecount)));
$('#uploadstatus').html(translt.errorMoreAllowed.replace('%s',(maxfiles - filecount)));
else
$('#uploadstatus').html(translt.errorMaxReached);

Expand Down Expand Up @@ -291,7 +291,7 @@ function deletefile(fieldname, count) {
if (filecount < minfiles)
$('#uploadstatus').html(translt.errorNeedMore.replace('%s',(minfiles - filecount)));
else
$('#uploadstatus').html(translt.errorMoreAllowed.raplce('%s',(maxfiles - filecount)));
$('#uploadstatus').html(translt.errorMoreAllowed.replace('%s',(maxfiles - filecount)));
}
}
file_index = $("#"+fieldname+"_file_index_"+count).val();
Expand Down

0 comments on commit a5b823b

Please sign in to comment.