Skip to content

Commit

Permalink
Fixed issue #8178: Upload file is broken in 2.05
Browse files Browse the repository at this point in the history
Fixed issue #8028: File upload dialogue window can't be styled (partial)
Dev: can replace doFileUpload() js function by own function in template.js
  • Loading branch information
Shnoulle committed Sep 25, 2013
1 parent 64eef4d commit 41ae8c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
28 changes: 17 additions & 11 deletions application/controllers/UploaderController.php
Expand Up @@ -25,9 +25,12 @@ function run($actionID)
{
$sLanguage='';
}

$clang = SetSurveyLanguage( $surveyid, $sLanguage);
$uploaddir = Yii::app()->getConfig("uploaddir");
$tempdir = Yii::app()->getConfig("tempdir");
$aSurveyInfo=getSurveyInfo($surveyid,$sLanguage);
$sTemplateUrl = getTemplateURL($aSurveyInfo['templatedir'])."/";

Yii::app()->loadHelper("database");
$param = $_REQUEST;
Expand Down Expand Up @@ -241,15 +244,16 @@ function run($actionID)
$meta = '';
App()->getClientScript()->registerPackage('jqueryui');
App()->getClientScript()->registerPackage('jquery-superfish');

$meta = '<script type="text/javascript">
$sNeededScriptVar='
var uploadurl = "'.$this->createUrl('/uploader/index/mode/upload/').'";
var imageurl = "'.Yii::app()->getConfig('imageurl').'/";
var surveyid = "'.$surveyid.'";
var fieldname = "'.$param['fieldname'].'";
var questgrppreview = '.$param['preview'].';
</script>';
$meta .= "<script type='text/javascript'>
csrfToken = "'.Yii::app()->request->csrfToken.'";
showpopups="'.Yii::app()->getConfig("showpopups").'";
';
$sLangScriptVar="
translt = {
titleFld: '" . $clang->gT('Title','js') . "',
commentFld: '" . $clang->gT('Comment','js') . "',
Expand All @@ -263,12 +267,14 @@ function run($actionID)
errorTooMuch: '" . $clang->gT('The maximum number of files has been uploaded. You may return back to survey.','js') . "',
errorNeedMoreConfirm: '" . $clang->gT("You need to upload %s more files for this question.\nAre you sure you want to exit?",'js') . "'
};
showpopups=".Yii::app()->getConfig("showpopups").";
</script>\n";
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig("generalscripts").'/ajaxupload.js');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig("generalscripts").'/uploader.js');
$meta.= '<link type="text/css" href="'.Yii::app()->getConfig("publicstyleurl").'uploader.css" rel="stylesheet" />';

";
App()->clientScript->registerScript('sNeededScriptVar',$sNeededScriptVar,CClientScript::POS_HEAD);
App()->clientScript->registerScript('sLangScriptVar',$sLangScriptVar,CClientScript::POS_HEAD);
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig("generalscripts").'ajaxupload.js');
App()->getClientScript()->registerScriptFile(Yii::app()->getConfig("generalscripts").'uploader.js');
App()->getClientScript()->registerScriptFile("{$sTemplateUrl}template.js");
App()->clientScript->registerCssFile(Yii::app()->getConfig("publicstyleurl")."uploader.css");
App()->clientScript->registerCssFile("{$sTemplateUrl}template.css");
$header = getHeader($meta);

echo $header;
Expand All @@ -279,7 +285,7 @@ function run($actionID)
$maxfiles = sanitize_int($param['maxfiles']);
$qidattributes=getQuestionAttributeValues($qid);

$body = '
$body = '</head><body>
<div id="notice"></div>
<input type="hidden" id="ia" value="'.$fn.'" />
<input type="hidden" id="'.$fn.'_minfiles" value="'.$minfiles.'" />
Expand Down
9 changes: 7 additions & 2 deletions scripts/uploader.js
@@ -1,4 +1,8 @@
$(document).ready(function(){
doFileUpload();
});

function doFileUpload(){
var fieldname = $('#ia').val();

/* Load the previously uploaded files */
Expand Down Expand Up @@ -58,7 +62,8 @@ $(document).ready(function(){
max_filesize : $('#'+fieldname+'_maxfilesize').val(),
preview : $('#preview').val(),
surveyid : surveyid,
fieldname : fieldname
fieldname : fieldname,
YII_CSRF_TOKEN : csrfToken
},
onSubmit : function(file, ext){

Expand Down Expand Up @@ -183,7 +188,7 @@ $(document).ready(function(){

// if it has been jst opened, the upload button should be automatically clicked !
// TODO: auto open using click() not working at all ! :(
});
}

function isValueInArray(arr, val) {
inArray = false;
Expand Down

0 comments on commit 41ae8c0

Please sign in to comment.