iexam.interactively.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. var serverInteractively = function(options) {
  2. var WAIT_EXAM_HANDLER_ID = "#msgSpan";
  3. var WAIT_EXAM_END_ID = "input[id$=hide_end]";
  4. var WAIT_EXAM_CONVAN = "#aninateConvan";
  5. var aninateArray = [".", "..", "...", "....", ".....", "......"];
  6. var EXAM_MSG_ID = "#txt_message";
  7. var personExchangeLabel = "personExchange";
  8. var publicExchangeLabel = "publicExchange";
  9. var examinerExchangeLabel = "examinerExchange";
  10. // 获取交互时间间隔默认5秒
  11. var exchangeInterval = 5000;
  12. var publicExchangeList = new Hashtable();
  13. options = options || {};
  14. options.test_id = options.test_id || "";
  15. options.user_id = options.user_id || "";
  16. var sender = this;
  17. // 现场考试等待方法
  18. this.registWaitExam = function(url) {
  19. var interval = 1000;
  20. var convan = $(WAIT_EXAM_CONVAN);
  21. $(WAIT_EXAM_HANDLER_ID).everyTime(interval, 'waitExam', function() {
  22. beginInvoke(CMS_SystemConfig.VirtualDirectoryPath + "/OnlineTest/GetTestStatus", { test_id: options.test_id, userid: options.user_id }, function (rs) {
  23. if (rs.state) {
  24. $(WAIT_EXAM_END_ID).val(rs.limit);
  25. sender.registStartCountDown(url);
  26. }
  27. else {
  28. if (rs.msg.length > 0)
  29. $(WAIT_EXAM_HANDLER_ID).text(rs.msg);
  30. else {
  31. convan.text(waitAninate(convan.text().length));
  32. }
  33. }
  34. });
  35. });
  36. }
  37. this.registStartCountDown = function(url) {
  38. $("#countDown").show();
  39. $("#msgSpan").hide();
  40. $(".timer").calcTimer({
  41. limit: $(WAIT_EXAM_END_ID).val(),
  42. inputType: "s",
  43. format: "<span style='color:blue'><span style='font-size:14px'>#H</span>时<span style='font-size:14px'>#M</span>分<span style='font-size:14px'>#S</span>秒</span>",
  44. ontimeout: function() {
  45. if (typeof (url) == 'string') {
  46. if (url.length > 0) {
  47. window.location.href = url;
  48. }
  49. }
  50. else {
  51. url();
  52. }
  53. },
  54. onCountdownError: function(container) {
  55. var examLength = Invoke(CMS_SystemConfig.VirtualDirectoryPath + "/OnlineTest/GetStartLengthOfExam", { test_id: examInfo.test_id, userid: examinee.userid });
  56. $(WAIT_EXAM_END_ID).val(examLength);
  57. sender.registStartCountDown(url);
  58. }
  59. });
  60. }
  61. this.registPersonExchange = function() {
  62. $(EXAM_MSG_ID).everyTime(exchangeInterval, personExchangeLabel, function() {
  63. beginInvoke(CMS_SystemConfig.VirtualDirectoryPath + "/OnlineTest/ListPersonalExchange", { test_id: options.test_id, userid: options.user_id }, function (rs) {
  64. var param = eval(rs);
  65. for (var i = 0; i < param.length; i++) {
  66. var p = param[i];
  67. behaviour.handleCommand(p.type, { type: 'person', intData: p.extendInt, sender: sender });
  68. }
  69. });
  70. });
  71. }
  72. this.registPublicExchange = function() {
  73. $(EXAM_MSG_ID).everyTime(exchangeInterval, publicExchangeLabel, function() {
  74. beginInvoke(CMS_SystemConfig.VirtualDirectoryPath + "/OnlineTest/ListPublicExchange", { test_id: options.test_id }, function (rs) {
  75. var param = eval(rs);
  76. for (var i = 0; i < param.length; i++) {
  77. var p = param[i];
  78. if (!publicExchangeList.contains(p.id)) {
  79. publicExchangeList.add(p.id, p.type);
  80. behaviour.handleCommand(p.type, { type: 'all', intData: p.extendInt, sender: sender });
  81. }
  82. }
  83. });
  84. });
  85. }
  86. this.removeExamineeExchangeEvent = function() {
  87. $(EXAM_MSG_ID).stopTime(personExchangeLabel);
  88. //$(EXAM_MSG_ID).stopTime(publicExchangeLabel);
  89. }
  90. var waitAninate = function(index) {
  91. if (index >= aninateArray.length)
  92. index = 0;
  93. return aninateArray[index];
  94. }
  95. }