-
Notifications
You must be signed in to change notification settings - Fork 0
/
presave.js
44 lines (39 loc) · 1.15 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
var H5PPresave = H5PPresave || {};
/**
* Resolve the presave logic for the content type Column
*
* @param {object} content
* @param finished
* @constructor
*/
H5PPresave['H5P.Column'] = function (content, finished) {
var presave = H5PEditor.Presave;
if (isContentInvalid()) {
throw new presave.exceptions.InvalidContentSemanticsException('Invalid Column Error');
}
var score = content.content
.map(function (content) {
return content.content;
})
.filter(function (action) {
return action.hasOwnProperty('library') && action.hasOwnProperty('params');
})
.map(function (action) {
return (new presave).process(action.library, action.params).maxScore;
})
.reduce(function (currentScore, scoreToAdd) {
if (presave.isInt(scoreToAdd)) {
currentScore += scoreToAdd;
}
return currentScore;
}, 0);
presave.validateScore(score);
finished({maxScore: score});
/**
* Check if required parameters is present
* @return {boolean}
*/
function isContentInvalid() {
return !presave.checkNestedRequirements(content, 'content.content') || !Array.isArray(content.content);
}
};