scorm-again 1.7.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +18 -7
- package/.github/dependabot.yml +5 -0
- package/.github/workflows/main.yml +79 -0
- package/.jsdoc.json +4 -5
- package/.mocharc.json +8 -0
- package/.run/Mocha Unit Tests.run.xml +5 -2
- package/CONTRIBUTING.md +1 -1
- package/README.md +14 -1
- package/dist/aicc.js +3661 -7170
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +2 -40
- package/dist/aicc.min.js.map +1 -0
- package/dist/scorm-again.js +5671 -10695
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +2 -52
- package/dist/scorm-again.min.js.map +1 -0
- package/dist/scorm12.js +2871 -5433
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +2 -34
- package/dist/scorm12.min.js.map +1 -0
- package/dist/scorm2004.js +3868 -6797
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +2 -40
- package/dist/scorm2004.min.js.map +1 -0
- package/eslint.config.js +21 -0
- package/package.json +73 -35
- package/results.json +34254 -0
- package/src/{AICC.js → AICC.ts} +27 -21
- package/src/BaseAPI.ts +1449 -0
- package/src/Scorm12API.ts +360 -0
- package/src/{Scorm2004API.js → Scorm2004API.ts} +245 -163
- package/src/cmi/aicc_cmi.ts +1248 -0
- package/src/cmi/common.ts +411 -0
- package/src/cmi/scorm12_cmi.ts +1426 -0
- package/src/cmi/scorm2004_cmi.ts +1874 -0
- package/src/constants/api_constants.ts +318 -0
- package/src/constants/error_codes.ts +88 -0
- package/src/constants/language_constants.ts +394 -0
- package/src/constants/regex.ts +97 -0
- package/src/constants/{response_constants.js → response_constants.ts} +67 -62
- package/src/exceptions.ts +133 -0
- package/src/exports/aicc.js +1 -1
- package/src/exports/scorm-again.js +3 -3
- package/src/exports/scorm12.js +1 -1
- package/src/exports/scorm2004.js +1 -1
- package/src/{utilities.js → utilities.ts} +114 -74
- package/tea.yaml +6 -0
- package/test/{AICC.spec.js → AICC.spec.ts} +70 -72
- package/test/Scorm12API.spec.ts +580 -0
- package/test/Scorm2004API.spec.ts +812 -0
- package/test/api_helpers.ts +176 -0
- package/test/cmi/{aicc_cmi.spec.js → aicc_cmi.spec.ts} +193 -209
- package/test/cmi/{scorm12_cmi.spec.js → scorm12_cmi.spec.ts} +251 -269
- package/test/cmi/scorm2004_cmi.spec.ts +1031 -0
- package/test/cmi_helpers.ts +207 -0
- package/test/exceptions.spec.ts +79 -0
- package/test/field_values.ts +202 -0
- package/test/utilities.spec.ts +322 -0
- package/tsconfig.json +18 -0
- package/webpack.config.js +65 -0
- package/.circleci/config.yml +0 -99
- package/.codeclimate.yml +0 -7
- package/.eslintrc.js +0 -36
- package/src/.flowconfig +0 -11
- package/src/BaseAPI.js +0 -1275
- package/src/Scorm12API.js +0 -308
- package/src/cmi/aicc_cmi.js +0 -1141
- package/src/cmi/common.js +0 -328
- package/src/cmi/scorm12_cmi.js +0 -1312
- package/src/cmi/scorm2004_cmi.js +0 -1692
- package/src/constants/api_constants.js +0 -218
- package/src/constants/error_codes.js +0 -87
- package/src/constants/language_constants.js +0 -76
- package/src/constants/regex.js +0 -84
- package/src/exceptions.js +0 -104
- package/test/Scorm12API.spec.js +0 -528
- package/test/Scorm2004API.spec.js +0 -775
- package/test/abstract_classes.spec.js +0 -17
- package/test/api_helpers.js +0 -128
- package/test/cmi/scorm2004_cmi.spec.js +0 -1066
- package/test/cmi_helpers.js +0 -161
- package/test/exceptions.spec.js +0 -71
- package/test/field_values.js +0 -353
- package/test/utilities.spec.js +0 -339
- package/webpack.js +0 -78
|
@@ -0,0 +1,1874 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseCMI,
|
|
3
|
+
BaseRootCMI,
|
|
4
|
+
checkValidFormat,
|
|
5
|
+
checkValidRange,
|
|
6
|
+
CMIArray,
|
|
7
|
+
CMIScore,
|
|
8
|
+
} from "./common";
|
|
9
|
+
import APIConstants from "../constants/api_constants";
|
|
10
|
+
import Regex from "../constants/regex";
|
|
11
|
+
import ErrorCodes from "../constants/error_codes";
|
|
12
|
+
import { Scorm2004ValidationError } from "../exceptions";
|
|
13
|
+
import * as Util from "../utilities";
|
|
14
|
+
import { LearnerResponses } from "../constants/response_constants";
|
|
15
|
+
|
|
16
|
+
const scorm2004_constants = APIConstants.scorm2004;
|
|
17
|
+
const scorm2004_error_codes = ErrorCodes.scorm2004;
|
|
18
|
+
const learner_responses = LearnerResponses;
|
|
19
|
+
const scorm2004_regex = Regex.scorm2004;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Helper method, no reason to have to pass the same error codes every time
|
|
23
|
+
* @param {string} value
|
|
24
|
+
* @param {string} regexPattern
|
|
25
|
+
* @param {boolean} allowEmptyString
|
|
26
|
+
* @return {boolean}
|
|
27
|
+
*/
|
|
28
|
+
function check2004ValidFormat(
|
|
29
|
+
value: string,
|
|
30
|
+
regexPattern: string,
|
|
31
|
+
allowEmptyString?: boolean,
|
|
32
|
+
): boolean {
|
|
33
|
+
return checkValidFormat(
|
|
34
|
+
value,
|
|
35
|
+
regexPattern,
|
|
36
|
+
scorm2004_error_codes.TYPE_MISMATCH,
|
|
37
|
+
Scorm2004ValidationError,
|
|
38
|
+
allowEmptyString,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Helper method, no reason to have to pass the same error codes every time
|
|
44
|
+
* @param {string} value
|
|
45
|
+
* @param {string} rangePattern
|
|
46
|
+
* @return {boolean}
|
|
47
|
+
*/
|
|
48
|
+
function check2004ValidRange(value: string, rangePattern: string): boolean {
|
|
49
|
+
return checkValidRange(
|
|
50
|
+
value,
|
|
51
|
+
rangePattern,
|
|
52
|
+
scorm2004_error_codes.VALUE_OUT_OF_RANGE,
|
|
53
|
+
Scorm2004ValidationError,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Class representing cmi object for SCORM 2004
|
|
59
|
+
*/
|
|
60
|
+
export class CMI extends BaseRootCMI {
|
|
61
|
+
/**
|
|
62
|
+
* Constructor for the SCORM 2004 cmi object
|
|
63
|
+
* @param {boolean} initialized
|
|
64
|
+
*/
|
|
65
|
+
constructor(initialized: boolean = false) {
|
|
66
|
+
super();
|
|
67
|
+
this.learner_preference = new CMILearnerPreference();
|
|
68
|
+
this.score = new Scorm2004CMIScore();
|
|
69
|
+
this.comments_from_learner = new CMICommentsFromLearner();
|
|
70
|
+
this.comments_from_lms = new CMICommentsFromLMS();
|
|
71
|
+
this.interactions = new CMIInteractions();
|
|
72
|
+
this.objectives = new CMIObjectives();
|
|
73
|
+
if (initialized) this.initialize();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public learner_preference: CMILearnerPreference;
|
|
77
|
+
public score: Scorm2004CMIScore;
|
|
78
|
+
public comments_from_learner: CMICommentsFromLearner;
|
|
79
|
+
public comments_from_lms: CMICommentsFromLMS;
|
|
80
|
+
public interactions: CMIInteractions;
|
|
81
|
+
public objectives: CMIObjectives;
|
|
82
|
+
|
|
83
|
+
private __version = "1.0";
|
|
84
|
+
private __children = scorm2004_constants.cmi_children;
|
|
85
|
+
private _completion_status = "unknown";
|
|
86
|
+
private _completion_threshold = "";
|
|
87
|
+
private _credit = "credit";
|
|
88
|
+
private _entry = "";
|
|
89
|
+
private _exit = "";
|
|
90
|
+
private _launch_data = "";
|
|
91
|
+
private _learner_id = "";
|
|
92
|
+
private _learner_name = "";
|
|
93
|
+
private _location = "";
|
|
94
|
+
private _max_time_allowed = "";
|
|
95
|
+
private _mode = "normal";
|
|
96
|
+
private _progress_measure = "";
|
|
97
|
+
private _scaled_passing_score = "";
|
|
98
|
+
private _session_time = "PT0H0M0S";
|
|
99
|
+
private _success_status = "unknown";
|
|
100
|
+
private _suspend_data = "";
|
|
101
|
+
private _time_limit_action = "continue,no message";
|
|
102
|
+
private _total_time = "";
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Called when the API has been initialized after the CMI has been created
|
|
106
|
+
*/
|
|
107
|
+
initialize() {
|
|
108
|
+
super.initialize();
|
|
109
|
+
this.learner_preference?.initialize();
|
|
110
|
+
this.score?.initialize();
|
|
111
|
+
this.comments_from_learner?.initialize();
|
|
112
|
+
this.comments_from_lms?.initialize();
|
|
113
|
+
this.interactions?.initialize();
|
|
114
|
+
this.objectives?.initialize();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Getter for __version
|
|
119
|
+
* @return {string}
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
get _version(): string {
|
|
123
|
+
return this.__version;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Setter for __version. Just throws an error.
|
|
128
|
+
* @param {string} _version
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
set _version(_version: string) {
|
|
132
|
+
throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Getter for __children
|
|
137
|
+
* @return {string}
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
get _children(): string {
|
|
141
|
+
return this.__children;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Setter for __children. Just throws an error.
|
|
146
|
+
* @param {number} _children
|
|
147
|
+
* @private
|
|
148
|
+
*/
|
|
149
|
+
set _children(_children: number) {
|
|
150
|
+
throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Getter for _completion_status
|
|
155
|
+
* @return {string}
|
|
156
|
+
*/
|
|
157
|
+
get completion_status(): string {
|
|
158
|
+
return this._completion_status;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Setter for _completion_status
|
|
163
|
+
* @param {string} completion_status
|
|
164
|
+
*/
|
|
165
|
+
set completion_status(completion_status: string) {
|
|
166
|
+
if (check2004ValidFormat(completion_status, scorm2004_regex.CMICStatus)) {
|
|
167
|
+
this._completion_status = completion_status;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Getter for _completion_threshold
|
|
173
|
+
* @return {string}
|
|
174
|
+
*/
|
|
175
|
+
get completion_threshold(): string {
|
|
176
|
+
return this._completion_threshold;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Setter for _completion_threshold. Can only be called before initialization.
|
|
181
|
+
* @param {string} completion_threshold
|
|
182
|
+
*/
|
|
183
|
+
set completion_threshold(completion_threshold: string) {
|
|
184
|
+
if (this.initialized) {
|
|
185
|
+
throw new Scorm2004ValidationError(
|
|
186
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
187
|
+
);
|
|
188
|
+
} else {
|
|
189
|
+
this._completion_threshold = completion_threshold;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Setter for _credit
|
|
195
|
+
* @return {string}
|
|
196
|
+
*/
|
|
197
|
+
get credit(): string {
|
|
198
|
+
return this._credit;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Setter for _credit. Can only be called before initialization.
|
|
203
|
+
* @param {string} credit
|
|
204
|
+
*/
|
|
205
|
+
set credit(credit: string) {
|
|
206
|
+
if (this.initialized) {
|
|
207
|
+
throw new Scorm2004ValidationError(
|
|
208
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
209
|
+
);
|
|
210
|
+
} else {
|
|
211
|
+
this._credit = credit;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Getter for _entry
|
|
217
|
+
* @return {string}
|
|
218
|
+
*/
|
|
219
|
+
get entry(): string {
|
|
220
|
+
return this._entry;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Setter for _entry. Can only be called before initialization.
|
|
225
|
+
* @param {string} entry
|
|
226
|
+
*/
|
|
227
|
+
set entry(entry: string) {
|
|
228
|
+
if (this.initialized) {
|
|
229
|
+
throw new Scorm2004ValidationError(
|
|
230
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
231
|
+
);
|
|
232
|
+
} else {
|
|
233
|
+
this._entry = entry;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Getter for _exit. Should only be called during JSON export.
|
|
239
|
+
* @return {string}
|
|
240
|
+
*/
|
|
241
|
+
get exit(): string {
|
|
242
|
+
if (!this.jsonString) {
|
|
243
|
+
throw new Scorm2004ValidationError(
|
|
244
|
+
scorm2004_error_codes.WRITE_ONLY_ELEMENT,
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
return this._exit;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Getter for _exit
|
|
252
|
+
* @param {string} exit
|
|
253
|
+
*/
|
|
254
|
+
set exit(exit: string) {
|
|
255
|
+
if (check2004ValidFormat(exit, scorm2004_regex.CMIExit, true)) {
|
|
256
|
+
this._exit = exit;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Getter for _launch_data
|
|
262
|
+
* @return {string}
|
|
263
|
+
*/
|
|
264
|
+
get launch_data(): string {
|
|
265
|
+
return this._launch_data;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Setter for _launch_data. Can only be called before initialization.
|
|
270
|
+
* @param {string} launch_data
|
|
271
|
+
*/
|
|
272
|
+
set launch_data(launch_data: string) {
|
|
273
|
+
if (this.initialized) {
|
|
274
|
+
throw new Scorm2004ValidationError(
|
|
275
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
276
|
+
);
|
|
277
|
+
} else {
|
|
278
|
+
this._launch_data = launch_data;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Getter for _learner_id
|
|
284
|
+
* @return {string}
|
|
285
|
+
*/
|
|
286
|
+
get learner_id(): string {
|
|
287
|
+
return this._learner_id;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Setter for _learner_id. Can only be called before initialization.
|
|
292
|
+
* @param {string} learner_id
|
|
293
|
+
*/
|
|
294
|
+
set learner_id(learner_id: string) {
|
|
295
|
+
if (this.initialized) {
|
|
296
|
+
throw new Scorm2004ValidationError(
|
|
297
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
298
|
+
);
|
|
299
|
+
} else {
|
|
300
|
+
this._learner_id = learner_id;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Getter for _learner_name
|
|
306
|
+
* @return {string}
|
|
307
|
+
*/
|
|
308
|
+
get learner_name(): string {
|
|
309
|
+
return this._learner_name;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Setter for _learner_name. Can only be called before initialization.
|
|
314
|
+
* @param {string} learner_name
|
|
315
|
+
*/
|
|
316
|
+
set learner_name(learner_name: string) {
|
|
317
|
+
if (this.initialized) {
|
|
318
|
+
throw new Scorm2004ValidationError(
|
|
319
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
320
|
+
);
|
|
321
|
+
} else {
|
|
322
|
+
this._learner_name = learner_name;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Getter for _location
|
|
328
|
+
* @return {string}
|
|
329
|
+
*/
|
|
330
|
+
get location(): string {
|
|
331
|
+
return this._location;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Setter for _location
|
|
336
|
+
* @param {string} location
|
|
337
|
+
*/
|
|
338
|
+
set location(location: string) {
|
|
339
|
+
if (check2004ValidFormat(location, scorm2004_regex.CMIString1000)) {
|
|
340
|
+
this._location = location;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Getter for _max_time_allowed
|
|
346
|
+
* @return {string}
|
|
347
|
+
*/
|
|
348
|
+
get max_time_allowed(): string {
|
|
349
|
+
return this._max_time_allowed;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Setter for _max_time_allowed. Can only be called before initialization.
|
|
354
|
+
* @param {string} max_time_allowed
|
|
355
|
+
*/
|
|
356
|
+
set max_time_allowed(max_time_allowed: string) {
|
|
357
|
+
if (this.initialized) {
|
|
358
|
+
throw new Scorm2004ValidationError(
|
|
359
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
360
|
+
);
|
|
361
|
+
} else {
|
|
362
|
+
this._max_time_allowed = max_time_allowed;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Getter for _mode
|
|
368
|
+
* @return {string}
|
|
369
|
+
*/
|
|
370
|
+
get mode(): string {
|
|
371
|
+
return this._mode;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Setter for _mode. Can only be called before initialization.
|
|
376
|
+
* @param {string} mode
|
|
377
|
+
*/
|
|
378
|
+
set mode(mode: string) {
|
|
379
|
+
if (this.initialized) {
|
|
380
|
+
throw new Scorm2004ValidationError(
|
|
381
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
382
|
+
);
|
|
383
|
+
} else {
|
|
384
|
+
this._mode = mode;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Getter for _progress_measure
|
|
390
|
+
* @return {string}
|
|
391
|
+
*/
|
|
392
|
+
get progress_measure(): string {
|
|
393
|
+
return this._progress_measure;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Setter for _progress_measure
|
|
398
|
+
* @param {string} progress_measure
|
|
399
|
+
*/
|
|
400
|
+
set progress_measure(progress_measure: string) {
|
|
401
|
+
if (
|
|
402
|
+
check2004ValidFormat(progress_measure, scorm2004_regex.CMIDecimal) &&
|
|
403
|
+
check2004ValidRange(progress_measure, scorm2004_regex.progress_range)
|
|
404
|
+
) {
|
|
405
|
+
this._progress_measure = progress_measure;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Getter for _scaled_passing_score
|
|
411
|
+
* @return {string}
|
|
412
|
+
*/
|
|
413
|
+
get scaled_passing_score(): string {
|
|
414
|
+
return this._scaled_passing_score;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Setter for _scaled_passing_score. Can only be called before initialization.
|
|
419
|
+
* @param {string} scaled_passing_score
|
|
420
|
+
*/
|
|
421
|
+
set scaled_passing_score(scaled_passing_score: string) {
|
|
422
|
+
if (this.initialized) {
|
|
423
|
+
throw new Scorm2004ValidationError(
|
|
424
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
425
|
+
);
|
|
426
|
+
} else {
|
|
427
|
+
this._scaled_passing_score = scaled_passing_score;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Getter for _session_time. Should only be called during JSON export.
|
|
433
|
+
* @return {string}
|
|
434
|
+
*/
|
|
435
|
+
get session_time(): string {
|
|
436
|
+
if (!this.jsonString) {
|
|
437
|
+
throw new Scorm2004ValidationError(
|
|
438
|
+
scorm2004_error_codes.WRITE_ONLY_ELEMENT,
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
return this._session_time;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Setter for _session_time
|
|
446
|
+
* @param {string} session_time
|
|
447
|
+
*/
|
|
448
|
+
set session_time(session_time: string) {
|
|
449
|
+
if (check2004ValidFormat(session_time, scorm2004_regex.CMITimespan)) {
|
|
450
|
+
this._session_time = session_time;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Getter for _success_status
|
|
456
|
+
* @return {string}
|
|
457
|
+
*/
|
|
458
|
+
get success_status(): string {
|
|
459
|
+
return this._success_status;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Setter for _success_status
|
|
464
|
+
* @param {string} success_status
|
|
465
|
+
*/
|
|
466
|
+
set success_status(success_status: string) {
|
|
467
|
+
if (check2004ValidFormat(success_status, scorm2004_regex.CMISStatus)) {
|
|
468
|
+
this._success_status = success_status;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Getter for _suspend_data
|
|
474
|
+
* @return {string}
|
|
475
|
+
*/
|
|
476
|
+
get suspend_data(): string {
|
|
477
|
+
return this._suspend_data;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Setter for _suspend_data
|
|
482
|
+
* @param {string} suspend_data
|
|
483
|
+
*/
|
|
484
|
+
set suspend_data(suspend_data: string) {
|
|
485
|
+
if (
|
|
486
|
+
check2004ValidFormat(suspend_data, scorm2004_regex.CMIString64000, true)
|
|
487
|
+
) {
|
|
488
|
+
this._suspend_data = suspend_data;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Getter for _time_limit_action
|
|
494
|
+
* @return {string}
|
|
495
|
+
*/
|
|
496
|
+
get time_limit_action(): string {
|
|
497
|
+
return this._time_limit_action;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Setter for _time_limit_action. Can only be called before initialization.
|
|
502
|
+
* @param {string} time_limit_action
|
|
503
|
+
*/
|
|
504
|
+
set time_limit_action(time_limit_action: string) {
|
|
505
|
+
if (this.initialized) {
|
|
506
|
+
throw new Scorm2004ValidationError(
|
|
507
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
508
|
+
);
|
|
509
|
+
} else {
|
|
510
|
+
this._time_limit_action = time_limit_action;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Getter for _total_time
|
|
516
|
+
* @return {string}
|
|
517
|
+
*/
|
|
518
|
+
get total_time(): string {
|
|
519
|
+
return this._total_time;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Setter for _total_time. Can only be called before initialization.
|
|
524
|
+
* @param {string} total_time
|
|
525
|
+
*/
|
|
526
|
+
set total_time(total_time: string) {
|
|
527
|
+
if (this.initialized) {
|
|
528
|
+
throw new Scorm2004ValidationError(
|
|
529
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
530
|
+
);
|
|
531
|
+
} else {
|
|
532
|
+
this._total_time = total_time;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Adds the current session time to the existing total time.
|
|
538
|
+
*
|
|
539
|
+
* @return {string} ISO8601 Duration
|
|
540
|
+
*/
|
|
541
|
+
getCurrentTotalTime(): string {
|
|
542
|
+
let sessionTime = this._session_time;
|
|
543
|
+
const startTime = this.start_time;
|
|
544
|
+
|
|
545
|
+
if (typeof startTime !== "undefined" && startTime !== null) {
|
|
546
|
+
const seconds = new Date().getTime() - startTime;
|
|
547
|
+
sessionTime = Util.getSecondsAsISODuration(seconds / 1000);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return Util.addTwoDurations(
|
|
551
|
+
this._total_time,
|
|
552
|
+
sessionTime,
|
|
553
|
+
scorm2004_regex.CMITimespan,
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* toJSON for cmi
|
|
559
|
+
*
|
|
560
|
+
* @return {
|
|
561
|
+
* {
|
|
562
|
+
* comments_from_learner: CMICommentsFromLearner,
|
|
563
|
+
* comments_from_lms: CMICommentsFromLMS,
|
|
564
|
+
* completion_status: string,
|
|
565
|
+
* completion_threshold: string,
|
|
566
|
+
* credit: string,
|
|
567
|
+
* entry: string,
|
|
568
|
+
* exit: string,
|
|
569
|
+
* interactions: CMIInteractions,
|
|
570
|
+
* launch_data: string,
|
|
571
|
+
* learner_id: string,
|
|
572
|
+
* learner_name: string,
|
|
573
|
+
* learner_preference: CMILearnerPreference,
|
|
574
|
+
* location: string,
|
|
575
|
+
* max_time_allowed: string,
|
|
576
|
+
* mode: string,
|
|
577
|
+
* objectives: CMIObjectives,
|
|
578
|
+
* progress_measure: string,
|
|
579
|
+
* scaled_passing_score: string,
|
|
580
|
+
* score: Scorm2004CMIScore,
|
|
581
|
+
* session_time: string,
|
|
582
|
+
* success_status: string,
|
|
583
|
+
* suspend_data: string,
|
|
584
|
+
* time_limit_action: string
|
|
585
|
+
* }
|
|
586
|
+
* }
|
|
587
|
+
*/
|
|
588
|
+
toJSON(): {
|
|
589
|
+
comments_from_learner: CMICommentsFromLearner;
|
|
590
|
+
comments_from_lms: CMICommentsFromLMS;
|
|
591
|
+
completion_status: string;
|
|
592
|
+
completion_threshold: string;
|
|
593
|
+
credit: string;
|
|
594
|
+
entry: string;
|
|
595
|
+
exit: string;
|
|
596
|
+
interactions: CMIInteractions;
|
|
597
|
+
launch_data: string;
|
|
598
|
+
learner_id: string;
|
|
599
|
+
learner_name: string;
|
|
600
|
+
learner_preference: CMILearnerPreference;
|
|
601
|
+
location: string;
|
|
602
|
+
max_time_allowed: string;
|
|
603
|
+
mode: string;
|
|
604
|
+
objectives: CMIObjectives;
|
|
605
|
+
progress_measure: string;
|
|
606
|
+
scaled_passing_score: string;
|
|
607
|
+
score: Scorm2004CMIScore;
|
|
608
|
+
session_time: string;
|
|
609
|
+
success_status: string;
|
|
610
|
+
suspend_data: string;
|
|
611
|
+
time_limit_action: string;
|
|
612
|
+
} {
|
|
613
|
+
this.jsonString = true;
|
|
614
|
+
const result = {
|
|
615
|
+
comments_from_learner: this.comments_from_learner,
|
|
616
|
+
comments_from_lms: this.comments_from_lms,
|
|
617
|
+
completion_status: this.completion_status,
|
|
618
|
+
completion_threshold: this.completion_threshold,
|
|
619
|
+
credit: this.credit,
|
|
620
|
+
entry: this.entry,
|
|
621
|
+
exit: this.exit,
|
|
622
|
+
interactions: this.interactions,
|
|
623
|
+
launch_data: this.launch_data,
|
|
624
|
+
learner_id: this.learner_id,
|
|
625
|
+
learner_name: this.learner_name,
|
|
626
|
+
learner_preference: this.learner_preference,
|
|
627
|
+
location: this.location,
|
|
628
|
+
max_time_allowed: this.max_time_allowed,
|
|
629
|
+
mode: this.mode,
|
|
630
|
+
objectives: this.objectives,
|
|
631
|
+
progress_measure: this.progress_measure,
|
|
632
|
+
scaled_passing_score: this.scaled_passing_score,
|
|
633
|
+
score: this.score,
|
|
634
|
+
session_time: this.session_time,
|
|
635
|
+
success_status: this.success_status,
|
|
636
|
+
suspend_data: this.suspend_data,
|
|
637
|
+
time_limit_action: this.time_limit_action,
|
|
638
|
+
};
|
|
639
|
+
delete this.jsonString;
|
|
640
|
+
return result;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Class for SCORM 2004's cmi.learner_preference object
|
|
646
|
+
*/
|
|
647
|
+
|
|
648
|
+
class CMILearnerPreference extends BaseCMI {
|
|
649
|
+
private __children = scorm2004_constants.student_preference_children;
|
|
650
|
+
private _audio_level = "1";
|
|
651
|
+
private _language = "";
|
|
652
|
+
private _delivery_speed = "1";
|
|
653
|
+
private _audio_captioning = "0";
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Constructor for cmi.learner_preference
|
|
657
|
+
*/
|
|
658
|
+
constructor() {
|
|
659
|
+
super();
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* Getter for __children
|
|
664
|
+
* @return {string}
|
|
665
|
+
* @private
|
|
666
|
+
*/
|
|
667
|
+
get _children(): string {
|
|
668
|
+
return this.__children;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Setter for __children. Just throws an error.
|
|
673
|
+
* @param {string} _children
|
|
674
|
+
* @private
|
|
675
|
+
*/
|
|
676
|
+
set _children(_children: string) {
|
|
677
|
+
throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Getter for _audio_level
|
|
682
|
+
* @return {string}
|
|
683
|
+
*/
|
|
684
|
+
get audio_level(): string {
|
|
685
|
+
return this._audio_level;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Setter for _audio_level
|
|
690
|
+
* @param {string} audio_level
|
|
691
|
+
*/
|
|
692
|
+
set audio_level(audio_level: string) {
|
|
693
|
+
if (
|
|
694
|
+
check2004ValidFormat(audio_level, scorm2004_regex.CMIDecimal) &&
|
|
695
|
+
check2004ValidRange(audio_level, scorm2004_regex.audio_range)
|
|
696
|
+
) {
|
|
697
|
+
this._audio_level = audio_level;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Getter for _language
|
|
703
|
+
* @return {string}
|
|
704
|
+
*/
|
|
705
|
+
get language(): string {
|
|
706
|
+
return this._language;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* Setter for _language
|
|
711
|
+
* @param {string} language
|
|
712
|
+
*/
|
|
713
|
+
set language(language: string) {
|
|
714
|
+
if (check2004ValidFormat(language, scorm2004_regex.CMILang)) {
|
|
715
|
+
this._language = language;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Getter for _delivery_speed
|
|
721
|
+
* @return {string}
|
|
722
|
+
*/
|
|
723
|
+
get delivery_speed(): string {
|
|
724
|
+
return this._delivery_speed;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Setter for _delivery_speed
|
|
729
|
+
* @param {string} delivery_speed
|
|
730
|
+
*/
|
|
731
|
+
set delivery_speed(delivery_speed: string) {
|
|
732
|
+
if (
|
|
733
|
+
check2004ValidFormat(delivery_speed, scorm2004_regex.CMIDecimal) &&
|
|
734
|
+
check2004ValidRange(delivery_speed, scorm2004_regex.speed_range)
|
|
735
|
+
) {
|
|
736
|
+
this._delivery_speed = delivery_speed;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Getter for _audio_captioning
|
|
742
|
+
* @return {string}
|
|
743
|
+
*/
|
|
744
|
+
get audio_captioning(): string {
|
|
745
|
+
return this._audio_captioning;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Setter for _audio_captioning
|
|
750
|
+
* @param {string} audio_captioning
|
|
751
|
+
*/
|
|
752
|
+
set audio_captioning(audio_captioning: string) {
|
|
753
|
+
if (
|
|
754
|
+
check2004ValidFormat(audio_captioning, scorm2004_regex.CMISInteger) &&
|
|
755
|
+
check2004ValidRange(audio_captioning, scorm2004_regex.text_range)
|
|
756
|
+
) {
|
|
757
|
+
this._audio_captioning = audio_captioning;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* toJSON for cmi.learner_preference
|
|
763
|
+
*
|
|
764
|
+
* @return {
|
|
765
|
+
* {
|
|
766
|
+
* audio_level: string,
|
|
767
|
+
* language: string,
|
|
768
|
+
* delivery_speed: string,
|
|
769
|
+
* audio_captioning: string
|
|
770
|
+
* }
|
|
771
|
+
* }
|
|
772
|
+
*/
|
|
773
|
+
toJSON(): {
|
|
774
|
+
audio_level: string;
|
|
775
|
+
language: string;
|
|
776
|
+
delivery_speed: string;
|
|
777
|
+
audio_captioning: string;
|
|
778
|
+
} {
|
|
779
|
+
this.jsonString = true;
|
|
780
|
+
const result = {
|
|
781
|
+
audio_level: this.audio_level,
|
|
782
|
+
language: this.language,
|
|
783
|
+
delivery_speed: this.delivery_speed,
|
|
784
|
+
audio_captioning: this.audio_captioning,
|
|
785
|
+
};
|
|
786
|
+
delete this.jsonString;
|
|
787
|
+
return result;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Class representing SCORM 2004's `cmi.interactions` object
|
|
793
|
+
*/
|
|
794
|
+
|
|
795
|
+
class CMIInteractions extends CMIArray {
|
|
796
|
+
/**
|
|
797
|
+
* Constructor for `cmi.objectives` Array
|
|
798
|
+
*/
|
|
799
|
+
constructor() {
|
|
800
|
+
super({
|
|
801
|
+
children: scorm2004_constants.interactions_children,
|
|
802
|
+
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
803
|
+
errorClass: Scorm2004ValidationError,
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Class representing SCORM 2004's `cmi.objectives` object
|
|
810
|
+
*/
|
|
811
|
+
|
|
812
|
+
class CMIObjectives extends CMIArray {
|
|
813
|
+
/**
|
|
814
|
+
* Constructor for `cmi.objectives` Array
|
|
815
|
+
*/
|
|
816
|
+
constructor() {
|
|
817
|
+
super({
|
|
818
|
+
children: scorm2004_constants.objectives_children,
|
|
819
|
+
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
820
|
+
errorClass: Scorm2004ValidationError,
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Class representing SCORM 2004's cmi.comments_from_lms object
|
|
827
|
+
*/
|
|
828
|
+
|
|
829
|
+
class CMICommentsFromLMS extends CMIArray {
|
|
830
|
+
/**
|
|
831
|
+
* Constructor for cmi.comments_from_lms Array
|
|
832
|
+
*/
|
|
833
|
+
constructor() {
|
|
834
|
+
super({
|
|
835
|
+
children: scorm2004_constants.comments_children,
|
|
836
|
+
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
837
|
+
errorClass: Scorm2004ValidationError,
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Class representing SCORM 2004's cmi.comments_from_learner object
|
|
844
|
+
*/
|
|
845
|
+
|
|
846
|
+
class CMICommentsFromLearner extends CMIArray {
|
|
847
|
+
/**
|
|
848
|
+
* Constructor for cmi.comments_from_learner Array
|
|
849
|
+
*/
|
|
850
|
+
constructor() {
|
|
851
|
+
super({
|
|
852
|
+
children: scorm2004_constants.comments_children,
|
|
853
|
+
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
854
|
+
errorClass: Scorm2004ValidationError,
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Class for SCORM 2004's cmi.interaction.n object
|
|
861
|
+
*/
|
|
862
|
+
|
|
863
|
+
export class CMIInteractionsObject extends BaseCMI {
|
|
864
|
+
private _id = "";
|
|
865
|
+
private _type = "";
|
|
866
|
+
private _timestamp = "";
|
|
867
|
+
private _weighting = "";
|
|
868
|
+
private _learner_response = "";
|
|
869
|
+
private _result = "";
|
|
870
|
+
private _latency = "";
|
|
871
|
+
private _description = "";
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Constructor for cmi.interaction.n
|
|
875
|
+
*/
|
|
876
|
+
constructor() {
|
|
877
|
+
super();
|
|
878
|
+
this.objectives = new CMIArray({
|
|
879
|
+
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
880
|
+
errorClass: Scorm2004ValidationError,
|
|
881
|
+
children: scorm2004_constants.objectives_children,
|
|
882
|
+
});
|
|
883
|
+
this.correct_responses = new CMIArray({
|
|
884
|
+
errorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
885
|
+
errorClass: Scorm2004ValidationError,
|
|
886
|
+
children: scorm2004_constants.correct_responses_children,
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
public objectives: CMIArray;
|
|
891
|
+
public correct_responses: CMIArray;
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Called when the API has been initialized after the CMI has been created
|
|
895
|
+
*/
|
|
896
|
+
initialize() {
|
|
897
|
+
super.initialize();
|
|
898
|
+
this.objectives?.initialize();
|
|
899
|
+
this.correct_responses?.initialize();
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Getter for _id
|
|
904
|
+
* @return {string}
|
|
905
|
+
*/
|
|
906
|
+
get id(): string {
|
|
907
|
+
return this._id;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* Setter for _id
|
|
912
|
+
* @param {string} id
|
|
913
|
+
*/
|
|
914
|
+
set id(id: string) {
|
|
915
|
+
if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
|
|
916
|
+
this._id = id;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
/**
|
|
921
|
+
* Getter for _type
|
|
922
|
+
* @return {string}
|
|
923
|
+
*/
|
|
924
|
+
get type(): string {
|
|
925
|
+
return this._type;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
/**
|
|
929
|
+
* Setter for _type
|
|
930
|
+
* @param {string} type
|
|
931
|
+
*/
|
|
932
|
+
set type(type: string) {
|
|
933
|
+
if (this.initialized && this._id === "") {
|
|
934
|
+
throw new Scorm2004ValidationError(
|
|
935
|
+
scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED,
|
|
936
|
+
);
|
|
937
|
+
} else {
|
|
938
|
+
if (check2004ValidFormat(type, scorm2004_regex.CMIType)) {
|
|
939
|
+
this._type = type;
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Getter for _timestamp
|
|
946
|
+
* @return {string}
|
|
947
|
+
*/
|
|
948
|
+
get timestamp(): string {
|
|
949
|
+
return this._timestamp;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* Setter for _timestamp
|
|
954
|
+
* @param {string} timestamp
|
|
955
|
+
*/
|
|
956
|
+
set timestamp(timestamp: string) {
|
|
957
|
+
if (this.initialized && this._id === "") {
|
|
958
|
+
throw new Scorm2004ValidationError(
|
|
959
|
+
scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED,
|
|
960
|
+
);
|
|
961
|
+
} else {
|
|
962
|
+
if (check2004ValidFormat(timestamp, scorm2004_regex.CMITime)) {
|
|
963
|
+
this._timestamp = timestamp;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Getter for _weighting
|
|
970
|
+
* @return {string}
|
|
971
|
+
*/
|
|
972
|
+
get weighting(): string {
|
|
973
|
+
return this._weighting;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Setter for _weighting
|
|
978
|
+
* @param {string} weighting
|
|
979
|
+
*/
|
|
980
|
+
set weighting(weighting: string) {
|
|
981
|
+
if (this.initialized && this._id === "") {
|
|
982
|
+
throw new Scorm2004ValidationError(
|
|
983
|
+
scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED,
|
|
984
|
+
);
|
|
985
|
+
} else {
|
|
986
|
+
if (check2004ValidFormat(weighting, scorm2004_regex.CMIDecimal)) {
|
|
987
|
+
this._weighting = weighting;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Getter for _learner_response
|
|
994
|
+
* @return {string}
|
|
995
|
+
*/
|
|
996
|
+
get learner_response(): string {
|
|
997
|
+
return this._learner_response;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* Setter for _learner_response. Does type validation to make sure response
|
|
1002
|
+
* matches SCORM 2004's spec
|
|
1003
|
+
* @param {string} learner_response
|
|
1004
|
+
*/
|
|
1005
|
+
set learner_response(learner_response: string) {
|
|
1006
|
+
if (this.initialized && (this._type === "" || this._id === "")) {
|
|
1007
|
+
throw new Scorm2004ValidationError(
|
|
1008
|
+
scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED,
|
|
1009
|
+
);
|
|
1010
|
+
} else {
|
|
1011
|
+
let nodes = [];
|
|
1012
|
+
const response_type = learner_responses[this.type];
|
|
1013
|
+
|
|
1014
|
+
if (response_type) {
|
|
1015
|
+
if (response_type?.delimiter) {
|
|
1016
|
+
nodes = learner_response.split(response_type.delimiter);
|
|
1017
|
+
} else {
|
|
1018
|
+
nodes[0] = learner_response;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
if (nodes.length > 0 && nodes.length <= response_type.max) {
|
|
1022
|
+
const formatRegex = new RegExp(response_type.format);
|
|
1023
|
+
|
|
1024
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
1025
|
+
if (response_type?.delimiter2) {
|
|
1026
|
+
const values = nodes[i].split(response_type.delimiter2);
|
|
1027
|
+
|
|
1028
|
+
if (values.length === 2) {
|
|
1029
|
+
if (!values[0].match(formatRegex)) {
|
|
1030
|
+
throw new Scorm2004ValidationError(
|
|
1031
|
+
scorm2004_error_codes.TYPE_MISMATCH,
|
|
1032
|
+
);
|
|
1033
|
+
} else {
|
|
1034
|
+
if (
|
|
1035
|
+
!response_type.format2 ||
|
|
1036
|
+
!values[1].match(new RegExp(response_type.format2))
|
|
1037
|
+
) {
|
|
1038
|
+
throw new Scorm2004ValidationError(
|
|
1039
|
+
scorm2004_error_codes.TYPE_MISMATCH,
|
|
1040
|
+
);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
} else {
|
|
1044
|
+
throw new Scorm2004ValidationError(
|
|
1045
|
+
scorm2004_error_codes.TYPE_MISMATCH,
|
|
1046
|
+
);
|
|
1047
|
+
}
|
|
1048
|
+
} else {
|
|
1049
|
+
if (!nodes[i].match(formatRegex)) {
|
|
1050
|
+
throw new Scorm2004ValidationError(
|
|
1051
|
+
scorm2004_error_codes.TYPE_MISMATCH,
|
|
1052
|
+
);
|
|
1053
|
+
} else {
|
|
1054
|
+
if (nodes[i] !== "" && response_type.unique) {
|
|
1055
|
+
for (let j = 0; j < i; j++) {
|
|
1056
|
+
if (nodes[i] === nodes[j]) {
|
|
1057
|
+
throw new Scorm2004ValidationError(
|
|
1058
|
+
scorm2004_error_codes.TYPE_MISMATCH,
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
} else {
|
|
1067
|
+
throw new Scorm2004ValidationError(
|
|
1068
|
+
scorm2004_error_codes.GENERAL_SET_FAILURE,
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
this._learner_response = learner_response;
|
|
1073
|
+
} else {
|
|
1074
|
+
throw new Scorm2004ValidationError(scorm2004_error_codes.TYPE_MISMATCH);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* Getter for _result
|
|
1081
|
+
* @return {string}
|
|
1082
|
+
*/
|
|
1083
|
+
get result(): string {
|
|
1084
|
+
return this._result;
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
/**
|
|
1088
|
+
* Setter for _result
|
|
1089
|
+
* @param {string} result
|
|
1090
|
+
*/
|
|
1091
|
+
set result(result: string) {
|
|
1092
|
+
if (check2004ValidFormat(result, scorm2004_regex.CMIResult)) {
|
|
1093
|
+
this._result = result;
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* Getter for _latency
|
|
1099
|
+
* @return {string}
|
|
1100
|
+
*/
|
|
1101
|
+
get latency(): string {
|
|
1102
|
+
return this._latency;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* Setter for _latency
|
|
1107
|
+
* @param {string} latency
|
|
1108
|
+
*/
|
|
1109
|
+
set latency(latency: string) {
|
|
1110
|
+
if (this.initialized && this._id === "") {
|
|
1111
|
+
throw new Scorm2004ValidationError(
|
|
1112
|
+
scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED,
|
|
1113
|
+
);
|
|
1114
|
+
} else {
|
|
1115
|
+
if (check2004ValidFormat(latency, scorm2004_regex.CMITimespan)) {
|
|
1116
|
+
this._latency = latency;
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Getter for _description
|
|
1123
|
+
* @return {string}
|
|
1124
|
+
*/
|
|
1125
|
+
get description(): string {
|
|
1126
|
+
return this._description;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
/**
|
|
1130
|
+
* Setter for _description
|
|
1131
|
+
* @param {string} description
|
|
1132
|
+
*/
|
|
1133
|
+
set description(description: string) {
|
|
1134
|
+
if (this.initialized && this._id === "") {
|
|
1135
|
+
throw new Scorm2004ValidationError(
|
|
1136
|
+
scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED,
|
|
1137
|
+
);
|
|
1138
|
+
} else {
|
|
1139
|
+
if (
|
|
1140
|
+
check2004ValidFormat(
|
|
1141
|
+
description,
|
|
1142
|
+
scorm2004_regex.CMILangString250,
|
|
1143
|
+
true,
|
|
1144
|
+
)
|
|
1145
|
+
) {
|
|
1146
|
+
this._description = description;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* toJSON for cmi.interactions.n
|
|
1153
|
+
*
|
|
1154
|
+
* @return {
|
|
1155
|
+
* {
|
|
1156
|
+
* id: string,
|
|
1157
|
+
* type: string,
|
|
1158
|
+
* objectives: CMIArray,
|
|
1159
|
+
* timestamp: string,
|
|
1160
|
+
* correct_responses: CMIArray,
|
|
1161
|
+
* weighting: string,
|
|
1162
|
+
* learner_response: string,
|
|
1163
|
+
* result: string,
|
|
1164
|
+
* latency: string,
|
|
1165
|
+
* description: string
|
|
1166
|
+
* }
|
|
1167
|
+
* }
|
|
1168
|
+
*/
|
|
1169
|
+
toJSON(): {
|
|
1170
|
+
id: string;
|
|
1171
|
+
type: string;
|
|
1172
|
+
objectives: CMIArray;
|
|
1173
|
+
timestamp: string;
|
|
1174
|
+
correct_responses: CMIArray;
|
|
1175
|
+
weighting: string;
|
|
1176
|
+
learner_response: string;
|
|
1177
|
+
result: string;
|
|
1178
|
+
latency: string;
|
|
1179
|
+
description: string;
|
|
1180
|
+
} {
|
|
1181
|
+
this.jsonString = true;
|
|
1182
|
+
const result = {
|
|
1183
|
+
id: this.id,
|
|
1184
|
+
type: this.type,
|
|
1185
|
+
objectives: this.objectives,
|
|
1186
|
+
timestamp: this.timestamp,
|
|
1187
|
+
weighting: this.weighting,
|
|
1188
|
+
learner_response: this.learner_response,
|
|
1189
|
+
result: this.result,
|
|
1190
|
+
latency: this.latency,
|
|
1191
|
+
description: this.description,
|
|
1192
|
+
correct_responses: this.correct_responses,
|
|
1193
|
+
};
|
|
1194
|
+
delete this.jsonString;
|
|
1195
|
+
return result;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* Class for SCORM 2004's cmi.objectives.n object
|
|
1201
|
+
*/
|
|
1202
|
+
export class CMIObjectivesObject extends BaseCMI {
|
|
1203
|
+
private _id = "";
|
|
1204
|
+
private _success_status = "unknown";
|
|
1205
|
+
private _completion_status = "unknown";
|
|
1206
|
+
private _progress_measure = "";
|
|
1207
|
+
private _description = "";
|
|
1208
|
+
|
|
1209
|
+
/**
|
|
1210
|
+
* Constructor for cmi.objectives.n
|
|
1211
|
+
*/
|
|
1212
|
+
constructor() {
|
|
1213
|
+
super();
|
|
1214
|
+
this.score = new Scorm2004CMIScore();
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
public score: Scorm2004CMIScore;
|
|
1218
|
+
|
|
1219
|
+
/**
|
|
1220
|
+
* Called when the API has been initialized after the CMI has been created
|
|
1221
|
+
*/
|
|
1222
|
+
initialize() {
|
|
1223
|
+
super.initialize();
|
|
1224
|
+
this.score?.initialize();
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* Getter for _id
|
|
1229
|
+
* @return {string}
|
|
1230
|
+
*/
|
|
1231
|
+
get id(): string {
|
|
1232
|
+
return this._id;
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
/**
|
|
1236
|
+
* Setter for _id
|
|
1237
|
+
* @param {string} id
|
|
1238
|
+
*/
|
|
1239
|
+
set id(id: string) {
|
|
1240
|
+
if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
|
|
1241
|
+
this._id = id;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* Getter for _success_status
|
|
1247
|
+
* @return {string}
|
|
1248
|
+
*/
|
|
1249
|
+
get success_status(): string {
|
|
1250
|
+
return this._success_status;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* Setter for _success_status
|
|
1255
|
+
* @param {string} success_status
|
|
1256
|
+
*/
|
|
1257
|
+
set success_status(success_status: string) {
|
|
1258
|
+
if (this.initialized && this._id === "") {
|
|
1259
|
+
throw new Scorm2004ValidationError(
|
|
1260
|
+
scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED,
|
|
1261
|
+
);
|
|
1262
|
+
} else {
|
|
1263
|
+
if (check2004ValidFormat(success_status, scorm2004_regex.CMISStatus)) {
|
|
1264
|
+
this._success_status = success_status;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* Getter for _completion_status
|
|
1271
|
+
* @return {string}
|
|
1272
|
+
*/
|
|
1273
|
+
get completion_status(): string {
|
|
1274
|
+
return this._completion_status;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* Setter for _completion_status
|
|
1279
|
+
* @param {string} completion_status
|
|
1280
|
+
*/
|
|
1281
|
+
set completion_status(completion_status: string) {
|
|
1282
|
+
if (this.initialized && this._id === "") {
|
|
1283
|
+
throw new Scorm2004ValidationError(
|
|
1284
|
+
scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED,
|
|
1285
|
+
);
|
|
1286
|
+
} else {
|
|
1287
|
+
if (check2004ValidFormat(completion_status, scorm2004_regex.CMICStatus)) {
|
|
1288
|
+
this._completion_status = completion_status;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
/**
|
|
1294
|
+
* Getter for _progress_measure
|
|
1295
|
+
* @return {string}
|
|
1296
|
+
*/
|
|
1297
|
+
get progress_measure(): string {
|
|
1298
|
+
return this._progress_measure;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
/**
|
|
1302
|
+
* Setter for _progress_measure
|
|
1303
|
+
* @param {string} progress_measure
|
|
1304
|
+
*/
|
|
1305
|
+
set progress_measure(progress_measure: string) {
|
|
1306
|
+
if (this.initialized && this._id === "") {
|
|
1307
|
+
throw new Scorm2004ValidationError(
|
|
1308
|
+
scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED,
|
|
1309
|
+
);
|
|
1310
|
+
} else {
|
|
1311
|
+
if (
|
|
1312
|
+
check2004ValidFormat(progress_measure, scorm2004_regex.CMIDecimal) &&
|
|
1313
|
+
check2004ValidRange(progress_measure, scorm2004_regex.progress_range)
|
|
1314
|
+
) {
|
|
1315
|
+
this._progress_measure = progress_measure;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
/**
|
|
1321
|
+
* Getter for _description
|
|
1322
|
+
* @return {string}
|
|
1323
|
+
*/
|
|
1324
|
+
get description(): string {
|
|
1325
|
+
return this._description;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
/**
|
|
1329
|
+
* Setter for _description
|
|
1330
|
+
* @param {string} description
|
|
1331
|
+
*/
|
|
1332
|
+
set description(description: string) {
|
|
1333
|
+
if (this.initialized && this._id === "") {
|
|
1334
|
+
throw new Scorm2004ValidationError(
|
|
1335
|
+
scorm2004_error_codes.DEPENDENCY_NOT_ESTABLISHED,
|
|
1336
|
+
);
|
|
1337
|
+
} else {
|
|
1338
|
+
if (
|
|
1339
|
+
check2004ValidFormat(
|
|
1340
|
+
description,
|
|
1341
|
+
scorm2004_regex.CMILangString250,
|
|
1342
|
+
true,
|
|
1343
|
+
)
|
|
1344
|
+
) {
|
|
1345
|
+
this._description = description;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
/**
|
|
1351
|
+
* toJSON for cmi.objectives.n
|
|
1352
|
+
*
|
|
1353
|
+
* @return {
|
|
1354
|
+
* {
|
|
1355
|
+
* id: string,
|
|
1356
|
+
* success_status: string,
|
|
1357
|
+
* completion_status: string,
|
|
1358
|
+
* progress_measure: string,
|
|
1359
|
+
* description: string,
|
|
1360
|
+
* score: Scorm2004CMIScore
|
|
1361
|
+
* }
|
|
1362
|
+
* }
|
|
1363
|
+
*/
|
|
1364
|
+
toJSON(): {
|
|
1365
|
+
id: string;
|
|
1366
|
+
success_status: string;
|
|
1367
|
+
completion_status: string;
|
|
1368
|
+
progress_measure: string;
|
|
1369
|
+
description: string;
|
|
1370
|
+
score: Scorm2004CMIScore;
|
|
1371
|
+
} {
|
|
1372
|
+
this.jsonString = true;
|
|
1373
|
+
const result = {
|
|
1374
|
+
id: this.id,
|
|
1375
|
+
success_status: this.success_status,
|
|
1376
|
+
completion_status: this.completion_status,
|
|
1377
|
+
progress_measure: this.progress_measure,
|
|
1378
|
+
description: this.description,
|
|
1379
|
+
score: this.score,
|
|
1380
|
+
};
|
|
1381
|
+
delete this.jsonString;
|
|
1382
|
+
return result;
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/**
|
|
1387
|
+
* Class for SCORM 2004's cmi *.score object
|
|
1388
|
+
*/
|
|
1389
|
+
|
|
1390
|
+
class Scorm2004CMIScore extends CMIScore {
|
|
1391
|
+
private _scaled = "";
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* Constructor for cmi *.score
|
|
1395
|
+
*/
|
|
1396
|
+
constructor() {
|
|
1397
|
+
super({
|
|
1398
|
+
score_children: scorm2004_constants.score_children,
|
|
1399
|
+
max: "",
|
|
1400
|
+
invalidErrorCode: scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
1401
|
+
invalidTypeCode: scorm2004_error_codes.TYPE_MISMATCH,
|
|
1402
|
+
invalidRangeCode: scorm2004_error_codes.VALUE_OUT_OF_RANGE,
|
|
1403
|
+
decimalRegex: scorm2004_regex.CMIDecimal,
|
|
1404
|
+
errorClass: Scorm2004ValidationError,
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
/**
|
|
1409
|
+
* Getter for _scaled
|
|
1410
|
+
* @return {string}
|
|
1411
|
+
*/
|
|
1412
|
+
get scaled(): string {
|
|
1413
|
+
return this._scaled;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
/**
|
|
1417
|
+
* Setter for _scaled
|
|
1418
|
+
* @param {string} scaled
|
|
1419
|
+
*/
|
|
1420
|
+
set scaled(scaled: string) {
|
|
1421
|
+
if (
|
|
1422
|
+
check2004ValidFormat(scaled, scorm2004_regex.CMIDecimal) &&
|
|
1423
|
+
check2004ValidRange(scaled, scorm2004_regex.scaled_range)
|
|
1424
|
+
) {
|
|
1425
|
+
this._scaled = scaled;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
/**
|
|
1430
|
+
* toJSON for cmi *.score
|
|
1431
|
+
*
|
|
1432
|
+
* @return {
|
|
1433
|
+
* {
|
|
1434
|
+
* scaled: string,
|
|
1435
|
+
* raw: string,
|
|
1436
|
+
* min: string,
|
|
1437
|
+
* max: string
|
|
1438
|
+
* }
|
|
1439
|
+
* }
|
|
1440
|
+
*/
|
|
1441
|
+
toJSON(): {
|
|
1442
|
+
scaled: string;
|
|
1443
|
+
raw: string;
|
|
1444
|
+
min: string;
|
|
1445
|
+
max: string;
|
|
1446
|
+
} {
|
|
1447
|
+
this.jsonString = true;
|
|
1448
|
+
const result = {
|
|
1449
|
+
scaled: this.scaled,
|
|
1450
|
+
raw: this.raw,
|
|
1451
|
+
min: this.min,
|
|
1452
|
+
max: this.max,
|
|
1453
|
+
};
|
|
1454
|
+
delete this.jsonString;
|
|
1455
|
+
return result;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
/**
|
|
1460
|
+
* Class representing SCORM 2004's cmi.comments_from_learner.n and cmi.comments_from_lms.n object
|
|
1461
|
+
*/
|
|
1462
|
+
|
|
1463
|
+
export class CMICommentsObject extends BaseCMI {
|
|
1464
|
+
private _comment = "";
|
|
1465
|
+
private _location = "";
|
|
1466
|
+
private _timestamp = "";
|
|
1467
|
+
private readonly _readOnlyAfterInit: boolean;
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* Constructor for cmi.comments_from_learner.n and cmi.comments_from_lms.n
|
|
1471
|
+
* @param {boolean} readOnlyAfterInit
|
|
1472
|
+
*/
|
|
1473
|
+
constructor(readOnlyAfterInit: boolean = false) {
|
|
1474
|
+
super();
|
|
1475
|
+
this._comment = "";
|
|
1476
|
+
this._location = "";
|
|
1477
|
+
this._timestamp = "";
|
|
1478
|
+
this._readOnlyAfterInit = readOnlyAfterInit;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
/**
|
|
1482
|
+
* Getter for _comment
|
|
1483
|
+
* @return {string}
|
|
1484
|
+
*/
|
|
1485
|
+
get comment(): string {
|
|
1486
|
+
return this._comment;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
/**
|
|
1490
|
+
* Setter for _comment
|
|
1491
|
+
* @param {string} comment
|
|
1492
|
+
*/
|
|
1493
|
+
set comment(comment: string) {
|
|
1494
|
+
if (this.initialized && this._readOnlyAfterInit) {
|
|
1495
|
+
throw new Scorm2004ValidationError(
|
|
1496
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
1497
|
+
);
|
|
1498
|
+
} else {
|
|
1499
|
+
if (
|
|
1500
|
+
check2004ValidFormat(comment, scorm2004_regex.CMILangString4000, true)
|
|
1501
|
+
) {
|
|
1502
|
+
this._comment = comment;
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
/**
|
|
1508
|
+
* Getter for _location
|
|
1509
|
+
* @return {string}
|
|
1510
|
+
*/
|
|
1511
|
+
get location(): string {
|
|
1512
|
+
return this._location;
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
/**
|
|
1516
|
+
* Setter for _location
|
|
1517
|
+
* @param {string} location
|
|
1518
|
+
*/
|
|
1519
|
+
set location(location: string) {
|
|
1520
|
+
if (this.initialized && this._readOnlyAfterInit) {
|
|
1521
|
+
throw new Scorm2004ValidationError(
|
|
1522
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
1523
|
+
);
|
|
1524
|
+
} else {
|
|
1525
|
+
if (check2004ValidFormat(location, scorm2004_regex.CMIString250)) {
|
|
1526
|
+
this._location = location;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
/**
|
|
1532
|
+
* Getter for _timestamp
|
|
1533
|
+
* @return {string}
|
|
1534
|
+
*/
|
|
1535
|
+
get timestamp(): string {
|
|
1536
|
+
return this._timestamp;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
/**
|
|
1540
|
+
* Setter for _timestamp
|
|
1541
|
+
* @param {string} timestamp
|
|
1542
|
+
*/
|
|
1543
|
+
set timestamp(timestamp: string) {
|
|
1544
|
+
if (this.initialized && this._readOnlyAfterInit) {
|
|
1545
|
+
throw new Scorm2004ValidationError(
|
|
1546
|
+
scorm2004_error_codes.READ_ONLY_ELEMENT,
|
|
1547
|
+
);
|
|
1548
|
+
} else {
|
|
1549
|
+
if (check2004ValidFormat(timestamp, scorm2004_regex.CMITime)) {
|
|
1550
|
+
this._timestamp = timestamp;
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* toJSON for cmi.comments_from_learner.n object
|
|
1557
|
+
* @return {
|
|
1558
|
+
* {
|
|
1559
|
+
* comment: string,
|
|
1560
|
+
* location: string,
|
|
1561
|
+
* timestamp: string
|
|
1562
|
+
* }
|
|
1563
|
+
* }
|
|
1564
|
+
*/
|
|
1565
|
+
toJSON(): {
|
|
1566
|
+
comment: string;
|
|
1567
|
+
location: string;
|
|
1568
|
+
timestamp: string;
|
|
1569
|
+
} {
|
|
1570
|
+
this.jsonString = true;
|
|
1571
|
+
const result = {
|
|
1572
|
+
comment: this.comment,
|
|
1573
|
+
location: this.location,
|
|
1574
|
+
timestamp: this.timestamp,
|
|
1575
|
+
};
|
|
1576
|
+
delete this.jsonString;
|
|
1577
|
+
return result;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
/**
|
|
1582
|
+
* Class representing SCORM 2004's cmi.interactions.n.objectives.n object
|
|
1583
|
+
*/
|
|
1584
|
+
export class CMIInteractionsObjectivesObject extends BaseCMI {
|
|
1585
|
+
private _id = "";
|
|
1586
|
+
|
|
1587
|
+
/**
|
|
1588
|
+
* Constructor for cmi.interactions.n.objectives.n
|
|
1589
|
+
*/
|
|
1590
|
+
constructor() {
|
|
1591
|
+
super();
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
/**
|
|
1595
|
+
* Getter for _id
|
|
1596
|
+
* @return {string}
|
|
1597
|
+
*/
|
|
1598
|
+
get id(): string {
|
|
1599
|
+
return this._id;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* Setter for _id
|
|
1604
|
+
* @param {string} id
|
|
1605
|
+
*/
|
|
1606
|
+
set id(id: string) {
|
|
1607
|
+
if (check2004ValidFormat(id, scorm2004_regex.CMILongIdentifier)) {
|
|
1608
|
+
this._id = id;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* toJSON for cmi.interactions.n.objectives.n
|
|
1614
|
+
* @return {
|
|
1615
|
+
* {
|
|
1616
|
+
* id: string
|
|
1617
|
+
* }
|
|
1618
|
+
* }
|
|
1619
|
+
*/
|
|
1620
|
+
toJSON(): {
|
|
1621
|
+
id: string;
|
|
1622
|
+
} {
|
|
1623
|
+
this.jsonString = true;
|
|
1624
|
+
const result = {
|
|
1625
|
+
id: this.id,
|
|
1626
|
+
};
|
|
1627
|
+
delete this.jsonString;
|
|
1628
|
+
return result;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* Class representing SCORM 2004's cmi.interactions.n.correct_responses.n object
|
|
1634
|
+
*/
|
|
1635
|
+
export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
|
|
1636
|
+
private _pattern = "";
|
|
1637
|
+
|
|
1638
|
+
/**
|
|
1639
|
+
* Constructor for cmi.interactions.n.correct_responses.n
|
|
1640
|
+
*/
|
|
1641
|
+
constructor() {
|
|
1642
|
+
super();
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
/**
|
|
1646
|
+
* Getter for _pattern
|
|
1647
|
+
* @return {string}
|
|
1648
|
+
*/
|
|
1649
|
+
get pattern(): string {
|
|
1650
|
+
return this._pattern;
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
/**
|
|
1654
|
+
* Setter for _pattern
|
|
1655
|
+
* @param {string} pattern
|
|
1656
|
+
*/
|
|
1657
|
+
set pattern(pattern: string) {
|
|
1658
|
+
if (check2004ValidFormat(pattern, scorm2004_regex.CMIFeedback)) {
|
|
1659
|
+
this._pattern = pattern;
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
/**
|
|
1664
|
+
* toJSON cmi.interactions.n.correct_responses.n object
|
|
1665
|
+
* @return {
|
|
1666
|
+
* {
|
|
1667
|
+
* pattern: string
|
|
1668
|
+
* }
|
|
1669
|
+
* }
|
|
1670
|
+
*/
|
|
1671
|
+
toJSON(): {
|
|
1672
|
+
pattern: string;
|
|
1673
|
+
} {
|
|
1674
|
+
this.jsonString = true;
|
|
1675
|
+
const result = {
|
|
1676
|
+
pattern: this.pattern,
|
|
1677
|
+
};
|
|
1678
|
+
delete this.jsonString;
|
|
1679
|
+
return result;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
/**
|
|
1684
|
+
* Class representing SCORM 2004's adl object
|
|
1685
|
+
*/
|
|
1686
|
+
export class ADL extends BaseCMI {
|
|
1687
|
+
/**
|
|
1688
|
+
* Constructor for adl
|
|
1689
|
+
*/
|
|
1690
|
+
constructor() {
|
|
1691
|
+
super();
|
|
1692
|
+
this.nav = new ADLNav();
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
public nav: ADLNav;
|
|
1696
|
+
|
|
1697
|
+
/**
|
|
1698
|
+
* Called when the API has been initialized after the CMI has been created
|
|
1699
|
+
*/
|
|
1700
|
+
initialize() {
|
|
1701
|
+
super.initialize();
|
|
1702
|
+
this.nav?.initialize();
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
/**
|
|
1706
|
+
* toJSON for adl
|
|
1707
|
+
* @return {
|
|
1708
|
+
* {
|
|
1709
|
+
* nav: ADLNav
|
|
1710
|
+
* }
|
|
1711
|
+
* }
|
|
1712
|
+
*/
|
|
1713
|
+
toJSON(): {
|
|
1714
|
+
nav: ADLNav;
|
|
1715
|
+
} {
|
|
1716
|
+
this.jsonString = true;
|
|
1717
|
+
const result = {
|
|
1718
|
+
nav: this.nav,
|
|
1719
|
+
};
|
|
1720
|
+
delete this.jsonString;
|
|
1721
|
+
return result;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
/**
|
|
1726
|
+
* Class representing SCORM 2004's `adl.nav` object
|
|
1727
|
+
*/
|
|
1728
|
+
|
|
1729
|
+
class ADLNav extends BaseCMI {
|
|
1730
|
+
private _request = "_none_";
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
* Constructor for `adl.nav`
|
|
1734
|
+
*/
|
|
1735
|
+
constructor() {
|
|
1736
|
+
super();
|
|
1737
|
+
this.request_valid = new ADLNavRequestValid();
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
public request_valid: ADLNavRequestValid;
|
|
1741
|
+
|
|
1742
|
+
/**
|
|
1743
|
+
* Called when the API has been initialized after the CMI has been created
|
|
1744
|
+
*/
|
|
1745
|
+
initialize() {
|
|
1746
|
+
super.initialize();
|
|
1747
|
+
this.request_valid?.initialize();
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
/**
|
|
1751
|
+
* Getter for _request
|
|
1752
|
+
* @return {string}
|
|
1753
|
+
*/
|
|
1754
|
+
get request(): string {
|
|
1755
|
+
return this._request;
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
/**
|
|
1759
|
+
* Setter for _request
|
|
1760
|
+
* @param {string} request
|
|
1761
|
+
*/
|
|
1762
|
+
set request(request: string) {
|
|
1763
|
+
if (check2004ValidFormat(request, scorm2004_regex.NAVEvent)) {
|
|
1764
|
+
this._request = request;
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
/**
|
|
1769
|
+
* toJSON for adl.nav
|
|
1770
|
+
*
|
|
1771
|
+
* @return {
|
|
1772
|
+
* {
|
|
1773
|
+
* request: string
|
|
1774
|
+
* }
|
|
1775
|
+
* }
|
|
1776
|
+
*/
|
|
1777
|
+
toJSON(): {
|
|
1778
|
+
request: string;
|
|
1779
|
+
} {
|
|
1780
|
+
this.jsonString = true;
|
|
1781
|
+
const result = {
|
|
1782
|
+
request: this.request,
|
|
1783
|
+
};
|
|
1784
|
+
delete this.jsonString;
|
|
1785
|
+
return result;
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
|
|
1789
|
+
/**
|
|
1790
|
+
* Class representing SCORM 2004's adl.nav.request_valid object
|
|
1791
|
+
*/
|
|
1792
|
+
|
|
1793
|
+
class ADLNavRequestValid extends BaseCMI {
|
|
1794
|
+
private _continue = "unknown";
|
|
1795
|
+
private _previous = "unknown";
|
|
1796
|
+
choice = class {
|
|
1797
|
+
/**
|
|
1798
|
+
* Check if target is valid
|
|
1799
|
+
* @param {string} _target
|
|
1800
|
+
* @return {string}
|
|
1801
|
+
*/
|
|
1802
|
+
_isTargetValid = (_target: string): string => "unknown";
|
|
1803
|
+
};
|
|
1804
|
+
jump = class {
|
|
1805
|
+
/**
|
|
1806
|
+
* Check if target is valid
|
|
1807
|
+
* @param {string} _target
|
|
1808
|
+
* @return {string}
|
|
1809
|
+
*/
|
|
1810
|
+
_isTargetValid = (_target: string): string => "unknown";
|
|
1811
|
+
};
|
|
1812
|
+
|
|
1813
|
+
/**
|
|
1814
|
+
* Constructor for adl.nav.request_valid
|
|
1815
|
+
*/
|
|
1816
|
+
constructor() {
|
|
1817
|
+
super();
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
/**
|
|
1821
|
+
* Getter for _continue
|
|
1822
|
+
* @return {string}
|
|
1823
|
+
*/
|
|
1824
|
+
get continue(): string {
|
|
1825
|
+
return this._continue;
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
/**
|
|
1829
|
+
* Setter for _continue. Just throws an error.
|
|
1830
|
+
* @param {string} _continue
|
|
1831
|
+
*/
|
|
1832
|
+
set continue(_continue: string) {
|
|
1833
|
+
throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
/**
|
|
1837
|
+
* Getter for _previous
|
|
1838
|
+
* @return {string}
|
|
1839
|
+
*/
|
|
1840
|
+
get previous(): string {
|
|
1841
|
+
return this._previous;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
/**
|
|
1845
|
+
* Setter for _previous. Just throws an error.
|
|
1846
|
+
* @param {string} _previous
|
|
1847
|
+
*/
|
|
1848
|
+
set previous(_previous: string) {
|
|
1849
|
+
throw new Scorm2004ValidationError(scorm2004_error_codes.READ_ONLY_ELEMENT);
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
/**
|
|
1853
|
+
* toJSON for adl.nav.request_valid
|
|
1854
|
+
*
|
|
1855
|
+
* @return {
|
|
1856
|
+
* {
|
|
1857
|
+
* previous: string,
|
|
1858
|
+
* continue: string
|
|
1859
|
+
* }
|
|
1860
|
+
* }
|
|
1861
|
+
*/
|
|
1862
|
+
toJSON(): {
|
|
1863
|
+
previous: string;
|
|
1864
|
+
continue: string;
|
|
1865
|
+
} {
|
|
1866
|
+
this.jsonString = true;
|
|
1867
|
+
const result = {
|
|
1868
|
+
previous: this._previous,
|
|
1869
|
+
continue: this.continue,
|
|
1870
|
+
};
|
|
1871
|
+
delete this.jsonString;
|
|
1872
|
+
return result;
|
|
1873
|
+
}
|
|
1874
|
+
}
|