From: <se...@us...> - 2008-05-02 09:54:54
|
Revision: 71 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=71&view=rev Author: sem62 Date: 2008-05-02 02:54:59 -0700 (Fri, 02 May 2008) Log Message: ----------- Initial import of template Added Paths: ----------- WebEditor/src/template/ WebEditor/src/template/LectureModel.conf WebEditor/src/template/LectureModel.html WebEditor/src/template/SimpleQuestionModel.conf WebEditor/src/template/SimpleQuestionModel.html WebEditor/src/template/SummaryPageModel.html WebEditor/src/template/global/ WebEditor/src/template/global/APIWrapper.js WebEditor/src/template/global/SummaryPage.js WebEditor/src/template/global/main.css WebEditor/src/template/global/simpleQ.js Added: WebEditor/src/template/LectureModel.conf =================================================================== --- WebEditor/src/template/LectureModel.conf (rev 0) +++ WebEditor/src/template/LectureModel.conf 2008-05-02 09:54:59 UTC (rev 71) @@ -0,0 +1,5 @@ +<?xml version = "1.0" ?> +<LectureModel> + <caption>New caption</caption> + <content>New content.</content> +</LectureModel> Added: WebEditor/src/template/LectureModel.html =================================================================== --- WebEditor/src/template/LectureModel.html (rev 0) +++ WebEditor/src/template/LectureModel.html 2008-05-02 09:54:59 UTC (rev 71) @@ -0,0 +1,16 @@ +<html> +<head> + <title>title</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf8" /> + <script type="text/javascript" src="global/APIWrapper.js"></script> +</head> + +<body onload="Initialize();" onunload="Terminate();"> + <div id="lecture_caption"> + <!--caption start-->New caption<!--caption end--> + </div> + <div id="lecture_content"> + <!--content start--><!--content end--> + </div> +</body> +</html> \ No newline at end of file Added: WebEditor/src/template/SimpleQuestionModel.conf =================================================================== --- WebEditor/src/template/SimpleQuestionModel.conf (rev 0) +++ WebEditor/src/template/SimpleQuestionModel.conf 2008-05-02 09:54:59 UTC (rev 71) @@ -0,0 +1,9 @@ +<?xml version = "1.0" ?> +<SimpleQuestionModel> + <caption>New caption</caption> + <question>Answer "Yes" to question, please.</question> + <answers singleVariant="false"> + <answer point="0">Yes</answer> + <answer point="1">No</answer> + </answers> +</SimpleQuestionModel> Added: WebEditor/src/template/SimpleQuestionModel.html =================================================================== --- WebEditor/src/template/SimpleQuestionModel.html (rev 0) +++ WebEditor/src/template/SimpleQuestionModel.html 2008-05-02 09:54:59 UTC (rev 71) @@ -0,0 +1,27 @@ +<html> +<head> + <title>title</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf8" /> + <script type="text/javascript" src="global/APIWrapper.js"></script> + <script type="text/javascript" src="global/simpleQ.js"></script> +</head> + +<body onload="Initialize();" onunload="Terminate();"> + <div id="simpleQ_caption"> + <!--caption start-->New caption<!--caption end--> + </div> + <div id="simpleQ_question"> + <!--question start-->Answer "Yes" to question, please.<!--question end--> + </div> + <form onsubmit="return checkAnswer(this);"> + <div id="simpleQ_answers"> + <script language="javascript"> + <!--answers start--> + <!--answers end--> + show(); + </script> + </div> + <input type=submit value="Next"> + </form> +</body> +</html> \ No newline at end of file Added: WebEditor/src/template/SummaryPageModel.html =================================================================== --- WebEditor/src/template/SummaryPageModel.html (rev 0) +++ WebEditor/src/template/SummaryPageModel.html 2008-05-02 09:54:59 UTC (rev 71) @@ -0,0 +1,17 @@ +<html> +<head> + <title>title</title> + <meta http-equiv="Content-Type" content="text/html; charset=utf8" /> + <script type="text/javascript" src="global/APIWrapper.js"></script> + <script type="text/javascript" src="global/SummaryPage.js"></script> +</head> + +<body onload="Initialize();" onunload="Terminate();"> + <div id="page_content"> + <script type="text/javascript"> + <!--content start--> + <!--content end--> + </script> + </div> +</body> +</html> \ No newline at end of file Added: WebEditor/src/template/global/APIWrapper.js =================================================================== --- WebEditor/src/template/global/APIWrapper.js (rev 0) +++ WebEditor/src/template/global/APIWrapper.js 2008-05-02 09:54:59 UTC (rev 71) @@ -0,0 +1,458 @@ +/******************************************************************************* +** +** Advanced Distributed Learning Co-Laboratory (ADL Co-Lab) grants you +** ("Licensee") a non-exclusive, royalty free, license to use and redistribute +** this software in source and binary code form, provided that i) this copyright +** notice and license appear on all copies of the software; and ii) Licensee +** does not utilize the software in a manner which is disparaging to ADL Co-Lab. +** +** This software is provided "AS IS," without a warranty of any kind. ALL +** EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY +** IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR +** NON-INFRINGEMENT, ARE HEREBY EXCLUDED. ADL Co-Lab AND ITS LICENSORS SHALL +** NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, +** MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL +** ADL Co-Lab OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, +** OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE +** DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING +** OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF ADL Co-Lab HAS BEEN +** ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +** +*******************************************************************************/ + +/******************************************************************************* +** +** This file is being presented to Content Developers, Content Programmers and +** Instructional Designers to demonstrate one way to abstract API calls from the +** actual content to allow for uniformity and reuse of content fragments. +** +** The purpose in wrapping the calls to the API is to (1) provide a +** consistent means of finding the LMS API adapter within the window +** hierarchy, (2) to ensure that the method calls are called correctly by the +** SCO and (3) to make possible changes to the actual API Specifications and +** Standards easier to implement/change quickly. +** +** This is just one possible example for implementing the API guidelines for +** runtime communication between an LMS and executable content components. +** There are many other possible implementations. +** +*******************************************************************************/ + +// local variable definitions used for finding the API +var apiHandle = null; +var findAPITries = 0; +var noAPIFound = "false"; + +// local variable used to keep from calling Terminate() more than once +var terminated = "false"; + +// local variable used by the content developer to debug +// This should be set to true during development to find errors. However, +// This should be set to false prior to deployment. +var _debug = false; + +/******************************************************************************* +** +** This function looks for an object named API in parent and opener windows +** +** Inputs: Object - The Window Object +** +** Return: Object - If the API object is found, it's returned, otherwise null +** is returned +** +*******************************************************************************/ +function findAPI( win ) +{ + while ( (win.API_1484_11 == null) && + (win.parent != null) && + (win.parent != win) ) + { + findAPITries++; + + if ( findAPITries > 500 ) + { + alert( "Error finding API -- too deeply nested." ); + return null; + } + + win = win.parent; + } + + return win.API_1484_11; +} + +/******************************************************************************* +** +** This function looks for an object named API, first in the current window's +** frame hierarchy and then, if necessary, in the current window's opener window +** hierarchy (if there is an opener window). +** +** Inputs: none +** +** Return: Object - If the API object is found, it's returned, otherwise null +** is returned +** +*******************************************************************************/ +function getAPI() +{ + var theAPI = findAPI( window ); + + if ( (theAPI == null) && + (window.opener != null) && + (typeof(window.opener) != "undefined") ) + { + theAPI = findAPI( window.opener ); + } + + if (theAPI == null) + { + alert( "Unable to locate the LMS's API Implementation.\n" + + "Communication with the LMS will not occur." ); + + noAPIFound = "true"; + } + + return theAPI +} + +/******************************************************************************* +** +** Returns the handle to API object if it was previously set, otherwise it +** returns null +** +** Inputs: None +** +** Return: Object - The value contained by the apiHandle variable. +** +*******************************************************************************/ +function getAPIHandle() +{ + if ( apiHandle == null ) + { + if ( noAPIFound == "false" ) + { + apiHandle = getAPI(); + } + } + + return apiHandle; +} + +/******************************************************************************* +** +** This function is used to tell the LMS to initiate the communication session. +** +** Inputs: None +** +** Return: String - "true" if the initialization was successful, or +** "false" if the initialization failed. +** +*******************************************************************************/ +function initializeCommunication() +{ + var api = getAPIHandle(); + + if ( api == null ) + { + return "false"; + } + else + { + var result = api.Initialize(""); + + if ( result != "true" ) + { + var errCode = retrieveLastErrorCode(); + + displayErrorInfo( errCode ); + + // may want to do some error handling + } + } + + return result; +} + +/******************************************************************************* +** +** This function is used to tell the LMS to terminate the communication session +** +** Inputs: None +** +** Return: String - "true" if successful or +** "false" if failed. +** +*******************************************************************************/ +function terminateCommunication() +{ + var api = getAPIHandle(); + + if ( api == null ) + { + return "false"; + } + else + { + // call Terminate only if it was not previously called + if ( terminated != "true" ) + { + // call the Terminate function that should be implemented by + // the API + var result = api.Terminate(""); + + if ( result != "true" ) + { + var errCode = retrieveLastErrorCode(); + + displayErrorInfo( errCode ); + + // may want to do some error handling + } + else // terminate was successful + { + terminated = "true"; + } + } + } + + return result; +} + +/******************************************************************************* +** +** This function requests information from the LMS. +** +** Inputs: String - Name of the data model defined category or element +** (e.g. cmi.core.learner_id) +** +** Return: String - The value presently assigned to the specified data model +** element. +** +*******************************************************************************/ +function retrieveDataValue( name ) +{ + // do not call a set after finish was called + if ( terminated != "true" ) + { + var api = getAPIHandle(); + + if ( api == null ) + { + return ""; + } + else + { + var value = api.GetValue( name ); + + var errCode = api.GetLastError(); + + if ( errCode != "0" ) + { + var errCode = retrieveLastErrorCode(); + + displayErrorInfo( errCode ); + } + else + { + return value; + } + } + } + + return; +} + +/******************************************************************************* +** +** This function is used to tell the LMS to assign the value to the named data +** model element. +** +** Inputs: String - Name of the data model defined category or element value +** +** String - The value that the named element or category will be +** assigned +** +** Return: String - "true" if successful or +** "false" if failed. +** +*******************************************************************************/ +function storeDataValue( name, value ) +{ + // do not call a set after finish was called + if ( terminated != "true" ) + { + var api = getAPIHandle(); + + if ( api == null ) + { + return; + } + else + { + var result = api.SetValue( name, value ); + + if ( result != "true" ) + { + var errCode = retrieveLastErrorCode(); + + displayErrorInfo( errCode ); + + // may want to do some error handling + } + } + } + + return; +} + +/******************************************************************************* +** +** This function requests the error code for the current error state from the +** LMS. +** +** Inputs: None +** +** Return: String - The last error code. +** +*******************************************************************************/ +function retrieveLastErrorCode() +{ + // It is permitted to call GetLastError() after Terminate() + + var api = getAPIHandle(); + + if ( api == null ) + { + return ""; + } + else + { + return api.GetLastError(); + } +} + +/******************************************************************************* +** +** This function requests a textual description of the current error state from +** the LMS +** +** Inputs: String - The error code. +** +** Return: String - Textual description of the given error state. +** +*******************************************************************************/ +function retrieveErrorInfo( errCode ) +{ + // It is permitted to call GetLastError() after Terminate() + + var api = getAPIHandle(); + + if ( api == null ) + { + return ""; + } + else + { + + return api.GetErrorString( errCode ); + } +} + +/******************************************************************************* +** +** This function requests additional diagnostic information about the given +** error code. This information is LMS specific, but can help a developer find +** errors in the SCO. +** +** Inputs: String - The error code. +** +** Return: String - Additional diagnostic information about the given error +** code +** +*******************************************************************************/ +function retrieveDiagnosticInfo( error ) +{ + // It is permitted to call GetLastError() after Terminate() + + var api = getAPIHandle(); + + if ( api == null ) + { + return ""; + } + else + { + return api.GetDiagnostic( error ); + } +} + +/******************************************************************************* +** +** This function requests that the LMS persist all data to this point in the +** session. +** +** Inputs: None +** +** Return: None +** +*******************************************************************************/ +function persistData() +{ + // do not call a set after Terminate() was called + if ( terminated != "true" ) + { + var api = getAPIHandle(); + + if ( api == null ) + { + return ""; + } + else + { + return api.Commit(); + } + } + else + { + return ""; + } +} + +/******************************************************************************* +** +** Display the last error code, error description and diagnostic information. +** +** Inputs: String - The error code +** +** Return: None +** +*******************************************************************************/ +function displayErrorInfo( errCode ) +{ + if ( _debug ) + { + var errString = retrieveErrorInfo( errCode ); + var errDiagnostic = retrieveDiagnosticInfo( errCode ); + + alert( "ERROR: " + errCode + " - " + errString + "\n" + + "DIAGNOSTIC: " + errDiagnostic ); + } +} + +function Terminate() +{ + terminateCommunication(); +} + +function Initialize() +{ + initializeCommunication(); +} + +function SetValue(p1, p2){ + storeDataValue(p1, p2); +} + +function GetValue(p1){ + return retrieveDataValue(p1); +} Added: WebEditor/src/template/global/SummaryPage.js =================================================================== Added: WebEditor/src/template/global/main.css =================================================================== --- WebEditor/src/template/global/main.css (rev 0) +++ WebEditor/src/template/global/main.css 2008-05-02 09:54:59 UTC (rev 71) @@ -0,0 +1,18 @@ +body { + font-family:Verdana,Tahoma,Arial,Sans-Serif; + font-size:11px; + background-color: #DAF3FF; + padding:10px 20px 20px 10px; + scrollbar-3dlight-color:#C4C4B8; + scrollbar-arrow-color:#6A6A53; + scrollbar-darkshadow-color:#8A8A73; + scrollbar-face-color:#D9D9D0; + scrollbar-highlight-color:#FFFFFF; + scrollbar-shadow-color:#8A8A73; + scrollbar-track-color:#EFEFEF +} + +.head{ + font-size: 36px; + text-decoration: bold, underline; +} Added: WebEditor/src/template/global/simpleQ.js =================================================================== --- WebEditor/src/template/global/simpleQ.js (rev 0) +++ WebEditor/src/template/global/simpleQ.js 2008-05-02 09:54:59 UTC (rev 71) @@ -0,0 +1,142 @@ +var singleAnswer=false; +var answers=new Array(); +function setSingleVariant(singleVariant){ + singleAnswer = singleVariant; +} +function addAnswer(_text, _point){ + var answer = { + point: _point, + text: _text, + id: "answer" + answers.length + }; + answers.push(answer); +}; +function show(){ + var i; + var interactions = GetValue("cmi.interactions._count"); + var pref = "cmi.interactions." + interactions + "."; + if (singleAnswer){ + SetValue(pref + "type", "choice"); + } else { + SetValue(pref + "type", "other"); + } + + for (i=0; i < answers.length; i++){ + if (singleAnswer){ + document.write("<input type='radio' name='answer' id='" + answers[i].id + "' value='" + answers[i].id + "'>"); + } else { + document.write("<input type='checkbox' id='" + answers[i].id + "'>"); + } + document.write(answers[i].text); + document.write("<BR>"); + + SetValue(pref + "correct_responses." + i + ".pattern", "\"" + answers[i].id + "\""); + SetValue(pref + "correct_responses." + i + ".weighting", "\"" + answers[i].point + "\""); + } +} +function getMaxScore(){ + if (singleAnswer){ + var i; + var max = answers[0].point; + for (i=1; i < answers.length; i++){ + if (answers[i].point > max){ + max = answers[i].point; + } + } + } else { + var i; + var max = 0; + for (i=0; i < answers.length; i++){ + if (answers[i].point > 0){ + max += answers[i].point; + } + } + } + return max; +} +function getMinScore(){ + if (singleAnswer){ + var i; + var min = answers[0].point; + for (i=1; i < answers.length; i++){ + if (answers[i].point < min){ + min = answers[i].point; + } + } + } else { + var i; + var min = 0; + for (i=0; i < answers.length; i++){ + if (answers[i].point < 0){ + min += answers[i].point; + } + } + } + return min; +} +function getRawScore(){ + var i; + var res=0; + for (i=0; i < answers.length; i++){ + var ans = document.getElementById(answers[i].id); + if (ans.checked){ + res += answers[i].point; + } + } + + return res; +} +function checkAnswer(frm){ + SetValue("cmi.complation_status", "complated"); + SetValue("cmi.exit", "normal"); + + var max = getMaxScore(); + var min = getMinScore(); + var raw = getRawScore() + var scaled = ((raw - min)/(max - min))*2 - 1; + + SetValue("cmi.score.min", min); + SetValue("cmi.score.max", max); + SetValue("cmi.score.raw", raw); + SetValue("cmi.score.scaled", scaled); + SetValue("cmi.success_status", (raw==max)?"complate":"incomplate"); + + SetValue("cmi.objectives.0.score.min", min); + SetValue("cmi.objectives.0.score.max", max); + SetValue("cmi.objectives.0.score.raw", raw); + SetValue("cmi.objectives.0.score.scaled", scaled); + + var pref = "cmi.interactions." + (GetValue("cmi.interactions._count") - 1); + if (singleAnswer){ + var i; + for (i=0; i < answers.length; i++){ + var ans = document.getElementById(answers[i].id); + if (ans.checked){ + SetValue(pref + ".learner_response", "\"" + answers[i].id + "\""); + + break; + } + } + } else { + var i; + var checkedCount = 0; + var res = ""; + for (i=0; i < answers.length; i++){ + var ans = document.getElementById(answers[i].id); + if (ans.checked){ + checkedCount++; + if (checkedCount > 1){ + res += "[,]"; + } + res += answers[i].id; + } + } + SetValue(pref + ".learner_response", "\"" + res + "\""); + } + + SetValue(pref + ".result", "\"" + scaled + "\""); + + Terminate(); + + return false; +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |