<commit_before>/**
 * Created by Reza on 2016-04-29.
 */

var parsed;
var testStorageName = 'testdata';
var questionNumber = 1;

var testName;
var testTime;
var gPercent;
var vgPercent;
var onlyGquestions;

var testNameArray = [];
var testTimeArray = [];
var gProcentArray = [];
var vgProcentArray = [];
var questionArray = [];
var answerArray = [];
var pointsArray = [];
var correctAnswersArray = [];
var questionTypeArray = [];
var isChecked = false;
var answerNotChecked = false;

var questionText;
var questionType;
var numberOfAnswers;
var answers = [];
var answer1, answer2, answer3, answer4, answer5, answer6;
var answer1Radio, answer2Radio, answer3Radio, answer4Radio;
var answer1Chb, answer2Chb, answer3Chb, answer4Chb, answer5Chb, answer6Chb;
var correctAnswer;
var corrAnsCheckArray = [];
var points;
var autoCorrect = [];

var out = document.getElementById('output');

$(document).ready(function () {
    document.getElementById("createQuestionForm").style.visibility = "hidden";
    document.getElementById("saveTest").style.visibility = "hidden";
});

// TODO saveTestInfo
function saveTestInfo() {

    testName = document.getElementById('testName').value;
    testTime = document.getElementById('testTime').value;
    gPercent = +document.getElementById('gPercent').value;
    vgPercent = +document.getElementById('vgPercent').value;
    onlyGquestions = document.getElementById('onlyGId').checked;

    testNameArray.push(testName);
    testTimeArray.push(testTime);
    gProcentArray.push(gPercent);
    vgProcentArray.push(vgPercent);
    // TODO onlyGquestions används inte vidare i koden, om vgpercent = null bara G-frågor?

    if (onlyGquestions) {
        document.getElementById("createQuestionForm").style.visibility = "visible";
        document.getElementById("questionId").innerHTML = "Fråga " + questionNumber;
    } else if (vgPercent <= gPercent) {
        alert("Gränsen för VG måste vara högre än för G." + "\nG-gräns: " + gPercent +
            "\nVG-gräns: " + vgPercent);
    } else {
        document.getElementById("createQuestionForm").style.visibility = "visible";
        document.getElementById("questionId").innerHTML = "Fråga " + questionNumber;
    }

    parsed = JSON.parse(localStorage.getItem(testStorageName));

    if (parsed == null) {
        var obj = {
            "testName": [["test1"]],
            "testTime": [[40]],
            "questionString": [[["huvudstad?"], ["Städer?"]]],
            "answerType": [[["singleChoice"], ["multiChoice"]]],
            "points": [[1], [2]],
            "answers": [[["Stockholm", "Göteborg", "Malmö", "Luleå"], ["Göteborg", "Stenköping", "London"]]],
            "correctAnswers": [["Stockholm"], [["Göteborg"], ["London"]]],
            "gProcent": [[60]],
            "vgProcent": [[80]],
            "autoCorrect": [[1]]
        }
        var objdata = JSON.stringify(obj);
        localStorage.setItem(testStorageName, objdata);
    }

}
// TODO saveQuestion
function saveQuestion() {

    questionText = document.getElementById('questionText').value;
    questionType = document.getElementById('typeId').options[document.getElementById('typeId').selectedIndex].value;
    points = document.getElementById('maxPoint').value;
    isChecked = false;

    questionArray.push(questionText);
    questionTypeArray.push(questionType);
    pointsArray.push(points);

    if (questionType === 'singleChoice') {
        numberOfAnswers = document.getElementById('numberOfAnswersSC').value;
        if (numberOfAnswers === 'twoSC') {
            answer1 = document.getElementById('answerSC12text').value;
            answer2 = document.getElementById('answerSC22text').value;
            answer1Radio = document.getElementById('answerSC12radio');
            answer2Radio = document.getElementById('answerSC22radio');
            if (answer1Radio.checked) {
                correctAnswer = answer1;
                isChecked = true;
            }
            else if (answer2Radio.checked) {
                correctAnswer = answer2;
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            correctAnswersArray.push(correctAnswer);
        }
        else if (numberOfAnswers === 'threeSC') {
            answer1 = document.getElementById('answerSC13text').value;
            answer2 = document.getElementById('answerSC23text').value;
            answer3 = document.getElementById('answerSC33text').value;
            answer1Radio = document.getElementById('answerSC13radio');
            answer2Radio = document.getElementById('answerSC23radio');
            answer3Radio = document.getElementById('answerSC33radio');
            if (answer1Radio.checked) {
                correctAnswer = answer1;
                isChecked = true;
            }
            else if (answer2Radio.checked) {
                correctAnswer = answer2;
                isChecked = true;
            }
            else if (answer3Radio.checked) {
                correctAnswer = answer3;
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            correctAnswersArray.push(correctAnswer);
        }
        else if (numberOfAnswers === 'fourSC') {
            answer1 = document.getElementById('answerSC14text').value;
            answer2 = document.getElementById('answerSC24text').value;
            answer3 = document.getElementById('answerSC34text').value;
            answer4 = document.getElementById('answerSC44text').value;
            answer1Radio = document.getElementById('answerSC14radio');
            answer2Radio = document.getElementById('answerSC24radio');
            answer3Radio = document.getElementById('answerSC34radio');
            answer4Radio = document.getElementById('answerSC44radio');
            if (answer1Radio.checked) {
                correctAnswer = answer1;
                isChecked = true;
            }
            else if (answer2Radio.checked) {
                correctAnswer = answer2;
                isChecked = true;
            }
            else if (answer3Radio.checked) {
                correctAnswer = answer3;
                isChecked = true;
            }
            else if (answer4Radio.checked) {
                correctAnswer = answer4;
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            answers.push(answer4);
            correctAnswersArray.push(correctAnswer);
        }
    }
    else if (questionType === 'multiChoice') {
        numberOfAnswers = document.getElementById('numberOfAnswersMC').value;

        if (numberOfAnswers === 'twoMC') {
            answer1 = document.getElementById('answerMC12text').value;
            answer2 = document.getElementById('answerMC22text').value;
            answer1Chb = document.getElementById('answerMC12check');
            answer2Chb = document.getElementById('answerMC22check');
            if (answer1Chb.checked) {
                corrAnsCheckArray.push(answer1);
                isChecked = true;
            }
            if (answer2Chb.checked) {
                corrAnsCheckArray.push(answer2);
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            correctAnswersArray.push(corrAnsCheckArray);

        }
        else if (numberOfAnswers === 'threeMC') {
            answer1 = document.getElementById('answerMC13text').value;
            answer2 = document.getElementById('answerMC23text').value;
            answer3 = document.getElementById('answerMC33text').value;
            answer1Chb = document.getElementById('answerMC13check');
            answer2Chb = document.getElementById('answerMC23check');
            answer3Chb = document.getElementById('answerMC33check');
            if (answer1Chb.checked) {
                corrAnsCheckArray.push(answer1);
                isChecked = true;
            }
            if (answer2Chb.checked) {
                corrAnsCheckArray.push(answer2);
                isChecked = true;
            }
            if (answer3Chb.checked) {
                corrAnsCheckArray.push(answer3);
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            correctAnswersArray.push(corrAnsCheckArray);

        }
        else if (numberOfAnswers === 'fourMC') {
            answer1 = document.getElementById('answerMC14text').value;
            answer2 = document.getElementById('answerMC24text').value;
            answer3 = document.getElementById('answerMC34text').value;
            answer4 = document.getElementById('answerMC44text').value;
            answer1Chb = document.getElementById('answerMC14check');
            answer2Chb = document.getElementById('answerMC24check');
            answer3Chb = document.getElementById('answerMC34check');
            answer4Chb = document.getElementById('answerMC44check');
            if (answer1Chb.checked) {
                corrAnsCheckArray.push(answer1);
                isChecked = true;
            }
            if (answer2Chb.checked) {
                corrAnsCheckArray.push(answer2);
                isChecked = true;
            }
            if (answer3Chb.checked) {
                corrAnsCheckArray.push(answer3);
                isChecked = true;
            }
            if (answer4Chb.checked) {
                corrAnsCheckArray.push(answer4);
                isChecked = true;
            }
            isChecked = (answer1Chb || answer2Chb || answer3Chb || answer4Chb);
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            answers.push(answer4);

        }
        else if (numberOfAnswers === 'fiveMC') {
            answer1 = document.getElementById('answerMC15text').value;
            answer2 = document.getElementById('answerMC25text').value;
            answer3 = document.getElementById('answerMC35text').value;
            answer4 = document.getElementById('answerMC45text').value;
            answer5 = document.getElementById('answerMC55text').value;
            answer1Chb = document.getElementById('answerMC15check');
            answer2Chb = document.getElementById('answerMC25check');
            answer3Chb = document.getElementById('answerMC35check');
            answer4Chb = document.getElementById('answerMC45check');
            answer5Chb = document.getElementById('answerMC55check');
            if (answer1Chb.checked) {
                corrAnsCheckArray.push(answer1);
                isChecked = true;
            }
            if (answer2Chb.checked) {
                corrAnsCheckArray.push(answer2);
                isChecked = true;
            }
            if (answer3Chb.checked) {
                corrAnsCheckArray.push(answer3);
                isChecked = true;
            }
            if (answer4Chb.checked) {
                corrAnsCheckArray.push(answer4);
                isChecked = true;
            }
            if (answer5Chb.checked) {
                corrAnsCheckArray.push(answer5);
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            answers.push(answer4);
            answers.push(answer5);
            correctAnswersArray.push(corrAnsCheckArray);

        }
        else if (numberOfAnswers === 'sixMC') {
            answer1 = document.getElementById('answerMC16text').value;
            answer2 = document.getElementById('answerMC26text').value;
            answer3 = document.getElementById('answerMC36text').value;
            answer4 = document.getElementById('answerMC46text').value;
            answer5 = document.getElementById('answerMC56text').value;
            answer6 = document.getElementById('answerMC66text').value;
            answer1Chb = document.getElementById('answerMC16check');
            answer2Chb = document.getElementById('answerMC26check');
            answer3Chb = document.getElementById('answerMC36check');
            answer4Chb = document.getElementById('answerMC46check');
            answer5Chb = document.getElementById('answerMC56check');
            answer6Chb = document.getElementById('answerMC66check');
            if (answer1Chb.checked) {
                corrAnsCheckArray.push(answer1);
                isChecked = true;
            }
            if (answer2Chb.checked) {
                corrAnsCheckArray.push(answer2);
                isChecked = true;
            }
            if (answer3Chb.checked) {
                corrAnsCheckArray.push(answer3);
                isChecked = true;
            }
            if (answer4Chb.checked) {
                corrAnsCheckArray.push(answer4);
                isChecked = true;
            }
            if (answer5Chb.checked) {
                corrAnsCheckArray.push(answer5);
                isChecked = true;
            }
            if (answer6Chb.checked) {
                corrAnsCheckArray.push(answer6);
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            answers.push(answer4);
            answers.push(answer5);
            answers.push(answer6);
            correctAnswersArray.push(corrAnsCheckArray);

        }

        else if (questionType === 'open') {

            autoCorrect.push(0);
        }

    }
    answerNotChecked = ((!isChecked) && (questionType !== 'open'));

    if (answerNotChecked) {
        alert("Ange det rätta svaret på frågan");
    } else {
        answerArray.push(answers);

        parsed = JSON.parse(localStorage.getItem(testStorageName));

        parsed.questionString.push(questionArray);
        parsed.answerType.push(questionTypeArray);
        parsed.points.push(pointsArray);
        parsed.answers.push(answerArray);
        parsed.correctAnswers.push(correctAnswersArray);

        answers = [];
        /*
         parsed = JSON.parse(localStorage.getItem('test2'));

         parsed.testName.push(testNameArray);
         parsed.testTime.push(testTimeArray);
         parsed.questionString.push(questionArray);
         parsed.answerType.push(questionTypeArray);
         parsed.points.push(pointsArray);
         parsed.answers.push(answerArray);
         parsed.correctAnswers.push(correctAnswersArray);
         parsed.gProcent.push(gProcentArray);
         parsed.vgProcent.push(vgProcentArray);

         var data = JSON.stringify(parsed);
         localStorage.setItem('test2', data);
         */

        var test = JSON.parse(localStorage.getItem(testStorageName));

        /*
         out.innerHTML = 'Questiontext: ' + questionText + '
' + 'Questiontype: ' + questionType +  '
'
         + 'antal svar: ' + numberOfAnswers + '
' + 'svar1: ' + answer1 + '
'
         + 'svar2: ' + answer2 + '
' + 'svar3: ' + answer3 + '
'
         + 'svar4: ' + answer4 + '
' + 'rätt svar: ' + corrAnsCheckArray[0] + '
'
         + 'rätt svar: ' + corrAnsCheckArray[1] + '
';
         */

        //out.innerHTML = test.testName[0];

    document.getElementById("createQuestionForm").reset();

            $("#singleC").hide();
            $("#multiC").hide();
            $("#open").hide();

        document.getElementById("questionId").innerHTML = "Fråga " + ++questionNumber;
        document.getElementById("saveTest").style.visibility = "visible";
    }
}

// TODO saveTest
function saveTest() {

    parsed.testName.push(testNameArray);
    parsed.testTime.push(testTimeArray);
    parsed.gProcent.push(gProcentArray);
    parsed.vgProcent.push(vgProcentArray);

    var temp;

    for (i = 0; i < parsed.questionString.length; i++) {
        if (autoCorrect[i] == 0) {
            temp = 0;
            break;
        }
        else {
            temp = 1;
        }
    }

    parsed.autoCorrect.push(temp);

    var data = JSON.stringify(parsed);
    localStorage.setItem(testStorageName, data);

    userTest = JSON.parse(localStorage.getItem("usertest"));
    userTest.testName.push(testNameArray);
    var emptyArray = [];
    userTest.mail.push(emptyArray);

    var objdata = JSON.stringify(userTest);
    localStorage.setItem("usertest", objdata);

    alert("Testet är sparat");

    $('#testHeaderForm')[0].reset();
    $("#createQuestionForm").hide();
    $("#saveTest").hide();

}

/*$("#saveTest").click(function(){
 $('#testHeaderForm')[0].reset();
 $("#createQuestionForm").hide();
 $("#saveTest").hide();
 });*/

<commit_msg>2 buggfix i saveTest<commit_after>/**
 * Created by Reza on 2016-04-29.
 */

var parsed;
var testStorageName = 'testdata';
var questionNumber = 1;

var testName;
var testTime;
var gPercent;
var vgPercent;
var onlyGquestions;

var testNameArray = [];
var testTimeArray = [];
var gProcentArray = [];
var vgProcentArray = [];
var questionArray = [];
var answerArray = [];
var pointsArray = [];
var correctAnswersArray = [];
var questionTypeArray = [];
var isChecked = false;
var answerNotChecked = false;

var questionText;
var questionType;
var numberOfAnswers;
var answers = [];
var answer1, answer2, answer3, answer4, answer5, answer6;
var answer1Radio, answer2Radio, answer3Radio, answer4Radio;
var answer1Chb, answer2Chb, answer3Chb, answer4Chb, answer5Chb, answer6Chb;
var correctAnswer;
var corrAnsCheckArray = [];
var points;
var autoCorr = 1;

var out = document.getElementById('output');

$(document).ready(function () {
    document.getElementById("createQuestionForm").style.visibility = "hidden";
    document.getElementById("saveTest").style.visibility = "hidden";
});

// TODO saveTestInfo
function saveTestInfo() {

    testName = document.getElementById('testName').value;
    testTime = document.getElementById('testTime').value;
    gPercent = +document.getElementById('gPercent').value;
    vgPercent = +document.getElementById('vgPercent').value;
    onlyGquestions = document.getElementById('onlyGId').checked;

    testNameArray.push(testName);
    testTimeArray.push(testTime);
    gProcentArray.push(gPercent);
    vgProcentArray.push(vgPercent);
    // TODO onlyGquestions används inte vidare i koden, om vgpercent = null bara G-frågor?

    if (onlyGquestions) {
        document.getElementById("createQuestionForm").style.visibility = "visible";
        document.getElementById("questionId").innerHTML = "Fråga " + questionNumber;
    } else if (vgPercent <= gPercent) {
        alert("Gränsen för VG måste vara högre än för G." + "\nG-gräns: " + gPercent +
            "\nVG-gräns: " + vgPercent);
    } else {
        document.getElementById("createQuestionForm").style.visibility = "visible";
        document.getElementById("questionId").innerHTML = "Fråga " + questionNumber;
    }

    parsed = JSON.parse(localStorage.getItem(testStorageName));

    if (parsed == null) {
        var obj = {
            "testName": [["test1"]],
            "testTime": [[40]],
            "questionString": [[["huvudstad?"], ["Städer?"]]],
            "answerType": [[["singleChoice"], ["multiChoice"]]],
            "points": [[1], [2]],
            "answers": [[["Stockholm", "Göteborg", "Malmö", "Luleå"], ["Göteborg", "Stenköping", "London"]]],
            "correctAnswers": [["Stockholm"], [["Göteborg"], ["London"]]],
            "gProcent": [[60]],
            "vgProcent": [[80]],
            "autoCorrect": [[1]]
        }
        var objdata = JSON.stringify(obj);
        localStorage.setItem(testStorageName, objdata);
    }

}
// TODO saveQuestion
function saveQuestion() {

    questionText = document.getElementById('questionText').value;
    questionType = document.getElementById('typeId').options[document.getElementById('typeId').selectedIndex].value;
    points = document.getElementById('maxPoint').value;
    isChecked = false;

    questionArray.push(questionText);
    questionTypeArray.push(questionType);
    pointsArray.push(points);

    if (questionType === 'singleChoice') {
        numberOfAnswers = document.getElementById('numberOfAnswersSC').value;
        if (numberOfAnswers === 'twoSC') {
            answer1 = document.getElementById('answerSC12text').value;
            answer2 = document.getElementById('answerSC22text').value;
            answer1Radio = document.getElementById('answerSC12radio');
            answer2Radio = document.getElementById('answerSC22radio');
            if (answer1Radio.checked) {
                correctAnswer = answer1;
                isChecked = true;
            }
            else if (answer2Radio.checked) {
                correctAnswer = answer2;
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            correctAnswersArray.push(correctAnswer);
        }
        else if (numberOfAnswers === 'threeSC') {
            answer1 = document.getElementById('answerSC13text').value;
            answer2 = document.getElementById('answerSC23text').value;
            answer3 = document.getElementById('answerSC33text').value;
            answer1Radio = document.getElementById('answerSC13radio');
            answer2Radio = document.getElementById('answerSC23radio');
            answer3Radio = document.getElementById('answerSC33radio');
            if (answer1Radio.checked) {
                correctAnswer = answer1;
                isChecked = true;
            }
            else if (answer2Radio.checked) {
                correctAnswer = answer2;
                isChecked = true;
            }
            else if (answer3Radio.checked) {
                correctAnswer = answer3;
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            correctAnswersArray.push(correctAnswer);
        }
        else if (numberOfAnswers === 'fourSC') {
            answer1 = document.getElementById('answerSC14text').value;
            answer2 = document.getElementById('answerSC24text').value;
            answer3 = document.getElementById('answerSC34text').value;
            answer4 = document.getElementById('answerSC44text').value;
            answer1Radio = document.getElementById('answerSC14radio');
            answer2Radio = document.getElementById('answerSC24radio');
            answer3Radio = document.getElementById('answerSC34radio');
            answer4Radio = document.getElementById('answerSC44radio');
            if (answer1Radio.checked) {
                correctAnswer = answer1;
                isChecked = true;
            }
            else if (answer2Radio.checked) {
                correctAnswer = answer2;
                isChecked = true;
            }
            else if (answer3Radio.checked) {
                correctAnswer = answer3;
                isChecked = true;
            }
            else if (answer4Radio.checked) {
                correctAnswer = answer4;
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            answers.push(answer4);
            correctAnswersArray.push(correctAnswer);
        }
    }
    else if (questionType === 'multiChoice') {
        numberOfAnswers = document.getElementById('numberOfAnswersMC').value;

        if (numberOfAnswers === 'twoMC') {
            answer1 = document.getElementById('answerMC12text').value;
            answer2 = document.getElementById('answerMC22text').value;
            answer1Chb = document.getElementById('answerMC12check');
            answer2Chb = document.getElementById('answerMC22check');
            if (answer1Chb.checked) {
                corrAnsCheckArray.push(answer1);
                isChecked = true;
            }
            if (answer2Chb.checked) {
                corrAnsCheckArray.push(answer2);
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            correctAnswersArray.push(corrAnsCheckArray);

        }
        else if (numberOfAnswers === 'threeMC') {
            answer1 = document.getElementById('answerMC13text').value;
            answer2 = document.getElementById('answerMC23text').value;
            answer3 = document.getElementById('answerMC33text').value;
            answer1Chb = document.getElementById('answerMC13check');
            answer2Chb = document.getElementById('answerMC23check');
            answer3Chb = document.getElementById('answerMC33check');
            if (answer1Chb.checked) {
                corrAnsCheckArray.push(answer1);
                isChecked = true;
            }
            if (answer2Chb.checked) {
                corrAnsCheckArray.push(answer2);
                isChecked = true;
            }
            if (answer3Chb.checked) {
                corrAnsCheckArray.push(answer3);
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            correctAnswersArray.push(corrAnsCheckArray);

        }
        else if (numberOfAnswers === 'fourMC') {
            answer1 = document.getElementById('answerMC14text').value;
            answer2 = document.getElementById('answerMC24text').value;
            answer3 = document.getElementById('answerMC34text').value;
            answer4 = document.getElementById('answerMC44text').value;
            answer1Chb = document.getElementById('answerMC14check');
            answer2Chb = document.getElementById('answerMC24check');
            answer3Chb = document.getElementById('answerMC34check');
            answer4Chb = document.getElementById('answerMC44check');
            if (answer1Chb.checked) {
                corrAnsCheckArray.push(answer1);
                isChecked = true;
            }
            if (answer2Chb.checked) {
                corrAnsCheckArray.push(answer2);
                isChecked = true;
            }
            if (answer3Chb.checked) {
                corrAnsCheckArray.push(answer3);
                isChecked = true;
            }
            if (answer4Chb.checked) {
                corrAnsCheckArray.push(answer4);
                isChecked = true;
            }
            isChecked = (answer1Chb || answer2Chb || answer3Chb || answer4Chb);
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            answers.push(answer4);

        }
        else if (numberOfAnswers === 'fiveMC') {
            answer1 = document.getElementById('answerMC15text').value;
            answer2 = document.getElementById('answerMC25text').value;
            answer3 = document.getElementById('answerMC35text').value;
            answer4 = document.getElementById('answerMC45text').value;
            answer5 = document.getElementById('answerMC55text').value;
            answer1Chb = document.getElementById('answerMC15check');
            answer2Chb = document.getElementById('answerMC25check');
            answer3Chb = document.getElementById('answerMC35check');
            answer4Chb = document.getElementById('answerMC45check');
            answer5Chb = document.getElementById('answerMC55check');
            if (answer1Chb.checked) {
                corrAnsCheckArray.push(answer1);
                isChecked = true;
            }
            if (answer2Chb.checked) {
                corrAnsCheckArray.push(answer2);
                isChecked = true;
            }
            if (answer3Chb.checked) {
                corrAnsCheckArray.push(answer3);
                isChecked = true;
            }
            if (answer4Chb.checked) {
                corrAnsCheckArray.push(answer4);
                isChecked = true;
            }
            if (answer5Chb.checked) {
                corrAnsCheckArray.push(answer5);
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            answers.push(answer4);
            answers.push(answer5);
            correctAnswersArray.push(corrAnsCheckArray);

        }
        else if (numberOfAnswers === 'sixMC') {
            answer1 = document.getElementById('answerMC16text').value;
            answer2 = document.getElementById('answerMC26text').value;
            answer3 = document.getElementById('answerMC36text').value;
            answer4 = document.getElementById('answerMC46text').value;
            answer5 = document.getElementById('answerMC56text').value;
            answer6 = document.getElementById('answerMC66text').value;
            answer1Chb = document.getElementById('answerMC16check');
            answer2Chb = document.getElementById('answerMC26check');
            answer3Chb = document.getElementById('answerMC36check');
            answer4Chb = document.getElementById('answerMC46check');
            answer5Chb = document.getElementById('answerMC56check');
            answer6Chb = document.getElementById('answerMC66check');
            if (answer1Chb.checked) {
                corrAnsCheckArray.push(answer1);
                isChecked = true;
            }
            if (answer2Chb.checked) {
                corrAnsCheckArray.push(answer2);
                isChecked = true;
            }
            if (answer3Chb.checked) {
                corrAnsCheckArray.push(answer3);
                isChecked = true;
            }
            if (answer4Chb.checked) {
                corrAnsCheckArray.push(answer4);
                isChecked = true;
            }
            if (answer5Chb.checked) {
                corrAnsCheckArray.push(answer5);
                isChecked = true;
            }
            if (answer6Chb.checked) {
                corrAnsCheckArray.push(answer6);
                isChecked = true;
            }
            answers.push(answer1);
            answers.push(answer2);
            answers.push(answer3);
            answers.push(answer4);
            answers.push(answer5);
            answers.push(answer6);
            correctAnswersArray.push(corrAnsCheckArray);

        }
    }
    else if (questionType === 'open') {

        autoCorr = 0;
    }

    answerNotChecked = ((!isChecked) && (questionType !== 'open'));

    if (answerNotChecked) {
        alert("Ange det rätta svaret på frågan");
    }
    else {
        answerArray.push(answers);

        parsed = JSON.parse(localStorage.getItem(testStorageName));

        parsed.questionString.push(questionArray);
        parsed.answerType.push(questionTypeArray);
        parsed.points.push(pointsArray);
        parsed.answers.push(answerArray);
        parsed.correctAnswers.push(correctAnswersArray);

        answers = [];
        /*
         parsed = JSON.parse(localStorage.getItem('test2'));

         parsed.testName.push(testNameArray);
         parsed.testTime.push(testTimeArray);
         parsed.questionString.push(questionArray);
         parsed.answerType.push(questionTypeArray);
         parsed.points.push(pointsArray);
         parsed.answers.push(answerArray);
         parsed.correctAnswers.push(correctAnswersArray);
         parsed.gProcent.push(gProcentArray);
         parsed.vgProcent.push(vgProcentArray);

         var data = JSON.stringify(parsed);
         localStorage.setItem('test2', data);
         */

        var test = JSON.parse(localStorage.getItem(testStorageName));

        /*
         out.innerHTML = 'Questiontext: ' + questionText + '
' + 'Questiontype: ' + questionType +  '
'
         + 'antal svar: ' + numberOfAnswers + '
' + 'svar1: ' + answer1 + '
'
         + 'svar2: ' + answer2 + '
' + 'svar3: ' + answer3 + '
'
         + 'svar4: ' + answer4 + '
' + 'rätt svar: ' + corrAnsCheckArray[0] + '
'
         + 'rätt svar: ' + corrAnsCheckArray[1] + '
';
         */

        //out.innerHTML = test.testName[0];

        document.getElementById("createQuestionForm").reset();

        $("#singleC").hide();
        $("#multiC").hide();
        $("#open").hide();

        document.getElementById("questionId").innerHTML = "Fråga " + ++questionNumber;
        document.getElementById("saveTest").style.visibility = "visible";
    }
}

// TODO saveTest
function saveTest() {

    parsed.testName.push(testNameArray);
    parsed.testTime.push(testTimeArray);
    parsed.gProcent.push(gProcentArray);
    parsed.vgProcent.push(vgProcentArray);

    var temp;

    if (autoCorr == 0) {
        temp = 0;
    }
    else {
        temp = 1;
    }

    parsed.autoCorrect.push(temp);

    var data = JSON.stringify(parsed);
    localStorage.setItem(testStorageName, data);

    userTest = JSON.parse(localStorage.getItem("usertest"));
    userTest.testName.push(testNameArray);
    var emptyArray = [];
    userTest.mail.push(emptyArray);

    var objdata = JSON.stringify(userTest);
    localStorage.setItem("usertest", objdata);

    alert("Testet är sparat");

    $('#testHeaderForm')[0].reset();
    $("#createQuestionForm").hide();
    $("#saveTest").hide();

}

/*$("#saveTest").click(function(){
 $('#testHeaderForm')[0].reset();
 $("#createQuestionForm").hide();
 $("#saveTest").hide();
 });*/

<|endoftext|>


<commit_before>// Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> <%= pkg.version %>
'use strict';
var fs = require('fs');
<% if (buildTool == 'maven') { %>
var parseString = require('xml2js').parseString;
// Returns the second occurence of the version number
var parseVersionFromPomXml = function() {
    var version;
    var pomXml = fs.readFileSync('pom.xml', "utf8");
    parseString(pomXml, function (err, result){
        version = result.project.version[0];
    });
    return version;
};<% } else { %>
// Returns the first occurence of the version number
var parseVersionFromBuildGradle = function() {
    var versionRegex = /^version\s*=\s*[',"]([^',"]*)[',"]/gm; // Match and group the version number
    var buildGradle = fs.readFileSync('build.gradle', "utf8");
    return versionRegex.exec(buildGradle)[1];
};<% } %>

// usemin custom step
var useminAutoprefixer = {
    name: 'autoprefixer',
    createConfig: function(context, block) {
        if(block.src.length === 0) {
            return {};
        } else {
            return require('grunt-usemin/lib/config/cssmin').createConfig(context, block) // Reuse cssmins createConfig
        }
    }
};

module.exports = function (grunt) {
    require('load-grunt-tasks')(grunt);
    require('time-grunt')(grunt);

    grunt.initConfig({
        yeoman: {
            // configurable paths
            app: require('./bower.json').appPath || 'app',
            dist: 'src/main/webapp/dist'
        },
        watch: {
            bower: {
                files: ['bower.json'],
                tasks: ['wiredep']
            },
            ngconstant: {
                files: ['Gruntfile.js', <% if(buildTool == 'maven') { %>'pom.xml'<% } else { %>'build.gradle'<% } %>],
                tasks: ['ngconstant:dev']
            }<% if (useCompass) { %>,
            compass: {
                files: ['src/main/scss/**/*.{scss,sass}'],
                tasks: ['compass:server']
            }<% } %>
        },
        autoprefixer: {
            // src and dest is configured in a subtask called "generated" by usemin
        },
        wiredep: {
            app: {<% if (useCompass) { %>
                src: ['src/main/webapp/index.html', 'src/main/scss/main.scss'],
                exclude: [
                    /angular-i18n/, // localizations are loaded dynamically
                    'bower_components/bootstrap/' // Exclude Bootstrap LESS as we use bootstrap-sass
                ],
                ignorePath: /\.\.\/webapp\/bower_components\// // remove ../webapp/bower_components/ from paths of injected sass files <% } else { %>
                src: ['src/main/webapp/index.html'],
                exclude: [
                    /angular-i18n/  // localizations are loaded dynamically
                ]<% } %>
            },
            test: {
                src: 'src/test/javascript/karma.conf.js',
                exclude: [/angular-i18n/, /angular-scenario/],
                ignorePath: /\.\.\/\.\.\//, // remove ../../ from paths of injected javascripts
                devDependencies: true,
                fileTypes: {
                    js: {
                        block: /(([\s\t]*)\/\/\s*bower:*(\S*))(\n|\r|.)*?(\/\/\s*endbower)/gi,
                        detect: {
                            js: /'(.*\.js)'/gi
                        },
                        replace: {
                            js: '\'{{filePath}}\','
                        }
                    }
                }
            }
        },
        browserSync: {
            dev: {
                bsFiles: {
                    src : [
                        'src/main/webapp/**/*.html',
                        'src/main/webapp/**/*.json',
                        'src/main/webapp/assets/styles/**/*.css',
                        'src/main/webapp/scripts/**/*.js',
                        'src/main/webapp/assets/images/**/*.{png,jpg,jpeg,gif,webp,svg}',
                        'tmp/**/*.{css,js}'
                    ]
                }
            },
            options: {
                watchTask: true,
                proxy: "localhost:8080"
            }
        },
        clean: {
            dist: {
                files: [{
                    dot: true,
                    src: [
                        '.tmp',
                        '<%%= yeoman.dist %>/*',
                        '!<%%= yeoman.dist %>/.git*'
                    ]
                }]
            },
            server: '.tmp'
        },
        jshint: {
            options: {
                jshintrc: '.jshintrc'
            },
            all: [
                'Gruntfile.js',
                'src/main/webapp/scripts/app.js',
                'src/main/webapp/scripts/app/**/*.js',
                'src/main/webapp/scripts/components/**/*.js'
            ]
        },<% if (useCompass) { %>
        compass: {
            options: {
                sassDir: 'src/main/scss',
                cssDir: 'src/main/webapp/assets/styles',
                generatedImagesDir: '.tmp/assets/images/generated',
                imagesDir: 'src/main/webapp/assets/images',
                javascriptsDir: 'src/main/webapp/scripts',
                fontsDir: 'src/main/webapp/assets/fonts',
                importPath: 'src/main/webapp/bower_components',
                httpImagesPath: '/assets/images',
                httpGeneratedImagesPath: '/assets/images/generated',
                httpFontsPath: '/assets/fonts',
                relativeAssets: false
            },
            dist: {},
            server: {
                options: {
                    debugInfo: true
                }
            }
        },<% } %>
        concat: {
            // src and dest is configured in a subtask called "generated" by usemin
        },
        uglifyjs: {
            // src and dest is configured in a subtask called "generated" by usemin
        },
        rev: {
            dist: {
                files: {
                    src: [
                        '<%%= yeoman.dist %>/scripts/**/*.js',
                        '<%%= yeoman.dist %>/assets/styles/**/*.css',
                        '<%%= yeoman.dist %>/assets/images/**/*.{png,jpg,jpeg,gif,webp,svg}',
                        '<%%= yeoman.dist %>/assets/fonts/*'
                    ]
                }
            }
        },
        useminPrepare: {
            html: 'src/main/webapp/**/*.html',
            options: {
                dest: '<%%= yeoman.dist %>',
                flow: {
                    html: {
                        steps: {
                            js: ['concat', 'uglifyjs'],
                            css: ['cssmin', useminAutoprefixer] // Let cssmin concat files so it corrects relative paths to fonts and images
                        },
                            post: {}
                        }
                    }
            }
        },
        usemin: {
            html: ['<%%= yeoman.dist %>/**/*.html'],
            css: ['<%%= yeoman.dist %>/assets/styles/**/*.css'],
            js: ['<%%= yeoman.dist %>/scripts/**/*.js'],
            options: {
                assetsDirs: ['<%%= yeoman.dist %>', '<%%= yeoman.dist %>/assets/styles', '<%%= yeoman.dist %>/assets/images', '<%%= yeoman.dist %>/assets/fonts'],
                patterns: {
                    js: [
                        [/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images']
                    ]
                },
                dirs: ['<%%= yeoman.dist %>']
            }
        },
        imagemin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: 'src/main/webapp/assets/images',
                    src: '**/*.{jpg,jpeg}', // we don't optimize PNG files as it doesn't work on Linux. If you are not on Linux, feel free to use '**/*.{png,jpg,jpeg}'
                    dest: '<%%= yeoman.dist %>/assets/images'
                }]
            }
        },
        svgmin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: 'src/main/webapp/assets/images',
                    src: '**/*.svg',
                    dest: '<%%= yeoman.dist %>/assets/images'
                }]
            }
        },
        cssmin: {
            // src and dest is configured in a subtask called "generated" by usemin
        },
        ngtemplates:    {
            dist: {
                cwd: 'src/main/webapp',
                src: ['scripts/app/**/*.html', 'scripts/components/**/*.html',],
                dest: '.tmp/templates/templates.js',
                options: {
                    module: '<%= angularAppName%>',
                    usemin: 'scripts/app.js',
                    htmlmin:  {
                        removeCommentsFromCDATA: true,
                        // https://github.com/yeoman/grunt-usemin/issues/44
                        collapseWhitespace: true,
                        collapseBooleanAttributes: true,
                        conservativeCollapse: true,
                        removeAttributeQuotes: true,
                        removeRedundantAttributes: true,
                        useShortDoctype: true,
                        removeEmptyAttributes: true
                    }
                }
            }
        },
        htmlmin: {
            dist: {
                options: {
                    removeCommentsFromCDATA: true,
                    // https://github.com/yeoman/grunt-usemin/issues/44
                    collapseWhitespace: true,
                    collapseBooleanAttributes: true,
                    conservativeCollapse: true,
                    removeAttributeQuotes: true,
                    removeRedundantAttributes: true,
                    useShortDoctype: true,
                    removeEmptyAttributes: true,
                    keepClosingSlash: true
                },
                files: [{
                    expand: true,
                    cwd: '<%%= yeoman.dist %>',
                    src: ['*.html'],
                    dest: '<%%= yeoman.dist %>'
                }]
            }
        },
        // Put files not handled in other tasks here
        copy: {
            fonts: {
                files: [{
                    expand: true,
                    dot: true,
                    flatten: true,
                    cwd: 'src/main/webapp',
                    dest: '<%%= yeoman.dist %>/assets/fonts',
                    src: [
                      'bower_components/bootstrap/fonts/*.*'
                    ]
                }]
            },
            dist: {
                files: [{
                    expand: true,
                    dot: true,
                    cwd: 'src/main/webapp',
                    dest: '<%%= yeoman.dist %>',
                    src: [
                        '*.html',
                        'scripts/**/*.html',
                        'assets/images/**/*.{png,gif,webp,jpg,jpeg,svg}',
                        'assets/fonts/*'
                    ]
                }, {
                    expand: true,
                    cwd: '.tmp/assets/images',
                    dest: '<%%= yeoman.dist %>/assets/images',
                    src: [
                        'generated/*'
                    ]
                }]
            },
            generateOpenshiftDirectory: {
                    expand: true,
                    dest: 'deploy/openshift',
                    src: [
                        'pom.xml',
                        'src/main/**'
                ]
            }
        },
        karma: {
            unit: {
                configFile: 'src/test/javascript/karma.conf.js',
                singleRun: true
            }
        },
        ngAnnotate: {
            dist: {
                files: [{
                    expand: true,
                    cwd: '.tmp/concat/scripts',
                    src: '*.js',
                    dest: '.tmp/concat/scripts'
                }]
            }
        },
        buildcontrol: {
            options: {
                commit: true,
                push: false,
                connectCommits: false,
                message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%'
            },
            openshift: {
                options: {
                    dir: 'deploy/openshift',
                    remote: 'openshift',
                    branch: 'master'
                }
            }
        },
        ngconstant: {
            options: {
                name: '<%= angularAppName%>',
                deps: false,
                wrap: '"use strict";\n// DO NOT EDIT THIS FILE, EDIT THE GRUNT TASK NGCONSTANT SETTINGS INSTEAD WHICH GENERATES THIS FILE\n{%= __ngModule %}'
            },
            dev: {
                options: {
                    dest: 'src/main/webapp/scripts/app/app.constants.js'
                },
                constants: {
                    ENV: 'dev',
                    VERSION: <% if(buildTool == 'maven') { %>parseVersionFromPomXml()<% } else { %>parseVersionFromBuildGradle()<% } %>
                }
            },
            prod: {
                options: {
                    dest: '.tmp/scripts/app/app.constants.js'
                },
                constants: {
                    ENV: 'prod',
                    VERSION: <% if(buildTool == 'maven') { %>parseVersionFromPomXml()<% } else { %>parseVersionFromBuildGradle()<% } %>
                }
            }
        }
    });

    grunt.registerTask('serve', [
        'clean:server',
        'wiredep',
        'ngconstant:dev',<% if (useCompass) { %>
        'compass:server',<% } %>
        'browserSync',
        'watch'
    ]);

    grunt.registerTask('server', function (target) {
        grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
        grunt.task.run([target ? ('serve:' + target) : 'serve']);
    });

    grunt.registerTask('test', [
        'clean:server',
        'wiredep:test',
        'ngconstant:dev',<% if (useCompass) { %>
        'compass',<% } %>
        'karma'
    ]);

    grunt.registerTask('build', [
        'clean:dist',
        'wiredep:app',
        'ngconstant:prod',
        'useminPrepare',
        'ngtemplates',<% if (useCompass) { %>
        'compass:dist',<% } %>
        'imagemin',
        'svgmin',
        'concat',
        'copy:fonts',
        'copy:dist',
        'ngAnnotate',
        'cssmin',
        'autoprefixer',
        'uglify',
        'rev',
        'usemin',
        'htmlmin'
    ]);

	grunt.registerTask('appendSkipBower', 'Force skip of bower for Gradle', function () {

		if (!grunt.file.exists(filepath)) {
			// Assume this is a maven project
			return true;
		}

		var fileContent = grunt.file.read(filepath);
		var skipBowerIndex = fileContent.indexOf("skipBower=true");

		if (skipBowerIndex != -1) {
			return true;
		}

		grunt.file.write(filepath, fileContent + "\nskipBower=true\n");
	});

    grunt.registerTask('buildOpenshift', [
        'test',
        'build',
        'copy:generateOpenshiftDirectory',
    ]);

    grunt.registerTask('deployOpenshift', [
        'test',
        'build',
        'copy:generateOpenshiftDirectory',
        'buildcontrol:openshift'
    ]);

    grunt.registerTask('default', [
        'test',
        'build'
    ]);
};
<commit_msg>Reuse htmlmin options in ngtemplates<commit_after>// Generated on <%= (new Date).toISOString().split('T')[0] %> using <%= pkg.name %> <%= pkg.version %>
'use strict';
var fs = require('fs');
<% if (buildTool == 'maven') { %>
var parseString = require('xml2js').parseString;
// Returns the second occurence of the version number
var parseVersionFromPomXml = function() {
    var version;
    var pomXml = fs.readFileSync('pom.xml', "utf8");
    parseString(pomXml, function (err, result){
        version = result.project.version[0];
    });
    return version;
};<% } else { %>
// Returns the first occurence of the version number
var parseVersionFromBuildGradle = function() {
    var versionRegex = /^version\s*=\s*[',"]([^',"]*)[',"]/gm; // Match and group the version number
    var buildGradle = fs.readFileSync('build.gradle', "utf8");
    return versionRegex.exec(buildGradle)[1];
};<% } %>

// usemin custom step
var useminAutoprefixer = {
    name: 'autoprefixer',
    createConfig: function(context, block) {
        if(block.src.length === 0) {
            return {};
        } else {
            return require('grunt-usemin/lib/config/cssmin').createConfig(context, block) // Reuse cssmins createConfig
        }
    }
};

module.exports = function (grunt) {
    require('load-grunt-tasks')(grunt);
    require('time-grunt')(grunt);

    grunt.initConfig({
        yeoman: {
            // configurable paths
            app: require('./bower.json').appPath || 'app',
            dist: 'src/main/webapp/dist'
        },
        watch: {
            bower: {
                files: ['bower.json'],
                tasks: ['wiredep']
            },
            ngconstant: {
                files: ['Gruntfile.js', <% if(buildTool == 'maven') { %>'pom.xml'<% } else { %>'build.gradle'<% } %>],
                tasks: ['ngconstant:dev']
            }<% if (useCompass) { %>,
            compass: {
                files: ['src/main/scss/**/*.{scss,sass}'],
                tasks: ['compass:server']
            }<% } %>
        },
        autoprefixer: {
            // src and dest is configured in a subtask called "generated" by usemin
        },
        wiredep: {
            app: {<% if (useCompass) { %>
                src: ['src/main/webapp/index.html', 'src/main/scss/main.scss'],
                exclude: [
                    /angular-i18n/, // localizations are loaded dynamically
                    'bower_components/bootstrap/' // Exclude Bootstrap LESS as we use bootstrap-sass
                ],
                ignorePath: /\.\.\/webapp\/bower_components\// // remove ../webapp/bower_components/ from paths of injected sass files <% } else { %>
                src: ['src/main/webapp/index.html'],
                exclude: [
                    /angular-i18n/  // localizations are loaded dynamically
                ]<% } %>
            },
            test: {
                src: 'src/test/javascript/karma.conf.js',
                exclude: [/angular-i18n/, /angular-scenario/],
                ignorePath: /\.\.\/\.\.\//, // remove ../../ from paths of injected javascripts
                devDependencies: true,
                fileTypes: {
                    js: {
                        block: /(([\s\t]*)\/\/\s*bower:*(\S*))(\n|\r|.)*?(\/\/\s*endbower)/gi,
                        detect: {
                            js: /'(.*\.js)'/gi
                        },
                        replace: {
                            js: '\'{{filePath}}\','
                        }
                    }
                }
            }
        },
        browserSync: {
            dev: {
                bsFiles: {
                    src : [
                        'src/main/webapp/**/*.html',
                        'src/main/webapp/**/*.json',
                        'src/main/webapp/assets/styles/**/*.css',
                        'src/main/webapp/scripts/**/*.js',
                        'src/main/webapp/assets/images/**/*.{png,jpg,jpeg,gif,webp,svg}',
                        'tmp/**/*.{css,js}'
                    ]
                }
            },
            options: {
                watchTask: true,
                proxy: "localhost:8080"
            }
        },
        clean: {
            dist: {
                files: [{
                    dot: true,
                    src: [
                        '.tmp',
                        '<%%= yeoman.dist %>/*',
                        '!<%%= yeoman.dist %>/.git*'
                    ]
                }]
            },
            server: '.tmp'
        },
        jshint: {
            options: {
                jshintrc: '.jshintrc'
            },
            all: [
                'Gruntfile.js',
                'src/main/webapp/scripts/app.js',
                'src/main/webapp/scripts/app/**/*.js',
                'src/main/webapp/scripts/components/**/*.js'
            ]
        },<% if (useCompass) { %>
        compass: {
            options: {
                sassDir: 'src/main/scss',
                cssDir: 'src/main/webapp/assets/styles',
                generatedImagesDir: '.tmp/assets/images/generated',
                imagesDir: 'src/main/webapp/assets/images',
                javascriptsDir: 'src/main/webapp/scripts',
                fontsDir: 'src/main/webapp/assets/fonts',
                importPath: 'src/main/webapp/bower_components',
                httpImagesPath: '/assets/images',
                httpGeneratedImagesPath: '/assets/images/generated',
                httpFontsPath: '/assets/fonts',
                relativeAssets: false
            },
            dist: {},
            server: {
                options: {
                    debugInfo: true
                }
            }
        },<% } %>
        concat: {
            // src and dest is configured in a subtask called "generated" by usemin
        },
        uglifyjs: {
            // src and dest is configured in a subtask called "generated" by usemin
        },
        rev: {
            dist: {
                files: {
                    src: [
                        '<%%= yeoman.dist %>/scripts/**/*.js',
                        '<%%= yeoman.dist %>/assets/styles/**/*.css',
                        '<%%= yeoman.dist %>/assets/images/**/*.{png,jpg,jpeg,gif,webp,svg}',
                        '<%%= yeoman.dist %>/assets/fonts/*'
                    ]
                }
            }
        },
        useminPrepare: {
            html: 'src/main/webapp/**/*.html',
            options: {
                dest: '<%%= yeoman.dist %>',
                flow: {
                    html: {
                        steps: {
                            js: ['concat', 'uglifyjs'],
                            css: ['cssmin', useminAutoprefixer] // Let cssmin concat files so it corrects relative paths to fonts and images
                        },
                            post: {}
                        }
                    }
            }
        },
        usemin: {
            html: ['<%%= yeoman.dist %>/**/*.html'],
            css: ['<%%= yeoman.dist %>/assets/styles/**/*.css'],
            js: ['<%%= yeoman.dist %>/scripts/**/*.js'],
            options: {
                assetsDirs: ['<%%= yeoman.dist %>', '<%%= yeoman.dist %>/assets/styles', '<%%= yeoman.dist %>/assets/images', '<%%= yeoman.dist %>/assets/fonts'],
                patterns: {
                    js: [
                        [/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images']
                    ]
                },
                dirs: ['<%%= yeoman.dist %>']
            }
        },
        imagemin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: 'src/main/webapp/assets/images',
                    src: '**/*.{jpg,jpeg}', // we don't optimize PNG files as it doesn't work on Linux. If you are not on Linux, feel free to use '**/*.{png,jpg,jpeg}'
                    dest: '<%%= yeoman.dist %>/assets/images'
                }]
            }
        },
        svgmin: {
            dist: {
                files: [{
                    expand: true,
                    cwd: 'src/main/webapp/assets/images',
                    src: '**/*.svg',
                    dest: '<%%= yeoman.dist %>/assets/images'
                }]
            }
        },
        cssmin: {
            // src and dest is configured in a subtask called "generated" by usemin
        },
        ngtemplates:    {
            dist: {
                cwd: 'src/main/webapp',
                src: ['scripts/app/**/*.html', 'scripts/components/**/*.html',],
                dest: '.tmp/templates/templates.js',
                options: {
                    module: '<%= angularAppName%>',
                    usemin: 'scripts/app.js',
                    htmlmin: '<%%= htmlmin.dist.options %>'
                }
            }
        },
        htmlmin: {
            dist: {
                options: {
                    removeCommentsFromCDATA: true,
                    // https://github.com/yeoman/grunt-usemin/issues/44
                    collapseWhitespace: true,
                    collapseBooleanAttributes: true,
                    conservativeCollapse: true,
                    removeAttributeQuotes: true,
                    removeRedundantAttributes: true,
                    useShortDoctype: true,
                    removeEmptyAttributes: true,
                    keepClosingSlash: true
                },
                files: [{
                    expand: true,
                    cwd: '<%%= yeoman.dist %>',
                    src: ['*.html'],
                    dest: '<%%= yeoman.dist %>'
                }]
            }
        },
        // Put files not handled in other tasks here
        copy: {
            fonts: {
                files: [{
                    expand: true,
                    dot: true,
                    flatten: true,
                    cwd: 'src/main/webapp',
                    dest: '<%%= yeoman.dist %>/assets/fonts',
                    src: [
                      'bower_components/bootstrap/fonts/*.*'
                    ]
                }]
            },
            dist: {
                files: [{
                    expand: true,
                    dot: true,
                    cwd: 'src/main/webapp',
                    dest: '<%%= yeoman.dist %>',
                    src: [
                        '*.html',
                        'scripts/**/*.html',
                        'assets/images/**/*.{png,gif,webp,jpg,jpeg,svg}',
                        'assets/fonts/*'
                    ]
                }, {
                    expand: true,
                    cwd: '.tmp/assets/images',
                    dest: '<%%= yeoman.dist %>/assets/images',
                    src: [
                        'generated/*'
                    ]
                }]
            },
            generateOpenshiftDirectory: {
                    expand: true,
                    dest: 'deploy/openshift',
                    src: [
                        'pom.xml',
                        'src/main/**'
                ]
            }
        },
        karma: {
            unit: {
                configFile: 'src/test/javascript/karma.conf.js',
                singleRun: true
            }
        },
        ngAnnotate: {
            dist: {
                files: [{
                    expand: true,
                    cwd: '.tmp/concat/scripts',
                    src: '*.js',
                    dest: '.tmp/concat/scripts'
                }]
            }
        },
        buildcontrol: {
            options: {
                commit: true,
                push: false,
                connectCommits: false,
                message: 'Built %sourceName% from commit %sourceCommit% on branch %sourceBranch%'
            },
            openshift: {
                options: {
                    dir: 'deploy/openshift',
                    remote: 'openshift',
                    branch: 'master'
                }
            }
        },
        ngconstant: {
            options: {
                name: '<%= angularAppName%>',
                deps: false,
                wrap: '"use strict";\n// DO NOT EDIT THIS FILE, EDIT THE GRUNT TASK NGCONSTANT SETTINGS INSTEAD WHICH GENERATES THIS FILE\n{%= __ngModule %}'
            },
            dev: {
                options: {
                    dest: 'src/main/webapp/scripts/app/app.constants.js'
                },
                constants: {
                    ENV: 'dev',
                    VERSION: <% if(buildTool == 'maven') { %>parseVersionFromPomXml()<% } else { %>parseVersionFromBuildGradle()<% } %>
                }
            },
            prod: {
                options: {
                    dest: '.tmp/scripts/app/app.constants.js'
                },
                constants: {
                    ENV: 'prod',
                    VERSION: <% if(buildTool == 'maven') { %>parseVersionFromPomXml()<% } else { %>parseVersionFromBuildGradle()<% } %>
                }
            }
        }
    });

    grunt.registerTask('serve', [
        'clean:server',
        'wiredep',
        'ngconstant:dev',<% if (useCompass) { %>
        'compass:server',<% } %>
        'browserSync',
        'watch'
    ]);

    grunt.registerTask('server', function (target) {
        grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
        grunt.task.run([target ? ('serve:' + target) : 'serve']);
    });

    grunt.registerTask('test', [
        'clean:server',
        'wiredep:test',
        'ngconstant:dev',<% if (useCompass) { %>
        'compass',<% } %>
        'karma'
    ]);

    grunt.registerTask('build', [
        'clean:dist',
        'wiredep:app',
        'ngconstant:prod',
        'useminPrepare',
        'ngtemplates',<% if (useCompass) { %>
        'compass:dist',<% } %>
        'imagemin',
        'svgmin',
        'concat',
        'copy:fonts',
        'copy:dist',
        'ngAnnotate',
        'cssmin',
        'autoprefixer',
        'uglify',
        'rev',
        'usemin',
        'htmlmin'
    ]);

	grunt.registerTask('appendSkipBower', 'Force skip of bower for Gradle', function () {

		if (!grunt.file.exists(filepath)) {
			// Assume this is a maven project
			return true;
		}

		var fileContent = grunt.file.read(filepath);
		var skipBowerIndex = fileContent.indexOf("skipBower=true");

		if (skipBowerIndex != -1) {
			return true;
		}

		grunt.file.write(filepath, fileContent + "\nskipBower=true\n");
	});

    grunt.registerTask('buildOpenshift', [
        'test',
        'build',
        'copy:generateOpenshiftDirectory',
    ]);

    grunt.registerTask('deployOpenshift', [
        'test',
        'build',
        'copy:generateOpenshiftDirectory',
        'buildcontrol:openshift'
    ]);

    grunt.registerTask('default', [
        'test',
        'build'
    ]);
};
<|endoftext|>


<commit_before>//  Copyright 2002-2014, University of Colorado Boulder

/**
 * A physical-looking probe with a handle and a semicircular sensor region, used in simulations like Bending Light and
 * Beer's Law Lab to show how much light is being received. It is typically connected to a body with readouts with a
 * curved wire. The origin is in the center of the circular part of the sensor (which is not vertically symmetrical).
 *
 * This code was generalized from Bending Light, see https://github.com/phetsims/bending-light/issues/165
 *
 * TODO: This is under development and not ready for review or usage in simulations other than Bending Light.
 *
 * @author Sam Reid (PhET Interactive Simulations)
 * @author Chandrashekar Bemagoni (Actual Concepts)
 * @author Chris Malley (PixelZoom, Inc.)
 */
define( function( require ) {
  'use strict';

  // modules
  var inherit = require( 'PHET_CORE/inherit' );
  var Node = require( 'SCENERY/nodes/Node' );
  var Shape = require( 'KITE/Shape' );
  var Path = require( 'SCENERY/nodes/Path' );
  var Vector2 = require( 'DOT/Vector2' );
  var LinearGradient = require( 'SCENERY/util/LinearGradient' );
  var RadialGradient = require( 'SCENERY/util/RadialGradient' );
  var Color = require( 'SCENERY/util/Color' );
  var Line = require( 'SCENERY/nodes/Line' );
  var Circle = require( 'SCENERY/nodes/Circle' );
  var EllipticalArc = require( 'KITE/segments/EllipticalArc' );

  // Glass is one of the probe types, shows a shiny reflective interior in the central circle
  var glass = function( options ) {
    var GLASS_DEFAULTS = {
      centerColor: 'white',
      middleColor: '#E6F5FF', // light blue
      edgeColor: '#C2E7FF'    // slightly darker blue, like glass
    };
    options = _.extend( GLASS_DEFAULTS, options );
    return function( radius ) {
      return new Circle( radius, {
        fill: new RadialGradient( -radius * 0.15, -radius * 0.15, 0, -radius * 0.15, -radius * 0.20, radius * 0.60 )
          .addColorStop( 0, options.centerColor )
          .addColorStop( 0.4, options.middleColor ) // light blue
          .addColorStop( 1, options.edgeColor ) // slightly darker blue, like glass
      } );
    };
  };

  // Crosshairs can be shown in the central circle
  var crosshairs = function( options ) {
    var CROSSHAIRS_DEFAULTS = {
      stroke: 'black',
      lineWidth: 3,

      // The amount of blank space visible at the intersection of the 2 crosshairs lines
      intersectionRadius: 8
    };
    options = _.extend( CROSSHAIRS_DEFAULTS, options );
    return function( radius ) {

      var lineOptions = { stroke: options.stroke, lineWidth: options.lineWidth };
      return new Node( {
        children: [
          new Line( -radius, 0, -options.intersectionRadius, 0, lineOptions ),
          new Line( +radius, 0, +options.intersectionRadius, 0, lineOptions ),
          new Line( 0, -radius, 0, -options.intersectionRadius, lineOptions ),
          new Line( 0, +radius, 0, +options.intersectionRadius, lineOptions ) ]
      } );
    };
  };

  // constants
  var DEFAULT_OPTIONS = {
    radius: 50,
    innerRadius: 35,
    handleWidth: 50,
    handleHeight: 30,
    handleCornerRadius: 10,
    lightAngle: 4.25, // in radians, the angle of the incoming light.  0 is from the right, PI/2 from the bottom,
                      // PI from the left, etc.  The default is from the upper-left
    color: '#008541', // {Color|string} darkish green

    // The circular part of the ProbeNode is called the sensor, where it receives light or has crosshairs, etc.
    // or null for an empty region
    sensorType: glass()
  };

  /**
   * Constructor for the ProbeNode
   * @param {Object} [options]
   * @constructor
   */
  function ProbeNode( options ) {

    options = _.extend( _.clone( DEFAULT_OPTIONS ), options );

    var color =  Color.toColor( options.color );

    // To improve readability
    var radius = options.radius;

    // the top of the handle, below the circle at the top of the sensor
    var handleBottom = radius + options.handleHeight;

    // The shape of the outer body, circular at top with a handle at the bottom
    var arcExtent = 0.8;
    var handleWidth = options.handleWidth;
    var innerRadius = Math.min( options.innerRadius, options.radius );
    var cornerRadius = options.handleCornerRadius;

    var neckCornerRadius = 10;

    // We must know where the elliptical arc begins, so create an explicit EllipticalArc for that
    // Note: This elliptical arc must match the ellipticalArc call below
    var ellipticalArcStart = new EllipticalArc( new Vector2( 0, 0 ), radius, radius, 0, Math.PI * arcExtent, Math.PI * (1 - arcExtent), false ).start;

    // start in the bottom center
    var sensorShape = new Shape()
      .moveTo( 0, handleBottom )

      // Kite Shape automatically lineTo's to the first point of an arc, so no need to lineTo ourselves
      .arc( -handleWidth / 2 + cornerRadius, handleBottom - cornerRadius, cornerRadius, Math.PI / 2, Math.PI, false )
      .lineTo( -handleWidth / 2, radius + neckCornerRadius )
      .quadraticCurveTo( -handleWidth / 2, radius, ellipticalArcStart.x, ellipticalArcStart.y )

      // Top arc
      // Note: his elliptical arc must match the EllipticalArc above
      .ellipticalArc( 0, 0, radius, radius, 0, Math.PI * arcExtent, Math.PI * (1 - arcExtent), false )

      .quadraticCurveTo( handleWidth / 2, radius, +handleWidth / 2, radius + neckCornerRadius )
      .arc( handleWidth / 2 - cornerRadius, handleBottom - cornerRadius, cornerRadius, 0, Math.PI / 2, false )

      .lineTo( 0, handleBottom )
      .moveTo( innerRadius, 0 )
      .arc( 0, 0, innerRadius, Math.PI * 2, 0, true )
      .close();

    // The light angle is variable so that you can create a probe node that is pointing up or to the side
    var lightAngle = options.lightAngle;
    var lightOrigin = Vector2.createPolar( radius / 2, lightAngle );
    var lightDestination = Vector2.createPolar( handleBottom, lightAngle + Math.PI );
    var gradientSource = lightOrigin;
    var gradientDestination = lightDestination;

    var outerShapePath = new Path( sensorShape, {
      stroke: new LinearGradient( gradientSource.x, gradientSource.y, gradientDestination.x, gradientDestination.y )
        .addColorStop( 0.0, color.colorUtilsBrightness( -0.1 ) ) // dark
        .addColorStop( 1.0, color.colorUtilsBrightness( -0.2 ) ), // darker
      fill: new LinearGradient( gradientSource.x, gradientSource.y, gradientDestination.x, gradientDestination.y )
        .addColorStop( 0.0, color.colorUtilsBrightness( +0.4 ) ) // light
        .addColorStop( 0.3, color.colorUtilsBrightness( +0.2 ) ) // medium light
        .addColorStop( 1.0, color.colorUtilsBrightness( -0.1 ) ), // less light
      lineWidth: 2
    } );

    // the front flat "surface" of the sensor, makes it look 3d by putting a shiny glare on the top edge
    var innerPath = new Path( sensorShape, {
      fill: options.color,
      lineWidth: 2,
      scale: new Vector2( 0.9, 0.93 ),
      centerX: outerShapePath.centerX,

      // Shift it down a bit to make the face look a bit more 3d
      y: 2
    } );

    var children = [];

    if ( options.sensorType ) {
      children.push( options.sensorType( radius ) );
    }

    children.push( outerShapePath, innerPath );

    Node.call( this, {
      children: children
    } );

    this.mutate( options );
  }

  return inherit( Node, ProbeNode, {},

    // statics
    {

      // @public {read-only}, make the defaults publicly available to clients in case they need to make
      // customizations, such as 0.9 x the default width
      DEFAULT_OPTIONS: DEFAULT_OPTIONS,

      // Sensor types
      // @public
      crosshairs: crosshairs,
      glass: glass
    } );
} );<commit_msg>Factored out Math.PI from ProbeNode's lightAngle, see #183<commit_after>//  Copyright 2002-2014, University of Colorado Boulder

/**
 * A physical-looking probe with a handle and a semicircular sensor region, used in simulations like Bending Light and
 * Beer's Law Lab to show how much light is being received. It is typically connected to a body with readouts with a
 * curved wire. The origin is in the center of the circular part of the sensor (which is not vertically symmetrical).
 *
 * This code was generalized from Bending Light, see https://github.com/phetsims/bending-light/issues/165
 *
 * TODO: This is under development and not ready for review or usage in simulations other than Bending Light.
 *
 * @author Sam Reid (PhET Interactive Simulations)
 * @author Chandrashekar Bemagoni (Actual Concepts)
 * @author Chris Malley (PixelZoom, Inc.)
 */
define( function( require ) {
  'use strict';

  // modules
  var inherit = require( 'PHET_CORE/inherit' );
  var Node = require( 'SCENERY/nodes/Node' );
  var Shape = require( 'KITE/Shape' );
  var Path = require( 'SCENERY/nodes/Path' );
  var Vector2 = require( 'DOT/Vector2' );
  var LinearGradient = require( 'SCENERY/util/LinearGradient' );
  var RadialGradient = require( 'SCENERY/util/RadialGradient' );
  var Color = require( 'SCENERY/util/Color' );
  var Line = require( 'SCENERY/nodes/Line' );
  var Circle = require( 'SCENERY/nodes/Circle' );
  var EllipticalArc = require( 'KITE/segments/EllipticalArc' );

  // Glass is one of the probe types, shows a shiny reflective interior in the central circle
  var glass = function( options ) {
    var GLASS_DEFAULTS = {
      centerColor: 'white',
      middleColor: '#E6F5FF', // light blue
      edgeColor: '#C2E7FF'    // slightly darker blue, like glass
    };
    options = _.extend( GLASS_DEFAULTS, options );
    return function( radius ) {
      return new Circle( radius, {
        fill: new RadialGradient( -radius * 0.15, -radius * 0.15, 0, -radius * 0.15, -radius * 0.20, radius * 0.60 )
          .addColorStop( 0, options.centerColor )
          .addColorStop( 0.4, options.middleColor ) // light blue
          .addColorStop( 1, options.edgeColor ) // slightly darker blue, like glass
      } );
    };
  };

  // Crosshairs can be shown in the central circle
  var crosshairs = function( options ) {
    var CROSSHAIRS_DEFAULTS = {
      stroke: 'black',
      lineWidth: 3,

      // The amount of blank space visible at the intersection of the 2 crosshairs lines
      intersectionRadius: 8
    };
    options = _.extend( CROSSHAIRS_DEFAULTS, options );
    return function( radius ) {

      var lineOptions = { stroke: options.stroke, lineWidth: options.lineWidth };
      return new Node( {
        children: [
          new Line( -radius, 0, -options.intersectionRadius, 0, lineOptions ),
          new Line( +radius, 0, +options.intersectionRadius, 0, lineOptions ),
          new Line( 0, -radius, 0, -options.intersectionRadius, lineOptions ),
          new Line( 0, +radius, 0, +options.intersectionRadius, lineOptions ) ]
      } );
    };
  };

  // constants
  var DEFAULT_OPTIONS = {
    radius: 50,
    innerRadius: 35,
    handleWidth: 50,
    handleHeight: 30,
    handleCornerRadius: 10,
    /**
     * in radians, the angle of the incoming light.  0 is from the right, PI/2 from the bottom, PI from the left, etc.
     * The default is from the upper-left
     */
    lightAngle: 1.35 * Math.PI,
    color: '#008541', // {Color|string} darkish green

    // The circular part of the ProbeNode is called the sensor, where it receives light or has crosshairs, etc.
    // or null for an empty region
    sensorType: glass()
  };

  /**
   * Constructor for the ProbeNode
   * @param {Object} [options]
   * @constructor
   */
  function ProbeNode( options ) {

    options = _.extend( _.clone( DEFAULT_OPTIONS ), options );

    var color = Color.toColor( options.color );

    // To improve readability
    var radius = options.radius;

    // the top of the handle, below the circle at the top of the sensor
    var handleBottom = radius + options.handleHeight;

    // The shape of the outer body, circular at top with a handle at the bottom
    var arcExtent = 0.8;
    var handleWidth = options.handleWidth;
    var innerRadius = Math.min( options.innerRadius, options.radius );
    var cornerRadius = options.handleCornerRadius;

    var neckCornerRadius = 10;

    // We must know where the elliptical arc begins, so create an explicit EllipticalArc for that
    // Note: This elliptical arc must match the ellipticalArc call below
    var ellipticalArcStart = new EllipticalArc( new Vector2( 0, 0 ), radius, radius, 0, Math.PI * arcExtent, Math.PI * (1 - arcExtent), false ).start;

    // start in the bottom center
    var sensorShape = new Shape()
      .moveTo( 0, handleBottom )

      // Kite Shape automatically lineTo's to the first point of an arc, so no need to lineTo ourselves
      .arc( -handleWidth / 2 + cornerRadius, handleBottom - cornerRadius, cornerRadius, Math.PI / 2, Math.PI, false )
      .lineTo( -handleWidth / 2, radius + neckCornerRadius )
      .quadraticCurveTo( -handleWidth / 2, radius, ellipticalArcStart.x, ellipticalArcStart.y )

      // Top arc
      // Note: his elliptical arc must match the EllipticalArc above
      .ellipticalArc( 0, 0, radius, radius, 0, Math.PI * arcExtent, Math.PI * (1 - arcExtent), false )

      .quadraticCurveTo( handleWidth / 2, radius, +handleWidth / 2, radius + neckCornerRadius )
      .arc( handleWidth / 2 - cornerRadius, handleBottom - cornerRadius, cornerRadius, 0, Math.PI / 2, false )

      .lineTo( 0, handleBottom )
      .moveTo( innerRadius, 0 )
      .arc( 0, 0, innerRadius, Math.PI * 2, 0, true )
      .close();

    // The light angle is variable so that you can create a probe node that is pointing up or to the side
    var lightAngle = options.lightAngle;
    var lightOrigin = Vector2.createPolar( radius / 2, lightAngle );
    var lightDestination = Vector2.createPolar( handleBottom, lightAngle + Math.PI );
    var gradientSource = lightOrigin;
    var gradientDestination = lightDestination;

    var outerShapePath = new Path( sensorShape, {
      stroke: new LinearGradient( gradientSource.x, gradientSource.y, gradientDestination.x, gradientDestination.y )
        .addColorStop( 0.0, color.colorUtilsBrightness( -0.1 ) ) // dark
        .addColorStop( 1.0, color.colorUtilsBrightness( -0.2 ) ), // darker
      fill: new LinearGradient( gradientSource.x, gradientSource.y, gradientDestination.x, gradientDestination.y )
        .addColorStop( 0.0, color.colorUtilsBrightness( +0.4 ) ) // light
        .addColorStop( 0.3, color.colorUtilsBrightness( +0.2 ) ) // medium light
        .addColorStop( 1.0, color.colorUtilsBrightness( -0.1 ) ), // less light
      lineWidth: 2
    } );

    // the front flat "surface" of the sensor, makes it look 3d by putting a shiny glare on the top edge
    var innerPath = new Path( sensorShape, {
      fill: options.color,
      lineWidth: 2,
      scale: new Vector2( 0.9, 0.93 ),
      centerX: outerShapePath.centerX,

      // Shift it down a bit to make the face look a bit more 3d
      y: 2
    } );

    var children = [];

    if ( options.sensorType ) {
      children.push( options.sensorType( radius ) );
    }

    children.push( outerShapePath, innerPath );

    Node.call( this, {
      children: children
    } );

    this.mutate( options );
  }

  return inherit( Node, ProbeNode, {},

    // statics
    {

      // @public {read-only}, make the defaults publicly available to clients in case they need to make
      // customizations, such as 0.9 x the default width
      DEFAULT_OPTIONS: DEFAULT_OPTIONS,

      // Sensor types
      // @public
      crosshairs: crosshairs,
      glass: glass
    } );
} );<|endoftext|>