var serverInteractively = function(options) { var WAIT_EXAM_HANDLER_ID = "#msgSpan"; var WAIT_EXAM_END_ID = "input[id$=hide_end]"; var WAIT_EXAM_CONVAN = "#aninateConvan"; var aninateArray = [".", "..", "...", "....", ".....", "......"]; var EXAM_MSG_ID = "#txt_message"; var personExchangeLabel = "personExchange"; var publicExchangeLabel = "publicExchange"; var examinerExchangeLabel = "examinerExchange"; // 获取交互时间间隔默认5秒 var exchangeInterval = 5000; var publicExchangeList = new Hashtable(); options = options || {}; options.test_id = options.test_id || ""; options.user_id = options.user_id || ""; var sender = this; // 现场考试等待方法 this.registWaitExam = function(url) { var interval = 1000; var convan = $(WAIT_EXAM_CONVAN); $(WAIT_EXAM_HANDLER_ID).everyTime(interval, 'waitExam', function() { beginInvoke(CMS_SystemConfig.VirtualDirectoryPath + "/OnlineTest/GetTestStatus", { test_id: options.test_id, userid: options.user_id }, function (rs) { if (rs.state) { $(WAIT_EXAM_END_ID).val(rs.limit); sender.registStartCountDown(url); } else { if (rs.msg.length > 0) $(WAIT_EXAM_HANDLER_ID).text(rs.msg); else { convan.text(waitAninate(convan.text().length)); } } }); }); } this.registStartCountDown = function(url) { $("#countDown").show(); $("#msgSpan").hide(); $(".timer").calcTimer({ limit: $(WAIT_EXAM_END_ID).val(), inputType: "s", format: "#H#M#S", ontimeout: function() { if (typeof (url) == 'string') { if (url.length > 0) { window.location.href = url; } } else { url(); } }, onCountdownError: function(container) { var examLength = Invoke(CMS_SystemConfig.VirtualDirectoryPath + "/OnlineTest/GetStartLengthOfExam", { test_id: examInfo.test_id, userid: examinee.userid }); $(WAIT_EXAM_END_ID).val(examLength); sender.registStartCountDown(url); } }); } this.registPersonExchange = function() { $(EXAM_MSG_ID).everyTime(exchangeInterval, personExchangeLabel, function() { beginInvoke(CMS_SystemConfig.VirtualDirectoryPath + "/OnlineTest/ListPersonalExchange", { test_id: options.test_id, userid: options.user_id }, function (rs) { var param = eval(rs); for (var i = 0; i < param.length; i++) { var p = param[i]; behaviour.handleCommand(p.type, { type: 'person', intData: p.extendInt, sender: sender }); } }); }); } this.registPublicExchange = function() { $(EXAM_MSG_ID).everyTime(exchangeInterval, publicExchangeLabel, function() { beginInvoke(CMS_SystemConfig.VirtualDirectoryPath + "/OnlineTest/ListPublicExchange", { test_id: options.test_id }, function (rs) { var param = eval(rs); for (var i = 0; i < param.length; i++) { var p = param[i]; if (!publicExchangeList.contains(p.id)) { publicExchangeList.add(p.id, p.type); behaviour.handleCommand(p.type, { type: 'all', intData: p.extendInt, sender: sender }); } } }); }); } this.removeExamineeExchangeEvent = function() { $(EXAM_MSG_ID).stopTime(personExchangeLabel); //$(EXAM_MSG_ID).stopTime(publicExchangeLabel); } var waitAninate = function(index) { if (index >= aninateArray.length) index = 0; return aninateArray[index]; } }