1 |
efrain |
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 |
import {getStrings} from 'core/str';
|
|
|
17 |
import {saveCancelPromise, alert as displayAlert} from "core/notification";
|
|
|
18 |
import MoodleConfig from 'core/config';
|
|
|
19 |
|
|
|
20 |
export const init = (form) => {
|
|
|
21 |
form?.addEventListener('submit', async(e) => {
|
|
|
22 |
e.preventDefault();
|
|
|
23 |
const selectedOptions = form.querySelector('#menuuninstalllang')?.selectedOptions;
|
|
|
24 |
if (!selectedOptions?.length) {
|
|
|
25 |
const alertStrings = await getStrings(
|
|
|
26 |
['noenglishuninstalltitle', 'selectlangs'].map((key) => ({key, component: 'tool_langimport'})
|
|
|
27 |
));
|
|
|
28 |
displayAlert(...alertStrings);
|
|
|
29 |
return;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
if ([...selectedOptions].map((node) => node.value).indexOf('en') !== -1) {
|
|
|
33 |
const alertStrings = await getStrings(
|
|
|
34 |
['noenglishuninstalltitle', 'noenglishuninstall'].map((key) => ({key, component: 'tool_langimport'})
|
|
|
35 |
));
|
|
|
36 |
displayAlert(...alertStrings);
|
|
|
37 |
return;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
const confirmationStrings = await getStrings([
|
|
|
41 |
{
|
|
|
42 |
key: 'uninstall',
|
|
|
43 |
component: 'tool_langimport',
|
|
|
44 |
},
|
|
|
45 |
{
|
|
|
46 |
key: 'uninstallconfirm',
|
|
|
47 |
component: 'tool_langimport',
|
|
|
48 |
param: [...selectedOptions].map((node) => node.textContent).join(', '),
|
|
|
49 |
},
|
|
|
50 |
{
|
|
|
51 |
key: 'yes',
|
|
|
52 |
component: 'core',
|
|
|
53 |
},
|
|
|
54 |
]);
|
|
|
55 |
|
|
|
56 |
saveCancelPromise(...confirmationStrings).then(() => {
|
|
|
57 |
const url = new URL(form.action);
|
|
|
58 |
url.searchParams.append('sesskey', MoodleConfig.sesskey);
|
|
|
59 |
url.searchParams.append('confirmtouninstall', [...selectedOptions].map((node) => node.value).join('/'));
|
|
|
60 |
form.action = url.toString();
|
|
|
61 |
form.submit();
|
|
|
62 |
return true;
|
|
|
63 |
})
|
|
|
64 |
.catch(() => {
|
|
|
65 |
return false;
|
|
|
66 |
});
|
|
|
67 |
});
|
|
|
68 |
};
|