1 |
efrain |
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/progress_bar
|
|
|
19 |
|
|
|
20 |
Progress bar.
|
|
|
21 |
|
|
|
22 |
Example context (json):
|
|
|
23 |
{
|
|
|
24 |
"id": "progressbar_test",
|
|
|
25 |
"width": "500"
|
|
|
26 |
}
|
|
|
27 |
}}
|
|
|
28 |
<div id="{{id}}" class="row progressbar_container rui-progressbar_container">
|
|
|
29 |
<div class="col push-md-3 p-0">
|
|
|
30 |
<p id="{{id}}_status" class="rui-progressbar-status m-0"></p>
|
|
|
31 |
<progress id="{{id}}_bar" class="rui-progress rui-progress-striped rui-progress-animated" value="0" max="100"></progress>
|
|
|
32 |
<p id="{{id}}_estimate" class="rui-progressbar-estimate mt-1 mb-0"></p>
|
|
|
33 |
</div>
|
|
|
34 |
</div>
|
|
|
35 |
|
|
|
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');
|
|
|
43 |
|
|
|
44 |
el.addEventListener('update', function(e) {
|
|
|
45 |
var msg = e.detail.message,
|
|
|
46 |
percent = e.detail.percent,
|
|
|
47 |
estimate = e.detail.estimate;
|
|
|
48 |
|
|
|
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>
|