6831a0b9df7d451f4396af6c22ac0f60b43c22ef
[moodle.git] / course / templates / defaultactivitycompletion.mustache
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/>.
16 }}
17 {{!
18     @template core_course/defaultactivitycompletion
20     Activity completion selector.
22     Example context (json):
23     {
24         "courseid": "2",
25         "sesskey": "AAAAAA",
26         "modules": [{
27             "id": "10",
28             "formattedname": "Assignment",
29             "canmanage": true,
30             "icon": "https://raw.githubusercontent.com/moodle/moodle/master/mod/assign/pix/icon.png",
31             "completionstatus": {
32                 "string": "Manual",
33                 "icon": "https://raw.githubusercontent.com/moodle/moodle/master/pix/i/completion-manual-enabled.png"
34             }
35         }]
36     }
37 }}
38 <div class="container-fluid">
39     <div class="row mb-2">
40         <div class="col">{{#str}}bulkactivitydetail, core_completion{{/str}}</div>
41     </div>
42 <form method="post" action="editdefaultcompletion.php" class="mform" id="theform">
43     <div class="row mb-2">
44         <div class="col">
45             <input type="submit" value="{{#str}}edit{{/str}}" class="btn btn-primary" name="submitbutton" aria-label="{{#str}}updateactivities, completion{{/str}}" disabled/>
46         </div>
47     </div>
48     <div class="row mb-1">
49         <div class="col-xs-6">
50             <input type="checkbox" class="mastercheck mr-1" aria-label="{{#str}}checkall, completion{{/str}}">
51             <label class="font-weight-bold">{{#str}}activitieslabel, core_completion{{/str}}</label>
52         </div>
53         <div class="col-xs-6">
54             <label class="font-weight-bold">{{#str}}completion, core_completion{{/str}}</label>
55             <span>{{{helpicon}}}</span>
56         </div>
57     </div>
58     <hr class="row">
59     <div class="modules">
60         {{#modules}}
61             {{#canmanage}}
62              <div class="mb-1">
63                 <div class="row mb-1 row-fluid">
64                     <div class="col-xs-6">
65                         <label class="accesshide" for="modtype_{{id}}">{{#str}}select, core_completion{{/str}} {{formattedname}}</label>
66                         <input id="modtype_{{id}}" type="checkbox" class="mr-1" name="modids[]" value="{{id}}" aria-label="{{#str}}checkactivity, completion, {{{formattedname}}}{{/str}}">
67                         <img class="iconlarge activityicon" src="{{icon}}" alt=" " role="presentation" />
68                         <span>{{{formattedname}}}</span>
69                     </div>
70                     <div class="activity-completionstatus col-xs-6">
71                         <div class="col-sm-1 p-l-0">
72                             {{#completionstatus.icon}}
73                                 {{{completionstatus.icon}}}
74                             {{/completionstatus.icon}}
75                             {{^completionstatus.icon}}
76                                 <span class="mr-3"></span>
77                             {{/completionstatus.icon}}
78                         </div>
79                         <div class="col-sm-11 p-l-0">
80                             <span class="text-muted muted">{{{completionstatus.string}}}</span>
81                         </div>
82                     </div>
83                 </div>
84             </div>
85             <hr class="row">
86             {{/canmanage}}
87         {{/modules}}
88     </div>
89     <input type="hidden" name="id" value="{{courseid}}" />
90     <input type="hidden" name="sesskey" value="{{sesskey}}" />
91     <div class="row">
92         <div class="col">
93             <input type="submit" value="{{#str}}edit{{/str}}" class="btn btn-primary" name="submitbutton" disabled/>
94         </div>
95     </div>
96 </form>
97 </div>
99 {{#js}}
100 require([
101     'jquery',
102 ], function($) {
103     $('.mastercheck').click(function() {
104         var checked = $('.mastercheck').is(':checked');
105         $('input[type=checkbox]').each(function() {
106             $(this).prop('checked', checked);
107             $(this).trigger('change');
108         });
109     });
111     $('input[type=checkbox][id^=modtype_]').change(function() {
112         if ($(this).is(':checked')) {
113             $('[name=submitbutton]').removeAttr('disabled');
114         } else {
115             // Is this the last activity checkbox to be un-checked? If so, disable the edit button.
116             var somechecked = false;
117             $('input[type=checkbox][id^=modtype_]').each(function() {
118                 if ($(this).is(':checked')) {
119                     somechecked = true;
120                     return false;
121                 }
122                 return true;
123             });
124             if (!somechecked) {
125                 $('[name=submitbutton]').attr('disabled', 'disabled');
126             }
127         }
128     });
129 });
130 {{/js}}