/**
 * /sQuiz/sQuiz_module_simpleQuestion.js
 * @version 1.2
 * @desc sQuiz class for simpleQuestions
 * @author Fándly Gergő Zoltán (gergo@systemtest.tk, systemtest.tk)
 * @copy 2017 Fándly Gergő Zoltán
 * License:
    sQuiz for creating small jQuery based quizs in an implementable way
    Copyright (C) 2017  Fándly Gergő Zoltán

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 **/

(function($){
    $.sQuiz_module_simpleQuestion=function(parent, quiz){
        this.parent=parent;
        this.quiz=quiz;
        this.container=parent.element.children("#sqTestArea");
        this.qidMap={};
    };
    
    $.sQuiz_module_simpleQuestion.prototype={
        submit: function(){
            var self=this;
            this.parent.stopTimer();
            var sub={};
            sub.answered=this.container.children("input[data-qid="+this.qidMap["answer"]+"]").val();
            if(sub.answered.toLowerCase()==this.quiz.answer){
                this.container.children("input[data-qid="+this.qidMap["answer"]+"]").addClass("sq-green");
                sub.correct=true;
            }
            else{
                this.container.children("input[data-qid="+this.qidMap["answer"]+"]").addClass("sq-red");
                sub.correct=false;
            }
            sub.timeElapsed=this.parent.elapsedPerTest;
            this.parent.answers.push(sub);
        },
        
        load: function(){
            var qid=0;
            this.container.html("<h2>"+this.quiz.question+"</h2><br><p>"+this.parent.reg.answer+":</p><input type=\"text\" class=\"sq\" data-qid=\""+qid.toString()+"\" placeholder=\""+this.parent.reg.answer+"...\">");
            this.qidMap["answer"]=qid;
            $("input[data-qid="+this.qidMap["answer"]+"]").focus();
        }
    };
}(jQuery));
