Skip to content

Commit

Permalink
Fixed issue #17201: Easier switch between customized condition and co…
Browse files Browse the repository at this point in the history
…ndition designer (#1874)

Co-authored-by: encuestabizdevgit <devgit@encuesta.biz>
  • Loading branch information
gabrieljenik and encuestabizdevgit committed May 18, 2021
1 parent e8b6041 commit 85e16c6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
8 changes: 8 additions & 0 deletions application/controllers/QuestionAdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2458,6 +2458,8 @@ private function updateQuestionData(&$oQuestion, $aQuestionData)
}
}

$originalRelevance = $oQuestion->relevance;

$oQuestion->setAttributes($aQuestionData, false);
if ($oQuestion == null) {
throw new LSJsonException(
Expand All @@ -2480,6 +2482,12 @@ private function updateQuestionData(&$oQuestion, $aQuestionData)
true
);
}

// If relevance equation was manually edited, existing conditions must be cleared
if ($oQuestion->relevance != $originalRelevance && !empty($oQuestion->conditions)) {
Condition::model()->deleteAllByAttributes(['qid' => $oQuestion->qid]);
}

return $oQuestion;
}

Expand Down
6 changes: 5 additions & 1 deletion application/controllers/admin/conditionsaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ public function index($subaction, $iSurveyID = null, $gid = null, $qid = null)
$aData['sCurrentQuestionText'] = $questiontitle . ': ' . viewHelper::flatEllipsizeText($sCurrentFullQuestionText, true, '120');
//$aData['subaction'] = $subaction;
$aData['scenariocount'] = $scenariocount;
$aViewUrls['conditionslist_view'][] = $aData;
if (empty(trim($oQuestion->relevance)) || !empty($oQuestion->conditions)) {
$aViewUrls['conditionslist_view'][] = $aData;
}

if ($scenariocount > 0) {
App()->getClientScript()->registerScriptFile(App()->getConfig('adminscripts') . 'checkgroup.js', LSYii_ClientScript::POS_BEGIN);
Expand Down Expand Up @@ -600,6 +602,8 @@ public function index($subaction, $iSurveyID = null, $gid = null, $qid = null)
}
// If we have a condition, all ways reset the condition, this can fix old import (see #09344)
// LimeExpressionManager::UpgradeConditionsToRelevance(NULL,$qid);
} elseif(!empty(trim($oQuestion->relevance))) {
$aViewUrls['output'] = $this->getController()->renderPartial('/admin/conditions/customized_conditions', $aData, true);
} else {
// no condition ==> disable delete all conditions button, and display a simple comment
// no_conditions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __construct(Question $question)
{
if (count($question->conditions) > 0) {
$inputType = 'text';
$help = gT("Note: You can't edit the condition because there are currently conditions set for this question by the condition designer.");
$help = gT("Note: If you customize & save this condition you will not be able to use the condition editor for this, anymore.");
} else {
$inputType = 'textarea';
$help = gT("A condition can be used to add branching logic using ExpressionScript. Either edit it directly here or use the Condition designer.");
Expand All @@ -30,7 +30,7 @@ public function __construct(Question $question)
'classes' => ['form-control'],
'attributes' => [
'rows' => 1,
'readonly' => count($question->conditions) > 0
'data-has-conditions' => count($question->conditions) > 0
],
'inputGroup' => [
'prefix' => '{',
Expand Down
13 changes: 13 additions & 0 deletions application/views/admin/conditions/customized_conditions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* This is shown when the question has a customized relevance equation
*/
?>

<div class="row">
<div class="col-lg-12">
<div class="alert alert-warning">
<?php echo gT("Note: This question uses a customized condition. If you create a condition using this editor the current customized condition will be overwritten.");?>
</div>
</div>
</div>
9 changes: 9 additions & 0 deletions assets/scripts/admin/questionEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,13 @@ $(document).on('ready pjax:scriptcomplete', function () {
showAnswerOptionCodeUniqueError: createCheckUniqueFunction(languageJson.answeroptions.duplicateanswercode)
};

function showConditionsWarning(e) {
if (!$(this).data('hasConditions')) {
return;
}
$('#general-setting-help-relevance').show();
}

// Below, things run on pjax:scriptcomplete.

$('.answertable tbody').sortable({
Expand Down Expand Up @@ -1888,4 +1895,6 @@ $(document).on('ready pjax:scriptcomplete', function () {
alert('Internal error: qidInput is not an HTMLInputElement');
throw 'abort';
}

$('#relevance').on('keyup', showConditionsWarning);
});

0 comments on commit 85e16c6

Please sign in to comment.