Proyectos de Subversion Moodle

Rev

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