11 |
efrain |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* format_buttons_renderer
|
|
|
18 |
*
|
|
|
19 |
* @package format_buttons
|
|
|
20 |
* @author Rodrigo Brandão <https://www.linkedin.com/in/brandaorodrigo>
|
|
|
21 |
* @copyright 2020 Rodrigo Brandão <rodrigo.brandao.contato@gmail.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
M.course = M.course || {};
|
|
|
26 |
|
|
|
27 |
M.course.format = M.course.format || {};
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Get sections config for this format
|
|
|
31 |
*
|
|
|
32 |
* The section structure is:
|
|
|
33 |
* <ul class="buttons">
|
|
|
34 |
* <li class="section">...</li>
|
|
|
35 |
* <li class="section">...</li>
|
|
|
36 |
* ...
|
|
|
37 |
* </ul>
|
|
|
38 |
*
|
|
|
39 |
* @return {object} section list configuration
|
|
|
40 |
*/
|
|
|
41 |
M.course.format.get_config = function() {
|
|
|
42 |
return {
|
|
|
43 |
container_node: 'ul',
|
|
|
44 |
container_class: 'buttons',
|
|
|
45 |
section_node: 'li',
|
|
|
46 |
section_class: 'section'
|
|
|
47 |
};
|
|
|
48 |
};
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Swap section
|
|
|
52 |
*
|
|
|
53 |
* @param {YUI} Y YUI3 instance
|
|
|
54 |
* @param {string} node1 node to swap to
|
|
|
55 |
* @param {string} node2 node to swap with
|
|
|
56 |
* @return {NodeList} section list
|
|
|
57 |
*/
|
|
|
58 |
M.course.format.swap_sections = function(Y, node1, node2) {
|
|
|
59 |
var CSS = {
|
|
|
60 |
COURSECONTENT: 'course-content',
|
|
|
61 |
SECTIONADDMENUS: 'section_add_menus'
|
|
|
62 |
};
|
|
|
63 |
|
|
|
64 |
var sectionlist = Y.Node.all('.' + CSS.COURSECONTENT + ' ' + M.course.format.get_section_selector(Y));
|
|
|
65 |
// Swap menus.
|
|
|
66 |
sectionlist.item(node1).one('.' + CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.' + CSS.SECTIONADDMENUS));
|
|
|
67 |
};
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Process sections after ajax response
|
|
|
71 |
*
|
|
|
72 |
* @param {YUI} Y YUI3 instance
|
|
|
73 |
* @param {array} response ajax response
|
|
|
74 |
* @param {string} sectionfrom first affected section
|
|
|
75 |
* @param {string} sectionto last affected section
|
|
|
76 |
* @return void
|
|
|
77 |
*/
|
|
|
78 |
M.course.format.process_sections = function(Y, sectionlist, response, sectionfrom, sectionto) {
|
|
|
79 |
var CSS = {
|
|
|
80 |
SECTIONNAME: 'sectionname'
|
|
|
81 |
},
|
|
|
82 |
SELECTORS = {
|
|
|
83 |
SECTIONLEFTSIDE: '.left .section-handle .icon'
|
|
|
84 |
};
|
|
|
85 |
|
|
|
86 |
if (response.action == 'move') {
|
|
|
87 |
// If moving up swap around 'sectionfrom' and 'sectionto' so the that loop operates.
|
|
|
88 |
if (sectionfrom > sectionto) {
|
|
|
89 |
var temp = sectionto;
|
|
|
90 |
sectionto = sectionfrom;
|
|
|
91 |
sectionfrom = temp;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
// Update titles and move icons in all affected sections.
|
|
|
95 |
var ele, str, stridx, newstr;
|
|
|
96 |
|
|
|
97 |
for (var i = sectionfrom; i <= sectionto; i++) {
|
|
|
98 |
// Update section title.
|
|
|
99 |
var content = Y.Node.create('<span>' + response.sectiontitles[i] + '</span>');
|
|
|
100 |
sectionlist.item(i).all('.' + CSS.SECTIONNAME).setHTML(content);
|
|
|
101 |
// Update move icon.
|
|
|
102 |
ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE);
|
|
|
103 |
str = ele.getAttribute('alt');
|
|
|
104 |
stridx = str.lastIndexOf(' ');
|
|
|
105 |
newstr = str.substr(0, stridx + 1) + i;
|
|
|
106 |
ele.setAttribute('alt', newstr);
|
|
|
107 |
ele.setAttribute('title', newstr); // For FireFox as 'alt' is not refreshed.
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
};
|