-
Notifications
You must be signed in to change notification settings - Fork 26
/
goal-instance.js
114 lines (100 loc) · 3.06 KB
/
goal-instance.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var H5P = H5P || {};
H5P.GoalsPage = H5P.GoalsPage || {};
/**
* Goal Instance module
*/
H5P.GoalsPage.GoalInstance = (function () {
/**
* Initialize module.
* @param {String} defineGoalPlaceholder Placeholder for Goal Instance
* @param {Number} uniqueId Unique identifier for Goal Instance.
* @param {String} goalTypeDescription String describing the goal type, that will be displayed in its' footer
* @returns {Object} GoalInstance GoalInstance instance
*/
function GoalInstance(defineGoalPlaceholder, uniqueId, goalTypeDescription, goalText) {
this.uniqueId = uniqueId;
this.answer = -1;
this.textualAnswer = '';
this.text = goalText;
this.placeholder = defineGoalPlaceholder;
this.goalTypeDescription = goalTypeDescription;
}
/**
* Get goal type description
* @returns {String} String representation of the goal type
*/
GoalInstance.prototype.getGoalTypeDescription = function () {
return this.goalTypeDescription;
};
/**
* Get goal id
* @returns {Number} uniqueId A unique identifier for the goal
*/
GoalInstance.prototype.getUniqueId = function () {
return this.uniqueId;
};
/**
* Set or get goal answer/assessment depending on provided parameter
* @param {Number} answer If defined the goal will be set to this value.
* @returns {*} Returns answer with no parameters, and return this when setting parameter for chaining
*/
GoalInstance.prototype.goalAnswer = function (answer) {
// Get answer value if no arguments
if (answer === undefined) {
return this.answer;
}
// Set answer value
this.answer = answer;
return this;
};
/**
* Get or set goal text depending on provided parameter
* @param {String} text If defined this will be the new goal text for the goal
* @returns {*} Returns text with no parameters, and return this when setting parameter for chaining
*/
GoalInstance.prototype.goalText = function (text) {
// Get text value if no arguments
if (text === undefined) {
return this.text;
}
// Set text value
this.text = text;
return this;
};
/**
* Get goal placeholder
* @returns {*} Returns placeholder
*/
GoalInstance.prototype.getGoalPlaceholder = function () {
return this.placeholder;
};
/**
* Set textual answer in goal instance
* @param {String} textualAnswer Textual answer
*/
GoalInstance.prototype.setTextualAnswer = function (textualAnswer) {
this.textualAnswer = textualAnswer;
};
/**
* Get textual answer from goal instance
* @returns {string} textualAnswer Textual answer
*/
GoalInstance.prototype.getTextualAnswer = function () {
return this.textualAnswer;
};
/**
* Answer call to return the current state.
*
* @return {object} Current state.
*/
GoalInstance.prototype.getCurrentState = function () {
return {
answer: this.answer,
textualAnswer: this.getTextualAnswer(),
text: this.text,
placeholder: this.placeholder,
goalTypeDescription: this.goalTypeDescription
};
};
return GoalInstance;
}());