From 998ad23c4d395ade6d381bfce34b5cfc34bf0f29 Mon Sep 17 00:00:00 2001 From: Denis Chenu Date: Wed, 28 Nov 2018 14:30:48 +0100 Subject: [PATCH] =?UTF-8?q?Fixed=20issue=20#14194:=20Datepicker=20not=20wo?= =?UTF-8?q?rking=20with=20user=20theme=20Dev:=20must=20create=20a=20packag?= =?UTF-8?q?e=20for=20date=20question,=20but=20since=20expressions=20is=20l?= =?UTF-8?q?oaded=20Dev:=20on=20public=20survey=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/config/packages.php | 2 + assets/packages/expressions/em_javascript.js | 177 ++++++++++++++++++ assets/scripts/survey_runtime.js | 178 ------------------- 3 files changed, 179 insertions(+), 178 deletions(-) diff --git a/application/config/packages.php b/application/config/packages.php index 501bbce1ea1..191778b1918 100644 --- a/application/config/packages.php +++ b/application/config/packages.php @@ -31,6 +31,8 @@ ), 'depends' => array( 'jquery', + 'moment', // Used by LEMval function + 'decimalcustom', // Use by fixnum_checkconditions ) ), /* For public template functionnality */ diff --git a/assets/packages/expressions/em_javascript.js b/assets/packages/expressions/em_javascript.js index f33718ae6b5..50ca2297576 100644 --- a/assets/packages/expressions/em_javascript.js +++ b/assets/packages/expressions/em_javascript.js @@ -17,7 +17,184 @@ * Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io) * and Contributors (http://phpjs.org/authors) */ +/** + * checkconditions : javascript function attach to some element + * Launch ExprMgr_process_relevance_and_tailoring with good value + * @todo : move this directly to event + */ +function checkconditions(value, name, type, evt_type) +{ + if (typeof evt_type === 'undefined') + { + evt_type = 'onchange'; + } + if (type == 'radio' || type == 'select-one') + { + $('#java'+name).val(value); + } + else if (type == 'checkbox') + { + if ($('#answer'+name).is(':checked')) + { + $('#java'+name).val('Y'); + } else + { + $('#java'+name).val(''); + } + } + else if (type == 'text' && name.match(/other$/)) + { + $('#java'+name).val(value); + } + + aQuestionsWithDependencies = $('#aQuestionsWithDependencies').data('qids'); + var questionCode; + if(typeof name !== 'undefined') { + var parts = name.split('X'); + questionCode = parts[2]; + var LEMvarNameAttr = LEMvarNameAttr || {}; + if (LEMvarNameAttr['java' + name] != undefined) { + questionCode = '' + LEMvarNameAttr['java' + name].qid; + } + } + + /* + // STILL NOT WORKING !!!!! + // But we're getting closer... + var $isRelevant = $.inArray(questionCode, aQuestionsWithDependencies);// NEED TO ADD THE QUESTIONS WITH CONDITIONS BEFORE WE CAN USE IT !!!! + if($.isFunction(window.ExprMgr_process_relevance_and_tailoring ) && $isRelevant!=-1) { + ExprMgr_process_relevance_and_tailoring(evt_type,name,type); + }*/ + try{ + ExprMgr_process_relevance_and_tailoring(evt_type,name,type); + } catch(e) { console.ls.error(e); } +} + +/** + * fixnum_checkconditions : javascript function attach to some element + * Update the answer of the user to be numeric and launch checkconditions + * + * Also checks if any of the arrow keys is pressed to avoid unecessary hassle. + * @todo : move this directly to event + */ +function fixnum_checkconditions(value, name, type, evt_type, intonly) +{ + if(window.event){ + var keyPressed = window.event.keyCode || 0; + if( + keyPressed == 37 //left arrow + || keyPressed == 39 //right arrow + ){return false; } + } + + var decimalValue; + var newval = new String(value); + var checkNumericRegex = new RegExp(/^(-)?[0-9]*(,|\.|)[0-9]*$/); + var cleansedValue = newval.replace(numRegex,''); + /** + * If have to use parsed value. + */ + if(!bNumRealValue) + { + if(checkNumericRegex.test(value)) { + try{ + decimalValue = new Decimal(cleansedValue); + } catch(e){ + try{ + decimalValue = new Decimal(cleansedValue.replace(',','.')); + } catch(e){ + decimalValue = new Decimal(NaN); + } + } + + if (typeof intonly !=='undefined' && intonly==1) { + newval = decimalValue.trunc(); + } + } else { + newval = cleansedValue; + } + + } + + /** + * If have to fix numbers automatically. + */ + if(bFixNumAuto && (newval != "")) + { + if(window.correctNumberField!=null) { + clearTimeout(window.correctNumberField); + window.correctNumberField = null; + } + + var addition = ""; + if(cleansedValue && cleansedValue.split("").pop().match(/(,)|(\.)/)){ + addition = cleansedValue.split("").pop(); + } + + var matchFollowingZeroes = cleansedValue.match(/^-?([0-9])*(,|\.)(0+)$/); + if(matchFollowingZeroes){ + addition = LEMradix+matchFollowingZeroes[3]; + } + if(decimalValue == undefined){ + try{ + decimalValue = new Decimal(cleansedValue); + } catch(e){ + try{ + decimalValue = new Decimal(cleansedValue.replace(',','.')); + } catch(e){ + decimalValue = new Decimal(NaN); + + } + } + } + + /** + * Work on length of the number + * Avoid numbers longer than 20 characters before the decimal separator and 10 after the decimal separator. + */ + // Treat decimal part, if there is one. + // Trim after 10th decimal if larger than 10 decimals. + if(decimalValue.dp()>10){ + decimalValue.toDecimalPlaces(10); + } + + /** + * Set display value + */ + displayVal = decimalValue.toString(); + if (displayVal=='NaN') + { + newval=displayVal; + displayVal=value; + } + else{ + if(LEMradix==",") + displayVal = displayVal.replace(/\./,','); + + newval = displayVal+addition + + if (name.match(/other$/)) { + if($('#answer'+name+'text').val() != newval){ + $('#answer'+name+'text').val(newval); + } + } + + if($('#answer'+name).val() != newval){ + window.correctNumberField = setTimeout(function(){$('#answer'+name).val(newval);}, 400); + } + } + } + + /** + * Check conditions + */ + if (typeof evt_type === 'undefined') + { + evt_type = 'onchange'; + } + checkconditions(newval, name, type, evt_type); +} /** * Default event to trigger on answer part * Launch function according to anser-item type diff --git a/assets/scripts/survey_runtime.js b/assets/scripts/survey_runtime.js index 37b6cd6bc22..62e9b4038bc 100644 --- a/assets/scripts/survey_runtime.js +++ b/assets/scripts/survey_runtime.js @@ -76,184 +76,6 @@ function setJsVar(){ intRegex = new RegExp('[^-0-9]','g'); } -/** - * checkconditions : javascript function attach to some element - * Launch ExprMgr_process_relevance_and_tailoring with good value - */ -function checkconditions(value, name, type, evt_type) -{ - if (typeof evt_type === 'undefined') - { - evt_type = 'onchange'; - } - if (type == 'radio' || type == 'select-one') - { - $('#java'+name).val(value); - } - else if (type == 'checkbox') - { - if ($('#answer'+name).is(':checked')) - { - $('#java'+name).val('Y'); - } else - { - $('#java'+name).val(''); - } - } - else if (type == 'text' && name.match(/other$/)) - { - $('#java'+name).val(value); - } - - aQuestionsWithDependencies = $('#aQuestionsWithDependencies').data('qids'); - - var questionCode; - if(typeof name !== 'undefined') { - var parts = name.split('X'); - questionCode = parts[2]; - var LEMvarNameAttr = LEMvarNameAttr || {}; - if (LEMvarNameAttr['java' + name] != undefined) { - questionCode = '' + LEMvarNameAttr['java' + name].qid; - } - } - - /* - // STILL NOT WORKING !!!!! - // But we're getting closer... - var $isRelevant = $.inArray(questionCode, aQuestionsWithDependencies);// NEED TO ADD THE QUESTIONS WITH CONDITIONS BEFORE WE CAN USE IT !!!! - if($.isFunction(window.ExprMgr_process_relevance_and_tailoring ) && $isRelevant!=-1) { - ExprMgr_process_relevance_and_tailoring(evt_type,name,type); - }*/ - try{ - ExprMgr_process_relevance_and_tailoring(evt_type,name,type); - } catch(e) { console.ls.error(e); } -} - -/** - * fixnum_checkconditions : javascript function attach to some element - * Update the answer of the user to be numeric and launch checkconditions - * - * Also checks if any of the arrow keys is pressed to avoid unecessary hassle. - */ -function fixnum_checkconditions(value, name, type, evt_type, intonly) -{ - if(window.event){ - var keyPressed = window.event.keyCode || 0; - if( - keyPressed == 37 //left arrow - || keyPressed == 39 //right arrow - ){return false; } - } - - var decimalValue; - var newval = new String(value); - var checkNumericRegex = new RegExp(/^(-)?[0-9]*(,|\.|)[0-9]*$/); - var cleansedValue = newval.replace(numRegex,''); - /** - * If have to use parsed value. - */ - if(!bNumRealValue) - { - if(checkNumericRegex.test(value)) { - try{ - decimalValue = new Decimal(cleansedValue); - } catch(e){ - try{ - decimalValue = new Decimal(cleansedValue.replace(',','.')); - } catch(e){ - decimalValue = new Decimal(NaN); - } - } - - if (typeof intonly !=='undefined' && intonly==1) { - newval = decimalValue.trunc(); - } - } else { - newval = cleansedValue; - } - - } - - /** - * If have to fix numbers automatically. - */ - if(bFixNumAuto && (newval != "")) - { - if(window.correctNumberField!=null) { - clearTimeout(window.correctNumberField); - window.correctNumberField = null; - } - - var addition = ""; - if(cleansedValue && cleansedValue.split("").pop().match(/(,)|(\.)/)){ - addition = cleansedValue.split("").pop(); - } - - var matchFollowingZeroes = cleansedValue.match(/^-?([0-9])*(,|\.)(0+)$/); - if(matchFollowingZeroes){ - addition = LEMradix+matchFollowingZeroes[3]; - } - if(decimalValue == undefined){ - try{ - decimalValue = new Decimal(cleansedValue); - } catch(e){ - try{ - decimalValue = new Decimal(cleansedValue.replace(',','.')); - } catch(e){ - decimalValue = new Decimal(NaN); - - } - } - } - - /** - * Work on length of the number - * Avoid numbers longer than 20 characters before the decimal separator and 10 after the decimal separator. - */ - // Treat decimal part, if there is one. - // Trim after 10th decimal if larger than 10 decimals. - if(decimalValue.dp()>10){ - decimalValue.toDecimalPlaces(10); - } - - /** - * Set display value - */ - displayVal = decimalValue.toString(); - if (displayVal=='NaN') - { - newval=displayVal; - displayVal=value; - } - else{ - if(LEMradix==",") - displayVal = displayVal.replace(/\./,','); - - newval = displayVal+addition - - if (name.match(/other$/)) { - if($('#answer'+name+'text').val() != newval){ - $('#answer'+name+'text').val(newval); - } - } - - if($('#answer'+name).val() != newval){ - window.correctNumberField = setTimeout(function(){$('#answer'+name).val(newval);}, 400); - } - } - } - - /** - * Check conditions - */ - if (typeof evt_type === 'undefined') - { - evt_type = 'onchange'; - } - checkconditions(newval, name, type, evt_type); -} - - /** * Adapt cell to have a click on cell do a click on input:radio or input:checkbox (if unique) * Using delegate the can be outside document.ready (using .on is possible but on $(document) then : less readbale