Skip to content

Commit

Permalink
Dev: upload images in all theme option views
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Nov 23, 2017
1 parent f8408bf commit 8a6f345
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
4 changes: 2 additions & 2 deletions application/config/internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
'imageSrc' => 'LS_Twig_Extension::imageSrc',
'sprintf' => 'sprintf',
'gT' => 'gT',
'getMaximumFileUploadSize'=> 'getMaximumFileUploadSize'
'createUrl' => 'LS_Twig_Extension::createUrl',
),
'filters' => array(
'jencode' => 'CJSON::encode',
Expand All @@ -264,7 +264,7 @@
'Question' => array('qid', 'parent_qid', 'sid', 'gid', 'type', 'title', 'question', 'help', 'other', 'mandatory', 'language', 'scale_qid'),
'QuestionGroups' => array('gid', 'sid', 'group_name', 'group_order', 'description', 'language', 'randomization_group', 'grelevance')
),
'functions' => array('include', 'dump', 'flatEllipsizeText', 'getLanguageData', 'array_flip', 'array_intersect_key', 'registerPublicCssFile', 'registerTemplateCssFile', 'registerGeneralScript', 'registerTemplateScript', 'registerScript', 'unregisterPackage', 'unregisterScriptFile', 'unregisterScriptForAjax', 'listCoreScripts', 'listScriptFiles', 'getAllQuestionClasses', 'intval', 'count', 'empty', 'reset', 'renderCaptcha', 'getPost', 'getParam', 'getQuery', 'isset', 'str_replace', 'assetPublish', 'image', 'imageSrc', 'sprintf', 'gT'),
'functions' => array('include', 'dump', 'flatEllipsizeText', 'getLanguageData', 'array_flip', 'array_intersect_key', 'registerPublicCssFile', 'registerTemplateCssFile', 'registerGeneralScript', 'registerTemplateScript', 'registerScript', 'unregisterPackage', 'unregisterScriptFile', 'unregisterScriptForAjax', 'listCoreScripts', 'listScriptFiles', 'getAllQuestionClasses', 'intval', 'count', 'empty', 'reset', 'renderCaptcha', 'getPost', 'getParam', 'getQuery', 'isset', 'str_replace', 'assetPublish', 'image', 'imageSrc', 'sprintf', 'gT', 'createUrl'),
),

),
Expand Down
2 changes: 1 addition & 1 deletion application/core/LSETwigViewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function renderOptionPage($oTemplate, $renderArray = array())
}

if (file_exists($oRTemplate->path.$sOptionJS)) {
Yii::app()->getClientScript()->registerScriptFile($oRTemplate->sTemplateurl.$sOptionJS, CClientScript::POS_BEGIN);
Yii::app()->getClientScript()->registerScriptFile($oRTemplate->sTemplateurl.$sOptionJS, LSYii_ClientScript::POS_BEGIN);
}

$this->_twig = $twig = parent::getTwig();
Expand Down
8 changes: 8 additions & 0 deletions application/core/LS_Twig_Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ public static function renderCaptcha()
'buttonLabel' => gt('Reload image', 'unescaped')
));
}


public static function createUrl($url, $params = array())
{
return App()->getController()->createUrl($url, $params);
}

/**
* @param string $sRessource
Expand All @@ -234,6 +240,7 @@ public static function image($sImagePath, $alt = '', $htmlOptions = array( ))
if ($oTemplate) {
$sUrlImgAsset = self::assetPublish($oTemplate->path.$sImagePath);
} else {
$sUrlImgAsset = '';
// TODO: publish a default image "not found"
}

Expand All @@ -250,6 +257,7 @@ public static function imageSrc($sImagePath, $default = './files/pattern.png')
{
// Reccurence on templates to find the file
$oTemplate = self::getTemplateForRessource($sImagePath);
$sUrlImgAsset = '';

if ($oTemplate) {
$sUrlImgAsset = self::assetPublish($oTemplate->path.$sImagePath);
Expand Down
3 changes: 3 additions & 0 deletions application/views/admin/themeoptions/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@
var $activeInput = $(options.input);
var $progressBar = $(options.progress);

var onSuccess = options.onSuccess || function(){};

var progressHandling = function(event){
var percent = 0;
var position = event.loaded || event.position;
Expand Down Expand Up @@ -247,6 +249,7 @@
$('#notif-container').append('<div class="alert alert-success" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+data.message+'</div>');
$progressBar.css("width", "0%");
$progressBar.find('span.sr-only').text('0%');
onSuccess();
} else {
$('#notif-container').append('<div class="alert alert-danger" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+data.message+'</div>');
$progressBar.css("width", "0%");
Expand Down
12 changes: 11 additions & 1 deletion themes/survey/default/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,15 @@ $(document).on('ready pjax:scriptcomplete',function(){
$('.simple-template-edit-loading').css('display','block');
prepare().then(function(){
$('.simple-template-edit-loading').remove();
})
});
var uploadImageBind = new bindUpload({
form: '#upload_frontend',
input: '#upload_image_frontend',
progress: '#upload_progress_frontend',
onSuccess : function(){
var triggerEvent = new Event('pjax:load');
triggerEvent.url = window.location.href;
window.dispatchEvent( triggerEvent );
}
});
});
9 changes: 5 additions & 4 deletions themes/survey/default/options/options.twig
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,16 @@
{{ sprintf( gT("Upload an image (maximum size: %d MB):"), (templateConfiguration.maxFileSize/1024/1024) ) }}
</div>
<div class="col-sm-6">
{{ C.Html.form('admin/themes/sa/upload', 'post', { 'id' : 'upload_frontend', 'name' : 'upload_frontend', 'enctype' :'multipart/form-data' }) }}
{{ C.Html.form(createUrl('/admin/themes/sa/upload'), 'post', { 'id' : 'upload_frontend', 'name' : 'upload_frontend', 'enctype' :'multipart/form-data' }) }}
<span id="fileselector">
<label class="btn btn-default col-xs-8" for="upload_image_frontend">
<input class="hidden" id="upload_logo" name="upload_image_frontend" type="file">
<i class="fa fa-upload ls-space margin right-10"></i><{{ gT("Upload") }}
<input class="hidden" id="upload_image_frontend" name="upload_image_frontend" type="file">
<i class="fa fa-upload ls-space margin right-10"></i>
{{ gT("Upload") }}
</label>
</span>

<input type='hidden' name='templatename' value='{{ templateConfiguration.name }}' />
<input type='hidden' name='templatename' value='{{ templateConfiguration.template_name }}' />
<input type='hidden' name='templateconfig' value='{{ templateConfiguration.id }}' />
<input type='hidden' name='action' value='templateuploadimagefile' />
</form>
Expand Down

0 comments on commit 8a6f345

Please sign in to comment.