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