Merge branch 'MDL-35134_master' of git://github.com/pauln/moodle
[moodle.git] / course / format / weeks / format.js
CommitLineData
9f3015ec 1// Javascript functions for Weeks course format
c77582fe
RK
2
3M.course = M.course || {};
4
5M.course.format = M.course.format || {};
6
7/**
405eaac2 8 * Get sections config for this format
c77582fe 9 *
405eaac2
RK
10 * The section structure is:
11 * <ul class="weeks">
12 * <li class="section">...</li>
13 * <li class="section">...</li>
14 * ...
15 * </ul>
16 *
17 * @return {object} section list configuration
c77582fe 18 */
405eaac2
RK
19M.course.format.get_config = function() {
20 return {
21 container_node : 'ul',
22 container_class : 'weeks',
23 section_node : 'li',
24 section_class : 'section'
25 };
c77582fe
RK
26}
27
28/**
29 * Swap section
30 *
31 * @param {YUI} Y YUI3 instance
32 * @param {string} node1 node to swap to
33 * @param {string} node2 node to swap with
34 * @return {NodeList} section list
35 */
36M.course.format.swap_sections = function(Y, node1, node2) {
37 var CSS = {
38 COURSECONTENT : 'course-content',
f32cdf71 39 SECTIONADDMENUS : 'section_add_menus'
c77582fe
RK
40 };
41
42 var sectionlist = Y.Node.all('.'+CSS.COURSECONTENT+' '+M.course.format.get_section_selector(Y));
c77582fe
RK
43 // Swap menus
44 sectionlist.item(node1).one('.'+CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.'+CSS.SECTIONADDMENUS));
9f3015ec
RK
45}
46
47/**
48 * Process sections after ajax response
49 *
50 * @param {YUI} Y YUI3 instance
51 * @param {array} response ajax response
52 * @param {string} sectionfrom first affected section
53 * @param {string} sectionto last affected section
54 * @return void
55 */
56M.course.format.process_sections = function(Y, sectionlist, response, sectionfrom, sectionto) {
57 var CSS = {
58 SECTIONNAME : 'sectionname'
59 };
60
61 if (response.action == 'move') {
62 // update titles in all affected sections
63 for (var i = sectionfrom; i <= sectionto; i++) {
64 sectionlist.item(i).one('.'+CSS.SECTIONNAME).setContent(response.sectiontitles[i]);
65 }
66 }
c77582fe 67}