mirrored from git://git.moodle.org/moodle.git
/
coursebase.js
224 lines (203 loc) · 7.26 KB
/
coursebase.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
YUI.add('moodle-course-coursebase', function(Y) {
/**
* The coursebase class
*/
var COURSEBASENAME = 'course-coursebase';
var COURSEBASE = function() {
COURSEBASE.superclass.constructor.apply(this, arguments);
}
Y.extend(COURSEBASE, Y.Base, {
// Registered Modules
registermodules : [],
/**
* Initialize the coursebase module
*/
initializer : function(config) {
// We don't actually perform any work here
},
/**
* Register a new Javascript Module
*
* @param object The instantiated module to call functions on
*/
register_module : function(object) {
this.registermodules.push(object);
},
/**
* Invoke the specified function in all registered modules with the given arguments
*
* @param functionname The name of the function to call
* @param args The argument supplied to the function
*/
invoke_function : function(functionname, args) {
for (module in this.registermodules) {
if (functionname in this.registermodules[module]) {
this.registermodules[module][functionname](args);
}
}
}
},
{
NAME : COURSEBASENAME,
ATTRS : {}
}
);
// Ensure that M.course exists and that coursebase is initialised correctly
M.course = M.course || {};
M.course.coursebase = M.course.coursebase || new COURSEBASE();
// Abstract functions that needs to be defined per format (course/format/somename/format.js)
M.course.format = M.course.format || {}
/**
* Swap section (should be defined in format.js if requred)
*
* @param {YUI} Y YUI3 instance
* @param {string} node1 node to swap to
* @param {string} node2 node to swap with
* @return {NodeList} section list
*/
M.course.format.swap_sections = M.course.format.swap_sections || function(Y, node1, node2) {
return null;
}
/**
* Process sections after ajax response (should be defined in format.js)
* If some response is expected, we pass it over to format, as it knows better
* hot to process it.
*
* @param {YUI} Y YUI3 instance
* @param {NodeList} list of sections
* @param {array} response ajax response
* @param {string} sectionfrom first affected section
* @param {string} sectionto last affected section
* @return void
*/
M.course.format.process_sections = M.course.format.process_sections || function(Y, sectionlist, response, sectionfrom, sectionto) {
return null;
}
/**
* Get sections config for this format, for examples see function definition
* in the formats.
*
* @return {object} section list configuration
*/
M.course.format.get_config = M.course.format.get_config || function() {
return {
container_node : null, // compulsory
container_class : null, // compulsory
section_wrapper_node : null, // optional
section_wrapper_class : null, // optional
section_node : null, // compulsory
section_class : null // compulsory
}
}
/**
* Get section list for this format (usually items inside container_node.container_class selector)
*
* @param {YUI} Y YUI3 instance
* @return {string} section selector
*/
M.course.format.get_section_selector = M.course.format.get_section_selector || function(Y) {
var config = M.course.format.get_config();
if (config.section_node && config.section_class) {
return config.section_node + '.' + config.section_class;
}
console.log('section_node and section_class are not defined in M.course.format.get_config');
return null;
}
/**
* Get section wraper for this format (only used in case when each
* container_node.container_class node is wrapped in some other element).
*
* @param {YUI} Y YUI3 instance
* @return {string} section wrapper selector or M.course.format.get_section_selector
* if section_wrapper_node and section_wrapper_class are not defined in the format config.
*/
M.course.format.get_section_wrapper = M.course.format.get_section_wrapper || function(Y) {
var config = M.course.format.get_config();
if (config.section_wrapper_node && config.section_wrapper_class) {
return config.section_wrapper_node + '.' + config.section_wrapper_class;
}
return M.course.format.get_section_selector(Y);
}
/**
* Get the tag of container node
*
* @return {string} tag of container node.
*/
M.course.format.get_containernode = M.course.format.get_containernode || function() {
var config = M.course.format.get_config();
if (config.container_node) {
return config.container_node;
} else {
console.log('container_node is not defined in M.course.format.get_config');
}
}
/**
* Get the class of container node
*
* @return {string} class of the container node.
*/
M.course.format.get_containerclass = M.course.format.get_containerclass || function() {
var config = M.course.format.get_config();
if (config.container_class) {
return config.container_class;
} else {
console.log('container_class is not defined in M.course.format.get_config');
}
}
/**
* Get the tag of draggable node (section wrapper if exists, otherwise section)
*
* @return {string} tag of the draggable node.
*/
M.course.format.get_sectionwrappernode = M.course.format.get_sectionwrappernode || function() {
var config = M.course.format.get_config();
if (config.section_wrapper_node) {
return config.section_wrapper_node;
} else {
return config.section_node;
}
}
/**
* Get the class of draggable node (section wrapper if exists, otherwise section)
*
* @return {string} class of the draggable node.
*/
M.course.format.get_sectionwrapperclass = M.course.format.get_sectionwrapperclass || function() {
var config = M.course.format.get_config();
if (config.section_wrapper_class) {
return config.section_wrapper_class;
} else {
return config.section_class;
}
}
/**
* Get the tag of section node
*
* @return {string} tag of section node.
*/
M.course.format.get_sectionnode = M.course.format.get_sectionnode || function() {
var config = M.course.format.get_config();
if (config.section_node) {
return config.section_node;
} else {
console.log('section_node is not defined in M.course.format.get_config');
}
}
/**
* Get the class of section node
*
* @return {string} class of the section node.
*/
M.course.format.get_sectionclass = M.course.format.get_sectionclass || function() {
var config = M.course.format.get_config();
if (config.section_class) {
return config.section_class;
} else {
console.log('section_class is not defined in M.course.format.get_config');
}
}
},
'@VERSION@', {
requires : ['base', 'node']
}
);