Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed issue #14194: Datepicker not working with user theme
Dev: must create a package for date question, but since expressions is loaded
Dev: on public survey …
  • Loading branch information
Shnoulle committed Nov 28, 2018
1 parent 6743dd9 commit 998ad23
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 178 deletions.
2 changes: 2 additions & 0 deletions application/config/packages.php
Expand Up @@ -31,6 +31,8 @@
),
'depends' => array(
'jquery',
'moment', // Used by LEMval function
'decimalcustom', // Use by fixnum_checkconditions
)
),
/* For public template functionnality */
Expand Down
177 changes: 177 additions & 0 deletions assets/packages/expressions/em_javascript.js
Expand Up @@ -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
Expand Down
178 changes: 0 additions & 178 deletions assets/scripts/survey_runtime.js
Expand Up @@ -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
Expand Down

0 comments on commit 998ad23

Please sign in to comment.