Skip to content

Commit

Permalink
Dev: Refactored to use official counting in answers/subquestions
Browse files Browse the repository at this point in the history
  • Loading branch information
markusfluer committed Jul 29, 2016
1 parent 7c78912 commit e290f53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
15 changes: 11 additions & 4 deletions scripts/admin/answers.js
Expand Up @@ -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)
{
Expand All @@ -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
{
Expand Down
16 changes: 9 additions & 7 deletions scripts/admin/subquestions.js
Expand Up @@ -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)
{
Expand All @@ -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
{
Expand Down

0 comments on commit e290f53

Please sign in to comment.