Skip to content

Commit

Permalink
New feature #11692: Remove the display:none for EM filter (and condit…
Browse files Browse the repository at this point in the history
…ion) : use hidden, ls-hidden

Dev: Actually : just use ls-hidden ls-unrelevant ls-disabled
Dev: Question : what is the easiest for user : replace triggerEmRelevance or update !important css
Dev: javascript dev : replace triggerEmRelevance or add new function
Dev: other user ?
Dev: have some idea for 'core plugin' : hide/show slowly | add border for testing (survey not active)
Dev: etc ...
  • Loading branch information
Shnoulle committed Nov 6, 2016
1 parent a76dfed commit 5716190
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 81 deletions.
7 changes: 7 additions & 0 deletions application/core/packages/limesurvey/survey.css
Expand Up @@ -10,6 +10,13 @@
* Used in answers : bootsrap fix (specific single choice list)
*/

/**
* Expression manager relevance system
*/
.ls-hidden {display:none !important;}/* Need important : template can set display:block/table etc ... after */
.ls-unrelevant{}
.ls-disabled{opacity:0.4;}


/* Some tools
*/
Expand Down
33 changes: 33 additions & 0 deletions application/core/packages/limesurvey/survey.js
Expand Up @@ -8,6 +8,39 @@
* Always set an empty LSvar
*/
var LSvar = LSvar || { };

/**
* Action to do when relevance is set to on or off
*/
function triggerEmRelevance(){
/* Global ! question and subquestion */
$(document).on('relevance',function(event,data) {
if(data.style=='disabled'){
if(data.status){
$(event.target).prop("disabled", false ); // Review for ranking
$(event.target).closest("li,tr").removeClass("ls-unrelevant ls-disabled");
}else{
$(event.target).prop( "disabled", true );
$(event.target).closest("li,tr").addClass("ls-unrelevant ls-disabled");/* target is set to input : must move to line : one event needed only */
}
}
else{ // data.style=='hidden'
if(data.status){
$(event.target).removeClass("ls-unrelevant ls-hidden");
//$(event.target).show(); /* Set inlined display:none : class is better : can be replaced in template BUT : display none use !important */
}else{
$(event.target).addClass("ls-unrelevant ls-hidden");
//$(event.target).hide();
}
}
});
/* @todo : updateColors replacement */
$(".subquestion-list,.answers-list").on('relevance',function(event,data) {

});

}

/**
* Manage the index
*/
Expand Down
31 changes: 21 additions & 10 deletions application/helpers/SurveyRuntimeHelper.php
Expand Up @@ -888,7 +888,7 @@ function run($surveyid,$args)
$gnoshow = LimeExpressionManager::GroupIsIrrelevantOrHidden($_gseq);
if ($gnoshow && !$previewgrp)
{
echo " class='hidden'";
echo " class='ls-hidden'";/* Unsure for reason : hidden or unrelevant ?*/
}
echo ">\n";
echo templatereplace(file_get_contents($sTemplateViewPath."startgroup.pstpl"), array(), $redata);
Expand Down Expand Up @@ -981,6 +981,7 @@ function run($surveyid,$args)

LimeExpressionManager::FinishProcessingGroup($LEMskipReprocessing);
echo LimeExpressionManager::GetRelevanceAndTailoringJavaScript();
Yii::app()->clientScript->registerScript('triggerEmRelevance',"triggerEmRelevance();",CClientScript::POS_END);
LimeExpressionManager::FinishProcessingPage();

/**
Expand Down Expand Up @@ -1167,16 +1168,28 @@ public static function getQuestionReplacement($aQuestionQanda)

}
// Core value :the classes
$aReplacement['QUESTION_CLASS'] = Question::getQuestionClass($sType);

$aQuestionClass=array(
Question::getQuestionClass($sType),
);
/* Add the relevance class */
if (!$lemQuestionInfo['relevant'])
{
$aQuestionClass[]='ls-unrelevant';
$aQuestionClass[]='ls-hidden';
}
if ($lemQuestionInfo['hidden'])
{
$aQuestionClass[]='ls-hidden';
}
//get additional question classes from question attribute
$aQuestionAttributes = getQuestionAttributeValues($aQuestionQanda[4]);

//add additional classes
if(isset($aQuestionAttributes['cssclass']))
{
$aReplacement['QUESTION_CLASS'] .= " ".$aQuestionAttributes['cssclass'];
$aQuestionClass[]=htmlentities($aQuestionAttributes['cssclass']);
}
$aReplacement['QUESTION_CLASS'] =implode(" ",$aQuestionClass);

