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/>.
18 @template core/progress_bar
22 Example context (json):
24 "id": "progressbar_test",
28 <div id="{{id}}" class="progressbar_container mb-3">
29 <div class="progress">
30 <div id="{{id}}_bar" class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-value="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div>
33 <div style="flex: 1 1 0; min-width: 0;">
34 <div id="{{id}}_status" class="text-truncate"> </div>
36 <div class="text-right pl-3" style="flex: 0 0 content">
37 <span id="{{id}}_estimate" class=""> </span>
38 <span id="{{id}}_percentage" class="d-inline-block" style="width: 3em">0%</span>
43 {{! We must not use the JS helper otherwise this gets executed too late. }}
46 var el = document.getElementById('{{id}}'),
47 progressBar = document.getElementById('{{id}}_bar'),
48 statusIndicator = document.getElementById('{{id}}_status'),
49 estimateIndicator = document.getElementById('{{id}}_estimate');
50 percentageIndicator = document.getElementById('{{id}}_percentage');
52 el.addEventListener('update', function(e) {
53 var msg = e.detail.message,
54 percent = e.detail.percent,
55 estimate = e.detail.estimate;
57 statusIndicator.textContent = msg;
58 progressBar.style.width = percent.toFixed(1) + '%';
59 progressBar.setAttribute('value', percent.toFixed(1));
60 if (percent === 100) {
61 progressBar.classList.add('bg-success');
62 progressBar.classList.remove('progress-bar-striped');
63 progressBar.classList.remove('progress-bar-animated');
64 percentageIndicator.textContent = '100%';
65 estimateIndicator.textContent = '';
67 estimateIndicator.textContent = estimate;
68 percentageIndicator.textContent = percent.toFixed(1) + '%';
69 progressBar.classList.remove('bg-success');