Skip to content

Commit

Permalink
Dev: moved Question theme dropdown to General options on edit questio…
Browse files Browse the repository at this point in the history
…n page
  • Loading branch information
dominikvitt committed May 16, 2018
1 parent 08677d1 commit e8061f5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
23 changes: 20 additions & 3 deletions application/controllers/admin/questions.php
Expand Up @@ -1280,6 +1280,8 @@ public function index($sa, $surveyid, $gid, $qid = null)
$aData['eqrow'] = $eqrow;
$aData['surveyid'] = $surveyid;
$aData['gid'] = $gid;
$aData['aQuestionTemplateAttributes'] = Question::model()->getAdvancedSettingsWithValues($qid, $eqrow['type'], $surveyid)['question_template'];
$aData['aQuestionTemplateList'] = \QuestionTemplate::getQuestionTemplateList($eqrow['type']);

if (!$adding) {
$criteria = new CDbCriteria;
Expand Down Expand Up @@ -1676,8 +1678,8 @@ public function ajaxquestionattributes()
$aAttributesWithValues[$attribute['name']] = $attribute;
}
}

uasort($aAttributesWithValues, 'categorySort');
unset($aAttributesWithValues['question_template']);
$aAttributesPrepared = array();
foreach ($aAttributesWithValues as $aAttribute) {
// SET QUESTION TEMPLATE FORM ATTRIBUTES WHEN $question_template VARIABLE IS SET
Expand Down Expand Up @@ -1853,7 +1855,7 @@ public function ajaxValidate($surveyid, $qid = false)
echo CJSON::encode($oQuestion->getErrors());
Yii::app()->end();
}
/**
/**
* Todo : update whole view to use CActiveForm
*/
# protected function performAjaxValidation($model)
Expand All @@ -1863,7 +1865,22 @@ public function ajaxValidate($surveyid, $qid = false)
# echo CActiveForm::validate($model);
# Yii::app()->end();
# }
# }
# }

/**
* @param string $question_type
* @return string JSON data
*/
public function ajaxGetQuestionTemplateList()
{
$type = Yii::app()->request->getParam('type');
$questionTemplateList = \QuestionTemplate::getQuestionTemplateList($type);
if (YII_DEBUG)
header('Content-type: application/json');
echo CJSON::encode($questionTemplateList);
Yii::app()->end();
}

/**
* Renders template(s) wrapped in header and footer
*
Expand Down
23 changes: 23 additions & 0 deletions application/views/admin/survey/Question/editQuestion_view.php
Expand Up @@ -231,6 +231,29 @@
<?php endif; ?>
</div>
<!-- Question selector end -->

<div class="form-group" id="QuestionTemplateSelection">
<label class=" control-label" for='gid' title="<?php eT("Use a customized question theme for this question");?>"><?php eT("Question theme:"); ?></label>
<div class="">
<select id="question_template" name="question_template" class="form-control">
<?php
foreach ($aQuestionTemplateList as $code => $title) {
$selected = $aQuestionTemplateAttributes['value'] == $code ? 'selected' : '';
if(YII_DEBUG) {
echo sprintf("<option value='%s' %s>%s (code: %s)</option>", $code, $selected, $title, $code);
} else {
echo sprintf("<option value='%s' %s>%s</option>", $code, $selected, $title);
}

}
?>
</select>
<?php if ($activated == "Y"): ?>
<input type='hidden' name='gid' value='<?php echo $eqrow['gid'];?>' />
<?php endif; ?>
</div>
</div>

<div class="form-group">
<label class=" control-label" for='gid' title="<?php eT("Set question group");?>"><?php eT("Question group:"); ?></label>
<div class="">
Expand Down
Expand Up @@ -5,6 +5,7 @@

App()->getClientScript()->registerScript("EditQuestionView_basic_variables" ,"
var attr_url = '".$this->createUrl('admin/questions', array('sa' => 'ajaxquestionattributes'))."';
var get_question_template_options_url = '".$this->createUrl('admin/questions', array('sa' => 'ajaxGetQuestionTemplateList'))."';
var imgurl = '".Yii::app()->getConfig('imageurl')."';
var validateUrl = '".$sValidateUrl."';
var questionTypeArray = ".$qTypeOutput.";
Expand Down
17 changes: 16 additions & 1 deletion assets/scripts/admin/questions.js
Expand Up @@ -110,7 +110,7 @@ var QuestionFunctions = function () {

if(selectormodeclass == 'default' || selectormodeclass == 'full'){
//bind advanced selector
$('#selector__modal_select-question-type').on('hide.bs.modal', updatequestionattributes);
$('#selector__modal_select-question-type').on('hide.bs.modal', function(){updatequestionattributes(''); updateQuestionTemplateOptions();});
$('#selector__modal_select-question-type').on('show.bs.modal', function () {
var question_class = questionTypeArray[$('#question_type').val()].class;
$('#selector__question-type-select-modal_question-type-' + question_class).addClass('mark-as-selected').trigger('click').closest('div.panel-collapse').addClass('in');
Expand Down Expand Up @@ -222,6 +222,21 @@ function updatequestionattributes(question_template_name) {
});
}

function updateQuestionTemplateOptions() {
var type = $('#question_type').val();
$.ajax({
url: get_question_template_options_url,
data: {'type': type},
method: 'POST',
success: function (data) {
$("#question_template").html("");
$.each(data, function (key, title) {
$("#question_template").append("<option value="+key+">"+title+"</option>");
});
}
});
}

var qtypes = new Array();
var qnames = new Array();
var qhelp = new Array();
Expand Down

0 comments on commit e8061f5

Please sign in to comment.