$aMandatoryClass = array();
if ($lemQuestionInfo['info']['mandatory'] == 'Y')// $aQuestionQanda[0]['mandatory']=="*"
Expand All @@ -1198,10 +1211,6 @@ public static function getQuestionReplacement($aQuestionQanda)
$aReplacement['QUESTION_MANDATORY']=$aQuestionQanda[0]['mandatory'];
// For QUESTION_ESSENTIALS
$aHtmlOptions=array();
if ((!$lemQuestionInfo['relevant']) || ($lemQuestionInfo['hidden']))// && $lemQuestionInfo['info']['type'] == '*'))
{
$aHtmlOptions['style'] = 'display: none;';
}

// Launch the event
$event = new PluginEvent('beforeQuestionRender');
Expand Down Expand Up @@ -1243,8 +1252,10 @@ public static function getQuestionReplacement($aQuestionQanda)
$aReplacement['QUESTION_VALID_MESSAGE'] = $event->get('valid_message');
$aReplacement['QUESTION_FILE_VALID_MESSAGE'] = $event->get('file_valid_message');
$aReplacement['QUESTION_MANDATORY'] = $event->get('mandatory',$aReplacement['QUESTION_MANDATORY']);
// Always add id for QUESTION_ESSENTIALS
$aHtmlOptions['id']="question{$iQid}";
//Another data for QUESTION_ESSENTIALS
$aHtmlOptions= (array) $event->get('aHtmlOptions');
unset($aHtmlOptions['class']);// Disallowing update/set class
$aHtmlOptions['id']="question{$iQid}";// Always add id for QUESTION_ESSENTIALS
$aReplacement['QUESTION_ESSENTIALS']=CHtml::renderAttributes($aHtmlOptions);

return $aReplacement;
Expand Down
43 changes: 20 additions & 23 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -7211,7 +7211,7 @@ static function GetRelevanceAndTailoringJavaScript()

// Do all sub-question filtering (e..g array_filter)
/**
* $afHide - if true, then use jQuery.show(). If false, then disable/enable the row
* $afHide - if true, then use jQuery.relevanceOn(). If false, then disable/enable the row
*/
$afHide = (isset($LEM->qattr[$arg['qid']]['array_filter_style']) ? ($LEM->qattr[$arg['qid']]['array_filter_style'] == '0') : true);
$inputSelector = (($arg['type'] == 'R') ? '' : ' :input:not(:hidden)');
Expand All @@ -7238,20 +7238,19 @@ static function GetRelevanceAndTailoringJavaScript()
$relParts[] = " if ( " . (empty($sq['relevancejs'])?'1':$sq['relevancejs']) . " ) {\n";
if ($afHide)
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "').show();\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "').relevanceOn();\n";
}
else
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').removeAttr('disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').relevanceOn({ style : 'disabled' });\n";
}
if ($sq['isExclusiveJS'] != '')
{
$relParts[] = " if ( " . $sq['isExclusiveJS'] . " ) {\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').attr('disabled','disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').relevanceOff({ style : 'disabled' });\n";
$relParts[] = " }\n";
$relParts[] = " else {\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').removeAttr('disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " th.answertext').removeClass('text-muted');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').relevanceOn({ style : 'disabled' });\n";
$relParts[] = " }\n";
}
$relParts[] = " relChange" . $arg['qid'] . "=true;\n";
Expand All @@ -7263,36 +7262,34 @@ static function GetRelevanceAndTailoringJavaScript()
if ($sq['irrelevantAndExclusiveJS'] != '')
{
$relParts[] = " if ( " . $sq['irrelevantAndExclusiveJS'] . " ) {\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').attr('disabled','disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " th.answertext').addClass('text-muted');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').relevanceOff({ style : 'disabled' });\n";
$relParts[] = " }\n";
$relParts[] = " else {\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').removeAttr('disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . " th.answertext').removeClass('text-muted');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').relevanceOn({ style : 'disabled' });\n";
if ($afHide)
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "').hide();\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "').relevanceOff();\n";
}
else
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').attr('disabled','disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').relevanceOff({ style : 'disabled' });\n";
}
$relParts[] = " }\n";
}
else
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').attr('disabled','disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').relevanceOff({ style : 'disabled' });\n";
}
}
else
{
if ($afHide)
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "').hide();\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "').relevanceOff();\n";
}
else
{
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').attr('disabled','disabled');\n";
$relParts[] = " $('#javatbd" . $sq['rowdivid'] . "$inputSelector').relevanceOff({ style : 'disabled' });\n";
}
}
$relParts[] = " relChange" . $arg['qid'] . "=true;\n";
Expand Down Expand Up @@ -7481,14 +7478,14 @@ static function GetRelevanceAndTailoringJavaScript()
}

