1441 |
ariadna |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Task indicator
|
|
|
18 |
*
|
|
|
19 |
* Watches the progress bar inside the task indicator for updates, and redirects when the progress is complete.
|
|
|
20 |
*
|
|
|
21 |
* @module core/task_indicator
|
|
|
22 |
* @copyright 2024 Catalyst IT Europe Ltd
|
|
|
23 |
* @author Mark Johnson <mark.johnson@catalyst-eu.net>
|
|
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
25 |
*/
|
|
|
26 |
export default class {
|
|
|
27 |
/**
|
|
|
28 |
* Watch the progress bar for updates.
|
|
|
29 |
*
|
|
|
30 |
* When the progress bar is updated to 100%, wait a couple of seconds so the user gets to see it if they are watching,
|
|
|
31 |
* then redirect to the specified URL.
|
|
|
32 |
*
|
|
|
33 |
* @param {String} id The ID of the progress bar element.
|
|
|
34 |
* @param {String} redirectUrl Optional URL to redirect to once the task is complete.
|
|
|
35 |
*/
|
|
|
36 |
static init(id, redirectUrl) {
|
|
|
37 |
const bar = document.getElementById(id);
|
|
|
38 |
bar.addEventListener('update', (event) => {
|
|
|
39 |
const percent = event?.detail?.percent;
|
|
|
40 |
if (percent > 0) {
|
|
|
41 |
// Once progress starts, display the progress bar and remove the run link.
|
|
|
42 |
bar.classList.remove('stored-progress-notstarted');
|
|
|
43 |
const runlink = document.querySelector(`.runlink[data-idnumber=${id}]`);
|
|
|
44 |
if (runlink) {
|
|
|
45 |
runlink.remove();
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
// Once the progress bar completes, redirect the page.
|
|
|
49 |
if (redirectUrl !== '' && percent === 100) {
|
|
|
50 |
window.setTimeout(() => window.location.assign(redirectUrl), 2000);
|
|
|
51 |
}
|
|
|
52 |
});
|
|
|
53 |
}
|
|
|
54 |
}
|