// // Licensed Materials - Property of IBM // 5724I83 // (C) Copyright IBM Corp. 1995, 2006 All Rights Reserved. // /* ■ イベントで呼び出す関数 HpbELTInit() - BODY の onload で呼び出す HpbELTExit() - BODY の onunload で呼び出す HpbELTStart() - テスト開始ボタンで呼び出す(必ず ELTInit の後で) HpbELTCheck() - 採点ボタンで呼び出す HpbELTSendResult() - 送信ボタンで呼び出す ■ JavaScript の拡張なしの場合使用する HTML 部品の ID HPB_ELT_Start - 開始ボタン HPB_ELT_Check - 採点ボタン HPB_ELT_NotQuestion - テスト時に隠すオブジェクト HPB_ELT_Question - テスト時のみに表示するオブジェクト HPB_ELT_RestTime - 残り時間を表示するエリア ■ JavaScript で拡張可能な関数 ELT_SetEnabled 指定されたオブジェクトのアクティブ状態を切り替える ELT_SetVisible 指定されたオブジェクトを表示・非表示にする ELT_GetResultColor 正解・不正解 を表示するための色を返す ELT_ShowResult テストの採点結果を表示する ELT_ShowResultEach それぞれの問題の結果を表示する ELT_GetQ id で指定されるオブジェクトを返す */ var _debug = false; // // EXPORT FUNCTIONS // function HpbELTInit() { if(navigator.appName == "Netscape"){ alert("Netscape ブラウザでテストを行うことはできません。"); return; } if(typeof HpbELTData == "object"){ HpbELTObj = new ELTState(HpbELTData); HpbELTObj.doInit(); } else { alert("テスト用のデータが定義されていません。\nテストを実行できません。"); } } function HpbELTStart() { if(HpbELTObj != null) HpbELTObj.doStart(); } function HpbELTCheck() { if(HpbELTObj != null){ HpbELTObj.doCheck(); HpbELTObj.showResult(); } } function HpbELTSendResult() { HpbELTObj.sendResult(); } function HpbELTExit() { if(HpbELTObj != null) HpbELTObj.doExit(); if(HpbELTCommentWindow != null) HpbELTCommentWindow.close(); } function HpbELTCorrectAnswer() { var q = HpbELTObj.data.questions; for(var i=0; i 0) { resultform.Score.value = this.data.score; resultform.Result.value = this.data.mastery_score > 0 ? (this.data.score >= this.data.mastery_score ? "合格" : "不合格") : ""; resultform.submit(); //送信実行 } else { alert("送信方法が定義されていません。"); } } this.doc.setEnabled("submit", false); } //----------------------------------------- // Timer Events //----------------------------------------- this.onTimer = function() { switch(this.getState()){ case "loading": if(!this.doc.isLoading()) this.doReady(); break; case "testing": if( this.test.isTimeExpired() ){ alert("制限時間がきたので採点します。"); this.doCheck(); this.showResult(); } this.doc.setString("resttime", this.test.getRestTimeInString()); } if(this.timerId > 0) this.startTimer(); } //----------------------------------------- // protected //----------------------------------------- //---------------------------------- state this.setState = function(mode) { var restr = { none : "loading", loading : "waiting", waiting : "testing", testing : "checked", checked : "" }; var mode2sco = { loading : { sco : "browsed", btnStart : false, btnCheck : false, btnSubmit : false }, waiting : { sco : "browsed", btnStart : true, btnCheck : false, btnSubmit : false }, testing : { sco : "incomplete", btnStart : false, btnCheck : true, btnSubmit : false }, checked : { sco : "", btnStart : false, btnCheck : false, btnSubmit : true } }; var old_state = this.getState(); if( old_state == "" ) old_state = "none"; if( restr[old_state].indexOf(mode) == -1 ){ if(_debug) alter("Illegal state change: " + old_state + " to " + mode); return; } var n = mode2sco[mode]; this.eltState = mode; this.sco.updateLessonStatus(n.sco); this.doc.setEnabled("start", n.btnStart); this.doc.setEnabled("check", n.btnCheck); this.doc.setEnabled("submit",n.btnSubmit); } this.getState = function() { return this.eltState; } //------------------------------- timer this.startTimer = function() { this.timerId = setTimeout("HpbELTOnTimer();", 1000); } this.stopTimer = function() { if(this.timerId > 0){ clearTimeout(this.timerId); } this.timerId = 0; } } function HpbELTOnTimer() { HpbELTObj.onTimer(); } //====---- STATE //====---- TEST function ELTest(data, sco, doc) { this.data = data; this.sco = sco; this.doc = doc; //----------------------------------------------------------- // for Checking Answers //----------------------------------------------------------- this.check = function() { var score = 0; var nQ = this.data.questions.length; for(var i=0; i0 ? true : false); } else { if(_debug) alert("テストの採点をする関数がありません: "+objQ.type); } } this.data.result = this.sco.judgeScore(score, this.data.max_score, this.data.mastery_score); this.data.score = score; } this.checkEachSelection = function(doc, obj, id) { obj.score = 0; if(obj.single){ // Single Selection obj.result = false; var ansObj = doc.getQ(id); var ans; for(var i=0; i this.getLimitTime()*60*1000 ) return true; return false; } this.getLimitTime = function() { if(typeof this.data.limit_time != "undefined") return this.data.limit_time; return 0; } this.getRestTimeInString = function() { if(this.getLimitTime() <= 0) return "(時間制限なし)"; var r = 0; if(typeof this.rtTimeStarted == "undefined"){ r = this.getLimitTime()*60*1000; } else { r = this.getLimitTime()*60*1000 - ( (new Date()).getTime() - this.rtTimeStarted ); } if( r <= 0) return "0:00"; var rm = Math.floor(r/60000); var rs = Math.floor((r%60000)/1000); return rm.toString() + ":" + (rs<10 ? "0":"") + rs.toString(); } } //====---- TEST //====---- SCORM //--------------- // for NOT SCROM mode function ELTwoSco() { this.updateLessonStatus = function(){}; this.judgeScore = woscoJudgeScore; } function woscoJudgeScore(score, max_score, mastery_score) { return (score < mastery_score) ? "failed" : "passed"; } //--------------- // for SCROM mode function ELTSco() { this.updateLessonStatus = scoUpdateLessonStatus; this.judgeScore = scoJudgeScore; } var SCO_LESSON_STATUS_ORDER = [ "", "not attempted", "browsed", "incomplete", "completed", "failed", "passed" ]; var scoLessonStatus = -1; function scoUpdateLessonStatus(newStatus) { if(scoLessonStatus == -1){ var v = doLMSGetValue("cmi.core.lesson_status"); scoLessonStatus = scoFindLessonStatusId(v); } var newId = newStatus; if(typeof newId == "string") newId = scoFindLessonStatusId(newId); if(_debug) alert("scoUpdateId: "+scoGetLessonStatusId()+" -> "+newId); if( newId <= scoGetLessonStatusId() ) return false; // no need to update scoLessonStatus = newId; //scoUpdateLessonStatus(newId); var s = scoFindLessonStatusString(scoLessonStatus); doLMSSetValue("cmi.core.lesson_status", s); doLMSCommit(); return true; } function scoGetLessonStatusId() { if(typeof scoLessonStatus != "number"){ var s = doLMSGetValue("cmi.core.lesson_status"); scoLessonStatus = scoFindLessonStatusId(s); } return scoLessonStatus; } function scoGetLessonStatusString() { return scoFindLessonStatusString(scoGetLessonStatusId()); } function scoFindLessonStatusId(status) { for(var i=0; i 0){ if( max_score <= 0 ) max_score = 100; server_raw_score = Math.round(score * max_score / server_max_score); if(server_raw_score < 0) server_raw_score = 0; if(server_raw_score > server_max_score) server_raw_score = server_max_score; if( isNaN(server_mas_score) ) server_mas_score = Math.round(mastery_score * max_score / server_max_score); } else if( !isNaN(server_mas_score) ){ server_max_score = max_score; server_raw_score = score; } else { server_raw_score = score; server_max_score = max_score; server_mas_score = mastery_score; } // judgement... var result; if(server_mas_score <= server_raw_score) result = "passed"; else result = "failed"; var old_score = parseInt(doLMSGetValue("cmi.core.score.raw")); if(_debug) alert(" server_max_score:" + server_max_score + " server_mas_score:" + server_mas_score + " server_raw_score:" + server_raw_score + " old_score: " + old_score); if( isNaN(old_score) || score > old_score ){ // send the raw score doLMSSetValue("cmi.core.score.raw", server_raw_score); // update status (and commit) scoUpdateLessonStatus(result); } else if( score != old_score ){ alert("残念ながら前回の得点を下回ってしまいました。\n今回の得点は記録されません。"); } return result; } //====---- SCORM //====---- DOCUMENT function ELTDoc() { ///////////////////////////////////////////////////////// // EXTENTION POINT this.setExtention = function() { if(typeof ELT_SetEnabled == "function") this.setEnabled = ELT_SetEnabled; // // ■ void ELT_SetEnabled(string name, bool bEnabled) // name: // "start" - 開始ボタン // "check" - 採点ボタン // "submit" - 送信ボタン if(typeof ELT_SetVisible == "function") this.setVisible = ELT_SetVisible; // // ■ void ELT_SetVisible(string name, bool bEnabled) // name: // "question" - 問題 if(typeof ELT_GetResultColor == "function") this.getResultColor = ELT_GetResultColor; // // ■ string ELT_GetResultColor(bool bSuccess) // bSuccess: // true - 問題に正解した if(typeof ELT_ShowResult == "function") this.showResult = ELT_ShowResult; // // ■ void ELT_ShowResult(string result, int score) // result: // "passed" - 合格 // "failed" - 不合格 // score: // 得点 if(typeof ELT_ShowResultEach == "function") this.showResultEach = ELT_ShowResult; // // ■ void ELT_ShowResultEach(Question q, string id, bool bSuccess) // q: // Question オブジェクト // id: // 問題の id // bSuccess: // true - 問題に正解した if(typeof ELT_GetQ == "function") this.getQ = ELT_GetQ; // // ■ Object ELT_GetQ(string id) // id: // Get するオブジェクトの id } //----------------------------------------------------------- // for Object //----------------------------------------------------------- this.getQ = function(id) { if( eval("typeof "+id) == "undefined" ) return null; return eval(id); } this.setEnabled = function(name, bEnabled) { var obj = null; switch(name){ case "start": obj = this.getQ("HPB_ELT_START"); break; case "check": obj = this.getQ("HPB_ELT_CHECK"); break; case "submit": obj = this.getQ("HPB_ELT_SEND"); break; default: if(_debug) alter("setEnabled: Unknown name: "+name); break; } if(obj != null) obj.disabled = !bEnabled; } this.setVisible = function(name, bVisible) { switch(name){ case "question": var N = this.getQ("HPB_ELT_NOTQUESTION"); var Q = this.getQ("HPB_ELT_QUESTION"); if(N != null) N.style.display = bVisible ? "none" : ""; if(Q != null) Q.style.display = bVisible ? "" : "none"; break; case "resultmsg": var R = this.getQ("HPB_ELT_RESULTMSG"); if (R != null) R.style.display = bVisible ? "" : "none"; break; default: if(_debug) alert("setVisible: Unknown name: "+name); } } this.setString = function(name, str) { switch(name){ case "resttime": var T = this.getQ("HPB_ELT_RESTTIME"); if(T != null) T.value = str; break; default: if(_debug) alert("setString: unknown name: "+name); } } //----------------------------------------------------------- // for Showing result //----------------------------------------------------------- this.showResult = function(score, mastery_score) { var rp = ""; // popup message var rd = ""; // document var bPassed = true; // Pass or fail if (mastery_score > 0) { if(score >= mastery_score) { rp = "\n結果: 合格"; rd = " (合格) " } else { rp = "\n結果: 不合格"; rd = " (不合格) " bPassed = false; } } this.setVisible("resultmsg", true); var T = this.getQ("HPB_ELT_RESULTMSG"); T.innerHTML = T.innerHTML + "" + score + " 点" + rd + ""; alert("得点: " + score + " 点です" + rp); } this.getResultColor = function(bOK) { if(bOK){ if(typeof HpbELTData.colorCorrectAns != "undefined") return HpbELTData.colorCorrectAns; return "#8080ff"; } else { if(typeof HpbELTData.colorIncorrectAns != "undefined") return HpbELTData.colorIncorrectAns; return "#ff8080"; } } this.showResultEach = function(q, id, bOK) { eval("this.showResult" + q.type + "(q, id, bOK)"); } this.showResultSelection = function(q, id, bOk) { var color = this.getResultColor(bOk); var title = this.getQ(id + "_head"); if(title != null && typeof title.innerHTML != "undefined"){ var html; if(bOk) html = " "; else html = "× "; title.innerHTML = html + title.innerHTML; } // show answer with color... if(this.bShowAns == false){ if(q.single == true){ var objs = this.getQ(id); for(var i=0; i○ "; else html = "× "; title.innerHTML = html + title.innerHTML; bResult = true; } obj.style.background = color; var text = obj.value; if(!bResult) text = (q.result ? "○ " : "× ") + text; if(this.bShowAns && !q.result) text += " (答え " + q.answer.join(", ") + ")"; obj.value = text; this.showComment(q, id); } this.showResultCloze = function(q, id, bOK) { var color = this.getResultColor(bOK); var bResult = false; var title = this.getQ(id + "_head"); if(title != null){ var corrects = 0; for(var i=0; i 0) mark = "△"; else mark = "×"; html = "" + mark + " "; title.innerHTML = html + title.innerHTML; bResult = true; } for(var i=0; i解説"; if (comment.tagName == "P") { comment.insertAdjacentHTML("AfterEnd", strComment); } else if (comment.tagName == "TABLE") { comment.insertAdjacentHTML("AfterEnd", strComment); } else if (comment.tagName == "TD") { var trParent = comment.parentElement; if (trParent != null) { var newTd = trParent.insertCell(); if (newTd != null) newTd.innerHTML = strComment; } } } //-------------------------- // Initialize //-------------------------- this.setExtention(); } //====---- DOCUMENT function decodeBase64AnswerData(obj) { var q = obj.questions; for(var i=0; i