1 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 * Enhance the gradebook tree setup with various facilities.
19 * @module core_grades/edittree_index
20 * @package core_grades
21 * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * Enhance the edittree functionality.
32 var edittree = function() {
33 // Watch items and toggle the move menu accordingly.
34 $('body').on('change', '.itemselect.ignoredirty', edittree.checkMoveMenuState);
36 // Watch for the 'All' and 'None' links.
37 $('body').on('click', '[data-action="grade_edittree-index-bulkselect"]', edittree.toggleAllSelectItems);
39 // Watch for the weight override checkboxes.
40 $('body').on('change', '.weightoverride', edittree.toggleWeightInput);
42 // Watch changes to the bulk move menu and submit.
43 $('#menumoveafter').on('change', function() {
44 var form = $(this).closest('form'),
45 bulkmove = form.find('#bulkmoveinput');
51 // CHeck the initial state of the move menu.
52 edittree.checkMoveMenuState();
56 * Toggle the weight input field based on its checkbox.
58 * @method toggleWeightInput
59 * @param {EventFacade} e
62 edittree.toggleWeightInput = function(e) {
65 row = node.closest('tr');
67 $('input[name="weight_' + row.data('itemid') + '"]').prop('disabled', !node.prop('checked'));
71 * Toggle all select boxes on or off.
73 * @method toggleAllSelectItems
74 * @param {EventFacade} e
77 edittree.toggleAllSelectItems = function(e) {
81 row = node.closest('tr');
82 $('.' + row.data('category') + ' .itemselect').prop('checked', node.data('checked'));
84 edittree.checkMoveMenuState();
94 edittree.getMoveMenu = function() {
95 return $('#menumoveafter');
99 * Check whether any checkboxes are ticked.
101 * @method checkMoveMenuState
105 edittree.checkMoveMenuState = function() {
106 var menu = edittree.getMoveMenu();
112 $('.itemselect').each(function() {
113 selected = $(this).prop('checked');
115 // Return early if any are checked.
119 menu.prop('disabled', !selected);
124 return /** @alias module:core_grades/edittree_index */ {