MDL-71090 tool_dataprivacy: convert cancellation of requests to ES6.
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
define ("tool_dataprivacy/myrequestactions",["jquery","core/ajax","core/notification","core/str","core/modal_factory","core/modal_events","core/templates","core/pending"],function(a,b,c,d,e,f,g,h){var j={CANCEL_REQUEST:"[data-action=\"cancel\"]",CONTACT_DPO:"[data-action=\"contactdpo\"]"},k=function(){this.registerEvents()};k.prototype.registerEvents=function(){a(j.CANCEL_REQUEST).click(function(g){g.preventDefault();var h=a(this).data("requestid");d.get_strings([{key:"cancelrequest",component:"tool_dataprivacy"},{key:"cancelrequestconfirmation",component:"tool_dataprivacy"}]).then(function(a){var d=a[0],g=a[1];return e.create({title:d,body:g,type:e.types.SAVE_CANCEL}).then(function(a){a.setSaveButtonText(d);a.getRoot().on(f.save,function(){b.call([{methodname:"tool_dataprivacy_cancel_data_request",args:{requestid:h}}])[0].done(function(a){if(a.result){window.location.reload()}else{c.addNotification({message:a.warnings[0].message,type:"error"})}}).fail(c.exception)});a.getRoot().on(f.hidden,function(){a.destroy()});return a})}).done(function(a){a.show()}).fail(c.exception)});a(j.CONTACT_DPO).click(function(b){var j=new h("dataprivacy/crud:initModal:contactdpo");b.preventDefault();var k=a(this).data("replytoemail"),l="";d.get_strings([{key:"contactdataprotectionofficer",component:"tool_dataprivacy"},{key:"send",component:"tool_dataprivacy"}]).then(function(a){var b=a[0];l=a[1];return e.create({title:b,body:g.render("tool_dataprivacy/contact_dpo",{replytoemail:k}),type:e.types.SAVE_CANCEL,large:!0})}).then(function(b){b.setSaveButtonText(l);b.show();b.getRoot().on(f.save,function(b){var c=a("#message").val().trim();if(0===c.length){b.preventDefault();a("[data-region=\"messageinput\"]").addClass("has-danger notifyproblem");a("#id_error_message").removeAttr("hidden")}else{i(c)}});b.getRoot().on(f.hidden,function(){b.destroy()})}).then(j.resolve).catch(c.exception)})};function i(a){var e="success";b.call([{methodname:"tool_dataprivacy_contact_dpo",args:{message:a}}])[0].then(function(a){if(a.result){return d.get_string("requestsubmitted","tool_dataprivacy")}e="error";return a.warnings.join("<br>")}).done(function(a){c.addNotification({message:a,type:e})}).fail(c.exception)}return{init:function init(){return new k}}});
|
||||
define ("tool_dataprivacy/myrequestactions",["exports","core/ajax","core/notification","core/pending","core/str"],function(a,b,c,d,e){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=f(b);c=f(c);d=f(d);function f(a){return a&&a.__esModule?a:{default:a}}function g(a,b){return m(a)||l(a,b)||j(a,b)||h()}function h(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function j(a,b){if(!a)return;if("string"==typeof a)return k(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return k(a,b)}function k(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c<b;c++){d[c]=a[c]}return d}function l(a,b){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(a)))return;var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function m(a){if(Array.isArray(a))return a}var n={CANCEL_REQUEST:"[data-action=\"cancel\"][data-requestid]"};a.init=function init(){document.addEventListener("click",function(a){var f=a.target.closest(n.CANCEL_REQUEST);if(null===f){return}a.preventDefault();(0,e.get_strings)([{key:"cancelrequest",component:"tool_dataprivacy"},{key:"cancelrequestconfirmation",component:"tool_dataprivacy"}]).then(function(a){var e=g(a,2),h=e[0],i=e[1];return c.default.confirm(h,i,h,null,function(){var a=new d.default("tool/dataprivacy:cancelRequest"),e={methodname:"tool_dataprivacy_cancel_data_request",args:{requestid:f.dataset.requestid}};b.default.call([e])[0].then(function(b){if(b.result){window.location.reload()}else{c.default.addNotification({type:"error",message:b.warnings[0].message})}return a.resolve()}).catch(c.default.exception)})}).catch()})}});
|
||||
//# sourceMappingURL=myrequestactions.min.js.map
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -21,206 +21,53 @@
|
||||
* @copyright 2018 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'core/ajax',
|
||||
'core/notification',
|
||||
'core/str',
|
||||
'core/modal_factory',
|
||||
'core/modal_events',
|
||||
'core/templates',
|
||||
'core/pending'],
|
||||
function($, Ajax, Notification, Str, ModalFactory, ModalEvents, Templates, Pending) {
|
||||
|
||||
/**
|
||||
* List of action selectors.
|
||||
*
|
||||
* @type {{CANCEL_REQUEST: string}}
|
||||
* @type {{CONTACT_DPO: string}}
|
||||
*/
|
||||
var ACTIONS = {
|
||||
CANCEL_REQUEST: '[data-action="cancel"]',
|
||||
CONTACT_DPO: '[data-action="contactdpo"]',
|
||||
};
|
||||
import Ajax from 'core/ajax';
|
||||
import Notification from 'core/notification';
|
||||
import Pending from 'core/pending';
|
||||
import {get_strings as getStrings} from 'core/str';
|
||||
|
||||
/**
|
||||
* MyRequestActions class.
|
||||
*/
|
||||
var MyRequestActions = function() {
|
||||
this.registerEvents();
|
||||
};
|
||||
const SELECTORS = {
|
||||
CANCEL_REQUEST: '[data-action="cancel"][data-requestid]',
|
||||
};
|
||||
|
||||
/**
|
||||
* Register event listeners.
|
||||
*/
|
||||
MyRequestActions.prototype.registerEvents = function() {
|
||||
$(ACTIONS.CANCEL_REQUEST).click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var requestId = $(this).data('requestid');
|
||||
var stringkeys = [
|
||||
{
|
||||
key: 'cancelrequest',
|
||||
component: 'tool_dataprivacy'
|
||||
},
|
||||
{
|
||||
key: 'cancelrequestconfirmation',
|
||||
component: 'tool_dataprivacy'
|
||||
}
|
||||
];
|
||||
|
||||
Str.get_strings(stringkeys).then(function(langStrings) {
|
||||
var title = langStrings[0];
|
||||
var confirmMessage = langStrings[1];
|
||||
return ModalFactory.create({
|
||||
title: title,
|
||||
body: confirmMessage,
|
||||
type: ModalFactory.types.SAVE_CANCEL
|
||||
}).then(function(modal) {
|
||||
modal.setSaveButtonText(title);
|
||||
|
||||
// Handle save event.
|
||||
modal.getRoot().on(ModalEvents.save, function() {
|
||||
// Cancel the request.
|
||||
var params = {
|
||||
'requestid': requestId
|
||||
};
|
||||
|
||||
var request = {
|
||||
methodname: 'tool_dataprivacy_cancel_data_request',
|
||||
args: params
|
||||
};
|
||||
|
||||
Ajax.call([request])[0].done(function(data) {
|
||||
if (data.result) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
Notification.addNotification({
|
||||
message: data.warnings[0].message,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}).fail(Notification.exception);
|
||||
});
|
||||
|
||||
// Handle hidden event.
|
||||
modal.getRoot().on(ModalEvents.hidden, function() {
|
||||
// Destroy when hidden.
|
||||
modal.destroy();
|
||||
});
|
||||
|
||||
return modal;
|
||||
});
|
||||
}).done(function(modal) {
|
||||
// Show the modal!
|
||||
modal.show();
|
||||
|
||||
}).fail(Notification.exception);
|
||||
});
|
||||
|
||||
$(ACTIONS.CONTACT_DPO).click(function(e) {
|
||||
var pendingPromise = new Pending('dataprivacy/crud:initModal:contactdpo');
|
||||
e.preventDefault();
|
||||
|
||||
var replyToEmail = $(this).data('replytoemail');
|
||||
|
||||
var keys = [
|
||||
{
|
||||
key: 'contactdataprotectionofficer',
|
||||
component: 'tool_dataprivacy'
|
||||
},
|
||||
{
|
||||
key: 'send',
|
||||
component: 'tool_dataprivacy'
|
||||
},
|
||||
];
|
||||
|
||||
var sendButtonText = '';
|
||||
Str.get_strings(keys).then(function(langStrings) {
|
||||
var modalTitle = langStrings[0];
|
||||
sendButtonText = langStrings[1];
|
||||
var context = {
|
||||
'replytoemail': replyToEmail
|
||||
};
|
||||
return ModalFactory.create({
|
||||
title: modalTitle,
|
||||
body: Templates.render('tool_dataprivacy/contact_dpo', context),
|
||||
type: ModalFactory.types.SAVE_CANCEL,
|
||||
large: true
|
||||
});
|
||||
}).then(function(modal) {
|
||||
modal.setSaveButtonText(sendButtonText);
|
||||
|
||||
// Show the modal!
|
||||
modal.show();
|
||||
|
||||
// Handle send event.
|
||||
modal.getRoot().on(ModalEvents.save, function(e) {
|
||||
var message = $('#message').val().trim();
|
||||
if (message.length === 0) {
|
||||
e.preventDefault();
|
||||
// Show validation error when the message is empty.
|
||||
$('[data-region="messageinput"]').addClass('has-danger notifyproblem');
|
||||
$('#id_error_message').removeAttr('hidden');
|
||||
} else {
|
||||
// Send the message.
|
||||
sendMessageToDPO(message);
|
||||
}
|
||||
});
|
||||
|
||||
// Handle hidden event.
|
||||
modal.getRoot().on(ModalEvents.hidden, function() {
|
||||
// Destroy when hidden.
|
||||
modal.destroy();
|
||||
});
|
||||
|
||||
return;
|
||||
}).then(pendingPromise.resolve)
|
||||
.catch(Notification.exception);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Send message to the Data Protection Officer.
|
||||
*
|
||||
* @param {String} message The message to send.
|
||||
*/
|
||||
function sendMessageToDPO(message) {
|
||||
var request = {
|
||||
methodname: 'tool_dataprivacy_contact_dpo',
|
||||
args: {
|
||||
message: message
|
||||
}
|
||||
};
|
||||
|
||||
var requestType = 'success';
|
||||
Ajax.call([request])[0].then(function(data) {
|
||||
if (data.result) {
|
||||
return Str.get_string('requestsubmitted', 'tool_dataprivacy');
|
||||
}
|
||||
requestType = 'error';
|
||||
return data.warnings.join('<br>');
|
||||
|
||||
}).done(function(message) {
|
||||
Notification.addNotification({
|
||||
message: message,
|
||||
type: requestType
|
||||
});
|
||||
|
||||
}).fail(Notification.exception);
|
||||
}
|
||||
|
||||
return /** @alias module:tool_dataprivacy/myrequestactions */ {
|
||||
// Public variables and functions.
|
||||
|
||||
/**
|
||||
* Initialise the unified user filter.
|
||||
*
|
||||
* @method init
|
||||
* @return {MyRequestActions}
|
||||
*/
|
||||
'init': function() {
|
||||
return new MyRequestActions();
|
||||
/**
|
||||
* Initialize module
|
||||
*/
|
||||
export const init = () => {
|
||||
document.addEventListener('click', event => {
|
||||
const triggerElement = event.target.closest(SELECTORS.CANCEL_REQUEST);
|
||||
if (triggerElement === null) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
const requiredStrings = [
|
||||
{key: 'cancelrequest', component: 'tool_dataprivacy'},
|
||||
{key: 'cancelrequestconfirmation', component: 'tool_dataprivacy'},
|
||||
];
|
||||
|
||||
getStrings(requiredStrings).then(([cancelRequest, cancelConfirm]) => {
|
||||
return Notification.confirm(cancelRequest, cancelConfirm, cancelRequest, null, () => {
|
||||
const pendingPromise = new Pending('tool/dataprivacy:cancelRequest');
|
||||
const request = {
|
||||
methodname: 'tool_dataprivacy_cancel_data_request',
|
||||
args: {requestid: triggerElement.dataset.requestid}
|
||||
};
|
||||
|
||||
Ajax.call([request])[0].then(response => {
|
||||
if (response.result) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
Notification.addNotification({
|
||||
type: 'error',
|
||||
message: response.warnings[0].message
|
||||
});
|
||||
}
|
||||
return pendingPromise.resolve();
|
||||
}).catch(Notification.exception);
|
||||
});
|
||||
}).catch();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
@tool @tool_dataprivacy
|
||||
Feature: Manage my own data requests
|
||||
In order to manage my own data requests
|
||||
As a user
|
||||
I need to be able to view and cancel all my data requests
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| student1 | Student | 1 | s1@example.com |
|
||||
And the following config values are set as admin:
|
||||
| contactdataprotectionofficer | 1 | tool_dataprivacy |
|
||||
|
||||
@javascript
|
||||
Scenario: Cancel my own data request
|
||||
Given I log in as "student1"
|
||||
And I follow "Profile" in the user menu
|
||||
And I click on "Contact the privacy officer" "link"
|
||||
And I set the field "Message" to "Hello DPO!"
|
||||
And I click on "Send" "button" in the "Contact the privacy officer" "dialogue"
|
||||
And I should see "Your request has been submitted to the privacy officer"
|
||||
When I click on "Data requests" "link"
|
||||
And I open the action menu in "Hello DPO!" "table_row"
|
||||
And I choose "Cancel" in the open action menu
|
||||
And I click on "Cancel request" "button" in the "Cancel request" "dialogue"
|
||||
Then I should see "Cancelled" in the "Hello DPO!" "table_row"
|
||||
Reference in New Issue
Block a user