Skip to content

Commit

Permalink
Merge branch 'MDL-77159-master' of https://github.com/andrewnicols/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed May 25, 2023
2 parents d895574 + c730b87 commit 881b51c
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 354 deletions.
3 changes: 3 additions & 0 deletions admin/tool/langimport/amd/build/uninstall.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions admin/tool/langimport/amd/build/uninstall.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions admin/tool/langimport/amd/src/uninstall.js
@@ -0,0 +1,68 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

import {get_strings as getStrings} from 'core/str';
import {saveCancelPromise, alert as displayAlert} from "core/notification";
import MoodleConfig from 'core/config';

export const init = (form) => {
form?.addEventListener('submit', async(e) => {
e.preventDefault();
const selectedOptions = form.querySelector('#menuuninstalllang')?.selectedOptions;
if (!selectedOptions?.length) {
const alertStrings = await getStrings(
['noenglishuninstalltitle', 'selectlangs'].map((key) => ({key, component: 'tool_langimport'})
));
displayAlert(...alertStrings);
return;
}

if ([...selectedOptions].map((node) => node.value).indexOf('en') !== -1) {
const alertStrings = await getStrings(
['noenglishuninstalltitle', 'noenglishuninstall'].map((key) => ({key, component: 'tool_langimport'})
));
displayAlert(...alertStrings);
return;
}

const confirmationStrings = await getStrings([
{
key: 'uninstall',
component: 'tool_langimport',
},
{
key: 'uninstallconfirm',
component: 'tool_langimport',
param: [...selectedOptions].map((node) => node.textContent).join(', '),
},
{
key: 'yes',
component: 'core',
},
]);

saveCancelPromise(...confirmationStrings).then(() => {
const url = new URL(form.action);
url.searchParams.append('sesskey', MoodleConfig.sesskey);
url.searchParams.append('confirmtouninstall', [...selectedOptions].map((node) => node.value).join('/'));
form.action = url.toString();
form.submit();
return true;
})
.catch(() => {
return false;
});
});
};
7 changes: 0 additions & 7 deletions admin/tool/langimport/index.php
Expand Up @@ -222,11 +222,4 @@
$renderable = new \tool_langimport\output\langimport_page($installedlangs, $options, $uninstallurl, $updateurl, $installurl);
$output = $PAGE->get_renderer('tool_langimport');
echo $output->render($renderable);

$PAGE->requires->strings_for_js(array('uninstallconfirm', 'uninstall', 'selectlangs', 'noenglishuninstall'),
'tool_langimport');
$PAGE->requires->yui_module('moodle-core-languninstallconfirm',
'Y.M.core.languninstallconfirm.init',
array(array('uninstallUrl' => $uninstallurl->out()))
);
echo $OUTPUT->footer();
1 change: 1 addition & 0 deletions admin/tool/langimport/lang/en/tool_langimport.php
Expand Up @@ -45,6 +45,7 @@
$string['langupdatecomplete'] = 'Language pack update completed';
$string['missingcfglangotherroot'] = 'Missing configuration value $CFG->langotherroot';
$string['missinglangparent'] = 'Missing parent language <em>{$a->parent}</em> of <em>{$a->lang}</em>.';
$string['noenglishuninstalltitle'] = 'Unable to uninstall';
$string['noenglishuninstall'] = 'The English language pack cannot be uninstalled.';
$string['nolangupdateneeded'] = 'All your language packs are up to date, no update is needed';
$string['pluginname'] = 'Language packs';
Expand Down
3 changes: 2 additions & 1 deletion admin/tool/langimport/templates/langimport.mustache
Expand Up @@ -126,7 +126,8 @@
</div>
</div>
{{#js}}
require(['tool_langimport/search'], function(search) {
require(['tool_langimport/search', 'tool_langimport/uninstall'], function(search, uninstall) {
search.init(document.querySelector('#installform'));
uninstall.init(document.querySelector('#uninstallform'));
});
{{/js}}

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions lib/yui/src/languninstallconfirm/build.json

This file was deleted.

0 comments on commit 881b51c

Please sign in to comment.