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
    return null;
129
};
130
 
131
/**
132
 * Get section wraper for this format (only used in case when each
133
 * container_node.container_class node is wrapped in some other element).
134
 *
135
 * @method M.course.format.get_section_wrapper
136
 * @param {YUI} Y YUI3 instance
137
 * @return {string} section wrapper selector or M.course.format.get_section_selector
138
 * if section_wrapper_node and section_wrapper_class are not defined in the format config.
139
 */
140
M.course.format.get_section_wrapper = M.course.format.get_section_wrapper || function(Y) {
141
    var config = M.course.format.get_config();
142
    if (config.section_wrapper_node && config.section_wrapper_class) {
143
        return config.section_wrapper_node + '.' + config.section_wrapper_class;
144
    }
145
    return M.course.format.get_section_selector(Y);
146
};
147
 
148
/**
149
 * Get the tag of container node
150
 *
151
 * @method M.course.format.get_containernode
152
 * @return {string} tag of container node.
153
 */
154
M.course.format.get_containernode = M.course.format.get_containernode || function() {
155
    var config = M.course.format.get_config();
156
    if (config.container_node) {
157
        return config.container_node;
158
    } else {
159
    }
160
};
161
 
162
/**
163
 * Get the class of container node
164
 *
165
 * @method M.course.format.get_containerclass
166
 * @return {string} class of the container node.
167
 */
168
M.course.format.get_containerclass = M.course.format.get_containerclass || function() {
169
    var config = M.course.format.get_config();
170
    if (config.container_class) {
171
        return config.container_class;
172
    } else {
173
    }
174
};
175
 
176
/**
177
 * Get the tag of draggable node (section wrapper if exists, otherwise section)
178
 *
179
 * @method M.course.format.get_sectionwrappernode
180
 * @return {string} tag of the draggable node.
181
 */
182
M.course.format.get_sectionwrappernode = M.course.format.get_sectionwrappernode || function() {
183
    var config = M.course.format.get_config();
184
    if (config.section_wrapper_node) {
185
        return config.section_wrapper_node;
186
    } else {
187
        return config.section_node;
188
    }
189
};
190
 
191
/**
192
 * Get the class of draggable node (section wrapper if exists, otherwise section)
193
 *
194
 * @method M.course.format.get_sectionwrapperclass
195
 * @return {string} class of the draggable node.
196
 */
197
M.course.format.get_sectionwrapperclass = M.course.format.get_sectionwrapperclass || function() {
198
    var config = M.course.format.get_config();
199
    if (config.section_wrapper_class) {
200
        return config.section_wrapper_class;
201
    } else {
202
        return config.section_class;
203
    }
204
};
205
 
206
/**
207
 * Get the tag of section node
208
 *
209
 * @method M.course.format.get_sectionnode
210
 * @return {string} tag of section node.
211
 */
212
M.course.format.get_sectionnode = M.course.format.get_sectionnode || function() {
213
    var config = M.course.format.get_config();
214
    if (config.section_node) {
215
        return config.section_node;
216
    } else {
217
    }
218
};
219
 
220
/**
221
 * Get the class of section node
222
 *
223
 * @method M.course.format.get_sectionclass
224
 * @return {string} class of the section node.
225
 */
226
M.course.format.get_sectionclass = M.course.format.get_sectionclass || function() {
227
    var config = M.course.format.get_config();
228
    if (config.section_class) {
229
        return config.section_class;
230
    } else {
231
    }
232
};
233
 
234
 
235
}, '@VERSION@', {"requires": ["base", "node"]});