if ($arg['hidden']) {
$relParts[] = " // This question should always be hidden\n";
$relParts[] = " $('#question" . $arg['qid'] . "').hide();\n";
$relParts[] = " // This question should always be hidden : not relevance, hidden question\n";
$relParts[] = " $('#question" . $arg['qid'] . "').addClass('hidden');\n";
}
else {
if (!($relevance == '' || $relevance == '1' || ($arg['result'] == true && $arg['numJsVars']==0)))
{
// In such cases, PHP will make the question visible by default. By not forcing a re-show(), template.js can hide questions with impunity
$relParts[] = " $('#question" . $arg['qid'] . "').show();\n";
$relParts[] = " $('#question" . $arg['qid'] . "').relevanceOn();\n";
if ($arg['type'] == 'S')
{
$relParts[] = " if($('#question" . $arg['qid'] . " div[id^=\"gmap_canvas\"]').length > 0)\n";
Expand Down Expand Up @@ -7520,7 +7517,7 @@ static function GetRelevanceAndTailoringJavaScript()
if( !($arg['hidden'] && $arg['type']=="*"))// Equation question type don't update visibility of group if hidden ( child of bug #08315).
$dynamicQinG[$arg['gseq']][$arg['qid']]=true;
$relParts[] = "else {\n";
$relParts[] = " $('#question" . $arg['qid'] . "').hide();\n";
$relParts[] = " $('#question" . $arg['qid'] . "').relevanceOff();\n";
$relParts[] = " if ($('#relevance" . $arg['qid'] . "').val()=='1') { relChange" . $arg['qid'] . "=true; }\n"; // only propagate changes if changing from relevant to irrelevant
$relParts[] = " $('#relevance" . $arg['qid'] . "').val('0');\n";
$relParts[] = "}\n";
Expand Down Expand Up @@ -7622,7 +7619,7 @@ static function GetRelevanceAndTailoringJavaScript()
// $jsParts[] = "\n// Process Relevance for Group " . $gr['gid'];
// $jsParts[] = ": { " . $gr['eqn'] . " }";
$jsParts[] = "\nif (" . $gr['relevancejs'] . ") {\n";
$jsParts[] = " $('#group-" . $gr['gseq'] . "').show();\n";
$jsParts[] = " $('#group-" . $gr['gseq'] . "').relevanceOn();\n";
$jsParts[] = " relChangeG" . $gr['gseq'] . "=true;\n";
$jsParts[] = " $('#relevanceG" . $gr['gseq'] . "').val(1);\n";

Expand Down Expand Up @@ -7659,7 +7656,7 @@ static function GetRelevanceAndTailoringJavaScript()
}

$jsParts[] = "}\nelse {\n";
$jsParts[] = " $('#group-" . $gr['gseq'] . "').hide();\n";
$jsParts[] = " $('#group-" . $gr['gseq'] . "').relevanceOff();\n";
$jsParts[] = " if ($('#relevanceG" . $gr['gseq'] . "').val()=='1') { relChangeG" . $gr['gseq'] . "=true; }\n";
$jsParts[] = " $('#relevanceG" . $gr['gseq'] . "').val(0);\n";
$jsParts[] = "}\n";
Expand Down Expand Up @@ -7709,11 +7706,11 @@ static function GetRelevanceAndTailoringJavaScript()
$relStatusTest = "($('#relevance" . implode("').val()=='1' || $('#relevance", array_keys($dynamicQidsInG)) . "').val()=='1')";

$jsParts[] = "\nif (" . $relStatusTest . ") {\n";
$jsParts[] = " $('#group-" . $gr['gseq'] . "').show();\n";
$jsParts[] = " $('#group-" . $gr['gseq'] . "').relevanceOn();\n";
$jsParts[] = " if ($('#relevanceG" . $gr['gseq'] . "').val()=='0') { relChangeG" . $gr['gseq'] . "=true; }\n";
$jsParts[] = " $('#relevanceG" . $gr['gseq'] . "').val(1);\n";
$jsParts[] = "}\nelse {\n";
$jsParts[] = " $('#group-" . $gr['gseq'] . "').hide();\n";
$jsParts[] = " $('#group-" . $gr['gseq'] . "').relevanceOff();\n";
$jsParts[] = " if ($('#relevanceG" . $gr['gseq'] . "').val()=='1') { relChangeG" . $gr['gseq'] . "=true; }\n";
$jsParts[] = " $('#relevanceG" . $gr['gseq'] . "').val(0);\n";
$jsParts[] = "}\n";
Expand Down
104 changes: 59 additions & 45 deletions application/helpers/qanda_helper.php
Expand Up @@ -696,55 +696,69 @@ function return_timer_script($aQuestionAttributes, $ia, $disable=null)
*/
function return_display_style($ia, $aQuestionAttributes, $thissurvey, $rowname)
{
$htmltbody2 = '';
$surveyid=$thissurvey['sid'];
/* Disabled actually : no inline style */
return "";
//~ $htmltbody2 = '';
//~ $surveyid=$thissurvey['sid'];
//~ if (isset($_SESSION["survey_{$surveyid}"]['relevanceStatus'][$rowname]) && !$_SESSION["survey_{$surveyid}"]['relevanceStatus'][$rowname])
//~ {
//~ // If using exclude_all_others, then need to know whether irrelevant rows should be hidden or disabled
//~ if (isset($aQuestionAttributes['exclude_all_others']))
//~ {
//~ $disableit=false;
//~ foreach(explode(';',trim($aQuestionAttributes['exclude_all_others'])) as $eo)
//~ {
//~ $eorow = $ia[1] . $eo;
//~ if ((!isset($_SESSION["survey_{$surveyid}"]['relevanceStatus'][$eorow]) || $_SESSION["survey_{$surveyid}"]['relevanceStatus'][$eorow])
//~ && (isset($_SESSION[$eorow]) && $_SESSION[$eorow] == "Y"))
//~ {
//~ $disableit = true;
//~ }
//~ }
//~ if ($disableit)
//~ {
//~ $htmltbody2 .= " disabled='disabled'";
//~ }
//~ else
//~ {
//~ if (!isset($aQuestionAttributes['array_filter_style']) || $aQuestionAttributes['array_filter_style'] == '0')
//~ {
//~ $htmltbody2 .= " style='display: none'";
//~ }
//~ else
//~ {
//~ $htmltbody2 .= " disabled='disabled'";
//~ }
//~ }
//~ }
//~ else
//~ {
//~ if (!isset($aQuestionAttributes['array_filter_style']) || $aQuestionAttributes['array_filter_style'] == '0')
//~ {
//~ $htmltbody2 .= " style='display: none'";
//~ }
//~ else
//~ {
//~ $htmltbody2 .= " disabled='disabled'";
//~ }
//~ }
//~ }

//~ return $htmltbody2;
}
/**
* @todo Return the Expression manager class of a subquestion
* @param integer $surveyid : the survey id
* @param string $subquestionName : the target name
* @param array $aQuestionAttributes : the attribute of the question (for array_filter_style actually)
*/
function getExpressionManagerClass($surveyid,$subquestionName,$aQuestionAttributes=null)
{
if (isset($_SESSION["survey_{$surveyid}"]['relevanceStatus'][$rowname]) && !$_SESSION["survey_{$surveyid}"]['relevanceStatus'][$rowname])
{
// If using exclude_all_others, then need to know whether irrelevant rows should be hidden or disabled
if (isset($aQuestionAttributes['exclude_all_others']))
{
$disableit=false;
foreach(explode(';',trim($aQuestionAttributes['exclude_all_others'])) as $eo)
{
$eorow = $ia[1] . $eo;
if ((!isset($_SESSION["survey_{$surveyid}"]['relevanceStatus'][$eorow]) || $_SESSION["survey_{$surveyid}"]['relevanceStatus'][$eorow])
&& (isset($_SESSION[$eorow]) && $_SESSION[$eorow] == "Y"))
{
$disableit = true;
}
}
if ($disableit)
{
$htmltbody2 .= " disabled='disabled'";
}
else
{
if (!isset($aQuestionAttributes['array_filter_style']) || $aQuestionAttributes['array_filter_style'] == '0')
{
$htmltbody2 .= " style='display: none'";
}
else
{
$htmltbody2 .= " disabled='disabled'";
}
}
}
else
{
if (!isset($aQuestionAttributes['array_filter_style']) || $aQuestionAttributes['array_filter_style'] == '0')
{
$htmltbody2 .= " style='display: none'";
}
else
{
$htmltbody2 .= " disabled='disabled'";
}
}
}

return $htmltbody2;
}
}

/**
* @param string $rowname
* @param string $valuename
Expand Down

0 comments on commit 5716190

Please sign in to comment.