MDL-58138 completion: conditional state buttons and css fixes
[moodle.git] / course / templates / bulkactivitycompletion.mustache
CommitLineData
0b620801
AG
1{{!
2 This file is part of Moodle - http://moodle.org/
3
4 Moodle is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 Moodle is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16}}
17{{!
18 @template core_course/bulkactivitycompletion
19
20 Activity completion selector.
21
22 Example context (json):
23 {
24 "courseid": "2",
25 "sesskey": "AAAAAA",
26 "sections": [{
27 "sectionnumber": "0",
28 "name": "General",
29 "activities": [{
30 "cmid": "4",
31 "modname": "Test activity",
7f53e8aa 32 "icon": "https://raw.githubusercontent.com/moodle/moodle/master/mod/feedback/pix/icon.png",
0b620801
AG
33 "completionstatus": {
34 "string": "Manual",
7f53e8aa 35 "icon": "https://raw.githubusercontent.com/moodle/moodle/master/pix/i/completion-manual-enabled.png"
0b620801
AG
36 }
37 }]
38 }]
39 }
40}}
41<div class="container-fluid">
42 <div class="row m-b-2">
43 <div class="col">{{#str}}bulkactivitydetail, moodle{{/str}}</div>
44 </div>
06cdda46 45<form method="post" action="editbulkcompletion.php" class="mform" id="theform">
0b620801
AG
46 <div class="row m-b-2">
47 <div class="col">
59d9c851 48 <input type="submit" value="{{#str}}edit{{/str}}" class="btn btn-primary" name="submitbutton" aria-label="{{#str}}updateactivities, completion{{/str}}" disabled/>
0b620801
AG
49 </div>
50 </div>
51 <div class="top-section row m-b-1">
52 <div class="col-sm-6 span6">
53 <input type="checkbox" class="mastercheck m-r-1" aria-label="{{#str}}checkall, completion{{/str}}">
54 <label class="font-weight-bold">{{#str}}activitieslabel, moodle{{/str}}</label>
55 </div>
56 <div class="col-sm-6">
57 <label class="font-weight-bold">{{#str}}completiontracking, moodle{{/str}}</label>
58 <span>{{{helpicon}}}</span>
59 </div>
60 </div>
61 <div class="topics">
0b620801 62 {{#sections}}
0b620801
AG
63 <div class="topic-section m-b-1">
64 <div class="row m-b-1">
65 <div class="col-sm-12">
66 <input type="checkbox" data-section-master="{{sectionnumber}}" class="m-r-1" aria-label="{{#str}}checkallsection, completion, {{name}}{{/str}}">
67 <h3>{{name}}</h3>
68 </div>
69 </div>
70 {{> core_course/activityinstance}}
71 </div>
0b620801 72 {{/sections}}
0b620801
AG
73 </div>
74 <input type="hidden" name="id" value="{{courseid}}" />
75 <input type="hidden" name="sesskey" value="{{sesskey}}" />
76 <div class="row">
77 <div class="col">
59d9c851 78 <input type="submit" value="{{#str}}edit{{/str}}" class="btn btn-primary" name="submitbutton" disabled/>
0b620801
AG
79 </div>
80 </div>
81</form>
82</div>
83
84{{#js}}
85require([
86 'jquery',
87], function($) {
88 $('.mastercheck').click(function() {
89 var checked = $('.mastercheck').is(':checked');
90 $('input[type=checkbox]').each(function() {
91 $(this).prop('checked', checked);
59d9c851 92 $(this).trigger('change'); // Hmmm. Could be smarter about this and only trigger once for the first checkbox.
0b620801
AG
93 });
94 });
95 var mastersection = $('input[data-section-master]');
96 mastersection.click(function() {
97 var checked = $(this).is(':checked');
98 var dataid = $(this).attr('data-section-master');
99 $('input[type=checkbox][data-section=\'' + dataid + '\']').each(function() {
100 $(this).prop('checked', checked);
59d9c851 101 $(this).trigger('change'); // Hmmm. Could be smarter about this and only trigger once for the first checkbox.
0b620801
AG
102 });
103 });
59d9c851
JD
104
105 $('input[type=checkbox][id^=selectactivity_]').change(function() {
106 if ($(this).is(':checked')) {
107 $('[name=submitbutton]').removeAttr('disabled');
108 } else {
109 // Is this the last activity checkbox to be un-checked? If so, disable the edit button.
110 var somechecked = false;
111 $('input[type=checkbox][id^=selectactivity_]').each(function() {
112 if ($(this).is(':checked')) {
113 somechecked = true;
114 return false;
115 }
116 return true;
117 });
118 if (!somechecked) {
119 $('[name=submitbutton]').attr('disabled', 'disabled');
120 }
121 }
122 });
0b620801
AG
123});
124{{/js}}