Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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="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>
31
    </div>
32
    <div class="d-flex">
33
        <div style="flex: 1 1 0; min-width: 0;">
34
            <div id="{{id}}_status" class="text-truncate">&nbsp;</div>
35
        </div>
36
        <div class="text-right pl-3" style="flex: 0 0 content">
37
            <span id="{{id}}_estimate" class="">&nbsp;</span>
38
            <span id="{{id}}_percentage" class="d-inline-block" style="width: 3em">0%</span>
39
        </div>
40
    </div>
41
</div>
42
 
43
{{! We must not use the JS helper otherwise this gets executed too late. }}
44
<script>
45
(function() {
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');
51
 
52
    el.addEventListener('update', function(e) {
53
        var msg = e.detail.message,
54
            percent = e.detail.percent,
55
            estimate = e.detail.estimate;
56
 
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 = '';
66
        } else {
67
            estimateIndicator.textContent = estimate;
68
            percentageIndicator.textContent =  percent.toFixed(1) + '%';
69
            progressBar.classList.remove('bg-success');
70
        }
71
    });
72
})();
73
</script>