on-demand release 4.0dev+
[moodle.git] / admin / tool / licensemanager / amd / src / delete_license.js
CommitLineData
4399e475
TD
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 * Modal for confirming deletion of a custom license.
18 *
19 * @module tool_licensemanager/delete_license
4399e475
TD
20 * @copyright 2019 Tom Dickman <tomdickman@catalyst-au.net>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23define(['jquery', 'core/modal_factory', 'core/modal_events', 'core/url', 'core/str'],
24 function($, ModalFactory, ModalEvents, Url, String) {
25
26 var trigger = $('.delete-license');
27 ModalFactory.create({
28 type: ModalFactory.types.SAVE_CANCEL,
29 title: String.get_string('deletelicense', 'tool_licensemanager'),
30 body: String.get_string('deletelicenseconfirmmessage', 'tool_licensemanager'),
31 preShowCallback: function(triggerElement, modal) {
32 triggerElement = $(triggerElement);
33 let params = {
34 'action': 'delete',
35 'license': triggerElement.data('license')
36 };
37 modal.deleteURL = Url.relativeUrl('/admin/tool/licensemanager/index.php', params, true);
38 },
39 large: true,
40 }, trigger)
41 .done(function(modal) {
42 modal.getRoot().on(ModalEvents.save, function(e) {
43 // Stop the default save button behaviour which is to close the modal.
44 e.preventDefault();
45 // Redirect to delete url.
46 window.location.href = modal.deleteURL;
47 });
48 });
49 });