Skip to content

Commit

Permalink
Dev: Fixed issue #11755: Default action for saveall/loadall
Browse files Browse the repository at this point in the history
Dev: remove button before ready if not usable (usabe only i form#limesurvey is here)
Dev: don't need button, but need javascript
Dev: function can be replaced in template (leave some core class)
  • Loading branch information
Shnoulle committed Oct 11, 2016
1 parent d38306b commit f2b923e
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 124 deletions.
80 changes: 52 additions & 28 deletions application/core/packages/limesurvey/survey.js
Expand Up @@ -14,48 +14,72 @@ function manageIndex(){
$(this).children("[name='move']").click();
}
});
$(".outerframe").addClass("withindex");// Did we need it ? Another class name ? Can not be added directly to body like showprogress showqnumcode- etc ?
//~ Don't know what this part done : comment before remove
//~ var idx = $("#index");
//~ var row = $("#index .row.current");
//~ if(row.length)
//~ idx.scrollTop(row.position().top - idx.height() / 2 - row.height() / 2);

}

/**
* Update survey just when select a new language
*/
function activateLanguageChanger(){
$('.ls-language-changer-item').on('change','select',function() {
if($(this).data('targeturl')){
/* We can't use get in all url combination */
var target=$(this).data('targeturl');
if(target.indexOf("?") >=0){
target+="&lang="+$(this).val();
if(!$(this).closest('form').length){
/* we are not in a forum, can not submit directly */
if($('form#limesurvey').length==1){
/* The limesurvey form exist in document, move select and button inside and click */
$("form#limesurvey [name='lang']").remove();// Remove existing lang selector
$("<input type='hidden']>").attr('name','lang').val($(this).find('option:selected').val()).appendTo($('form#limesurvey'));
$(this).closest('.ls-language-changer-item').find(".ls-change-lang").clone().addClass("ls-js-hidden").appendTo($('form#limesurvey')).click();
}else{
target+="?lang="+$(this).val();
}
location.href = target;
return false;
}else{
if(!$(this).closest('form').length){
if($('form#limesurvey').length==1){ // The limesurvey form exist in document, move select and button inside and click
$("form#limesurvey [name='lang']").remove();// Remove existing lang selector
$("<input type='hidden']>").attr('name','lang').val($(this).find('option:selected').val()).appendTo($('form#limesurvey'));
$(this).closest('.ls-language-changer-item').find(".ls-change-lang").clone().addClass("ls-js-hidden").appendTo($('form#limesurvey')).click();
}else{// If there are no form : we can't use it, we need to create and submit. This break no-js compatibility in some page (token for example).
// If there are no form : we can't use it */
if($(this).data('targeturl')){
/* If we have a target url : just move location to this url with lang set */
var target=$(this).data('targeturl');
/* adding lang in get param manually */
if(target.indexOf("?") >=0){
target+="&lang="+$(this).val();
}else{
target+="?lang="+$(this).val();
}
/* directly move to location */
location.href = target;
return false;
}else{
/* No form, not targeturl : just see what happen */
$("<form>", {
"class":'ls-js-hidden',
"html": '<input type="hidden" name="lang" value="' + $(this).find('option:selected').val() + '" />',
"action": target,
"method": 'post'
}).appendTo(document.body).append($("input[name='YII_CSRF_TOKEN']")).submit();
"method": 'get'
}).appendTo(document.body).submit();
}
}else{
$(this).closest('form').find("[name='lang']").not($(this)).remove();// Remove other lang
$(this).closest('.ls-language-changer-item').find(":submit").click();

}
}else{
/* we are inside a form : just submit : but remove other lang input if exist : be sure it's this one send */
$(this).closest('form').find("[name='lang']").not($(this)).remove();
$(this).closest('.ls-language-changer-item').find(":submit").click();
}
});
}
/**
* Action link with submit object (json) : add params to form and submit
*/
function activateActionLink(){
/* If no limesurvey form : don't need it */
if(!$('form#limesurvey').length){
$('[data-limesurvey-submit]').remove();
}
/* Submit limesurvey form on click */
$('[data-limesurvey-submit]').on('click',function() {
var submit=$(this).data('limesurvey-submit');
if($('form#limesurvey').length==1){
$.each(submit, function(name, value) {
$("<input/>",{
'type':"hidden",
'name':name,
'value':value,
}).appendTo('form#limesurvey');
});
$('form#limesurvey').submit();
}
});
}
38 changes: 27 additions & 11 deletions application/helpers/replacements_helper.php
Expand Up @@ -811,13 +811,22 @@ function doHtmlSaveLinks($move="")
$surveyid=Yii::app()->getConfig('surveyID');
$thissurvey=getsurveyinfo($surveyid);

$aHtmlOptionsLoadall['disabled']='';
$aHtmlOptionsSaveall['disabled']='';

if($thissurvey['allowsave'] == "Y")
{
$sLoadButton = '<li class="ls-no-js-hidden"><a href="#" id="loadallbtnlink" >'.gT("Load unfinished survey").'</a></li>';
$sSaveButton = '<li class="ls-no-js-hidden"><a href="#" id="saveallbtnlink" >'.gT("Resume later").'</a></li>';
$submit=ls_json_encode(array(
'loadall'=>'loadall'
));
$sLoadButton=App()->getController()->renderPartial("/survey/system/actionLink/saveLoad",array(
'submit'=>$submit,
'class'=>'ls-link-action ls-link-loadall'
),true);
$submit=ls_json_encode(array(
'saveall'=>'saveall'
));
$sSaveButton=App()->getController()->renderPartial("/survey/system/actionLink/saveSave",array(
'submit'=>$submit,
'class'=>'ls-link-action ls-link-saveall'
),true);
}
else
{
Expand All @@ -840,7 +849,7 @@ function doHtmlSaveLinks($move="")
{
$sSaveAllButtons .= $sLoadButton;
}
$sSaveAllButtons .= '<li class="ls-no-js-hidden"><a href="#" id="saveallbtnlink" '.$aHtmlOptionsSaveall['disabled'].' >'.gT("Resume later").'</a></li>';
$sSaveAllButtons .= $sSaveButton;
}
elseif (!$iSessionStep) //Welcome page, show load (but not save)
{
Expand Down Expand Up @@ -882,12 +891,19 @@ function doHtmlSaveAll($move="")
$surveyid=Yii::app()->getConfig('surveyID');
$thissurvey=getsurveyinfo($surveyid);

$aHtmlOptionsLoadall=array('type'=>'submit','id'=>'loadallbtn','value'=>'loadall','name'=>'loadall','class'=>"saveall btn btn-default");
$aHtmlOptionsSaveall=array('type'=>'submit','id'=>'saveallbtn','value'=>'saveall','name'=>'saveall','class'=>"saveall btn btn-default");
if($thissurvey['allowsave'] == "Y")
{
$sLoadButton=CHtml::htmlButton(gT("Load unfinished survey"),$aHtmlOptionsLoadall);
$sSaveButton=CHtml::htmlButton(gT("Resume later"),$aHtmlOptionsSaveall);
$sLoadButton=App()->getController()->renderPartial("/survey/system/actionButton/saveLoad",array(
'value'=>'loadall',
'name'=>'loadall',
'class'=>'ls-saveaction ls-loadall'
),true);
$sSaveButton=App()->getController()->renderPartial("/survey/system/actionButton/saveSave",array(
'value'=>'saveall',
'name'=>'saveall',
'class'=>'ls-saveaction ls-saveall'
),true);
App()->getClientScript()->registerScript("activateActionLink","activateActionLink();\n",CClientScript::POS_END);
}
else
{
Expand All @@ -909,7 +925,7 @@ function doHtmlSaveAll($move="")
{
$sSaveAllButtons .= $sLoadButton;
}
$sSaveAllButtons .= CHtml::htmlButton(gT("Resume later"),$aHtmlOptionsSaveall);
$sSaveAllButtons .= $sSaveButton;
}
elseif (!$iSessionStep) //Welcome page, show load (but not save)
{
Expand Down
18 changes: 18 additions & 0 deletions application/views/survey/system/actionButton/saveLoad.php
@@ -0,0 +1,18 @@
<?php
/**
* Move next button
*
* @var $value
* @var $class
*/
?>
<!-- views/survey/system/actionButton/moveNext -->
<?php
echo CHtml::htmlButton(gT("Load unfinished survey"),array(
'type'=>'submit',
'value'=>$value,
'name'=>$name,
'class'=>"$class btn btn-default",
));
?>
<!-- end of views/survey/system/actionButton/moveNext -->
18 changes: 18 additions & 0 deletions application/views/survey/system/actionButton/saveSave.php
@@ -0,0 +1,18 @@
<?php
/**
* Move next button
*
* @var $value
* @var $class
*/
?>
<!-- views/survey/system/actionButton/moveNext -->
<?php
echo CHtml::htmlButton(gT("Resume later"),array(
'type'=>'submit',
'value'=>$value,
'name'=>$name,
'class'=>"$class btn btn-default",
));
?>
<!-- end of views/survey/system/actionButton/moveNext -->
14 changes: 14 additions & 0 deletions application/views/survey/system/actionLink/saveLoad.php
@@ -0,0 +1,14 @@
<?php
/**
* Load link
*
* @var $submit
* @var $class
*/
?>
<li class="ls-no-js-hidden">
<a href="#" data-limesurvey-submit='<?php echo $submit ?>' class='<?php echo $class ?>'>
<?php echo gT("Load unfinished survey") ?>
</a>
</li>

13 changes: 13 additions & 0 deletions application/views/survey/system/actionLink/saveSave.php
@@ -0,0 +1,13 @@
<?php
/**
* Save all link
*
* @var $submit
* @var $class
*/
?>
<li class="ls-no-js-hidden">
<a href="#" data-limesurvey-submit='<?php echo $submit ?>' class='<?php echo $class ?>'>
<?php echo gT("Resume later") ?>
</a>
</li>
85 changes: 0 additions & 85 deletions templates/default/scripts/template.js
Expand Up @@ -42,48 +42,6 @@ $(document).ready(function(){
*/


/**
* Remake table @that with divs, by column
* Used by array-by-column question type on
* small screen
*
* TODO: remove all the HTML from this function.
*
* @param {object} that The table jQuery object
* @return void
*/
function replaceColumnWithDiv(that) {
var newHtml = '';
var nrOfColumns = $(that).find('tr:first th').length;
newHtml += "<div class='array-by-columns-div'>";
for (var i = 0; i < nrOfColumns; i++)
{
// Fetch each column from the table and put content in div
newHtml += "<div class='well radio-list array" + (i % 2 === 0 ? "2" : "1") + " '>";
$(that).find('tr > *:nth-child('+ (i + 2) + ')').each(function(j) {
// First one is header
if (j === 0) {
newHtml += "<div class='answertext clearfix'>";
newHtml += $(this).html();
newHtml += "</div>";
}
else {
newHtml += "<div class='radio-item radio clearfix'>";
newHtml += $(this).html();
newHtml += "</div>";
}
});
newHtml += "</div>";
}
newHtml += "</div>";
newHtml = $(newHtml);
newHtml.find('span.visible-sm-block').each(function(){
console.log(this);
$(this).removeClass('visible-xs-block').removeClass('visible-sm-block');
})
$(that).replaceWith(newHtml);
}

$(document).ready(function()
{

Expand All @@ -99,35 +57,8 @@ $(document).ready(function()
});
}

// Make the label clickable
$('.label-clickable').each(function(){
var $that = $(this);
var attrId = $that.attr('id');
if(attrId!=undefined){
attrId = attrId.replace("label-", "");
} else {
attrId = "";
}
var $inputEl = $("#"+attrId);
$that.on('click', function(){
console.log($inputEl.attr('id'));
$inputEl.trigger( "click" );
});
});

$('.if-no-js').hide();

// iPad has width 768, Google Nexus 10 width 800
// It's OK to keep tables on pads.
if($(window).width() < 768 && 1===2)
{
// Brutally remake the array-by-columns question type to divs,
// because you can't wrap table columns
$('.array-by-columns-table').each(function() {
replaceColumnWithDiv(this);
});
}

//var outerframeDistanceFromTop = 50;
//topsurveymenubar
var topsurveymenubarHeight = $('#topsurveymenubar').innerHeight();
Expand Down Expand Up @@ -183,22 +114,6 @@ $(document).ready(function()
});


// Load survey button
if ($('#loadallbtnlink').length > 0){
$('#loadallbtnlink').on('click', function()
{
$('#loadallbtn').trigger('click');
});
}

// Save survey button
if ($('#saveallbtnlink').length > 0){
$('#saveallbtnlink').on('click', function()
{
$('#saveallbtn').trigger('click');
});
}

// clearall
if ($('#clearallbtnlink').length > 0){
$('#clearallbtnlink').on('click', function()
Expand Down

0 comments on commit f2b923e

Please sign in to comment.