From 51483fe0ca66b2bba09c85e5040921f3b0681361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fl=C3=BCr?= Date: Mon, 16 Jul 2018 13:45:15 +0200 Subject: [PATCH] Fixed issue: Question selector not working on IE11 --- application/config/packages.php | 2 +- application/controllers/admin/questions.php | 6 +- .../survey/Question/editQuestion_view.php | 2 +- .../Question/questionJavascript_view.php | 6 +- assets/scripts/admin/questions.js | 327 +++++++++--------- 5 files changed, 180 insertions(+), 163 deletions(-) diff --git a/application/config/packages.php b/application/config/packages.php index 6e13ac967d7..b3b0dd6394c 100644 --- a/application/config/packages.php +++ b/application/config/packages.php @@ -130,7 +130,7 @@ 'devBaseUrl' => 'assets/packages/adminpanel/', 'basePath' => 'core.adminpanel', 'js' => array( - 'build/lsadminpanel'.(($debug > 0) ? '' : '.min').'.js', + 'build/lsadminpanel'.(($debug > 0) ? '.debug' : '.min').'.js', 'build/surveysettings'.$minVersion.'.js', 'build/hammer'.$minVersion.'.js' ), diff --git a/application/controllers/admin/questions.php b/application/controllers/admin/questions.php index 6525783254b..e1dbdc587d1 100644 --- a/application/controllers/admin/questions.php +++ b/application/controllers/admin/questions.php @@ -1110,7 +1110,11 @@ public function newquestion($surveyid) $aViewUrls = []; $aViewUrls['editQuestion_view'][] = $aData; - App()->getClientScript()->registerScript("EditQuestionView_question_jsviews_".$surveyid.$eqrow['gid'].'new', "OtherSelection('".$eqrow['type']."');", LSYii_ClientScript::POS_POSTSCRIPT); + App()->getClientScript()->registerScript("ZOrder-EditQuestionView_question_jsviews_".$surveyid.$eqrow['gid'].'new', " + if(window.questionFunctions) { + window.questionFunctions.OtherSelection('".$eqrow['type']."'); + } + ", LSYii_ClientScript::POS_POSTSCRIPT); diff --git a/application/views/admin/survey/Question/editQuestion_view.php b/application/views/admin/survey/Question/editQuestion_view.php index 92e8fda7419..e384f89174b 100644 --- a/application/views/admin/survey/Question/editQuestion_view.php +++ b/application/views/admin/survey/Question/editQuestion_view.php @@ -59,7 +59,7 @@ 'selectedClass' => Question::getQuestionClass($eqrow['type']), 'onUpdate' => [ 'value', - "console.ls.log(value); $('#question_type').val(value); updatequestionattributes(''); updateQuestionTemplateOptions();" + "console.ls.log(value); $('#question_type').val(value); window.questionFunctions.updatequestionattributes(''); window.questionFunctions.updateQuestionTemplateOptions();" ] ] )); diff --git a/application/views/admin/survey/Question/questionJavascript_view.php b/application/views/admin/survey/Question/questionJavascript_view.php index ef4cc15cb92..f044f66c7eb 100644 --- a/application/views/admin/survey/Question/questionJavascript_view.php +++ b/application/views/admin/survey/Question/questionJavascript_view.php @@ -1,2 +1,6 @@ getClientScript()->registerScript("EditQuestionView_question_jsviews" ,"OtherSelection('".$type."');", LSYii_ClientScript::POS_POSTSCRIPT ); +App()->getClientScript()->registerScript("ZOrder-EditQuestionView_question_jsviews" ," +if(window.questionFunctions) { + window.questionFunctions.OtherSelection('".$type."'); +} +", LSYii_ClientScript::POS_POSTSCRIPT ); diff --git a/assets/scripts/admin/questions.js b/assets/scripts/admin/questions.js index 760b5731a5d..e4d87602cf9 100644 --- a/assets/scripts/admin/questions.js +++ b/assets/scripts/admin/questions.js @@ -12,6 +12,13 @@ var LS = LS || { onDocumentReady: {} }; + +var qtypes = new Array(); +var qnames = new Array(); +var qhelp = new Array(); +var qcaption = new Array(); + + var QuestionFunctions = function () { var @@ -74,7 +81,164 @@ 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(""); + }); + } + } + }); + }, + 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; @@ -137,7 +301,10 @@ var QuestionFunctions = function () { }; return { - init: init + init: init, + OtherSelection: OtherSelection, + updatequestionattributes : updatequestionattributes, + updateQuestionTemplateOptions : updateQuestionTemplateOptions }; } @@ -148,161 +315,3 @@ $(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(""); - }); - } - } - }); -} - -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); - } -}