Skip to content

Commit

Permalink
Dev: Restructured uploader js
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Jan 4, 2019
1 parent d074062 commit fcfab76
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 29 deletions.
4 changes: 2 additions & 2 deletions application/config/questiontypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
'basePath' => 'core.questions.upload',
'position' => CClientScript::POS_BEGIN,
'css'=> array(
'css/uploader-file.css',
'css/uploader.css',
'styles/uploader-files.css',
'styles/uploader.css',
),
'js'=>array(
'build/uploadquestion'.$minVersion.'.js',
Expand Down
5 changes: 3 additions & 2 deletions application/config/third_party.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,11 @@
'position' => CClientScript::POS_BEGIN,
'js' => array(
'jquery.fn.sortable'.$minVersion.'.js'
)
),
)
),
'jquery-actual' => array(
'position' => CClientScript::POS_BEGIN,
'devBaseUrl' => 'third_party/jquery-actual',
'basePath' => 'third_party.jquery-actual', /* for samechoiceheight/samelistheight */
'js' => array(
'jquery.actual'.$minVersion.'.js'
Expand Down
47 changes: 24 additions & 23 deletions application/controllers/UploaderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function run($actionID)

$meta = '';
// App()->getClientScript()->registerPackage('jqueryui');
// App()->getClientScript()->registerPackage('jquery-superfish');
App()->getClientScript()->registerPackage('question-file-upload');

$aSurveyInfo = getSurveyInfo($surveyid, $sLanguage);
$oEvent = new PluginEvent('beforeSurveyPage');
Expand Down Expand Up @@ -286,21 +286,20 @@ public function run($actionID)
editFile : '".gT('Edit', 'js')."',
};
";
// $oTemplate = Template::model()->getInstance('', $surveyid);
// Yii::app()->clientScript->registerPackage('survey-template-'.$oTemplate->sTemplateName);

$oTemplate = Template::model()->getInstance('', $surveyid);
Yii::app()->clientScript->registerPackage('survey-template-'.$oTemplate->sTemplateName);
// App()->getClientScript()->registerCssFile(Yii::app()->getConfig("publicstyleurl")."uploader.css");
// App()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl')."uploader-files.css");
// App()->getClientScript()->registerScript('sNeededScriptVar', $sNeededScriptVar, LSYii_ClientScript::POS_BEGIN);
// App()->getClientScript()->registerScript('sLangScriptVar', $sLangScriptVar, LSYii_ClientScript::POS_BEGIN);
App()->getClientScript()->registerScript('sNeededScriptVar', $sNeededScriptVar, LSYii_ClientScript::POS_BEGIN);
App()->getClientScript()->registerScript('sLangScriptVar', $sLangScriptVar, LSYii_ClientScript::POS_BEGIN);
// App()->getClientScript()->registerScriptFile(Yii::app()->getConfig("generalscripts").'ajaxupload.js', LSYii_ClientScript::POS_END);
// App()->getClientScript()->registerScriptFile(Yii::app()->getConfig("generalscripts").'uploader.js', LSYii_ClientScript::POS_END);

// App()->bootstrap->register();
App()->bootstrap->register();

// $header = getHeader($meta);
$header = getHeader($meta);

// echo $header;
echo $header;

$fn = $sFieldName;
$qid = (int) Yii::app()->request->getParam('qid');
Expand All @@ -319,24 +318,26 @@ public function run($actionID)

$body = '<body class="uploader">';
$scripts = "<script>\n
".$sNeededScriptVar."\n\n
". $sLangScriptVar."\n\n
window.uploadModalObjects = window.uploadModalObjects || {};
window.uploadModalObjects['".$fn."'] = new uploadHandler( "
. $qid.", {"
. "sFieldName : '".$sFieldName."', "
. "sPreview : '".$sPreview."', "
. "csrfToken: '".ls_json_encode(Yii::app()->request->csrfToken)."', "
. "showpopups: '".Yii::app()->getConfig("showpopups")."'"
. "});
$(function(){
".$sNeededScriptVar."\n\n
". $sLangScriptVar."\n\n
window.uploadModalObjects = window.uploadModalObjects || {};
window.uploadModalObjects['".$fn."'] = window.getUploadHandler( "
. $qid.", {"
. "sFieldName : '".$sFieldName."', "
. "sPreview : '".$sPreview."', "
. "csrfToken: '".ls_json_encode(Yii::app()->request->csrfToken)."', "
. "showpopups: '".Yii::app()->getConfig("showpopups")."'"
. "});"
. "});
</script>";
$container = $this->renderPartial('/survey/questions/answer/file_upload/modal-container', $aData, true);
$body .= $container.$scripts;
$body .= '</body>
</html>';
// App()->getClientScript()->render($body);
// echo $body;
echo $container;
echo $scripts;
App()->getClientScript()->render($body);
echo $body;
//echo $container;
//echo $scripts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1139,4 +1139,8 @@ var uploadHandler = function uploadHandler(qid, options) {

function escapeHtml(unsafe) {
return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
}
}

window.getUploadHandler = function (qid, options) {
return new uploadHandler(qid, options);
};
4 changes: 4 additions & 0 deletions assets/packages/questions/upload/build/uploadquestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,3 +1192,7 @@ function escapeHtml(unsafe) {
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}

window.getUploadHandler = function(qid, options){
return new uploadHandler(qid, options);
}

0 comments on commit fcfab76

Please sign in to comment.