From f2b923e1b30f4281e65e103ae4d1a5ca4af06518 Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Wed, 12 Oct 2016 00:55:26 +0200 Subject: [PATCH] Dev: Fixed issue #11755: Default action for saveall/loadall 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) --- .../core/packages/limesurvey/survey.js | 80 +++++++++++------ application/helpers/replacements_helper.php | 38 ++++++--- .../survey/system/actionButton/saveLoad.php | 18 ++++ .../survey/system/actionButton/saveSave.php | 18 ++++ .../survey/system/actionLink/saveLoad.php | 14 +++ .../survey/system/actionLink/saveSave.php | 13 +++ templates/default/scripts/template.js | 85 ------------------- 7 files changed, 142 insertions(+), 124 deletions(-) create mode 100644 application/views/survey/system/actionButton/saveLoad.php create mode 100644 application/views/survey/system/actionButton/saveSave.php create mode 100644 application/views/survey/system/actionLink/saveLoad.php create mode 100644 application/views/survey/system/actionLink/saveSave.php diff --git a/application/core/packages/limesurvey/survey.js b/application/core/packages/limesurvey/survey.js index 84b9221e463..e7e8e40f666 100644 --- a/application/core/packages/limesurvey/survey.js +++ b/application/core/packages/limesurvey/survey.js @@ -14,13 +14,6 @@ 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); - } /** @@ -28,34 +21,65 @@ function manageIndex(){ */ 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 + $("").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 - $("").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 */ $("
", { "class":'ls-js-hidden', "html": '', "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) { + $("",{ + 'type':"hidden", + 'name':name, + 'value':value, + }).appendTo('form#limesurvey'); + }); + $('form#limesurvey').submit(); } }); } diff --git a/application/helpers/replacements_helper.php b/application/helpers/replacements_helper.php index ad006a21f33..48b2ec94b98 100644 --- a/application/helpers/replacements_helper.php +++ b/application/helpers/replacements_helper.php @@ -811,13 +811,22 @@ function doHtmlSaveLinks($move="") $surveyid=Yii::app()->getConfig('surveyID'); $thissurvey=getsurveyinfo($surveyid); - $aHtmlOptionsLoadall['disabled']=''; - $aHtmlOptionsSaveall['disabled']=''; - if($thissurvey['allowsave'] == "Y") { - $sLoadButton = '
  • '.gT("Load unfinished survey").'
  • '; - $sSaveButton = '
  • '.gT("Resume later").'
  • '; + $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 { @@ -840,7 +849,7 @@ function doHtmlSaveLinks($move="") { $sSaveAllButtons .= $sLoadButton; } - $sSaveAllButtons .= '
  • '.gT("Resume later").'
  • '; + $sSaveAllButtons .= $sSaveButton; } elseif (!$iSessionStep) //Welcome page, show load (but not save) { @@ -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 { @@ -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) { diff --git a/application/views/survey/system/actionButton/saveLoad.php b/application/views/survey/system/actionButton/saveLoad.php new file mode 100644 index 00000000000..546ea9b6214 --- /dev/null +++ b/application/views/survey/system/actionButton/saveLoad.php @@ -0,0 +1,18 @@ + + +'submit', + 'value'=>$value, + 'name'=>$name, + 'class'=>"$class btn btn-default", + )); +?> + diff --git a/application/views/survey/system/actionButton/saveSave.php b/application/views/survey/system/actionButton/saveSave.php new file mode 100644 index 00000000000..4115b5c5c3d --- /dev/null +++ b/application/views/survey/system/actionButton/saveSave.php @@ -0,0 +1,18 @@ + + +'submit', + 'value'=>$value, + 'name'=>$name, + 'class'=>"$class btn btn-default", + )); +?> + diff --git a/application/views/survey/system/actionLink/saveLoad.php b/application/views/survey/system/actionLink/saveLoad.php new file mode 100644 index 00000000000..aad07f3a297 --- /dev/null +++ b/application/views/survey/system/actionLink/saveLoad.php @@ -0,0 +1,14 @@ + +
  • + + + +
  • + diff --git a/application/views/survey/system/actionLink/saveSave.php b/application/views/survey/system/actionLink/saveSave.php new file mode 100644 index 00000000000..96ada463724 --- /dev/null +++ b/application/views/survey/system/actionLink/saveSave.php @@ -0,0 +1,13 @@ + +
  • + + + +
  • diff --git a/templates/default/scripts/template.js b/templates/default/scripts/template.js index 8b82c35a7b8..8ae810322ad 100644 --- a/templates/default/scripts/template.js +++ b/templates/default/scripts/template.js @@ -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 += "
    "; - for (var i = 0; i < nrOfColumns; i++) - { - // Fetch each column from the table and put content in div - newHtml += "
    "; - $(that).find('tr > *:nth-child('+ (i + 2) + ')').each(function(j) { - // First one is header - if (j === 0) { - newHtml += "
    "; - newHtml += $(this).html(); - newHtml += "
    "; - } - else { - newHtml += "
    "; - newHtml += $(this).html(); - newHtml += "
    "; - } - }); - newHtml += "
    "; - } - newHtml += "
    "; - 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() { @@ -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(); @@ -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()