From e290f5304722a50fdcb56e47da0911a822b79c90 Mon Sep 17 00:00:00 2001 From: markusfluer Date: Fri, 29 Jul 2016 10:59:28 +0200 Subject: [PATCH] Dev: Refactored to use official counting in answers/subquestions --- scripts/admin/answers.js | 15 +++++++++++---- scripts/admin/subquestions.js | 16 +++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/scripts/admin/answers.js b/scripts/admin/answers.js index 80edc520f36..edde7d7f633 100644 --- a/scripts/admin/answers.js +++ b/scripts/admin/answers.js @@ -749,20 +749,24 @@ function quickaddlabels(scale_id, addOrReplace, table_id) n = 1, numeric = true, codeAlphaPart = "", + currentCharacter, codeSigil = (codes[0] !== undefined ? codes[0].split("") : ("A01").split("")); while(numeric == true && n <= codeSigil.length){ - var currentCharacter = codeSigil.pop() // get the current character - if ( !isNaN(Number(currentCharacter)) ) // check if it's numerical + currentCharacter = codeSigil.pop() // get the current character + if ( !isNaN(Number(currentCharacter)) ) // check if it's numerical { numericSuffix = currentCharacter+""+numericSuffix; // store it in a string n++; } else { - codeAlphaPart = codeSigil.join("")+currentCharacter; $numeric = false; // At first non numeric character found, the loop is stoped } } + //Sometimes "0" is interpreted as NaN so test if it's just a missing Zero + if(isNaN(Number(currentCharacter))){ + codeSigil.push(currentCharacter); + } var tablerows = ""; for (var k in lsrows) { @@ -772,7 +776,10 @@ function quickaddlabels(scale_id, addOrReplace, table_id) if (thisrow.length<=languages.length) { var qCode = (parseInt(k)+(1+parseInt(allrows))); - thisrow.unshift(codeAlphaPart+qCode); + while(qCode.toString().length < numericSuffix.length){ + qCode = "0"+qCode; + } + thisrow.unshift( codeSigil.join('')+qCode); } else { diff --git a/scripts/admin/subquestions.js b/scripts/admin/subquestions.js index 075d0e11958..1c57588fa17 100644 --- a/scripts/admin/subquestions.js +++ b/scripts/admin/subquestions.js @@ -847,22 +847,24 @@ function quickaddlabels(scale_id, addOrReplace, table_id) var numericSuffix = '', n = 1, numeric = true, - codeAlphaPart = "", + currentCharacter, codeSigil = (codes[0] !== undefined ? codes[0].split("") : ("SQ0001").split("")); while(numeric == true && n <= codeSigil.length){ - var currentCharacter = codeSigil.pop() // get the current character - if ( !isNaN(Number(currentCharacter)) ) // check if it's numerical + currentCharacter = codeSigil.pop() // get the current character + if ( !isNaN(Number(currentCharacter)) ) // check if it's numerical { numericSuffix = currentCharacter+""+numericSuffix; // store it in a string n++; } else { - codeAlphaPart = codeSigil.join("")+currentCharacter; $numeric = false; // At first non numeric character found, the loop is stoped } } - codeSigil = codeSigil.join(""); + //Sometimes "0" is interpreted as NaN so test if it's just a missing Zero + if(isNaN(Number(currentCharacter))){ + codeSigil.push(currentCharacter); + } var tablerows = ""; for (var k in lsrows) { @@ -872,10 +874,10 @@ function quickaddlabels(scale_id, addOrReplace, table_id) if (thisrow.length<=languages.length) { var qCode = (parseInt(k)+(1+parseInt(allrows))); - while(qCode.length < numericSuffix.length){ + while(qCode.toString().length < numericSuffix.length){ qCode = "0"+qCode; } - thisrow.unshift(codeAlphaPart+qCode); + thisrow.unshift( codeSigil.join('')+qCode); } else {