Skip to content

Commit

Permalink
DEv: new editor language selector
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Jan 22, 2019
1 parent b3c4dad commit 16f12a2
Show file tree
Hide file tree
Showing 18 changed files with 18,229 additions and 12,322 deletions.
60 changes: 38 additions & 22 deletions application/controllers/admin/questionedit.php
Expand Up @@ -28,7 +28,6 @@
*/
class questionedit extends Survey_Common_Action
{

public function view($surveyid, $gid, $qid)
{
$aData = array();
Expand Down Expand Up @@ -89,30 +88,45 @@ public function view($surveyid, $gid, $qid)
**** All called via ajax
****/

public function getPossibleLanguages($iSurveyId){
public function getPossibleLanguages($iSurveyId)
{
$iSurveyId = (int) $iSurveyId;
$aLanguages = Survey::model()->findByPk($iSurveyId)->allLanguages;
$this->renderJSON($aLanguages);
}

public function getQuestionData($iQuestionId){
public function getQuestionData($iQuestionId)
{
$iQuestionId = (int) $iQuestionId;
$oQuestion = Question::model()->findByPk($iQuestionId);

$this->renderJSON(['question' => $oQuestion, 'i10n' => $oQuestion->questionL10ns]);
$aLanguages = [];
$aAllLanguages = getLanguageData(false, Yii::app()->session['adminlang']);
$aSurveyLanguages = $oQuestion->survey->getAllLanguages();
array_walk($aSurveyLanguages, function ($lngString) use (&$aLanguages, $aAllLanguages) {
$aLanguages[$lngString] = $aAllLanguages[$lngString]['description'];
});
$this->renderJSON([
'question' => $oQuestion,
'i10n' => $oQuestion->questionL10ns,
'languages' => $aLanguages,
'mainLanguage' => $oQuestion->survey->language
]);
}

public function getQuestionAttributeData($iQuestionId){
public function getQuestionAttributeData($iQuestionId)
{
$iQuestionId = (int) $iQuestionId;
$aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($iQuestionId);
$this->renderJSON($aQuestionAttributes);
}

public function getQuestionTypeList() {
public function getQuestionTypeList()
{
$this->renderJSON(QuestionType::modelsAttributes());
}

public function getGeneralOptions($iQuestionId, $sQuestionType=null){
public function getGeneralOptions($iQuestionId, $sQuestionType=null)
{
$oQuestion = Question::model()->findByPk($iQuestionId);
$this->renderJSON($oQuestion->getDataSetObject()->getGeneralSettingsArray(null, $sQuestionType));
}
Expand All @@ -126,18 +140,19 @@ public function getGeneralOptions($iQuestionId, $sQuestionType=null){
*
* @return void
*/
public function getRenderedPreview($iQuestionId, $sLanguage, $root=false) {
public function getRenderedPreview($iQuestionId, $sLanguage, $root=false)
{
$root = (bool) $root;
$oQuestion = Question::model()->findByPk($iQuestionId);

$changedText = App()->request->getPost('changedText', []);
$changedType = App()->request->getPost('changedType', $oQuestion->type);

if($changedText !== []) {
if ($changedText !== []) {
Yii::app()->session['edit_'.$iQuestionId.'_changedText'] = $changedText;
} else {
$changedText = isset(Yii::app()->session['edit_'.$iQuestionId.'_changedText'])
? Yii::app()->session['edit_'.$iQuestionId.'_changedText']
$changedText = isset(Yii::app()->session['edit_'.$iQuestionId.'_changedText'])
? Yii::app()->session['edit_'.$iQuestionId.'_changedText']
: [];
}

Expand Down Expand Up @@ -169,16 +184,16 @@ public function getRenderedPreview($iQuestionId, $sLanguage, $root=false) {
'number' => $oQuestion->question_order,
'code' => $oQuestion->title,
'text' => isset($changedText['question']) ? $changedText['question'] : $oQuestion->questionL10ns[$sLanguage]->question,
'help' => [
'show' => true,
'text' => ( isset($changedText['help']) ? $changedText['help'] : $oQuestion->questionL10ns[$sLanguage]->help )
'help' => [
'show' => true,
'text' => (isset($changedText['help']) ? $changedText['help'] : $oQuestion->questionL10ns[$sLanguage]->help)
],
]
);
$oTemplate = Template::model()->getInstance($oQuestion->survey->template);
Yii::app()->twigRenderer->renderTemplateForQuestionEditPreview(
'/subviews/survey/question_container.twig',
['aSurveyInfo' => $aSurveyInfo, 'aQuestion' => $aQuestion, 'session' => $_SESSION],
'/subviews/survey/question_container.twig',
['aSurveyInfo' => $aSurveyInfo, 'aQuestion' => $aQuestion, 'session' => $_SESSION],
$root
);

Expand All @@ -188,13 +203,15 @@ public function getRenderedPreview($iQuestionId, $sLanguage, $root=false) {

/**
* Method to render an array as a json document
*
*
* @param array $aData
* @return void
*/
protected function renderJSON($aData){
if(Yii::app()->getConfig('debug') > 0)
protected function renderJSON($aData)
{
if (Yii::app()->getConfig('debug') > 0) {
$aData['debug'] = [$_POST, $_GET];
}

echo Yii::app()->getController()->renderPartial('/admin/super/_renderJson', ['data' => $aData], true, false);
return;
Expand All @@ -211,5 +228,4 @@ protected function _renderWrappedTemplate($sAction = 'survey/Question2', $aViewU
{
parent::_renderWrappedTemplate($sAction, $aViewUrls, $aData, $sRenderFile);
}

}
}
43 changes: 25 additions & 18 deletions application/models/QuestionBaseDataSet.php
Expand Up @@ -96,6 +96,7 @@ public function getQuestionThemeOption()
'formElementName' => false, //false means identical to id
'formElementHelp' => gT("Use a customized question theme for this question"),
'formElement' => 'select',
'formElementValue' => isset($aQuestionTemplateAttributes['value']) ? $aQuestionTemplateAttributes['value'] : '',
'formElementOptions' => [
'classes' => ['form-control'],
'options' => $aOptionsArray,
Expand Down Expand Up @@ -134,6 +135,7 @@ function ($oQuestionGroup) {
'formElementName' => false,
'formElementHelp' => gT("If you want to change the question group this question is in."),
'formElement' => 'select',
'formElementValue' => $this->oQuestion->gid,
'formElementOptions' => [
'classes' => ['form-control'],
'options' => $aGroupOptions,
Expand All @@ -150,14 +152,15 @@ public function getOtherSwitch()
'formElementId' => 'other',
'formElementName' => false,
'formElementHelp' => gT('Activate the "other" option for your question'),
'formElement' => 'switcher',
'formElement' => 'checkboxswitch',
'formElementValue' => $this->oQuestion->other == 'Y',
'formElementOptions' => [
'classes' => [],
'switchData' => [
'on-text' => "On",
'off-text' => "Off",
'on-color' => "primary",
'off-color' => "warning",
'onText' => gT("On"),
'offText' => gT("Off"),
'onColor' => "primary",
'offColor' => "warning",
'size' => "small",
],
],
Expand All @@ -173,14 +176,15 @@ public function getMandatorySwitch()
'formElementId' => 'mandatory',
'formElementName' => false,
'formElementHelp' => gT('Makes this question mandatory in your survey'),
'formElement' => 'switcher',
'formElement' => 'checkboxswitch',
'formElementValue' => $this->oQuestion->mandatory == 'Y',
'formElementOptions' => [
'classes' => [],
'switchData' => [
'on-text' => "On",
'off-text' => "Off",
'on-color' => "primary",
'off-color' => "warning",
'onText' => gT("On"),
'offText' => gT("Off"),
'onColor' => "primary",
'offColor' => "warning",
'size' => "small",
],
],
Expand All @@ -190,6 +194,7 @@ public function getMandatorySwitch()

public function getRelevanceEquationInput()
{
$inputType = 'textarea';
$relevanceIntputHtml = ''
.'<div class="input-group">
<div class="input-group-addon">{</div>
Expand All @@ -200,6 +205,8 @@ public function getRelevanceEquationInput()
.'<div class="input-group-addon">}</div>'
.'</div>';
if (count($this->oQuestion->conditions) > 0) {
$inputType = 'text';
$content = gT("Note: You can't edit the relevance equation because there are currently conditions set for this question.");
$relevanceIntputHtml .= '<div class="help-block text-warning">'
. gT("Note: You can't edit the relevance equation because there are currently conditions set for this question.")
.'</div>';
Expand All @@ -210,12 +217,11 @@ public function getRelevanceEquationInput()
'title' => gT('Relevance equation'),
'formElementId' => 'relevance',
'formElementName' => false,
'formElementHelp' => (count($this->oQuestion->conditions)>0
? gT("Note: You can't edit the relevance equation because there are currently conditions set for this question.")
: gT("The relevance equation can be used to add branching logic. This is a rather advanced topic. If you are unsure, just leave it be.")),
'formElementHelp' => (count($this->oQuestion->conditions)>0 ? '' :gT("The relevance equation can be used to add branching logic. This is a rather advanced topic. If you are unsure, just leave it be.")),
'formElement' => 'textarea',
'formElementValue' => $this->oQuestion->relevance,
'formElementOptions' => [
'classes' => 'form-control',
'classes' => ['form-control'],
'attributes' => [
'rows' => 1,
'readonly' => count($this->oQuestion->conditions)>0
Expand All @@ -232,14 +238,15 @@ public function getRelevanceEquationInput()
public function getValidationInput()
{
return [
'name' => 'RelevanceEquation',
'title' => gT('Relevance equation'),
'name' => 'Validation',
'title' => gT('Input validation'),
'formElementId' => 'preg',
'formElementName' => false,
'formElementHelp' => gT('You can add any regular expression based validation in here'),
'formElement' => 'input',
'formElement' => 'textinput',
'formElementValue' => $this->oQuestion->preg,
'formElementOptions' => [
'classes' => 'form-control',
'classes' => ['form-control'],
'inputGroup' => [
'prefix' => 'RegExp',
]
Expand Down
6 changes: 6 additions & 0 deletions assets/packages/questioneditor/build/lsquestioneditor.css
Expand Up @@ -14,3 +14,9 @@

#advancedQuestionEditor .ck.ck-content {
min-height: 10rem; }

#advancedQuestionEditor .question-option-general-container .question-option-general-setting-block {
margin: 0.25rem 0 0.5rem 0; }
#advancedQuestionEditor .question-option-general-container .question-option-general-setting-block .question-option-help {
margin: 0.5rem 0;
padding: .75rem; }

0 comments on commit 16f12a2

Please sign in to comment.