-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
433 lines (367 loc) · 16.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<link rel="stylesheet" href="/node_modules/jquery-toast-plugin/dist/jquery.toast.min.css">
<title>Genesys PureCloud GDPR Requests</title>
<link href="/static/css/index.css" rel="stylesheet">
</head>
<body style="width: 480px;">
<noscript>You need to enable JavaScript to run this app.</noscript>
<!--#region Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div>
<button type="button" id="refresh" class="btn btn-info"><i class="fas fa-sync-alt"></i> Refresh</button>
<button type="button" id="newrequest" class="btn btn-primary"><i class="fas fa-plus"></i> New Request</button>
</div>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/">Current Requests</a>
</li>
</ul>
</div>
</nav>
<!--#endregion -->
<!--#region Current Requests -->
<div class="container mt-2">
<div>
<h6 id="currentRequests" class="text-center">Current Requests</h6>
<hr />
</div>
<div id="cards"></div>
</div>
<!--#endregion -->
<!--#region required scripts -->
<!-- Load scripts at the end for lazy loading -->
<script src="/node_modules/jquery/dist/jquery.min.js"></script>
<script src="/node_modules/popper.js/dist/umd/popper.min.js"></script>
<script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="/node_modules/moment/min/moment.min.js"></script>
<script src="https://sdk-cdn.mypurecloud.com/javascript/41.0.0/purecloud-platform-client-v2.min.js"></script>
<script src="/node_modules/jquery-toast-plugin/dist/jquery.toast.min.js"></script>
<script src="/static/js/notifications.js"></script>
<script src="/static/js/purecloud.js"></script>
<!--#endregion -->
<!-- Our scripts -->
<script>
// Refresh button
$("#refresh").click(() => {
loadCards();
});
// New request button
$("#newrequest").click(() => {
$(location).attr('href', 'newrequest.html');
});
loadCards();
function loadCards() {
getGDPRRequests().then(async (requests) => {
if (!requests || !requests.entities) {
console.log("No requests found");
return;
}
for (let i = 0; i < requests.entities.length; i++) {
$("#cards").empty();
const request = requests.entities[i];
$("#currentRequests").text(`Current Requests (${requests.entities ? requests.entities.length : null})`);
identifyCreatedByUserId(request).then((createdBy) => {
// Temporarily remove Eric's XSS attack
// if (createdBy == "Eric Cohen") {
// return true;
// }
var userId = request.subject ? request.subject.userId ? request.subject.userId : "" : "";
identifyUserId(request).then((username) => {
const type = request.requestType;
const status = request.status;
const phoneNumber = request.subject ? request.subject.phoneNumbers ? request.subject.phoneNumbers[0] : "" : "";
const address = request.subject ? request.subject.addresses ? request.subject.addresses[0] : "" : "";
const emailAddress = request.subject ? request.subject.emailAddresses ? request.subject.emailAddresses[0] : "" : "";
const externalContactId = request.subject ? request.subject.externalContactId ? request.subject.externalContactId : "" : "";
const dialerContactId = request.subject ? request.subject.dialerContactId ? request.subject.dialerContactId.id : "" : "";
const createdDate = moment(request.createdDate).fromNow();
const replacementTerms = request.replacementTerms ? request.replacementTerms : "";
var resultsUrl;
// Add resultsUrl if this is a GDPR_EXPORT COMPLETED request
if (type == "GDPR_EXPORT" && status == "COMPLETED") {
getGDPRRequest(request.id).then((data) => {
$("#cards").append(createCard(request.id, type, status, username, phoneNumber, address, emailAddress, createdBy, createdDate, userId, externalContactId, dialerContactId, data.resultsUrl, replacementTerms));
return;
}).catch((error) => {
console.error(error);
});
}
$("#cards").append(createCard(request.id, type, status, username, phoneNumber, address, emailAddress, createdBy, createdDate, userId, externalContactId, dialerContactId, resultsUrl, replacementTerms));
}).catch((error) => {
console.error(error);
});
}).catch((error) => {
console.error(error);
});
}
}).catch((error) => {
console.error(error);
});
}
function identifyCreatedByUserId(request) {
var promise = new Promise(function (resolve, reject) {
getUser(request.createdBy.id).then((user) => {
// Use the created by user's name
resolve(user.name);
}).catch((error) => {
// Error (user probably does not exist). Use the created by user id
resolve(request.createdBy.id);
});
});
return promise;
}
function identifyUserId(request) {
var promise = new Promise(function (resolve, reject) {
var userId = request.subject ? request.subject.userId ? request.subject.userId : "" : "";
if (!userId) {
// No user id present. Any other fields present?
if (request.subject.name) {
resolve(encodeURI(request.subject.name));
} else {
resolve("");
}
} else {
// We have a user id
getUser(userId).then((user) => {
// Use the user's name
resolve(user.name);
}).catch((error) => {
// Use the user id
resolve(userId);
});
}
});
return promise;
}
function createCard(requestId, type, status, name, phoneNumber, address, email, createdBy, createdDate, userId, externalContactId, dialerContactId, resultsUrl, replacementTerms) {
var cardDiv = document.createElement("div")
cardDiv.className = "card shadow mt-2";
//#region Header
var $headerDiv = $("<h6/>", { class: "card-header small" }).appendTo(cardDiv);
// Status
switch (status) {
case "COMPLETED":
$headerDiv.addClass("bg-success text-light");
break;
case "INITIATED":
case "DELETING":
case "FINALIZING":
case "SEARCHING":
case "UPDATING":
$headerDiv.addClass("bg-warning text-dark");
break;
case "ERROR":
$headerDiv.addClass("bg-danger text-light");
break;
default:
console.error(`Unknown status: ${status}`);
break;
}
// Type
switch (type) {
case "GDPR_EXPORT":
$headerDiv.append(`<i class="fas fa-file-export" data-toggle="tooltip" data-placement="top" title="Export"></i> `);
break;
case "GDPR_DELETE":
$headerDiv.append(`<i class="fas fa-trash" data-toggle="tooltip" data-placement="top" title="Delete"></i> `);
break;
case "GDPR_UPDATE":
$headerDiv.append(`<i class="fas fa-refresh" data-toggle="tooltip" data-placement="top" title="Update"></i> `);
break;
default:
console.error(`Unknown type: ${type}`);
break;
}
// Download button
// var downloadButton = document.createElement("button");
// downloadButton.setAttribute("id", `button-${requestId}`);
// downloadButton.innerHTML = '<i class="fas fa-download"></i> Download';
// downloadButton.className = "btn btn-sm btn-warning";
if (name) {
$headerDiv.append(`${name ? name : ""} <div class="float-right">${status}</div>`);
} else if (address) {
$headerDiv.append(`${address ? address : ""} <div class="float-right">${status}</div>`);
} else if (phoneNumber) {
$headerDiv.append(`${phoneNumber ? phoneNumber : ""} <div class="float-right">${status}</div>`);
} else if (email) {
$headerDiv.append(`${email ? email : ""} <div class="float-right">${status}</div>`);
}
if (status == "COMPLETED" && type == "GDPR_EXPORT") {
if (resultsUrl) {
console.log(resultsUrl);
if (!resultsUrl.startsWith("https://")) {
//This is due to an issue in PureCloud which provides links like "https:/app.my" instead of "https://apps.my" (missing a forward slash)
resultsUrl = resultsUrl.replace("https:/", "https://");
}
// $headerDiv.append(downloadButton);
// $(document).on("click", `#button-${requestId}`, function () {
// console.log('clicked');
// window.location.href = resultsUrl;
// });
$("<a/>", { href: resultsUrl }).html('<button>download</button>').appendTo($headerDiv);
//'<i class="fas fa-download fa-2x text-warning" data-toggle="tooltip" data-placement="top" title="Download"></i>'
//$download.setAttribute("href", resultsUrl);
//$downloadLink.innerHTML = `<a href="${resultsUrl}"><i class="fas fa-download fa-2x text-warning" data-toggle="tooltip" data-placement="top" title="Download"></i></a> `;
//$headerDiv.append(downloadLink);
} else {
$headerDiv.append("(No results)");
}
}
//#endregion
//#region Body
var body = document.createElement("div");
body.className = "card-body bg-light";
var rowDiv = document.createElement("div");
rowDiv.className = "row";
// Name
if (name) {
var nameSection = document.createElement("h6");
nameSection.className = "card-text small mr-1 ml-1";
if (type == "GDPR_UPDATE") {
for (let i = 0; i < replacementTerms.length; i++) {
const replacementTerm = replacementTerms[i];
if (replacementTerm.type == "NAME") {
nameSection.innerHTML = `<i class="fas fa-user-circle"></i> ${replacementTerm.existingValue} <i class="far fa-arrow-alt-circle-right text-danger"></i> ${replacementTerm.updatedValue}`;
}
}
} else {
nameSection.innerHTML = `<i class="fas fa-user-circle"></i> ${encodeURI(name)}`;
}
nameSection.setAttribute("data-toggle", "tooltip");
nameSection.setAttribute("data-placement", "top");
nameSection.setAttribute("title", "Name");
rowDiv.append(nameSection);
}
// Address
if (address) {
var addressSection = document.createElement("h6");
addressSection.className = "card-text small mr-1 ml-1";
if (type == "GDPR_UPDATE") {
for (let i = 0; i < replacementTerms.length; i++) {
const replacementTerm = replacementTerms[i];
if (replacementTerm.type == "ADDRESS") {
addressSection.innerHTML = `<i class="fas fa-user-circle"></i> ${replacementTerm.existingValue} <i class="far fa-arrow-alt-circle-right text-danger"></i> ${replacementTerm.updatedValue}`;
}
}
} else {
addressSection.innerHTML = `<i class="fas fa-address-card"></i> ${address}`;
}
addressSection.setAttribute("data-toggle", "tooltip");
addressSection.setAttribute("data-placement", "top");
addressSection.setAttribute("title", "Address");
rowDiv.append(addressSection);
}
// Phone Number
if (phoneNumber) {
var phoneNumberSection = document.createElement("h6");
phoneNumberSection.className = "card-text small mr-1 ml-1";
if (type == "GDPR_UPDATE") {
for (let i = 0; i < replacementTerms.length; i++) {
const replacementTerm = replacementTerms[i];
if (replacementTerm.type == "PHONE") {
phoneNumberSection.innerHTML = `<i class="fas fa-user-circle"></i> ${replacementTerm.existingValue} <i class="far fa-arrow-alt-circle-right text-danger"></i> ${replacementTerm.updatedValue}`;
}
}
} else {
phoneNumberSection.innerHTML = `<i class="fas fa-phone"></i> ${phoneNumber}`;
}
phoneNumberSection.setAttribute("data-toggle", "tooltip");
phoneNumberSection.setAttribute("data-placement", "top");
phoneNumberSection.setAttribute("title", "Phone Number");
rowDiv.append(phoneNumberSection);
}
// Email
if (email) {
var emailSection = document.createElement("h6");
emailSection.className = "card-text small mr-1 ml-1";
if (type == "GDPR_UPDATE") {
for (let i = 0; i < replacementTerms.length; i++) {
const replacementTerm = replacementTerms[i];
if (replacementTerm.type == "EMAIL") {
emailSection.innerHTML = `<i class="fas fa-user-circle"></i> ${replacementTerm.existingValue} <i class="far fa-arrow-alt-circle-right text-danger"></i> ${replacementTerm.updatedValue}`;
}
}
} else {
emailSection.innerHTML = `<i class="fas fa-envelope"></i> ${email}`;
}
emailSection.setAttribute("data-toggle", "tooltip");
emailSection.setAttribute("data-placement", "top");
emailSection.setAttribute("title", "Email Address");
rowDiv.append(emailSection);
}
body.append(rowDiv);
cardDiv.append(body);
//#endregion
//#region Footer
var footer = document.createElement("div");
footer.className = "row no-gutters bg-light";
var col = document.createElement("div");
col.className = "col";
var leftPart = document.createElement("div");
leftPart.className = "float-left text-secondary small ml-1";
// User Id
if (userId) {
var userIdSection = document.createElement("small");
userIdSection.setAttribute("id", "userId");
userIdSection.setAttribute("data-toggle", "tooltip");
userIdSection.setAttribute("data-placement", "top");
userIdSection.setAttribute("title", "User Id");
userIdSection.innerHTML = `<i class="fas fa-id-card"></i> ${userId}`;
leftPart.append(userIdSection);
}
// External Contact Id
if (externalContactId) {
var externalContactIdSection = document.createElement("small");
externalContactIdSection.className = "ml-1";
externalContactIdSection.setAttribute("id", "externalContactId");
externalContactIdSection.setAttribute("data-toggle", "tooltip");
externalContactIdSection.setAttribute("data-placement", "top");
externalContactIdSection.setAttribute("title", "External Contact Id");
externalContactIdSection.innerHTML = `<i class="fas fa-external-link-alt"></i> ${externalContactId}`;
leftPart.append(externalContactIdSection);
}
if (dialerContactId) {
// New Line
var newLine = document.createElement("br");
leftPart.append(newLine);
// Dialer Contact Id
var dialerContactIdSection = document.createElement("small");
dialerContactIdSection.className = "ml-1";
dialerContactIdSection.setAttribute("id", "dialerContactId");
dialerContactIdSection.setAttribute("data-toggle", "tooltip");
dialerContactIdSection.setAttribute("data-placement", "top");
dialerContactIdSection.setAttribute("title", "Dialer Contact Id");
dialerContactIdSection.innerHTML = `<i class="fas fa-sign-out-alt"></i> ${dialerContactId}`;
leftPart.append(dialerContactIdSection);
}
col.append(leftPart);
// Created By
var rightPart = document.createElement("div");
rightPart.className = "float-right text-secondary small";
var createdBySection = document.createElement("h6");
createdBySection.className = "small mr-2";
createdBySection.innerHTML = `Created by ${createdBy} (${createdDate})`;
rightPart.append(createdBySection);
col.append(rightPart);
footer.append(col);
cardDiv.append(footer);
//#endregion
// Activate bootstrap tooltips
$("[data-toggle='tooltip']").tooltip();
return cardDiv;
}
</script>
</body>
</html>