Skip to content

Commit

Permalink
Dev: Revert "Fixed issue: Question selector not working on IE11"
Browse files Browse the repository at this point in the history
Dev: This reverts commit 51483fe.
  • Loading branch information
olleharstedt committed Jul 19, 2018
1 parent bbd09ce commit 2616d12
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 180 deletions.
2 changes: 1 addition & 1 deletion application/config/packages.php
Expand Up @@ -130,7 +130,7 @@
'devBaseUrl' => 'assets/packages/adminpanel/',
'basePath' => 'core.adminpanel',
'js' => array(
'build/lsadminpanel'.(($debug > 0) ? '.debug' : '.min').'.js',
'build/lsadminpanel'.(($debug > 0) ? '' : '.min').'.js',
'build/surveysettings'.$minVersion.'.js',
'build/hammer'.$minVersion.'.js'
),
Expand Down
6 changes: 1 addition & 5 deletions application/controllers/admin/questions.php
Expand Up @@ -1110,11 +1110,7 @@ public function newquestion($surveyid)

$aViewUrls = [];
$aViewUrls['editQuestion_view'][] = $aData;
App()->getClientScript()->registerScript("ZOrder-EditQuestionView_question_jsviews_".$surveyid.$eqrow['gid'].'new', "
if(window.questionFunctions) {
window.questionFunctions.OtherSelection('".$eqrow['type']."');
}
", LSYii_ClientScript::POS_POSTSCRIPT);
App()->getClientScript()->registerScript("EditQuestionView_question_jsviews_".$surveyid.$eqrow['gid'].'new', "OtherSelection('".$eqrow['type']."');", LSYii_ClientScript::POS_POSTSCRIPT);



Expand Down
Expand Up @@ -59,7 +59,7 @@
'selectedClass' => Question::getQuestionClass($eqrow['type']),
'onUpdate' => [
'value',
"console.ls.log(value); $('#question_type').val(value); window.questionFunctions.updatequestionattributes(''); window.questionFunctions.updateQuestionTemplateOptions();"
"console.ls.log(value); $('#question_type').val(value); updatequestionattributes(''); updateQuestionTemplateOptions();"
]
]
));
Expand Down
@@ -1,6 +1,2 @@
<?php
App()->getClientScript()->registerScript("ZOrder-EditQuestionView_question_jsviews" ,"
if(window.questionFunctions) {
window.questionFunctions.OtherSelection('".$type."');
}
", LSYii_ClientScript::POS_POSTSCRIPT );
App()->getClientScript()->registerScript("EditQuestionView_question_jsviews" ,"OtherSelection('".$type."');", LSYii_ClientScript::POS_POSTSCRIPT );
327 changes: 159 additions & 168 deletions assets/scripts/admin/questions.js
Expand Up @@ -12,13 +12,6 @@
var LS = LS || {
onDocumentReady: {}
};

var qtypes = new Array();
var qnames = new Array();
var qhelp = new Array();
var qcaption = new Array();


var QuestionFunctions = function () {

var
Expand Down Expand Up @@ -81,164 +74,7 @@ var QuestionFunctions = function () {
);
},

updatequestionattributes = function(question_template_name, oldQuestionTemplate) {

question_template_name = question_template_name || '';
oldQuestionTemplate = oldQuestionTemplate || '';

var type = $('#question_type').val();
window.questionFunctions.OtherSelection(type);

$('.loader-advancedquestionsettings').removeClass("hidden");
$('.panel-advancedquestionsettings').remove();

var selected_value = $("#question_type").val();

var postData = {
'qid': $('#qid').val(),
'question_type': selected_value,
'sid': $('input[name=sid]').val(),
'old_question_template': oldQuestionTemplate
};

if (Object.prototype.toString.call(question_template_name) == '[object String]'){
postData['question_template'] = question_template_name;
}

$.ajax({
url: attr_url,
data: postData,
method: 'POST',
success: function (data) {
$('#container-advanced-question-settings').html(data);
$('.loader-advancedquestionsettings').addClass("hidden");
if(question_template_name) {
//$('#collapse-cat1').collapse('toggle');
}

$('label[title]').qtip({
style: {
name: 'cream',
tip: true,
color: '#111111',
border: {
width: 1,
radius: 5,
color: '#EADF95'
}
},
position: {
adjust: {
screen: true,
scroll: true
},
corner: {
target: 'bottomRight'
}
},
show: {
effect: {
length: 50
}
}
});
renderBootstrapSwitch();
}
});
},

// selector is only set when this function is called from #question_template
updateQuestionTemplateOptions = function(selector) {
selector = selector || '';

var type = $('#question_type').val();
var template = $('#question_template').val();
$.ajax({
url: get_question_template_options_url,
data: {'type': type},
method: 'POST',
success: function (data) {
if ( data[template] != undefined ) {
$("#QuestionTemplatePreview img").attr('src', data[template]['preview']);
} else {
$("#QuestionTemplatePreview img").attr('src', data['core']['preview']);
}

if (selector === ''){ // selector is not called from #question_template
$("#question_template").html("");
$.each(data, function (key, value) {
$("#question_template").append("<option value="+key+">"+value.title+"</option>");
});
}
}
});
},
OtherSelection = function (QuestionType) {
if (QuestionType == undefined) {
//console.log('Error: OtherSelection: QuestionType must not be undefined');
return;
}
try{
if (QuestionType == '') {
QuestionType = document.getElementById('question_type').value;
}
if (QuestionType == 'M' || QuestionType == 'P' || QuestionType == 'L' || QuestionType == '!') {
document.getElementById('OtherSelection').style.display = '';
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == 'W' || QuestionType == 'Z') {
document.getElementById('OtherSelection').style.display = '';
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == '|') {
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = 'none';
} else if (QuestionType == 'F' || QuestionType == 'H') {
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == ':' || QuestionType == ';') {
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('Validation').style.display = '';
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == '1') {
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == 'S' || QuestionType == 'T' || QuestionType == 'U' || QuestionType == 'N' || QuestionType == '' || QuestionType == 'K') {
document.getElementById('Validation').style.display = '';
document.getElementById('OtherSelection').style.display = 'none';
if (document.getElementById('ON')) {
document.getElementById('ON').checked = true;
}
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == 'X') {
document.getElementById('Validation').style.display = 'none';
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('MandatorySelection').style.display = 'none';
} else if (QuestionType == 'Q') {
document.getElementById('Validation').style.display = '';
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
} else {
document.getElementById('OtherSelection').style.display = 'none';
if (document.getElementById('ON')) {
document.getElementById('ON').checked = true;
}
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
}

if (QuestionType == 'H'){ // hide relevance equation input for array by column question type until it is fixed
document.getElementById('relevanceContainer').style.display = 'none';
} else {
document.getElementById('relevanceContainer').style.display = '';
}
} catch(e) {
if(window.debugState.backend) console.ls.error(e);
}
},
getQuestionTypeImage = function (questioncode) {

var multiple = 1;
Expand Down Expand Up @@ -301,10 +137,7 @@ var QuestionFunctions = function () {

};
return {
init: init,
OtherSelection: OtherSelection,
updatequestionattributes : updatequestionattributes,
updateQuestionTemplateOptions : updateQuestionTemplateOptions
init: init
};
}

Expand All @@ -315,3 +148,161 @@ $(document).on('ready pjax:scriptcomplete', function () {
});


function updatequestionattributes(question_template_name = '', oldQuestionTemplate = '') {
var type = $('#question_type').val();
OtherSelection(type);

$('.loader-advancedquestionsettings').removeClass("hidden");
$('.panel-advancedquestionsettings').remove();

var selected_value = $("#question_type").val();

var postData = {
'qid': $('#qid').val(),
'question_type': selected_value,
'sid': $('input[name=sid]').val(),
'old_question_template': oldQuestionTemplate
};

if (Object.prototype.toString.call(question_template_name) == '[object String]'){
postData['question_template'] = question_template_name;
}

$.ajax({
url: attr_url,
data: postData,
method: 'POST',
success: function (data) {
$('#container-advanced-question-settings').html(data);
$('.loader-advancedquestionsettings').addClass("hidden");
if(question_template_name) {
//$('#collapse-cat1').collapse('toggle');
}

$('label[title]').qtip({
style: {
name: 'cream',
tip: true,
color: '#111111',
border: {
width: 1,
radius: 5,
color: '#EADF95'
}
},
position: {
adjust: {
screen: true,
scroll: true
},
corner: {
target: 'bottomRight'
}
},
show: {
effect: {
length: 50
}
}
});
renderBootstrapSwitch();
}
});
}

function updateQuestionTemplateOptions(selector = '') { // selector is only set when this function is called from #question_template
var type = $('#question_type').val();
var template = $('#question_template').val();
$.ajax({
url: get_question_template_options_url,
data: {'type': type},
method: 'POST',
success: function (data) {
if ( data[template] != undefined ) {
$("#QuestionTemplatePreview img").attr('src', data[template]['preview']);
} else {
$("#QuestionTemplatePreview img").attr('src', data['core']['preview']);
}

if (selector === ''){ // selector is not called from #question_template
$("#question_template").html("");
$.each(data, function (key, value) {
$("#question_template").append("<option value="+key+">"+value.title+"</option>");
});
}
}
});
}

var qtypes = new Array();
var qnames = new Array();
var qhelp = new Array();
var qcaption = new Array();


function OtherSelection(QuestionType) {
if (QuestionType == undefined) {
//console.log('Error: OtherSelection: QuestionType must not be undefined');
return;
}
try{
if (QuestionType == '') {
QuestionType = document.getElementById('question_type').value;
}
if (QuestionType == 'M' || QuestionType == 'P' || QuestionType == 'L' || QuestionType == '!') {
document.getElementById('OtherSelection').style.display = '';
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == 'W' || QuestionType == 'Z') {
document.getElementById('OtherSelection').style.display = '';
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == '|') {
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = 'none';
} else if (QuestionType == 'F' || QuestionType == 'H') {
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == ':' || QuestionType == ';') {
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('Validation').style.display = '';
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == '1') {
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == 'S' || QuestionType == 'T' || QuestionType == 'U' || QuestionType == 'N' || QuestionType == '' || QuestionType == 'K') {
document.getElementById('Validation').style.display = '';
document.getElementById('OtherSelection').style.display = 'none';
if (document.getElementById('ON')) {
document.getElementById('ON').checked = true;
}
document.getElementById('MandatorySelection').style.display = '';
} else if (QuestionType == 'X') {
document.getElementById('Validation').style.display = 'none';
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('MandatorySelection').style.display = 'none';
} else if (QuestionType == 'Q') {
document.getElementById('Validation').style.display = '';
document.getElementById('OtherSelection').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
} else {
document.getElementById('OtherSelection').style.display = 'none';
if (document.getElementById('ON')) {
document.getElementById('ON').checked = true;
}
document.getElementById('Validation').style.display = 'none';
document.getElementById('MandatorySelection').style.display = '';
}

if (QuestionType == 'H'){ // hide relevance equation input for array by column question type until it is fixed
document.getElementById('relevanceContainer').style.display = 'none';
} else {
document.getElementById('relevanceContainer').style.display = '';
}
} catch(e) {
if(window.debugState.backend) console.ls.error(e);
}
}

0 comments on commit 2616d12

Please sign in to comment.