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 |
/**
|
|
|
17 |
* Evidence delete.
|
|
|
18 |
*
|
|
|
19 |
* @module tool_lp/evidence_delete
|
|
|
20 |
* @copyright 2016 Frédéric Massart - FMCorz.net
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
define(['jquery',
|
|
|
25 |
'core/notification',
|
|
|
26 |
'core/ajax',
|
|
|
27 |
'core/str',
|
|
|
28 |
'core/log'],
|
|
|
29 |
function($, Notification, Ajax, Str, Log) {
|
|
|
30 |
|
|
|
31 |
var selectors = {};
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Register an event listener.
|
|
|
35 |
*
|
|
|
36 |
* @param {String} triggerSelector The node on which the click will happen.
|
|
|
37 |
* @param {String} containerSelector The parent node that will be removed and contains the evidence ID.
|
|
|
38 |
*/
|
|
|
39 |
var register = function(triggerSelector, containerSelector) {
|
|
|
40 |
if (typeof selectors[triggerSelector] !== 'undefined') {
|
|
|
41 |
return;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
selectors[triggerSelector] = $('body').delegate(triggerSelector, 'click', function(e) {
|
|
|
45 |
var parent = $(e.currentTarget).parents(containerSelector);
|
|
|
46 |
if (!parent.length || parent.length > 1) {
|
|
|
47 |
Log.error('None or too many evidence container were found.');
|
|
|
48 |
return;
|
|
|
49 |
}
|
|
|
50 |
var evidenceId = parent.data('id');
|
|
|
51 |
if (!evidenceId) {
|
|
|
52 |
Log.error('Evidence ID was not found.');
|
|
|
53 |
return;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
e.preventDefault();
|
|
|
57 |
e.stopPropagation();
|
|
|
58 |
|
|
|
59 |
Str.get_strings([
|
|
|
60 |
{key: 'confirm', component: 'moodle'},
|
|
|
61 |
{key: 'areyousure', component: 'moodle'},
|
|
|
62 |
{key: 'delete', component: 'moodle'},
|
|
|
63 |
{key: 'cancel', component: 'moodle'}
|
|
|
64 |
]).done(function(strings) {
|
|
|
65 |
Notification.confirm(
|
|
|
66 |
strings[0], // Confirm.
|
|
|
67 |
strings[1], // Are you sure?
|
|
|
68 |
strings[2], // Delete.
|
|
|
69 |
strings[3], // Cancel.
|
|
|
70 |
function() {
|
|
|
71 |
var promise = Ajax.call([{
|
|
|
72 |
methodname: 'core_competency_delete_evidence',
|
|
|
73 |
args: {
|
|
|
74 |
id: evidenceId
|
|
|
75 |
}
|
|
|
76 |
}]);
|
|
|
77 |
promise[0].then(function() {
|
|
|
78 |
parent.remove();
|
|
|
79 |
return;
|
|
|
80 |
}).fail(Notification.exception);
|
|
|
81 |
}
|
|
|
82 |
);
|
|
|
83 |
}).fail(Notification.exception);
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
});
|
|
|
87 |
};
|
|
|
88 |
|
|
|
89 |
return /** @alias module:tool_lp/evidence_delete */ {
|
|
|
90 |
|
|
|
91 |
/**
|
|
|
92 |
* Register an event listener.
|
|
|
93 |
*
|
|
|
94 |
* @param {String} triggerSelector The node on which the click will happen.
|
|
|
95 |
* @param {String} containerSelector The parent node that will be removed and contains the evidence ID.
|
|
|
96 |
* @return {Void}
|
|
|
97 |
*/
|
|
|
98 |
register: register
|
|
|
99 |
};
|
|
|
100 |
|
|
|
101 |
});
|