mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/MI-38.git
synced 2026-01-24 02:45:39 +03:00
445 lines
12 KiB
JavaScript
445 lines
12 KiB
JavaScript
/*******************************************************************************
|
|
ADL SCORM 2004 4th Edition MSCE
|
|
|
|
The ADL SCORM 2004 4th Ed. MSCE is licensed under
|
|
|
|
Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States.
|
|
|
|
|
|
|
|
The Advanced Distributed Learning Initiative allows you to:
|
|
|
|
* Share - to copy, distribute and transmit the work.
|
|
|
|
* Remix - to adapt the work.
|
|
|
|
|
|
|
|
Under the following conditions:
|
|
|
|
* Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
|
|
|
|
* Noncommercial. You may not use this work for commercial purposes.
|
|
|
|
* Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
|
|
|
|
|
|
|
|
For any reuse or distribution, you must make clear to others the license terms of this work.
|
|
|
|
Any of the above conditions can be waived if you get permission from the ADL Initiative.
|
|
|
|
Nothing in this license impairs or restricts the author's moral rights.
|
|
**
|
|
** Usage: Executable course content can call the API Wrapper
|
|
** functions as follows:
|
|
**
|
|
** javascript:
|
|
** var result = doInitialize();
|
|
** if (result != true)
|
|
** {
|
|
** // handle error
|
|
** }
|
|
**
|
|
** authorware:
|
|
** result := ReadURL("javascript:doInitialize()", 100)
|
|
**
|
|
** director:
|
|
** result = externalEvent("javascript:doInitialize()")
|
|
**
|
|
**
|
|
*******************************************************************************/
|
|
|
|
var _Debug = false; // set this to false to turn debugging off
|
|
// and get rid of those annoying alert boxes.
|
|
|
|
// Define exception/error codes
|
|
var _NoError = 0;
|
|
var _GeneralException = 101;
|
|
var _GeneralInitializationFailure = 102;
|
|
var _AlreadyInitialized = 103;
|
|
var _ContentInstanceTerminated = 104;
|
|
var _GeneralTerminationFailure = 111;
|
|
var _TerminationBeforeInitialization = 112;
|
|
var _TerminationAfterTermination = 113;
|
|
var _ReceivedDataBeforeInitialization = 122;
|
|
var _ReceivedDataAfterTermination = 123;
|
|
var _StoreDataBeforeInitialization = 132;
|
|
var _StoreDataAfterTermination = 133;
|
|
var _CommitBeforeInitialization = 142;
|
|
var _CommitAfterTermination = 143;
|
|
var _GeneralArgumentError = 201;
|
|
var _GeneralGetFailure = 301;
|
|
var _GeneralSetFailure = 351;
|
|
var _GeneralCommitFailure = 391;
|
|
var _UndefinedDataModelElement = 401;
|
|
var _UnimplementedDataModelElement = 402;
|
|
var _DataModelElementValueNotInitialized = 403;
|
|
var _DataModelElementIsReadOnly = 404;
|
|
var _DataModelElementIsWriteOnly = 405;
|
|
var _DataModelElementTypeMismatch = 406;
|
|
var _DataModelElementValueOutOfRange = 407;
|
|
|
|
|
|
// local variable definitions
|
|
var apiHandle = null;
|
|
var API = null;
|
|
var findAPITries = 0;
|
|
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function: doInitialize()
|
|
** Inputs: None
|
|
** Return: CMIBoolean true if the initialization was successful, or
|
|
** CMIBoolean false if the initialization failed.
|
|
**
|
|
** Description:
|
|
** Initialize communication with LMS by calling the Initialize
|
|
** function which will be implemented by the LMS.
|
|
**
|
|
*******************************************************************************/
|
|
function doInitialize()
|
|
{
|
|
var api = getAPIHandle();
|
|
if (api == null)
|
|
{
|
|
// alert("Unable to locate the LMS's API Implementation.\nInitialize was not successful.");
|
|
return "false";
|
|
}
|
|
|
|
var result = api.Initialize("");
|
|
|
|
if (result.toString() != "true")
|
|
{
|
|
var err = ErrorHandler();
|
|
}
|
|
|
|
return result.toString();
|
|
}
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function doTerminate()
|
|
** Inputs: None
|
|
** Return: CMIBoolean true if successful
|
|
** CMIBoolean false if failed.
|
|
**
|
|
** Description:
|
|
** Close communication with LMS by calling the Terminate
|
|
** function which will be implemented by the LMS
|
|
**
|
|
*******************************************************************************/
|
|
function doTerminate()
|
|
{
|
|
var api = getAPIHandle();
|
|
if (api == null)
|
|
{
|
|
// alert("Unable to locate the LMS's API Implementation.\nTerminate was not successful.");
|
|
return "false";
|
|
}
|
|
else
|
|
{
|
|
// call the Terminate function that should be implemented by the API
|
|
|
|
var result = api.Terminate("");
|
|
if (result.toString() != "true")
|
|
{
|
|
var err = ErrorHandler();
|
|
}
|
|
|
|
}
|
|
|
|
return result.toString();
|
|
}
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function doGetValue(name)
|
|
** Inputs: name - string representing the cmi data model defined category or
|
|
** element (e.g. cmi.core.student_id)
|
|
** Return: The value presently assigned by the LMS to the cmi data model
|
|
** element defined by the element or category identified by the name
|
|
** input value.
|
|
**
|
|
** Description:
|
|
** Wraps the call to the GetValue method
|
|
**
|
|
*******************************************************************************/
|
|
function doGetValue(name)
|
|
{
|
|
var api = getAPIHandle();
|
|
if (api == null)
|
|
{
|
|
// alert("Unable to locate the LMS's API Implementation.\nGetValue was not successful.");
|
|
return "";
|
|
}
|
|
else
|
|
{
|
|
var value = api.GetValue(name);
|
|
var errCode = api.GetLastError().toString();
|
|
if (errCode != _NoError)
|
|
{
|
|
// an error was encountered so display the error description
|
|
var errDescription = api.GetErrorString(errCode);
|
|
// alert("GetValue("+name+") failed. \n"+ errDescription);
|
|
return "";
|
|
}
|
|
else
|
|
{
|
|
|
|
return value.toString();
|
|
}
|
|
}
|
|
}
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function doSetValue(name, value)
|
|
** Inputs: name -string representing the data model defined category or element
|
|
** value -the value that the named element or category will be assigned
|
|
** Return: CMIBoolean true if successful
|
|
** CMIBoolean false if failed.
|
|
**
|
|
** Description:
|
|
** Wraps the call to the SetValue function
|
|
**
|
|
*******************************************************************************/
|
|
function doSetValue(name, value)
|
|
{
|
|
var api = getAPIHandle();
|
|
if (api == null)
|
|
{
|
|
// alert("Unable to locate the LMS's API Implementation.\nSetValue was not successful.");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
var result = api.SetValue(name, value);
|
|
if (result.toString() != "true")
|
|
{
|
|
var err = ErrorHandler();
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function doCommit()
|
|
** Inputs: None
|
|
** Return: None
|
|
**
|
|
** Description:
|
|
** Call the Commit function
|
|
**
|
|
*******************************************************************************/
|
|
function doCommit()
|
|
{
|
|
var api = getAPIHandle();
|
|
if (api == null)
|
|
{
|
|
//alert("Unable to locate the LMS's API Implementation.\nCommit was not successful.");
|
|
return "false";
|
|
}
|
|
else
|
|
{
|
|
var result = api.Commit("");
|
|
if (result != "true")
|
|
{
|
|
var err = ErrorHandler();
|
|
}
|
|
}
|
|
|
|
return result.toString();
|
|
}
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function doGetLastError()
|
|
** Inputs: None
|
|
** Return: The error code that was set by the last LMS function call
|
|
**
|
|
** Description:
|
|
** Call the GetLastError function
|
|
**
|
|
*******************************************************************************/
|
|
function doGetLastError()
|
|
{
|
|
var api = getAPIHandle();
|
|
if (api == null)
|
|
{
|
|
// alert("Unable to locate the LMS's API Implementation.\nGetLastError was not successful.");
|
|
//since we can't get the error code from the LMS, return a general error
|
|
return _GeneralError;
|
|
}
|
|
|
|
return api.GetLastError().toString();
|
|
}
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function doGetErrorString(errorCode)
|
|
** Inputs: errorCode - Error Code
|
|
** Return: The textual description that corresponds to the input error code
|
|
**
|
|
** Description:
|
|
** Call the GetErrorString function
|
|
**
|
|
********************************************************************************/
|
|
function doGetErrorString(errorCode)
|
|
{
|
|
var api = getAPIHandle();
|
|
if (api == null)
|
|
{
|
|
// alert("Unable to locate the LMS's API Implementation.\nGetErrorString was not successful.");
|
|
}
|
|
|
|
return api.GetErrorString(errorCode).toString();
|
|
}
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function doGetDiagnostic(errorCode)
|
|
** Inputs: errorCode - Error Code(integer format), or null
|
|
** Return: The vendor specific textual description that corresponds to the
|
|
** input error code
|
|
**
|
|
** Description:
|
|
** Call the LMSGetDiagnostic function
|
|
**
|
|
*******************************************************************************/
|
|
function doGetDiagnostic(errorCode)
|
|
{
|
|
var api = getAPIHandle();
|
|
if (api == null)
|
|
{
|
|
// alert("Unable to locate the LMS's API Implementation.\nGetDiagnostic was not successful.");
|
|
}
|
|
|
|
return api.GetDiagnostic(errorCode).toString();
|
|
}
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function ErrorHandler()
|
|
** Inputs: None
|
|
** Return: The current value of the LMS Error Code
|
|
**
|
|
** Description:
|
|
** Determines if an error was encountered by the previous API call
|
|
** and if so, displays a message to the user. If the error code
|
|
** has associated text it is also displayed.
|
|
**
|
|
*******************************************************************************/
|
|
function ErrorHandler()
|
|
{
|
|
var api = getAPIHandle();
|
|
if (api == null)
|
|
{
|
|
//alert("Unable to locate the LMS's API Implementation.\nCannot determine LMS error code.");
|
|
return;
|
|
}
|
|
|
|
// check for errors caused by or from the LMS
|
|
var errCode = api.GetLastError().toString();
|
|
if (errCode != _NoError && errCode != _AlreadyInitialized )
|
|
{
|
|
// an error was encountered so display the error description
|
|
var errDescription = api.GetErrorString(errCode);
|
|
|
|
if (_Debug == true)
|
|
{
|
|
errDescription += "\n";
|
|
errDescription += api.GetDiagnostic(null);
|
|
// by passing null to GetDiagnostic, we get any available diagnostics
|
|
// on the previous error.
|
|
}
|
|
|
|
// alert(errDescription);
|
|
}
|
|
|
|
return errCode;
|
|
}
|
|
|
|
/******************************************************************************
|
|
**
|
|
** Function getAPIHandle()
|
|
** Inputs: None
|
|
** Return: value contained by APIHandle
|
|
**
|
|
** Description:
|
|
** Returns the handle to API object if it was previously set,
|
|
** otherwise it returns null
|
|
**
|
|
*******************************************************************************/
|
|
function getAPIHandle()
|
|
{
|
|
if (apiHandle == null)
|
|
{
|
|
apiHandle = getAPI();
|
|
}
|
|
|
|
return apiHandle;
|
|
}
|
|
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function findAPI(win)
|
|
** Inputs: win - a Window Object
|
|
** Return: If an API object is found, it's returned, otherwise null is returned
|
|
**
|
|
** Description:
|
|
** This function looks for an object named API in parent and opener windows
|
|
**
|
|
*******************************************************************************/
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function getAPI()
|
|
** Inputs: none
|
|
** Return: If an API object is found, it's returned, otherwise null is returned
|
|
**
|
|
** Description:
|
|
** 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).
|
|
**
|
|
*******************************************************************************/
|
|
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 find an API adapter");
|
|
}
|
|
return theAPI
|
|
}
|
|
|
|
|