Commit e62e8545 authored by Dan Marsden's avatar Dan Marsden
Browse files

MDL-56808 scorm: remove some eval function that aren't needed.

parent 5130953c
......@@ -155,7 +155,7 @@ function AICCapi(def, cmiobj, scormauto, cfgwwwroot, scormid, scoid, attempt, vi
for (element in datamodel[scoid]) {
if (element.match(/\.n\./) == null) {
if ((typeof eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue')) != 'undefined') {
if (typeof datamodel[scoid][element].defaultvalue != 'undefined') {
eval(element + ' = datamodel["' + scoid + '"]["' + element + '"].defaultvalue;');
} else {
eval(element + ' = "";');
......@@ -233,8 +233,8 @@ function AICCapi(def, cmiobj, scormauto, cfgwwwroot, scormid, scoid, attempt, vi
if (element != "") {
expression = new RegExp(CMIIndex,'g');
elementmodel = String(element).replace(expression,'.n.');
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].mod') != 'w') {
if (typeof datamodel[scoid][elementmodel] != "undefined") {
if (datamodel[scoid][elementmodel].mod != 'w') {
element = String(element).replace(expression, "_$1.");
elementIndexes = element.split('.');
subelement = 'cmi';
......@@ -249,21 +249,21 @@ function AICCapi(def, cmiobj, scormauto, cfgwwwroot, scormid, scoid, attempt, vi
errorCode = "0"; // Need to check if it is the right errorCode
}
} else {
errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].readerror');
errorCode = datamodel[scoid][elementmodel].readerror;
}
} else {
childrenstr = '._children';
countstr = '._count';
if (elementmodel.substr(elementmodel.length - childrenstr.length,elementmodel.length) == childrenstr) {
parentmodel = elementmodel.substr(0,elementmodel.length - childrenstr.length);
if ((typeof eval('datamodel["' + scoid + '"]["' + parentmodel + '"]')) != "undefined") {
if (typeof datamodel[scoid][parentmodel] != "undefined") {
errorCode = "202";
} else {
errorCode = "201";
}
} else if (elementmodel.substr(elementmodel.length - countstr.length,elementmodel.length) == countstr) {
parentmodel = elementmodel.substr(0,elementmodel.length - countstr.length);
if ((typeof eval('datamodel["' + scoid + '"]["' + parentmodel + '"]')) != "undefined") {
if (typeof datamodel[scoid][parentmodel] != "undefined") {
errorCode = "203";
} else {
errorCode = "201";
......@@ -287,9 +287,9 @@ function AICCapi(def, cmiobj, scormauto, cfgwwwroot, scormid, scoid, attempt, vi
if (element != "") {
expression = new RegExp(CMIIndex,'g');
elementmodel = String(element).replace(expression,'.n.');
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].mod') != 'r') {
expression = new RegExp(eval('datamodel["' + scoid + '"]["' + elementmodel + '"].format'));
if (typeof datamodel[scoid][elementmodel] != "undefined") {
if (datamodel[scoid][elementmodel].mod != 'r') {
expression = new RegExp(datamodel[scoid][elementmodel].format);
value = value + '';
matches = value.match(expression);
if (matches != null) {
......@@ -339,8 +339,8 @@ function AICCapi(def, cmiobj, scormauto, cfgwwwroot, scormid, scoid, attempt, vi
if (autocommit && !(AICCapi.timeout)) {
AICCapi.timeout = Y.later(60000, API, 'LMSCommit', [""], false);
}
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"].range')) != "undefined") {
range = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].range');
if (typeof datamodel[scoid][elementmodel].range != "undefined") {
range = datamodel[scoid][elementmodel].range;
ranges = range.split('#');
value = value * 1.0;
if ((value >= ranges[0]) && (value <= ranges[1])) {
......@@ -348,7 +348,7 @@ function AICCapi(def, cmiobj, scormauto, cfgwwwroot, scormid, scoid, attempt, vi
errorCode = "0";
return "true";
} else {
errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].writeerror');
errorCode = datamodel[scoid][elementmodel].writeerror;
}
} else {
if (element == 'cmi.comments') {
......@@ -361,10 +361,10 @@ function AICCapi(def, cmiobj, scormauto, cfgwwwroot, scormid, scoid, attempt, vi
}
}
} else {
errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].writeerror');
errorCode = datamodel[scoid][elementmodel].writeerror;
}
} else {
errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].writeerror');
errorCode = datamodel[scoid][elementmodel].writeerror;
}
} else {
errorCode = "201"
......@@ -490,11 +490,11 @@ function AICCapi(def, cmiobj, scormauto, cfgwwwroot, scormid, scoid, attempt, vi
element = parent + '.' + property;
expression = new RegExp(CMIIndex,'g');
elementmodel = String(element).replace(expression,'.n.');
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].mod') != 'r') {
if (typeof datamodel[scoid][elementmodel] != "undefined") {
if (datamodel[scoid][elementmodel].mod != 'r') {
elementstring = '&' + underscore(element) + '=' + escape(data[property]);
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"].defaultvalue')) != "undefined") {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].defaultvalue') != data[property]) {
if (typeof datamodel[scoid][elementmodel].defaultvalue != "undefined") {
if (datamodel[scoid][elementmodel].defaultvalue != data[property]) {
datastring += elementstring;
}
} else {
......
......@@ -147,7 +147,7 @@ function SCORMapi1_2(def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebu
for (element in datamodel[scoid]) {
if (element.match(/\.n\./) == null) {
if ((typeof eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue')) != 'undefined') {
if (typeof datamodel[scoid][element].defaultvalue != 'undefined') {
eval(element + ' = datamodel["' + scoid + '"]["' + element + '"].defaultvalue;');
} else {
eval(element + ' = "";');
......@@ -244,8 +244,8 @@ function SCORMapi1_2(def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebu
if (element != "") {
expression = new RegExp(CMIIndex,'g');
elementmodel = String(element).replace(expression,'.n.');
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].mod') != 'w') {
if (typeof datamodel[scoid][elementmodel] != "undefined") {
if (datamodel[scoid][elementmodel].mod != 'w') {
element = String(element).replace(expression, "_$1.");
elementIndexes = element.split('.');
subelement = 'cmi';
......@@ -263,21 +263,21 @@ function SCORMapi1_2(def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebu
errorCode = "0"; // Need to check if it is the right errorCode
}
} else {
errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].readerror');
errorCode = datamodel[scoid][elementmodel].readerror;
}
} else {
childrenstr = '._children';
countstr = '._count';
if (elementmodel.substr(elementmodel.length - childrenstr.length,elementmodel.length) == childrenstr) {
parentmodel = elementmodel.substr(0,elementmodel.length - childrenstr.length);
if ((typeof eval('datamodel["' + scoid + '"]["' + parentmodel + '"]')) != "undefined") {
if (typeof datamodel[scoid][parentmodel] != "undefined") {
errorCode = "202";
} else {
errorCode = "201";
}
} else if (elementmodel.substr(elementmodel.length - countstr.length,elementmodel.length) == countstr) {
parentmodel = elementmodel.substr(0,elementmodel.length - countstr.length);
if ((typeof eval('datamodel["' + scoid + '"]["' + parentmodel + '"]')) != "undefined") {
if (typeof datamodel[scoid][parentmodel] != "undefined") {
errorCode = "203";
} else {
errorCode = "201";
......@@ -304,9 +304,9 @@ function SCORMapi1_2(def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebu
if (element != "") {
expression = new RegExp(CMIIndex,'g');
elementmodel = String(element).replace(expression,'.n.');
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].mod') != 'r') {
expression = new RegExp(eval('datamodel["' + scoid + '"]["' + elementmodel + '"].format'));
if (typeof datamodel[scoid][elementmodel] != "undefined") {
if (datamodel[scoid][elementmodel].mod != 'r') {
expression = new RegExp(datamodel[scoid][elementmodel].format);
value = value + '';
matches = value.match(expression);
if (matches != null) {
......@@ -356,8 +356,8 @@ function SCORMapi1_2(def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebu
if (autocommit && !(SCORMapi1_2.timeout)) {
SCORMapi1_2.timeout = Y.later(60000, API, 'LMSCommit', [""], false);
}
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"].range')) != "undefined") {
range = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].range');
if (typeof datamodel[scoid][elementmodel].range != "undefined") {
range = datamodel[scoid][elementmodel].range;
ranges = range.split('#');
value = value * 1.0;
if ((value >= ranges[0]) && (value <= ranges[1])) {
......@@ -368,7 +368,7 @@ function SCORMapi1_2(def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebu
}
return "true";
} else {
errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].writeerror');
errorCode = datamodel[scoid][elementmodel].writeerror;
}
} else {
if (element == 'cmi.comments') {
......@@ -384,10 +384,10 @@ function SCORMapi1_2(def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebu
}
}
} else {
errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].writeerror');
errorCode = datamodel[scoid][elementmodel].writeerror;
}
} else {
errorCode = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].writeerror');
errorCode = datamodel[scoid][elementmodel].writeerror;
}
} else {
errorCode = "201"
......@@ -557,40 +557,39 @@ function SCORMapi1_2(def, cmiobj, cmiint, cmistring256, cmistring4096, scormdebu
// check if this specific element is not defined in the datamodel,
// but the generic element name is
if ((eval('typeof datamodel["' + scoid + '"]["' + element + '"]')) == "undefined"
&& (eval('typeof datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {
if (typeof datamodel[scoid][element] == "undefined" && typeof datamodel[scoid][elementmodel] != "undefined") {
// add this specific element to the data model (by cloning
// the generic element) so we can track changes to it
eval('datamodel["' + scoid + '"]["' + element + '"]=CloneObj(datamodel["' + scoid + '"]["' + elementmodel + '"]);');
datamodel[scoid][element] = CloneObj(datamodel[scoid][elementmodel]);
}
// check if the current element exists in the datamodel
if ((typeof eval('datamodel["' + scoid + '"]["' + element + '"]')) != "undefined") {
if (typeof datamodel[scoid][element] != "undefined") {
// make sure this is not a read only element
if (eval('datamodel["' + scoid + '"]["' + element + '"].mod') != 'r') {
if (datamodel[scoid][element].mod != 'r') {
elementstring = '&' + underscore(element) + '=' + encodeURIComponent(data[property]);
// check if the element has a default value
if ((typeof eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue')) != "undefined") {
if (typeof datamodel[scoid][element].defaultvalue != "undefined") {
// check if the default value is different from the current value
if (eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue') != data[property]
|| eval('typeof(datamodel["' + scoid + '"]["' + element + '"].defaultvalue)') != typeof(data[property])) {
if (datamodel[scoid][element].defaultvalue != data[property] ||
typeof datamodel[scoid][element].defaultvalue != typeof data[property]) {
// append the URI fragment to the string we plan to commit
datastring += elementstring;
// update the element default to reflect the current committed value
eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue=data[property];');
datamodel[scoid][element].defaultvalue = data[property];
}
} else {
// append the URI fragment to the string we plan to commit
datastring += elementstring;
// no default value for the element, so set it now
eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue=data[property];');
datamodel[scoid][element].defaultvalue = data[property];
}
}
}
......
......@@ -252,7 +252,7 @@ function SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scorm
for (element in datamodel[scoid]) {
if (element.match(/\.n\./) == null) {
if ((typeof eval('datamodel["' + scoid + '"]["' + element + '"].defaultvalue')) != 'undefined') {
if (typeof datamodel[scoid][element].defaultvalue != 'undefined') {
eval(element + ' = datamodel["' + scoid + '"]["' + element + '"].defaultvalue;');
} else {
eval(element + ' = "";');
......@@ -380,8 +380,8 @@ function SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scorm
if (element != "") {
var expression = new RegExp(CMIIndex,'g');
var elementmodel = String(element).replace(expression,'.n.');
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].mod') != 'w') {
if (typeof datamodel[scoid][elementmodel] != "undefined") {
if (datamodel[scoid][elementmodel].mod != 'w') {
element = String(element).replace(/\.(\d+)\./, ".N$1.");
element = element.replace(/\.(\d+)\./, ".N$1.");
......@@ -417,7 +417,7 @@ function SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scorm
var parentmodel = '';
if (elementmodel.substr(elementmodel.length - childrenstr.length,elementmodel.length) == childrenstr) {
parentmodel = elementmodel.substr(0,elementmodel.length - childrenstr.length);
if ((typeof eval('datamodel["' + scoid + '"]["' + parentmodel + '"]')) != "undefined") {
if (datamodel[scoid][parentmodel] != "undefined") {
errorCode = "301";
diagnostic = "Data Model Element Does Not Have Children";
} else {
......@@ -425,7 +425,7 @@ function SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scorm
}
} else if (elementmodel.substr(elementmodel.length - countstr.length,elementmodel.length) == countstr) {
parentmodel = elementmodel.substr(0,elementmodel.length - countstr.length);
if ((typeof eval('datamodel["' + scoid + '"]["' + parentmodel + '"]')) != "undefined") {
if (typeof datamodel[scoid][parentmodel] != "undefined") {
errorCode = "301";
diagnostic = "Data Model Element Cannot Have Count";
} else {
......@@ -473,10 +473,10 @@ function SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scorm
if (element != "") {
var expression = new RegExp(CMIIndex,'g');
var elementmodel = String(element).replace(expression,'.n.');
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].mod') != 'r') {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].format') != 'CMIFeedback') {
expression = new RegExp(eval('datamodel["' + scoid + '"]["' + elementmodel + '"].format'));
if (typeof datamodel[scoid][elementmodel] != "undefined") {
if (datamodel[scoid][elementmodel].mod != 'r') {
if (datamodel[scoid][elementmodel].format != 'CMIFeedback') {
expression = new RegExp(datamodel[scoid][elementmodel].format);
} else {
// cmi.interactions.n.type depending format accept everything at this stage
expression = new RegExp(CMIFeedback);
......@@ -749,8 +749,8 @@ function SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scorm
SCORMapi1_3.timeout = Y.later(60000, API_1484_11, 'Commit', [""], false);
}
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"].range')) != "undefined") {
range = eval('datamodel["' + scoid + '"]["' + elementmodel + '"].range');
if (typeof datamodel[scoid][elementmodel].range != "undefined") {
range = datamodel[scoid][elementmodel].range;
ranges = range.split('#');
value = value * 1.0;
if (value >= ranges[0]) {
......@@ -1180,11 +1180,12 @@ function SCORMapi1_3(def, cmiobj, cmiint, cmicommentsuser, cmicommentslms, scorm
var element = parent + '.' + property;
var expression = new RegExp(CMIIndexStore,'g');
var elementmodel = String(element).replace(expression,'.n.');
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"]')) != "undefined") {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].mod') != 'r') {
if (typeof datamodel[scoid][elementmodel] != "undefined") {
if (datamodel[scoid][elementmodel].mod != 'r') {
var elementstring = '&' + underscore(element) + '=' + encodeURIComponent(data[property]);
if ((typeof eval('datamodel["' + scoid + '"]["' + elementmodel + '"].defaultvalue')) != "undefined") {
if (eval('datamodel["' + scoid + '"]["' + elementmodel + '"].defaultvalue') != data[property] || eval('typeof(datamodel["' + scoid + '"]["' + elementmodel + '"].defaultvalue)') != typeof(data[property])) {
if (typeof datamodel[scoid][elementmodel].defaultvalue != "undefined") {
if (datamodel[scoid][elementmodel].defaultvalue != data[property] ||
typeof datamodel[scoid][elementmodel].defaultvalue != typeof data[property]) {
datastring += elementstring;
}
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment