Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed May 17, 2018
2 parents 3fbd949 + ff0ff76 commit 249d5ce
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 11 deletions.
24 changes: 21 additions & 3 deletions application/controllers/admin/questions.php
Expand Up @@ -1216,6 +1216,8 @@ public function index($sa, $surveyid, $gid, $qid = null)
$aData['oQuestion'] = $oQuestion;
$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 @@ -1570,6 +1572,7 @@ public function ajaxquestionattributes()
// INSERTING EACH OF THIS KEYS TO THE ARRAY IF KEYS ARE MISSING
if (empty($attribute['name'])){$attribute['name'] = 'default_theme_attribute_name';}
if (empty($attribute['readonly'])){$attribute['readonly'] = '';}
if (empty($attribute['default'])){$attribute['default'] = '';}
if (empty($attribute['readonly_when_active'])){$attribute['readonly_when_active'] = '';}
if (empty($attribute['value'])){$attribute['value'] = '';}
if (empty($attribute['i18n'])){$attribute['i18n'] = '';}
Expand All @@ -1581,8 +1584,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 @@ -1757,7 +1760,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 @@ -1767,7 +1770,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
4 changes: 2 additions & 2 deletions application/controllers/admin/themeoptions.php
Expand Up @@ -241,9 +241,9 @@ public function loadModel($id)
}


public function importManifest($templatename)
public function importManifest()
{
$templatename = sanitize_paranoid_string($templatename);
$templatename = Yii::app()->request->getPost('templatename');
if (Permission::model()->hasGlobalPermission('templates', 'update')) {
TemplateManifest::importManifest($templatename);
$this->getController()->redirect(array("admin/themeoptions"));
Expand Down
10 changes: 5 additions & 5 deletions application/models/TemplateManifest.php
Expand Up @@ -259,7 +259,6 @@ public function getTemplateURL()
public function getButtons()
{
$sEditorUrl = Yii::app()->getController()->createUrl('admin/themes/sa/view', array("templatename"=>$this->sTemplateName));
$sLoadUrl = Yii::app()->getController()->createUrl('admin/themeoptions/sa/importmanifest/', array("templatename"=>$this->sTemplateName));
$sDeleteUrl = Yii::app()->getController()->createUrl('admin/themeoptions/sa/deleteTemplate/', array("templatename"=>$this->sTemplateName));

// TODO: load to DB
Expand All @@ -275,13 +274,14 @@ class='btn btn-default btn-block'>

$sLoadLink = '';

$sLoadLink .= "<a
id='template_options_link_".$this->sTemplateName."'
href='".$sLoadUrl."'
$sLoadLink .= CHtml::form( array("/admin/themeoptions/sa/importmanifest/"), 'post',array('id'=>'frmínstalltheme','name'=>'frmínstalltheme')) .
"<input type='hidden' name='templatename' value='".$this->sTemplateName."'>
<button id='template_options_link_".$this->sTemplateName."'
class='btn btn-default btn-block'>
<span class='fa fa-download text-warning'></span>
".gT('Install')."
</a>";
</button>
</form>";

$sDeleteLink = "<a
id='template_options_link_".$this->sTemplateName."'
Expand Down
23 changes: 23 additions & 0 deletions application/views/admin/survey/Question/editQuestion_view.php
Expand Up @@ -239,6 +239,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 249d5ce

Please sign in to comment.