MDL-65948 core_grade: Use new core/checkbox-toggleall
[moodle.git] / grade / amd / src / edittree_index.js
CommitLineData
b5233f9b
AN
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/**
6b43e964 17 * Enhance the gradebook tree setup with various facilities.
b5233f9b 18 *
6b43e964
EL
19 * @module core_grades/edittree_index
20 * @package core_grades
b5233f9b
AN
21 * @copyright 2016 Andrew Nicols <andrew@nicols.co.uk>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24define([
25 'jquery',
26], function($) {
27 /**
28 * Enhance the edittree functionality.
29 *
30 * @method edittree
31 */
32 var edittree = function() {
b5233f9b
AN
33 // Watch for the weight override checkboxes.
34 $('body').on('change', '.weightoverride', edittree.toggleWeightInput);
35
36 // Watch changes to the bulk move menu and submit.
37 $('#menumoveafter').on('change', function() {
38 var form = $(this).closest('form'),
39 bulkmove = form.find('#bulkmoveinput');
40
41 bulkmove.val(1);
42 form.submit();
43 });
b5233f9b
AN
44 };
45
46 /**
47 * Toggle the weight input field based on its checkbox.
48 *
49 * @method toggleWeightInput
50 * @param {EventFacade} e
51 * @private
52 */
53 edittree.toggleWeightInput = function(e) {
54 e.preventDefault();
55 var node = $(this),
56 row = node.closest('tr');
57
58 $('input[name="weight_' + row.data('itemid') + '"]').prop('disabled', !node.prop('checked'));
59 };
60
6b43e964 61 return /** @alias module:core_grades/edittree_index */ {
b5233f9b
AN
62 enhance: edittree
63 };
64});