Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('moodle-course-coursebase', function (Y, NAME) {
2
 
3
/**
4
 * The coursebase class to provide shared functionality to Modules within
5
 * Moodle.
6
 *
7
 * @module moodle-course-coursebase
8
 */
9
var COURSEBASENAME = 'course-coursebase';
10
 
11
var COURSEBASE = function() {
12
    COURSEBASE.superclass.constructor.apply(this, arguments);
13
};
14
 
15
/**
16
 * The coursebase class to provide shared functionality to Modules within
17
 * Moodle.
18
 *
19
 * @class M.course.coursebase
20
 * @constructor
21
 */
22
Y.extend(COURSEBASE, Y.Base, {
23
    // Registered Modules
24
    registermodules: [],
25
 
26
    /**
27
     * Register a new Javascript Module
28
     *
29
     * @method register_module
30
     * @param {Object} The instantiated module to call functions on
31
     * @chainable
32
     */
33
    register_module: function(object) {
34
        this.registermodules.push(object);
35
 
36
        return this;
37
    },
38
 
39
    /**
40
     * Invoke the specified function in all registered modules with the given arguments
41
     *
42
     * @method invoke_function
43
     * @param {String} functionname The name of the function to call
44
     * @param {mixed} args The argument supplied to the function
45
     * @chainable
46
     */
47
    invoke_function: function(functionname, args) {
48
        var module;
49
        for (module in this.registermodules) {
50
            if (functionname in this.registermodules[module]) {
51
                this.registermodules[module][functionname](args);
52
            }
53
        }
54
 
55
        return this;
56
    }
57
}, {
58
    NAME: COURSEBASENAME,
59
    ATTRS: {}
60
});
61
 
62
// Ensure that M.course exists and that coursebase is initialised correctly
63
M.course = M.course || {};
64
M.course.coursebase = M.course.coursebase || new COURSEBASE();
65
 
66
// Abstract functions that needs to be defined per format (course/format/somename/format.js)
67
M.course.format = M.course.format || {};
68
 
69
/**
70
 * Swap section (should be defined in format.js if requred)
71
 *
72
 * @method M.course.format.swap_sections
73
 * @param {YUI} Y YUI3 instance
74
 * @param {string} node1 node to swap to
75
 * @param {string} node2 node to swap with
76
 * @return {NodeList} section list
77
 */
78
M.course.format.swap_sections = M.course.format.swap_sections || function() {
79
    return null;
80
};
81
 
82
/**
83
 * Process sections after ajax response (should be defined in format.js)
84
 * If some response is expected, we pass it over to format, as it knows better
85
 * hot to process it.
86
 *
87
 * @method M.course.format.process_sections
88
 * @param {YUI} Y YUI3 instance
89
 * @param {NodeList} list of sections
90
 * @param {array} response ajax response
91
 * @param {string} sectionfrom first affected section
92
 * @param {string} sectionto last affected section
93
 */
94
M.course.format.process_sections = M.course.format.process_sections || function() {
95
    return null;
96
};
97
 
98
/**
99
* Get sections config for this format, for examples see function definition
100
* in the formats.
101
*
102
* @method M.course.format.get_config
103
* @return {object} section list configuration
104
*/
105
M.course.format.get_config = M.course.format.get_config || function() {
106
    return {
107
        container_node: null, // compulsory
108
        container_class: null, // compulsory
109
        section_wrapper_node: null, // optional
110
        section_wrapper_class: null, // optional
111
        section_node: null,  // compulsory
112
        section_class: null  // compulsory
113
    };
114
};
115
 
116
/**
117
 * Get section list for this format (usually items inside container_node.container_class selector)
118
 *
119
 * @method M.course.format.get_section_selector
120
 * @param {YUI} Y YUI3 instance
121
 * @return {string} section selector
122
 */
123
M.course.format.get_section_selector = M.course.format.get_section_selector || function() {
124
    var config = M.course.format.get_config();
125
    if (config.section_node && config.section_class) {
126
        return config.section_node + '.' + config.section_class;
127
    }
128
    Y.log('section_node and section_class are not defined in M.course.format.get_config', 'warn', 'moodle-course-coursebase');
129
    return null;
130
};
131
 
132
/**
133
 * Get section wraper for this format (only used in case when each
134
 * container_node.container_class node is wrapped in some other element).
135
 *
136
 * @method M.course.format.get_section_wrapper
137
 * @param {YUI} Y YUI3 instance
138
 * @return {string} section wrapper selector or M.course.format.get_section_selector
139
 * if section_wrapper_node and section_wrapper_class are not defined in the format config.
140
 */
141
M.course.format.get_section_wrapper = M.course.format.get_section_wrapper || function(Y) {
142
    var config = M.course.format.get_config();
143
    if (config.section_wrapper_node && config.section_wrapper_class) {
144
        return config.section_wrapper_node + '.' + config.section_wrapper_class;
145
    }
146
    return M.course.format.get_section_selector(Y);
147
};
148
 
149
/**
150
 * Get the tag of container node
151
 *
152
 * @method M.course.format.get_containernode
153
 * @return {string} tag of container node.
154
 */
155
M.course.format.get_containernode = M.course.format.get_containernode || function() {
156
    var config = M.course.format.get_config();
157
    if (config.container_node) {
158
        return config.container_node;
159
    } else {
160
        Y.log('container_node is not defined in M.course.format.get_config', 'warn', 'moodle-course-coursebase');
161
    }
162
};
163
 
164
/**
165
 * Get the class of container node
166
 *
167
 * @method M.course.format.get_containerclass
168
 * @return {string} class of the container node.
169
 */
170
M.course.format.get_containerclass = M.course.format.get_containerclass || function() {
171
    var config = M.course.format.get_config();
172
    if (config.container_class) {
173
        return config.container_class;
174
    } else {
175
        Y.log('container_class is not defined in M.course.format.get_config', 'warn', 'moodle-course-coursebase');
176
    }
177
};
178
 
179
/**
180
 * Get the tag of draggable node (section wrapper if exists, otherwise section)
181
 *
182
 * @method M.course.format.get_sectionwrappernode
183
 * @return {string} tag of the draggable node.
184
 */
185
M.course.format.get_sectionwrappernode = M.course.format.get_sectionwrappernode || function() {
186
    var config = M.course.format.get_config();
187
    if (config.section_wrapper_node) {
188
        return config.section_wrapper_node;
189
    } else {
190
        return config.section_node;
191
    }
192
};
193
 
194
/**
195
 * Get the class of draggable node (section wrapper if exists, otherwise section)
196
 *
197
 * @method M.course.format.get_sectionwrapperclass
198
 * @return {string} class of the draggable node.
199
 */
200
M.course.format.get_sectionwrapperclass = M.course.format.get_sectionwrapperclass || function() {
201
    var config = M.course.format.get_config();
202
    if (config.section_wrapper_class) {
203
        return config.section_wrapper_class;
204
    } else {
205
        return config.section_class;
206
    }
207
};
208
 
209
/**
210
 * Get the tag of section node
211
 *
212
 * @method M.course.format.get_sectionnode
213
 * @return {string} tag of section node.
214
 */
215
M.course.format.get_sectionnode = M.course.format.get_sectionnode || function() {
216
    var config = M.course.format.get_config();
217
    if (config.section_node) {
218
        return config.section_node;
219
    } else {
220
        Y.log('section_node is not defined in M.course.format.get_config', 'warn', 'moodle-course-coursebase');
221
    }
222
};
223
 
224
/**
225
 * Get the class of section node
226
 *
227
 * @method M.course.format.get_sectionclass
228
 * @return {string} class of the section node.
229
 */
230
M.course.format.get_sectionclass = M.course.format.get_sectionclass || function() {
231
    var config = M.course.format.get_config();
232
    if (config.section_class) {
233
        return config.section_class;
234
    } else {
235
        Y.log('section_class is not defined in M.course.format.get_config', 'warn', 'moodle-course-coursebase');
236
    }
237
};
238
 
239
 
240
}, '@VERSION@', {"requires": ["base", "node"]});