Merge branch 'MDL-62144-master' of git://github.com/damyon/moodle
[moodle.git] / course / templates / bulkactivitycompletion.mustache
blobe40bca8541da908c7f825fee4ccd6b31bc5cd06a
1 {{!
2     This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 {{!
18     @template core_course/bulkactivitycompletion
20     Activity completion selector.
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",
32                 "icon": "https://raw.githubusercontent.com/moodle/moodle/master/mod/feedback/pix/icon.png",
33                 "completionstatus": {
34                     "string": "Manual",
35                     "icon": "https://raw.githubusercontent.com/moodle/moodle/master/pix/i/completion-manual-enabled.png"
36                 }
37             }]
38         }]
39     }
41 <div class="container-fluid">
42     <div class="row m-b-2">
43         <div class="col">{{#str}}bulkactivitydetail, core_completion{{/str}}</div>
44     </div>
45 <form method="post" action="editbulkcompletion.php" class="mform" id="theform">
46     <div class="row m-b-2">
47         <div class="col">
48             <input type="submit" value="{{#str}}edit{{/str}}" class="btn btn-primary" name="submitbutton" aria-label="{{#str}}updateactivities, completion{{/str}}" disabled/>
49         </div>
50     </div>
51     <div class="row m-b-1">
52         <div class="col-xs-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, core_completion{{/str}}</label>
55         </div>
56         <div class="col-xs-6 span6">
57             <label class="font-weight-bold">{{#str}}completion, core_completion{{/str}}</label>
58             <span>{{{helpicon}}}</span>
59         </div>
60     </div>
61     <hr class="row">
62     <div class="topics">
63         {{#sections}}
64                 <div class="m-b-1">
65                     <div class="row m-b-1 row-fluid">
66                         <div class="col-sm-12">
67                             <input type="checkbox" data-section-master="{{sectionnumber}}" class="m-r-1" aria-label="{{#str}}checkallsection, completion, {{{name}}}{{/str}}">
68                             <h3 class="d-inline-block">{{{name}}}</h3>
69                         </div>
70                     </div>
71                     {{> core_course/activityinstance}}
72                 </div>
73                 <hr class="row">
74         {{/sections}}
75     </div>
76     <input type="hidden" name="id" value="{{courseid}}" />
77     <input type="hidden" name="sesskey" value="{{sesskey}}" />
78     <div class="row">
79         <div class="col">
80             <input type="submit" value="{{#str}}edit{{/str}}" class="btn btn-primary" name="submitbutton" disabled/>
81         </div>
82     </div>
83 </form>
84 </div>
86 {{#js}}
87 require([
88     'jquery',
89 ], function($) {
90     $('.mastercheck').click(function() {
91         var checked = $('.mastercheck').is(':checked');
92         $('input[type=checkbox]').each(function() {
93             $(this).prop('checked', checked);
94             $(this).trigger('change'); // Hmmm. Could be smarter about this and only trigger once for the first checkbox.
95         });
96     });
97     var mastersection = $('input[data-section-master]');
98     mastersection.click(function() {
99         var checked = $(this).is(':checked');
100         var dataid = $(this).attr('data-section-master');
101         $('input[type=checkbox][data-section=\'' + dataid + '\']').each(function() {
102             $(this).prop('checked', checked);
103             $(this).trigger('change'); // Hmmm. Could be smarter about this and only trigger once for the first checkbox.
104         });
105     });
107     $('input[type=checkbox][id^=selectactivity_]').change(function() {
108         if ($(this).is(':checked')) {
109             $('[name=submitbutton]').removeAttr('disabled');
110         } else {
111             // Is this the last activity checkbox to be un-checked? If so, disable the edit button.
112             var somechecked = false;
113             $('input[type=checkbox][id^=selectactivity_]').each(function() {
114                 if ($(this).is(':checked')) {
115                     somechecked = true;
116                     return false;
117                 }
118                 return true;
119             });
120             if (!somechecked) {
121                 $('[name=submitbutton]').attr('disabled', 'disabled');
122             }
123         }
124     });
126 {{/js}}