MDL-75012 js: Bump stylelint and components
[moodle.git] / lib / templates / progress_bar.mustache
blob56f8212d8f87789261aa45df411f8ff44c927e8a
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/progress_bar
20     Progress bar.
22     Example context (json):
23     {
24         "id": "progressbar_test",
25         "width": "500"
26     }
28 <div id="{{id}}" class="row progressbar_container">
29     <div class="col-md-6 push-md-3">
30         <p id="{{id}}_status" class="text-xs-center"></p>
31         <progress id="{{id}}_bar" class="progress progress-striped progress-animated" value="0" max="100"></progress>
32         <p id="{{id}}_estimate" class="text-xs-center"></p>
33     </div>
34 </div>
36 {{! We must not use the JS helper otherwise this gets executed too late. }}
37 <script type="text/javascript">
38 (function() {
39     var el = document.getElementById('{{id}}'),
40         progressBar = document.getElementById('{{id}}_bar'),
41         statusIndicator = document.getElementById('{{id}}_status'),
42         estimateIndicator = document.getElementById('{{id}}_estimate');
44     el.addEventListener('update', function(e) {
45         var msg = e.detail.message,
46             percent = e.detail.percent,
47             estimate = e.detail.estimate;
49         statusIndicator.textContent = msg;
50         progressBar.setAttribute('value', Math.round(percent));
51         if (percent === 100) {
52             progressBar.classList.add('progress-success');
53             estimateIndicator.textContent = '100%';
54         } else {
55             if (estimate) {
56                 estimateIndicator.textContent = estimate + ' - ' + percent + '%';
57             } else {
58                 estimateIndicator.textContent = '' + percent + '%';
59             }
60             progressBar.classList.remove('progress-success');
61         }
62     });
63 })();
64 </script>