Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
}}
1441 ariadna 28
<div id="{{idnumber}}" class="progressbar_container mb-3 {{class}}" data-recordid="{{id}}">
1 efrain 29
    <div class="progress">
1441 ariadna 30
        <div id="{{idnumber}}_bar" class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-value="{{value}}" aria-valuemin="0" aria-valuemax="100" style="width: {{value}}%"></div>
1 efrain 31
    </div>
32
    <div class="d-flex">
33
        <div style="flex: 1 1 0; min-width: 0;">
1441 ariadna 34
            <div id="{{idnumber}}_status" class="text-truncate">{{message}}</div>
1 efrain 35
        </div>
1441 ariadna 36
        <div class="text-end ps-3" style="flex: 0 0 content">
37
            <span id="{{idnumber}}_estimate" class="">&nbsp;</span>
38
            <span id="{{idnumber}}_percentage" class="d-inline-block" style="width: 3em">{{value}}%</span>
1 efrain 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
 
1441 ariadna 47
    let el = document.getElementById('{{idnumber}}');
48
    let progressBar = document.getElementById('{{idnumber}}_bar');
49
    let statusIndicator = document.getElementById('{{idnumber}}_status');
50
    let estimateIndicator = document.getElementById('{{idnumber}}_estimate');
51
    let percentageIndicator = document.getElementById('{{idnumber}}_percentage');
52
 
53
    // Change background colour to red if there was an error.
54
    if ({{error}} == 1) {
55
        el.querySelector('.progress-bar').style.background = 'red';
56
    }
57
 
1 efrain 58
    el.addEventListener('update', function(e) {
59
        var msg = e.detail.message,
60
            percent = e.detail.percent,
1441 ariadna 61
            estimate = e.detail.estimate
62
            error = e.detail.error;
1 efrain 63
 
64
        statusIndicator.textContent = msg;
65
        progressBar.style.width = percent.toFixed(1) + '%';
66
        progressBar.setAttribute('value', percent.toFixed(1));
1441 ariadna 67
 
68
        if (error) {
69
            progressBar.classList.add('bg-danger');
70
            progressBar.classList.remove('bg-success');
71
            estimateIndicator.textContent = '';
72
        } else if (percent === 100) {
1 efrain 73
            progressBar.classList.add('bg-success');
74
            progressBar.classList.remove('progress-bar-striped');
75
            progressBar.classList.remove('progress-bar-animated');
76
            percentageIndicator.textContent = '100%';
77
            estimateIndicator.textContent = '';
78
        } else {
79
            estimateIndicator.textContent = estimate;
80
            percentageIndicator.textContent =  percent.toFixed(1) + '%';
81
            progressBar.classList.remove('bg-success');
82
        }
83
    });
84
})();
85
</script>