var swipe, aBook=[], aQuestion=[], iBook, iQuestion, iAnswer;
|
|
$(document).ready( onDocumentReady );
|
|
function onDocumentReady() {
|
pageInit(showBook);
|
}
|
|
function showBook() {
|
menuSwitch("book");
|
loadBook();
|
}
|
|
function loadBook() {
|
jsonRequest("quiz", "load_book", {}, onBookResponse, "正在获取培训题库…请稍候");
|
}
|
|
function onBookResponse(res) {
|
aBook=res.book_list;
|
|
var html="";
|
for (var i=0; i<aBook.length; i++) {
|
var book=aBook[i];
|
html+=div("div_book_item",
|
div("div_book_code", book.code)+
|
div("div_book_title", book.title)+
|
div("div_book_stats_group",
|
div("div_book_stats_item", "总共: "+book.question_num+"题")+
|
div("div_book_stats_item", "已回答: "+book.finish_num+"题")+
|
div("div_book_stats_item", "得分: "+book.score+"分")+
|
div("div_book_stats_item", "正确: "+book.correct_num+"题") ),
|
"iBook="+i+"; showQuestion()");
|
}
|
$("#div_book_group").html(html);
|
}
|
|
function showQuestion() {
|
pageGo("question");
|
loadQuestion();
|
}
|
|
function hideQuestion() {
|
pageBack("menu", loadBook);
|
}
|
|
function loadQuestion() {
|
var req={};
|
req.book_uid=aBook[iBook].uid;
|
jsonRequest("quiz", "load_question", req, onQuestionResponse, "正在获取题目……请稍候");
|
}
|
|
function onQuestionResponse(res) {
|
aQuestion=res.question_list;
|
$("#div_question_header_title").html(aBook[iBook].code+" - "+aBook[iBook].title);
|
$("#div_answer_header_title").html(aBook[iBook].code+" - "+aBook[iBook].title);
|
var html="";
|
for (var i=0; i<aQuestion.length; i++) {
|
var question=aQuestion[i];
|
var result=question.result? div("div_question_"+(question.result.correct?"correct":"wrong"), "") : "";
|
html+=div("div_question_item",
|
div("div_question_code", (i+1)+".")+
|
div("div_question_title", aQuestion[i].title)+
|
result,
|
"iQuestion="+i+"; showAnswer()");
|
}
|
if (getAccount().level=="RM") {
|
html+=div("div_question_item", "添加新的题目", "showAddQuestion()");
|
}
|
$("#div_question_group").html(html);
|
|
iQuestion=0;
|
var html=div("div_answer_start","");
|
for (i=0; i<aQuestion.length; i++) {
|
html+=div("div_answer_frame", "", "", "div_answer_frame_"+i);
|
}
|
html+=div("div_answer_frame","", "", "div_answer_end");
|
var wrap=div("swipe-wrap", html);
|
$("#div_answer_swipe").html(wrap);
|
for (i=0; i<aQuestion.length; i++) {
|
loadAnswer(i);
|
}
|
$("#page_answer").show();
|
var option = {
|
continuous: false,
|
disableScroll: false,
|
stopPropagation: false,
|
transitionEnd: refreshAnswer,
|
startSlide:0
|
}
|
swipe = new Swipe(document.getElementById("div_answer_swipe"), option);
|
$("#page_answer").hide();
|
}
|
|
function loadAnswer(i) {
|
var question=aQuestion[i];
|
console.log(question);
|
var html="";
|
html+=div("div_answer_question", question.title);
|
for (var j=0; j<question.answer_list.length; j++) {
|
var answer=question.answer_list[j];
|
var r=answer.rank;
|
var status=(question.result && question.result.rank==r)?"on":"off";
|
html+=div("div_answer_"+status,
|
div("div_index_"+status, String.fromCharCode(64+answer.rank), "", "index_"+i+"_"+r)+answer.title,
|
"selectAnswer("+r+")", "answer_"+i+"_"+r);
|
}
|
if (getAccount().level=="RM") {
|
html+=div("div_answer_off", div("div_index_off", "+")+"添加答案选项", "showAddAnswer()");
|
}
|
if (question.photo) {
|
html+=img("img_question_photo", "quiz/"+question.photo);
|
}
|
$("#div_answer_frame_"+i).html(html);
|
}
|
|
function startAnswer() {
|
iQuestion=0;
|
showAnswer();
|
}
|
|
function showAnswer() {
|
swipe.slide(0,0);
|
$("#page_answer").show();
|
setTimeout(slideAnswer, 100);
|
}
|
|
function slideAnswer() {
|
swipe.slide(iQuestion+1);
|
}
|
|
function refreshAnswer() {
|
var i=swipe.getPos(), n=aQuestion.length;
|
if (i==0) {
|
$("#page_answer").hide();
|
} else if (i==n+1) {
|
$("#div_question_index").html("");
|
checkResult();
|
} else {
|
iQuestion=i-1;
|
var question=aQuestion[iQuestion];
|
var aAnswer=question.answer_list;
|
$("#div_question_index").html("第"+question.rank+"题");
|
var bPrev=(iQuestion>0);
|
$("#div_prev_question").toggle(bPrev);
|
var bNext=(iQuestion<n-1);
|
$("#div_next_question").toggle(bNext);
|
var bSubmit=(iQuestion==n-1);
|
$("#div_submit_result").toggle(bSubmit);
|
var bHide=(iQuestion==0);
|
$("#div_hide_answer").toggle(bHide);
|
var percent=Math.floor(((iQuestion+1)*100)/n);
|
$("#div_answer_progress").css("width", percent+"%");
|
}
|
}
|
|
function hideAnswer() {
|
swipe.slide(0);
|
}
|
|
function selectAnswer(r) {
|
if (aQuestion[iQuestion].result) {
|
var r0=aQuestion[iQuestion].result.rank;
|
$("#index_"+iQuestion+"_"+r0).attr("class", "div_index_off");
|
$("#answer_"+iQuestion+"_"+r0).attr("class", "div_answer_off");
|
}
|
aQuestion[iQuestion].result={rank:r};
|
$("#index_"+iQuestion+"_"+r).attr("class", "div_index_on");
|
$("#answer_"+iQuestion+"_"+r).attr("class", "div_answer_on");
|
}
|
|
function nextQuestion() {
|
swipe.next();
|
}
|
|
function prevQuestion() {
|
swipe.prev();
|
}
|
|
function getBlank() {
|
var blank=0;
|
for (var i=0; i<aQuestion.length; i++) {
|
blank += aQuestion[i].result?0:1;
|
}
|
return blank;
|
}
|
|
function checkResult() {
|
var blank=getBlank();
|
if (blank>0) {
|
showConfirm("还有"+blank+"道题未回答,是否提交?", "submitResult()");
|
} else {
|
showConfirm("是否确认提交?", "submitResult()");
|
}
|
}
|
|
function submitResult() {
|
var list=[];
|
for (var i=0; i<aQuestion.length; i++) {
|
if (aQuestion[i].result) {
|
list.push({uid:aQuestion[i].uid, rank:aQuestion[i].result.rank});
|
}
|
}
|
|
var req={};
|
req.book_uid=aBook[iBook].uid;
|
req.result_list=list;
|
jsonRequest("quiz", "add_result", req, onSubmitResultResponse, "正在提交答案……请稍候");
|
}
|
|
function onSubmitResultResponse() {
|
hideAnswer();
|
loadQuestion();
|
}
|
|
/************ ADMIN ****************/
|
|
function showAddQuestion() {
|
$("#input_add_question_title").val("");
|
$("#div_add_question").show();
|
}
|
|
function hideAddQuestion() {
|
$("#div_add_question").hide();
|
}
|
|
function submitAddQuestion() {
|
var req={};
|
req.book_uid=aBook[iBook].uid;
|
req.title=$("#input_add_question_title").val();
|
hideAddQuestion();
|
jsonRequest("quiz", "add_question", req, loadQuestion);
|
}
|
|
function showAddAnswer() {
|
$("#input_add_answer_title").val("");
|
$("#div_add_answer").show();
|
}
|
|
function hideAddAnswer() {
|
$("#div_add_answer").hide();
|
}
|
|
function submitAddAnswer(correct) {
|
var req={};
|
req.question_uid=aQuestion[iQuestion].uid;
|
req.title=$("#input_add_answer_title").val();
|
req.correct=correct;
|
hideAddAnswer();
|
jsonRequest("quiz", "add_answer", req, onAddAnswerResponse);
|
}
|
|
function onAddAnswerResponse(res) {
|
aQuestion[iQuestion].answer_list.push(res);
|
showAnswer();
|
}
|