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-util-cm', function (Y, NAME) {
2
 
3
/**
4
 * A collection of utility classes for use with course modules.
5
 *
1441 ariadna 6
 * TODO: remove this module as part of MDL-83627.
7
 *
1 efrain 8
 * @module moodle-course-util
9
 * @submodule moodle-course-util-cm
10
 */
11
 
12
Y.namespace('Moodle.core_course.util.cm');
13
 
1441 ariadna 14
 
1 efrain 15
/**
16
 * A collection of utility classes for use with course modules.
17
 *
18
 * @class Moodle.core_course.util.cm
19
 * @static
20
 */
21
Y.Moodle.core_course.util.cm = {
22
    CONSTANTS: {
23
        MODULEIDPREFIX: 'module-'
24
    },
25
    SELECTORS: {
26
        COURSEMODULE: '.activity',
27
        INSTANCENAME: '.instancename'
28
    },
29
 
30
    /**
31
     * Retrieve the course module item from one of it's child Nodes.
32
     *
33
     * @method getCourseModuleNodeFromComponent
34
     * @param coursemodulecomponent {Node} The component Node.
35
     * @return {Node|null} The Course Module Node.
36
     */
37
    getCourseModuleFromComponent: function(coursemodulecomponent) {
38
        return Y.one(coursemodulecomponent).ancestor(this.SELECTORS.COURSEMODULE, true);
39
    },
40
 
41
    /**
42
     * Determines the section ID for the provided section.
43
     *
44
     * @method getId
45
     * @param coursemodule {Node} The course module to find an ID for.
46
     * @return {Number|false} The ID of the course module in question or false if no ID was found.
47
     */
48
    getId: function(coursemodule) {
49
        // We perform a simple substitution operation to get the ID.
50
        var id = coursemodule.get('id').replace(
51
                this.CONSTANTS.MODULEIDPREFIX, '');
52
 
53
        // Attempt to validate the ID.
54
        id = parseInt(id, 10);
55
        if (typeof id === 'number' && isFinite(id)) {
56
            return id;
57
        }
58
        return false;
59
    },
60
 
61
    /**
62
     * Determines the section ID for the provided section.
63
     *
64
     * @method getName
65
     * @param coursemodule {Node} The course module to find an ID for.
66
     * @return {Number|false} The ID of the course module in question or false if no ID was found.
67
     */
68
    getName: function(coursemodule) {
69
        var instance = coursemodule.one(this.SELECTORS.INSTANCENAME);
70
        if (instance) {
71
            return instance.get('firstChild').get('data');
72
        }
73
        return null;
74
    }
75
};
76
 
77
 
78
}, '@VERSION@', {"requires": ["node", "moodle-course-util-base"]});