Widget:Sandbox: Difference between revisions
Jump to navigation
Jump to search
Matt Pijoan (talk | contribs) No edit summary |
Matt Pijoan (talk | contribs) No edit summary |
||
Line 140: | Line 140: | ||
} | } | ||
function tutorOrExam(event) { | function tutorOrExam(event) { | ||
event.data.qbank = $(this).attr('id'); | event.data.qbank = $(this).attr('id'); | ||
var buttons = ''; | var buttons = ''; | ||
Line 310: | Line 310: | ||
for (var i = 0; i < categories['sub'].length; i++) { | for (var i = 0; i < categories['sub'].length; i++) { | ||
if (categories['main'][i]) { | if (categories['main'][i]) { | ||
table += "<tr><td><input type='checkbox' name='MainCat' value='" + categories['main'][i] + "' />" + categories['main'][i] + " ( "+exam.arrCounts['category']['main'][categories['main'][i]]+" ) </td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + " ( "+exam.arrCounts['category']['sub'][categories['sub'][i]]+" )</td></tr>"; | table += "<tr><td><input type='checkbox' name='MainCat' value='" + categories['main'][i] + "' />" + categories['main'][i] + " ( " + exam.arrCounts['category']['main'][categories['main'][i]] + " ) </td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + " ( " + exam.arrCounts['category']['sub'][categories['sub'][i]] + " )</td></tr>"; | ||
} else { | } else { | ||
table += "<tr><td></td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + " ( "+exam.arrCounts['category']['sub'][categories['sub'][i]]+" ) </td></tr>"; | table += "<tr><td></td><td><input type='checkbox' name='SubCat' value='" + categories['sub'][i] + "' />" + categories['sub'][i] + " ( " + exam.arrCounts['category']['sub'][categories['sub'][i]] + " ) </td></tr>"; | ||
} | } | ||
} | } | ||
Line 371: | Line 371: | ||
Sub.push($(this).val()); | Sub.push($(this).val()); | ||
}); | }); | ||
event.data.mainCat = Main; | |||
event.data.subCat = Sub; | |||
var api = new mw.Api(event, Main, Sub); | var api = new mw.Api(event, Main, Sub); | ||
api.get({ | |||
action : 'catcount', | |||
main : JSON.stringify(Main), | |||
sub : JSON.stringify(Sub), | |||
exam : event.data.examtype, | |||
format : 'json' | |||
}, { | |||
ok : function (res) { | |||
event.data.maxQ = res.Count; | |||
var output = "<b>Choose the number of questions you would like to answer. The maximum number of questions you can select is <span id='countShow'>" + event.data.maxQ + "</span>.</b><br /><br /><br />Number of questions:<input type='text' id='numQues' /><br /><br /><div id='Go' class='noSelect WBRButton'>Click here to begin the exam</div>"; | |||
if ($("#exam").find('#numQues').length == 0) { | |||
$("#exam").append(output); | |||
} | |||
$("#Go").click(event.data, inputValidation); | |||
} | |||
}); | |||
} else { | } else { | ||
alert('Please ensure you have both a main and a sub category selected'); | alert('Please ensure you have both a main and a sub category selected'); | ||
Line 438: | Line 438: | ||
} | } | ||
function loadNextQuestion(event) { | function loadNextQuestion(event) { | ||
var api = new mw.Api(event); | |||
api.get({ | |||
action : 'load', | |||
main : JSON.stringify(event.mainCat), | |||
sub : JSON.stringify(event.subCat), | |||
exam : event.examtype, | |||
num : event.numQuestion, | |||
format : 'json' | |||
}, { | |||
ok : function (res) { | ok : function (res) { | ||
var i = 0; | |||
event.currentQuestion = 0; | |||
$.each(res.questions.list, function (key, element) { | |||
element.PageName = key; | |||
event.examQuestions[i] = element; | event.examQuestions[i] = element; | ||
i++; | |||
}); | }); | ||
addToNavBar(event); | |||
} | } | ||
}); | }); | ||
Line 461: | Line 461: | ||
function addToNavBar(exam) { | function addToNavBar(exam) { | ||
$("#exam").html("<div id='navBar'><div id='back' class='noSelect WBRButton'><br />Back</div><div id='next' class='noSelect WBRButton'><br />Next</div><div id='finish' class='noSelect WBRButton'><br />Finish</div></div><div id='navPane'></div><div id='examSpace'></div><span id='timeRem' style='height: 0px; visibility: hidden'>" + exam.timeAmt.toString() + "</span>"); | $("#exam").html("<div id='navBar'><div id='back' class='noSelect WBRButton'><br />Back</div><div id='next' class='noSelect WBRButton'><br />Next</div><div id='finish' class='noSelect WBRButton'><br />Finish</div></div><div id='navPane'></div><div id='examSpace'></div><span id='timeRem' style='height: 0px; visibility: hidden'>" + exam.timeAmt.toString() + "</span>"); | ||
$("#back").click(exam, questionNavigation); | |||
$("#next").click(exam, questionNavigation); | |||
$("#finish").click(exam, endExam); | |||
if (exam.timer) { | if (exam.timer) { | ||
$("#bodyContent").append("<div style='position:absolute; z-index:1000; width:300px; height:50px; top:0px; right:0px; border: 1px solid #000; background-color:#EEE; float:right; visibility:hidden;' id='timerBox'>Testing.</div>"); | $("#bodyContent").append("<div style='position:absolute; z-index:1000; width:300px; height:50px; top:0px; right:0px; border: 1px solid #000; background-color:#EEE; float:right; visibility:hidden;' id='timerBox'>Testing.</div>"); | ||
Line 474: | Line 474: | ||
}); | }); | ||
$("#" + exam.currentQuestion).addClass("boxed"); | $("#" + exam.currentQuestion).addClass("boxed"); | ||
$(".navPaneButton:odd").css("background-color", "#3338CC"); | |||
$(".navPaneButton").click(exam, questionNavigation); | $(".navPaneButton").click(exam, questionNavigation); | ||
questionDisplay(exam); | questionDisplay(exam); | ||
Line 493: | Line 493: | ||
} | } | ||
if (obj.AnswerB && obj.AnswerB.length > 0) { | if (obj.AnswerB && obj.AnswerB.length > 0) { | ||
htmlStuff += "<div class='answer answerNoBorder' id='B'><input type='radio' id='Br' />"+ trimP(obj.AnswerB)+"</div>"; | htmlStuff += "<div class='answer answerNoBorder' id='B'><input type='radio' id='Br' />" + trimP(obj.AnswerB) + "</div>"; | ||
} | } | ||
if (obj.AnswerBExp && obj.AnswerBExp.length > 0 && exam.examType === "Tutor") { | if (obj.AnswerBExp && obj.AnswerBExp.length > 0 && exam.examType === "Tutor") { | ||
Line 533: | Line 533: | ||
} | } | ||
function trimP(data){ | function trimP(data) { | ||
return data.substring(3, data.length - 4).trim(); ; | |||
} | } | ||
function questionReview(exam) { | function questionReview(exam) { | ||
Line 588: | Line 588: | ||
} | } | ||
$("#examSpace").append("<br /><br />The correct answer is: " + exam.examQuestions[exam.currentQuestion].RightAnswer + "<br /><br /><i>" + exam.examQuestions[exam.currentQuestion].Explanation + "</i><br />"); | $("#examSpace").append("<br /><br />The correct answer is: " + exam.examQuestions[exam.currentQuestion].RightAnswer + "<br /><br /><i>" + exam.examQuestions[exam.currentQuestion].Explanation + "</i><br />"); | ||
} | |||
} | } | ||
function addRatyRating(exam) { | function addRatyRating(exam) { | ||
Line 857: | Line 858: | ||
} | } | ||
} | } | ||
function countCats(event) { | function countCats(event) { | ||
event.data.timeAmt = parseInt($(this).attr("id"), 10) * 6000; | event.data.timeAmt = parseInt($(this).attr("id"), 10) * 6000; | ||
var temp = event.data.examtype.replace(/ /g, "_"); | |||
var api = new mw.Api(); | var api = new mw.Api(); | ||
api.get({ | api.get({ | ||
Line 865: | Line 866: | ||
exam : temp, | exam : temp, | ||
format : 'json', | format : 'json', | ||
async : false | |||
}, { | }, { | ||
ok : function (data) { | ok : function (data) { | ||
event.data.arrCounts = data; | event.data.arrCounts = data; | ||
selectCats(event.data); | |||
} | } | ||
}); | }); |