123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- var paperBuilder = function (options) {
- var builder = this;
- options = options || {};
- options.paperTemplate = options.paperTemplate || CMS_SystemConfig.VirtualDirectoryPath + '/Scripts/Examinee/Template/PaperTemplate.htm?v=1.1';
- options.questionTemplate = options.questionTemplate || CMS_SystemConfig.VirtualDirectoryPath + '/Scripts/Examinee/Template/QuestionTemplate.htm?v=1.1';
- options.navigationTemplate = options.navigationTemplate || CMS_SystemConfig.VirtualDirectoryPath + '/Scripts/Examinee/Template/NavigationTemplate.htm';
- options.informationTemplate = options.informationTemplate || CMS_SystemConfig.VirtualDirectoryPath + '/Scripts/Examinee/Template/InformationTemplate.htm?v=1.5';
- this.BuildInformationPanel = function (examInfo) {
- if (typeof (examInfo) == 'undefined' || !examInfo)
- return false;
- behaviour.togglePapert(!examinee.isTakePaper);
- $("#information_bar").setTemplateURL(options.informationTemplate);
- $("#information_bar").processTemplate(examInfo);
- $("#exam_sign").text(0);
- $("#exam_over").text(0);
- $("#exam_count").text(examInfo.questionCount);
- behaviour.registTimer();
- return true;
- }
- this.BuildPaper = function (paperInfo) {
- if (typeof (paperInfo) == 'undefined' || !paperInfo)
- return false;
- // 设定导航条和答卷的高度
- $(window).resize(function () { AdjustTestPanel(); });
- AdjustTestPanel();
- // 呈现导航条
- $("#navigation_body").setTemplateURL(options.navigationTemplate);
- $("#navigation_body").processTemplate(paperInfo);
- // 呈现答卷
- if (examInfo.display_type == 2) {
- $("#question").setTemplateURL(options.questionTemplate, null, { filter_data: false });
- }
- else {
- $("#question").setTemplateURL(options.paperTemplate, null, { filter_data: false });
- }
- $("#question").processTemplate(paperInfo);
- // 如果考试为可控,则注册轮询事件
- if (controllable) {
- var server = new serverInteractively({ test_id: examInfo.test_id, user_id: examinee.userid });
- server.registPersonExchange();
- //server.registPublicExchange();
- }
- $(".PageLoad").hide();
- return true;
- }
- }
- function AdjustTestPanel() {
- $(".navigation_body").height(document.documentElement.clientHeight - 267);
- $("#question").height(document.documentElement.clientHeight - 215);
- }
- // 模版行为 --- 与样式相关
- var WordSerial = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
- // 乱序题目缓存
- var buff = new Hashtable();
- // 修改乱序答案的序号
- function ReplaceFirstChar(answer) {
- if (typeof (examInfo) == 'undefined' || !examInfo || examInfo.breaking == 1 || examInfo.breaking == 4)
- return answer;
- var reg1 = /^.{2}/;
- for (var i = 0; i < answer.length; i++) {
- answer[i].content = answer[i].content.replace(reg1, WordSerial[i] + "、");
- }
- return answer;
- }
- // 转换填空题单体占位符
- function transformSingle(type, question, answer) {
- var body = question.content;
- var answers = ""; //GetTextAnswer(question.id);
- var target = "<input type='text' questionid='" + question.question_id + "' answertype='" + type.Name +
- "' class='txt_underline' name='ST-" + type.id + "-" + question.id + "' value=\"" + answers + "\"" +
- "onblur=\"behaviour.Check_text(this,'" + question.answers[0].answer_id + "','" + question.question_id + "');\" />";
- body = transform(body, target);
- return body;
- }
- // 转换多项填空题占位符
- function transformMuilte(type, question, answer) {
- var body = question.content;
- var answers = ""; //GetTextAnswer(question.id).split('|');
- for (var a in question.answers) {
- var an = "";
- // if (answers.length > a)
- // an = answers[a];
- var ctrlName = "ST-" + type.id + "-" + question.question_id;
- var target = "<input type='text' questionid='" + question.question_id + "' answertype='" + type.Name +
- "' class='txt_underline' name='" + ctrlName + "' value=\"" + an + "\"" +
- "onblur=\"behaviour.Check_text2(this,'" + ctrlName + "','" + question.answers[a].answer_id + "','" + question.question_id + "');\" />";
- body = transform(body, target);
- }
- return body;
- }
- // 显示答卷问题及答案
- function transform2(type, question, answer) {
- var body = question.content;
- for (var a in question.answers) {
- var an = "";
- // if (answers.length > a)
- // an = answers[a];
- var ctrlName = "ST-" + type.id + "-" + question.question_id;
- var target = "<input type='text' questionid='" + question.question_id + "' answertype='" + type.Name +
- "' class='txt_underline' name='" + ctrlName + "' value=\"" + answer + "\"" +
- " />";
- body = transform(body, target);
- }
- return body;
- }
- function GetCheckAnswer() {
- return false;
- }
- //是否用户已选答案
- function IsUserAnswer(question_id, answer_id, rightAnswer) {
- var lan = rightAnswer.split(',');
- if (lan.toString().indexOf(answer_id) > -1) {
- return "checked='checked'";
- }
- return '';
- }
- // 替换占位符
- function transform(content, target) {
- var reg = /【.*?】/;
- return content.replace(reg, target);
- }
- // 检查完成状况
- function ChecComplate(id) {
- }
- function PreBtnEvent(sender) {
- var me = $(sender);
- var parent = me.closest(".q_container").hide();
- parent.prev().show();
- }
- function NextBtnEvent(sender) {
- var me = $(sender);
- var parent = me.closest(".q_container").hide();
- parent.next().show();
- }
- function q(question_id) {
- if (examInfo.display_type == 2) {
- $(".q_container").hide();
- $("#q_" + question_id).show();
- }
- }
- // 准备题目集
- function prepareQuestions(typeid, questions) {
- if (examInfo.breaking == 1 || examInfo.breaking == 3) {
- if (buff.contains(typeid))
- return buff.items(typeid);
- var result = chaosArray(questions);
- buff.add(typeid, result);
- return result;
- }
- return questions;
- }
- // 准备答案集
- function prepareAnswers(answers) {
- if (examInfo.breaking == 2 || examInfo.breaking == 3)
- return chaosArray(answers);
- return answers;
- }
- // 题目乱序,需要产生2个拷贝
- function chaosArray(array) {
- var src = array.slice();
- var result = new Array();
- var count = array.length;
- while (count > 0) {
- var index = 0;
- if (count > 1)
- index = getRandom(1, count) - 1
- result[result.length] = src[index];
- src.splice(index, 1);
- count--;
- }
- return result;
- }
- // 获取指定范围的随机数
- function getRandom(start, end) {
- return Math.ceil(Math.random() * ((end - start) + start));
- }
- //填空题题
- function ShowAnswer2(rightAnswer, provid_answer) {
- return rightAnswer;
- }
- //选择题
- function ShowAnswerSelect(rightAnswer, provid_answer) {
- var rightlist = new Array();
- var lan = rightAnswer.split(',');
- for (var index in provid_answer) {
- var ans = provid_answer[index];
- if (lan.toString().indexOf(ans.answer_id) > -1) {
- rightlist.push(ans.content.substring(0, 1));
- }
- }
- return rightlist.join(",");
- }
|