paperBuilder.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. var paperBuilder = function (options) {
  2. var builder = this;
  3. options = options || {};
  4. options.paperTemplate = options.paperTemplate || CMS_SystemConfig.VirtualDirectoryPath + '/Scripts/Examinee/Template/PaperTemplate.htm?v=1.1';
  5. options.questionTemplate = options.questionTemplate || CMS_SystemConfig.VirtualDirectoryPath + '/Scripts/Examinee/Template/QuestionTemplate.htm?v=1.1';
  6. options.navigationTemplate = options.navigationTemplate || CMS_SystemConfig.VirtualDirectoryPath + '/Scripts/Examinee/Template/NavigationTemplate.htm';
  7. options.informationTemplate = options.informationTemplate || CMS_SystemConfig.VirtualDirectoryPath + '/Scripts/Examinee/Template/InformationTemplate.htm?v=1.5';
  8. this.BuildInformationPanel = function (examInfo) {
  9. if (typeof (examInfo) == 'undefined' || !examInfo)
  10. return false;
  11. behaviour.togglePapert(!examinee.isTakePaper);
  12. $("#information_bar").setTemplateURL(options.informationTemplate);
  13. $("#information_bar").processTemplate(examInfo);
  14. $("#exam_sign").text(0);
  15. $("#exam_over").text(0);
  16. $("#exam_count").text(examInfo.questionCount);
  17. behaviour.registTimer();
  18. return true;
  19. }
  20. this.BuildPaper = function (paperInfo) {
  21. if (typeof (paperInfo) == 'undefined' || !paperInfo)
  22. return false;
  23. // 设定导航条和答卷的高度
  24. $(window).resize(function () { AdjustTestPanel(); });
  25. AdjustTestPanel();
  26. // 呈现导航条
  27. $("#navigation_body").setTemplateURL(options.navigationTemplate);
  28. $("#navigation_body").processTemplate(paperInfo);
  29. // 呈现答卷
  30. if (examInfo.display_type == 2) {
  31. $("#question").setTemplateURL(options.questionTemplate, null, { filter_data: false });
  32. }
  33. else {
  34. $("#question").setTemplateURL(options.paperTemplate, null, { filter_data: false });
  35. }
  36. $("#question").processTemplate(paperInfo);
  37. // 如果考试为可控,则注册轮询事件
  38. if (controllable) {
  39. var server = new serverInteractively({ test_id: examInfo.test_id, user_id: examinee.userid });
  40. server.registPersonExchange();
  41. //server.registPublicExchange();
  42. }
  43. $(".PageLoad").hide();
  44. return true;
  45. }
  46. }
  47. function AdjustTestPanel() {
  48. $(".navigation_body").height(document.documentElement.clientHeight - 267);
  49. $("#question").height(document.documentElement.clientHeight - 215);
  50. }
  51. // 模版行为 --- 与样式相关
  52. 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"];
  53. // 乱序题目缓存
  54. var buff = new Hashtable();
  55. // 修改乱序答案的序号
  56. function ReplaceFirstChar(answer) {
  57. if (typeof (examInfo) == 'undefined' || !examInfo || examInfo.breaking == 1 || examInfo.breaking == 4)
  58. return answer;
  59. var reg1 = /^.{2}/;
  60. for (var i = 0; i < answer.length; i++) {
  61. answer[i].content = answer[i].content.replace(reg1, WordSerial[i] + "、");
  62. }
  63. return answer;
  64. }
  65. // 转换填空题单体占位符
  66. function transformSingle(type, question, answer) {
  67. var body = question.content;
  68. var answers = ""; //GetTextAnswer(question.id);
  69. var target = "<input type='text' questionid='" + question.question_id + "' answertype='" + type.Name +
  70. "' class='txt_underline' name='ST-" + type.id + "-" + question.id + "' value=\"" + answers + "\"" +
  71. "onblur=\"behaviour.Check_text(this,'" + question.answers[0].answer_id + "','" + question.question_id + "');\" />";
  72. body = transform(body, target);
  73. return body;
  74. }
  75. // 转换多项填空题占位符
  76. function transformMuilte(type, question, answer) {
  77. var body = question.content;
  78. var answers = ""; //GetTextAnswer(question.id).split('|');
  79. for (var a in question.answers) {
  80. var an = "";
  81. // if (answers.length > a)
  82. // an = answers[a];
  83. var ctrlName = "ST-" + type.id + "-" + question.question_id;
  84. var target = "<input type='text' questionid='" + question.question_id + "' answertype='" + type.Name +
  85. "' class='txt_underline' name='" + ctrlName + "' value=\"" + an + "\"" +
  86. "onblur=\"behaviour.Check_text2(this,'" + ctrlName + "','" + question.answers[a].answer_id + "','" + question.question_id + "');\" />";
  87. body = transform(body, target);
  88. }
  89. return body;
  90. }
  91. // 显示答卷问题及答案
  92. function transform2(type, question, answer) {
  93. var body = question.content;
  94. for (var a in question.answers) {
  95. var an = "";
  96. // if (answers.length > a)
  97. // an = answers[a];
  98. var ctrlName = "ST-" + type.id + "-" + question.question_id;
  99. var target = "<input type='text' questionid='" + question.question_id + "' answertype='" + type.Name +
  100. "' class='txt_underline' name='" + ctrlName + "' value=\"" + question.answers[a].content + "\"" +
  101. " />";
  102. body = transform(body, target);
  103. }
  104. return body;
  105. }
  106. function GetCheckAnswer() {
  107. return false;
  108. }
  109. //是否用户已选答案
  110. function IsUserAnswer(question_id, answer_id, rightAnswer) {
  111. var lan = rightAnswer.split(',');
  112. if (lan.toString().indexOf(answer_id) > -1) {
  113. return "checked='checked'";
  114. }
  115. return '';
  116. }
  117. // 替换占位符
  118. function transform(content, target) {
  119. var reg = /【.*?】/;
  120. return content.replace(reg, target);
  121. }
  122. // 检查完成状况
  123. function ChecComplate(id) {
  124. }
  125. function PreBtnEvent(sender) {
  126. var me = $(sender);
  127. var parent = me.closest(".q_container").hide();
  128. parent.prev().show();
  129. }
  130. function NextBtnEvent(sender) {
  131. var me = $(sender);
  132. var parent = me.closest(".q_container").hide();
  133. parent.next().show();
  134. }
  135. function q(question_id) {
  136. if (examInfo.display_type == 2) {
  137. $(".q_container").hide();
  138. $("#q_" + question_id).show();
  139. }
  140. }
  141. // 准备题目集
  142. function prepareQuestions(typeid, questions) {
  143. if (examInfo.breaking == 1 || examInfo.breaking == 3) {
  144. if (buff.contains(typeid))
  145. return buff.items(typeid);
  146. var result = chaosArray(questions);
  147. buff.add(typeid, result);
  148. return result;
  149. }
  150. return questions;
  151. }
  152. // 准备答案集
  153. function prepareAnswers(answers) {
  154. if (examInfo.breaking == 2 || examInfo.breaking == 3)
  155. return chaosArray(answers);
  156. return answers;
  157. }
  158. // 题目乱序,需要产生2个拷贝
  159. function chaosArray(array) {
  160. var src = array.slice();
  161. var result = new Array();
  162. var count = array.length;
  163. while (count > 0) {
  164. var index = 0;
  165. if (count > 1)
  166. index = getRandom(1, count) - 1
  167. result[result.length] = src[index];
  168. src.splice(index, 1);
  169. count--;
  170. }
  171. return result;
  172. }
  173. // 获取指定范围的随机数
  174. function getRandom(start, end) {
  175. return Math.ceil(Math.random() * ((end - start) + start));
  176. }
  177. //填空题题
  178. function ShowAnswer2(rightAnswer, provid_answer) {
  179. var rightlist = new Array();
  180. var lan = rightAnswer.split(',');
  181. for (var index in provid_answer) {
  182. var ans = provid_answer[index];
  183. if (lan.toString().indexOf(ans.answer_id) > -1) {
  184. rightlist.push(ans.content);
  185. }
  186. }
  187. return rightlist.join(",");
  188. }
  189. //选择题
  190. function ShowAnswerSelect(rightAnswer, provid_answer) {
  191. var rightlist = new Array();
  192. var lan = rightAnswer.split(',');
  193. for (var index in provid_answer) {
  194. var ans = provid_answer[index];
  195. if (lan.toString().indexOf(ans.answer_id) > -1) {
  196. rightlist.push(ans.content.substring(0, 1));
  197. }
  198. }
  199. return rightlist.join(",");
  200. }