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