-
Notifications
You must be signed in to change notification settings - Fork 21
/
presave.js
65 lines (55 loc) · 1.92 KB
/
presave.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var H5PEditor = H5PEditor || {};
var H5PPresave = H5PPresave || {};
/**
* Resolve the presave logic for the content type Multiple Image Hotspots
*
* @param {object} content
* @param finished
* @constructor
*/
H5PPresave['H5P.ImageMultipleHotspotQuestion'] = function (content, finished) {
var presave = H5PEditor.Presave;
if (isContentInValid()) {
throw {
name: 'Invalid Find Multiple Hotspots Error',
message: "Could not find expected semantics in content."
};
}
var correctHotspots = content.imageMultipleHotspotQuestion.hotspotSettings.hotspot
.filter(function (hotspot) {
return hotspot.userSettings.correct;
}).length;
var score = useFixedNumberOfHotspots() ? content.imageMultipleHotspotQuestion.hotspotSettings.numberHotspots : correctHotspots;
presave.validateScore(score);
if (finished) {
finished({maxScore: score});
}
/**
* Check if required parameters is present
* @return {boolean}
*/
function isContentInValid() {
return !presave.checkNestedRequirements(content, 'content.imageMultipleHotspotQuestion.hotspotSettings.hotspot') || !Array.isArray(content.imageMultipleHotspotQuestion.hotspotSettings.hotspot);
}
/**
* Check if content uses fixed number of hotspots
* @return {boolean}
*/
function useFixedNumberOfHotspots() {
return hasFixedNumberOfHotspots() && isFixedNumberOfHotspotsLessThanCorrectHotspots();
}
/**
* Check if content has fixed number of hotspots
* @return {boolean}
*/
function hasFixedNumberOfHotspots(){
return presave.checkNestedRequirements(content, 'content.imageMultipleHotspotQuestion.hotspotSettings.numberHotspots');
}
/**
* Check if fixed number of hotspots is less than correct number of hotspots
* @return {boolean}
*/
function isFixedNumberOfHotspotsLessThanCorrectHotspots() {
return content.imageMultipleHotspotQuestion.hotspotSettings.numberHotspots <= correctHotspots;
}
};