-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
537 lines (489 loc) · 23 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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link href="/static/spreadsheets2/client/css/857739511-waffle_k_ltr.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<style>
p {color: red;}
.label{padding: 2px 0px 2px 0px;}
.label2{padding: 2px 0px 2px 0px;height:14px;}
body {
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
font-size: 13px;
margin-left: 5px;
}
.buton{
color: white;
padding: 4px 3px 4px 20px;
background-color: #398a00;
border: 1px solid #29691d;
width: 55px;
border-radius: 2px;
text-shadow:0 1px rgba(0, 0, 0, .1);
font-family: arial, sans-serif;
font-size: 11px;
font-weight: bold;
}
</style>
<script>
var emailSend=0;
var emailNoSend=0;
var flagNoti=true;
var formGlobal;
var valueCampo=0;
var numEma=0;
var flagError=true;
window.onload = function ()
{//cookie
var username = getCookie("notificationNoise");
if (username != ""){}
else
{
google.script.run.withSuccessHandler().showDialog();
}
//cookie
google.script.run.withSuccessHandler(addList).comboBox();
};
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function addList(infoList)
{
var select = document.getElementById("email");
var parts = infoList.split("-");
for(var i = 0; i <(parts.length-1); i++)
{
var option = document.createElement('option');
option.text = parts[i];
option.value = parts[i];
select.add(option, 0);
}
}
var banderaEnvio=false;
//This function clear the data in the form
function clearData()
{
document.getElementById("labData").style.color = "black";
document.getElementById("labColum").style.color = "black";
document.getElementById("labRow").style.color = "black";
var mesData =document.getElementById("mesData");
var mesColum =document.getElementById("mesColum");
var mesRow =document.getElementById("mesRow");
if(mesData.hasChildNodes()){mesData.removeChild(mesData.childNodes[0]);}
if(mesColum.hasChildNodes()){mesColum.removeChild(mesColum.childNodes[0]);}
if(mesRow.hasChildNodes()){mesRow.removeChild(mesRow.childNodes[0]);}
}
//This function validate the form
function validateForm()
{
clearData();
var bandera=false;
var txtData= document.getElementById("name").value;
var txtColunm= document.getElementById("colum").value;
var txtRow= document.getElementById("row").value;
if(txtData=="")
{
document.getElementById("labData").style.color = "red";
bandera=true;
}
else if(!validateRange(txtData))
{
var newP = document.getElementById("mesData");
document.getElementById("mesData").style.color = "red";
var content = document.createTextNode(" Invalid range");
newP.appendChild(content);
bandera=true;
}
if(txtColunm==""){}
else if(!validateRange(txtColunm))
{
var newP = document.getElementById("mesColum");
document.getElementById("mesColum").style.color = "red";
var content = document.createTextNode(" Invalid range");
newP.appendChild(content);
bandera=true;
}
if(txtRow=="")
{
document.getElementById("labRow").style.color = "red";
bandera=true;
}
else if(!validateRange(txtRow))
{
var newP = document.getElementById("mesRow");
document.getElementById("mesRow").style.color = "red";
var content = document.createTextNode(" Invalid range");
newP.appendChild(content);
bandera=true;
}
if(bandera){return false;}
else{banderaEnvio=true;}
submitData();
}
//This fucntion validate the input of select range
function validateRange(coordinate)
{
// A little input validation
if (typeof coordinate != "string" || !coordinate.length)
return false;
var parts = coordinate.split(":");
if(parts.length!=2)
return false;
// Find the first occurrence of a digit
var startIndex = parts[0].search(/[\d+]/);
// The column is the part from the beginning up until the first digit
var column = parts[0].substring(0, startIndex).toUpperCase();
// The row is the remainder of the string
var row = parseInt(parts[0].substring(startIndex), 10);
var sIndex = parts[1].search(/[\d+]/);
var column1 = parts[1].substring(0, sIndex).toUpperCase();
var row1 = parseInt(parts[1].substring(sIndex), 10);
return (column >= "A" && row >= 1) && (column <= "XFD" && row <= 1048576)&& (column1 >= "A" && row1 >= 1) && (column1 <= "XFD" && row1 <= 1048576);
}
//This function send the notification of sending emails
function notification(informe)
{
var str = informe.split("-");
var notiEmail=parseInt(str[0]);
var banderaNames=false;
if(notiEmail==1)
{emailSend++;}
else
{emailNoSend++;
banderaNames=true;}
if(flagNoti)
{
var div= document.getElementById("info");
var res1="Emails Sent: "+ emailSend+ " of " + numEma ;
var res2="Emails not Sent: "+ emailNoSend;
var para1 = document.createElement("label");
para1.setAttribute("id", "label1");
var node1 = document.createTextNode(res1);
para1.appendChild(node1);
div.appendChild(para1);
var br = document.createElement("br");
div.appendChild(br);
var para2 = document.createElement("label");
para2.setAttribute("id", "label2");
var node2 = document.createTextNode(res2);
para2.appendChild(node2);
div.appendChild(para2);
var br = document.createElement("br");
div.appendChild(br);
if(emailNoSend>0)
{
var para3 = document.createElement("label");
var node3 = document.createTextNode("List of people that the emails was not sent:");
para3.appendChild(node3);
div.appendChild(para3);
var para6 = document.createElement("ol");
para6.setAttribute("id", "ol1");
flagError=false;
var para4 = document.createElement("li");
var node4 = document.createTextNode(str[1]);
para4.appendChild(node4);
para6.appendChild(para4);
div.appendChild(para6);
}
flagNoti=false;
}
else
{
var label1 =document.getElementById("label1");
var label2 =document.getElementById("label2");
var res1="Emails Sent: "+ emailSend + " of " + numEma ;
var res2="Emails not Sent: "+ emailNoSend;
var node1 = document.createTextNode(res1);
label1.replaceChild(node1, label1.childNodes[0]);
var node2 = document.createTextNode(res2);
label2.replaceChild(node2, label2.childNodes[0]);
if(banderaNames)
{
if(flagError)
{
var para3 = document.createElement("label");
var node3 = document.createTextNode("List of people that the emails was not sent:");
para3.appendChild(node3);
div.appendChild(para3);
var para6 = document.createElement("ol");
para6.setAttribute("id", "ol1");
flagError=false;
}
var ol =document.getElementById("ol1");
var para4 = document.createElement("li");
var node4 = document.createTextNode(str[1]);
para4.appendChild(node4);
ol.appendChild(para4);
}
}
}
//This function validate the sending data and received the number of mails
function sharedSpreadSheet(numEmails)
{
numEma=numEmails;
document.getElementById("info").innerHTML="";
var div= document.getElementById("info");
if(Number.isInteger(numEmails))
{
if(numEmails==-2)//Los datos tienen texto en las celdas
{
var para = document.createElement("p");
var node = document.createTextNode("Error Notification");
para.style.color="#e60000";
para.style.fontSize="20px";
para.appendChild(node);
div.appendChild(para);
var para = document.createElement("p");
var node = document.createTextNode("There are some characters in the values selected, please correct the data and try again.");
para.style.color="#000000";
para.appendChild(node);
div.appendChild(para);
}
else if(numEmails==-1)
{
var para = document.createElement("p");
var node = document.createTextNode("Error Notification");
para.style.fontSize="20px";
para.appendChild(node);
div.appendChild(para);
var para4 = document.createElement("p");
var node4 = document.createTextNode("The sheet of emails has mistakes, please check that you select the correct sheet with the headers: name, last name, and email.");
para4.style.color="#000000";
para4.style.textAlign="justify"
para4.appendChild(node4);
div.appendChild(para4);
}
else if(numEmails==-3)//The file is in the root folder
{
var para = document.createElement("p");
var node = document.createTextNode("Error Notification");
para.style.color="#e60000";
para.style.fontSize="20px";
para.appendChild(node);
div.appendChild(para);
var para4 = document.createElement("p");
var node4 = document.createTextNode("Please create a folder in google drive, put the file inside the folder and try again.");
para4.style.color="#000000";
para4.appendChild(node4);
div.appendChild(para4);
}
else if(numEmails>0)
{
var para = document.createElement("p");
var node = document.createTextNode("The emails are being sent, This process will take some minutes depending on the data volume. Please don't close the page.");
para.style.textAlign="justify"
para.appendChild(node);
div.appendChild(para);
var para5 = document.createElement("p");
var node5 = document.createTextNode("If there were emails that were not sent, please correct them and then send only those that were not sent correctly.");
para5.style.color="#000000";
para5.style.textAlign="justify"
para5.appendChild(node5);
div.appendChild(para5);
for(var i=0; i <numEmails; i++)
{
for(var k=0; k < formGlobal.elements.length; k++)
{
var campo = formGlobal.elements[k];
if(campo.type == "hidden") {
formGlobal.elements[k].value=valueCampo;
valueCampo++;
break;
}
}
var myRunner = google.script.run.withFailureHandler(onFailure);
var myRunner1 = myRunner.withSuccessHandler(notification);
myRunner1.addNoiseFinal(formGlobal);
}
}
else
{
var para = document.createElement("p");
var node = document.createTextNode("An unexpected error has occurred please check that you selected the right values and try again. If the error persists please call the administrator.");
para.style.textAlign="justify"
para.appendChild(node);
div.appendChild(para);
}
}
else
{
var strRes = numEmails.split(",");
if(strRes[0]=='a')
{
var para = document.createElement("p");
var node = document.createTextNode("Error Notification");
para.style.fontSize="20px";
para.appendChild(node);
div.appendChild(para);
var para4 = document.createElement("p");
var node4 = document.createTextNode("The sheet of emails has mistakes, please check emails and try again.");
para4.style.color="#000000";
para4.style.textAlign="justify"
para4.appendChild(node4);
div.appendChild(para4);
var para3 = document.createElement("label");
var node3 = document.createTextNode("List of people who have invalid emails or do not have a gmail account:");
para3.appendChild(node3);
div.appendChild(para3);
var para6 = document.createElement("ol");
para6.setAttribute("id", "ol1");
for(var j=1; j<strRes.length;j++)
{
var para4 = document.createElement("li");
var node4 = document.createTextNode(strRes[j]);
para4.appendChild(node4);
para6.appendChild(para4);
}
div.appendChild(para6);
}
else if(strRes[0]=='b'){
var para = document.createElement("p");
var node = document.createTextNode("Error Notification");
para.style.fontSize="20px";
para.appendChild(node);
div.appendChild(para);
var para4 = document.createElement("p");
var node4 = document.createTextNode("The sheet of emails has mistakes, please check that you select the correct sheet with the headers: name, last name, and email. Also, that the emails are in the right format.");
para4.style.color="#000000";
para4.style.textAlign="justify"
para4.appendChild(node4);
div.appendChild(para4);
var para = document.createElement("p");
var node = document.createTextNode("The mistake is in the row "+ strRes[1]+ " of the sheet of emails.");
para.style.color="#000000";
para.appendChild(node);
div.appendChild(para);
}
else{
var para = document.createElement("p");
var node = document.createTextNode("An unexpected error has occurred please check that you selected the right values and try again. If the error persists please call the administrator.");
para.style.textAlign="justify"
para.appendChild(node);
div.appendChild(para);
}
}
}
function submitData()
{
if(banderaEnvio)
{
formGlobal= document.getElementById("form1");
var myRunner = google.script.run.withFailureHandler(onFailure);
var myRunner1 = myRunner.withSuccessHandler(sharedSpreadSheet);
myRunner1.getNumberEmails(formGlobal);
document.getElementById("info").innerHTML="";
document.getElementById("help").innerHTML="";
document.getElementById("help").style.border="none";
var div= document.getElementById("info");
var para4 = document.createElement("p");
var node4 = document.createTextNode("Validating information, this process will take some minutes depending on the data volume. Please don't close the page.");
para4.appendChild(node4);
div.appendChild(para4);
}
}
function onFailure()
{
document.getElementById("info").innerHTML="";
var div= document.getElementById("info");
var para = document.createElement("p");
var node = document.createTextNode("Error Notification");
para.style.fontSize="20px";
para.appendChild(node);
div.appendChild(para);
var para4 = document.createElement("p");
var node4 = document.createTextNode("An unexpected error has occurred please check that you selected the right values and try again. If the error persists please call the administrator.");
para4.style.color="#000000";
para4.style.textAlign="justify"
para4.appendChild(node4);
div.appendChild(para4);
}
function getCeldas()
{
google.script.run.withSuccessHandler(setData).celdas();
}
function setData(range)
{
var elemento = document.getElementById("name");
elemento.value=range;
}
function getCeldas1()
{
google.script.run.withSuccessHandler(setData1).celdas();
}
function setData1(range)
{
var elemento = document.getElementById("row");
elemento.value=range;
}
function getCeldas2()
{
google.script.run.withSuccessHandler(setData2).celdas();
}
function setData2(range)
{
var elemento = document.getElementById("colum");
elemento.value=range;
}
</script>
</head>
<body>
<div style="overflow-y: scroll; height: 100%; position: absolute;">
<div id="info" style="height:auto;">
<form id="form1">
<div class="label2" style="margin-top:4px;"><div style="float: left; padding-top:5px; margin-right: 9px;"><span id="labRow"> * </span><label>Header: </label></div><div style="padding:0px; width: 120px; float: left"><table cellpadding="0" cellspacing="0" class="waffle-range-selection-container"><tbody><tr>
<td style="padding:0px; width: 80%;"><input class="waffle-range-selection-input waffle-named-ranges-range-select" spellcheck="false" placeholder="" name="row" id="row"></td>
<td style="padding:0px 0px 0px 4px; width: 20%;" class="waffle-range-selection-button-container"><div role="button" onclick="getCeldas1();" class="goog-inline-block jfk-button jfk-button-standard jfk-button-narrow waffle-range-selection-button" tabindex="0" data-tooltip="Select data range" aria-label="Select data range" style="user-select: none;">
<div class="docs-icon goog-inline-block "><div class="docs-icon-img-container docs-icon-img docs-icon-grid" aria-hidden="true"> </div></div></div></td></tr></tbody></table>
</div><div style="padding-top: 6px;padding-left: 189px;"><span id="mesRow"></span></div></div><br />
<div class="label2"><div style="float: left; padding-top:5px; margin-right: 9px;"><span id="labData"> * </span><label>Values: </label></div><div style="padding:0px; width: 120px; float: left"><table cellpadding="0" cellspacing="0" class="waffle-range-selection-container"><tbody><tr>
<td style="padding:0px; width: 80%;"><input class="waffle-range-selection-input waffle-named-ranges-range-select" spellcheck="false" placeholder="" name="name" id="name"></td>
<td style="padding:0px 0px 0px 4px; width: 20%;" class="waffle-range-selection-button-container"><div role="button" onclick="getCeldas();" class="goog-inline-block jfk-button jfk-button-standard jfk-button-narrow waffle-range-selection-button" tabindex="0" data-tooltip="Select data range" aria-label="Select data range" style="user-select: none;">
<div class="docs-icon goog-inline-block "><div class="docs-icon-img-container docs-icon-img docs-icon-grid" aria-hidden="true"> </div></div></div></td></tr></tbody></table>
</div><div style="padding-top: 6px;padding-left: 185px;"><span id="mesData"></span></div></div><br />
<div class="label2"><div style="float: left; padding-top:5px; margin-right: 9px;"><span id="labColum"></span><label>Other Data: </label></div><div style="padding:0px; width: 120px; float: left"><table cellpadding="0" cellspacing="0" class="waffle-range-selection-container"><tbody><tr>
<td style="padding:0px; width: 80%;"><input class="waffle-range-selection-input waffle-named-ranges-range-select" spellcheck="false" placeholder="" name="colum" id="colum"></td>
<td style="padding:0px 0px 0px 4px; width: 20%;" class="waffle-range-selection-button-container"><div role="button" onclick="getCeldas2();" class="goog-inline-block jfk-button jfk-button-standard jfk-button-narrow waffle-range-selection-button" tabindex="0" data-tooltip="Select data range" aria-label="Select data range" style="user-select: none;">
<div class="docs-icon goog-inline-block "><div class="docs-icon-img-container docs-icon-img docs-icon-grid" aria-hidden="true"> </div></div></div></td></tr></tbody></table>
</div><div style="padding-top: 6px;padding-left: 199px;"><span id="mesColum"></span></div></div><br />
<div class="label"><label>Values distribution:</label>
<select id="type" name="type">
<option value="2">Column</option>
<option value="3">Row</option>
<option value="1">Matrix</option>
</select><br /></div>
<div class="label"><input id="negative" type="checkbox" name="negative"/> Negative values<br /></div>
<div class="label"><input id="decimal" type="checkbox" name="decimal" checked/> Decimal values<br /></div>
<div class="label"><label> Emails: </label>
<select id="email" name="email">
</select><br /></div>
<div class="label"><label> Message: </label><br /><textarea rows="4" cols="35" name="message" id="message" form="form1"></textarea><br /></div>
<input type="hidden" id="numEmails2" name="numEmails2" value="-1">
<div class="buton" onclick="validateForm();">Share</div>
</form>
</div>
<div id="help" style="margin-top:10px; border-top: 1px solid; padding: 4px; width: auto; line-height:130%; text-align: justify; height:auto;">
<div class="label"><strong>Header:</strong> is the first cell of the data which contains the name of each column.<br /></div>
<div class="label"><strong>Values:</strong> is the range of cells from which you want to add noise. Data in range must be numeric.<br /></div>
<div class="label"><strong>Other data:</strong> is the range of cells which contains data that have not been considered to add noise, but needs to be referenced in the new dataset. For this case the data can be in form of text.<br /></div>
<div class="label"><strong>Values distribution:</strong> How the values are distributed in the spreadsheet and how the noise will be added. You can select matrix, row or column distribution.<br /></div>
<div class="label"><strong>Negative values:</strong> Allows to add negative values to new dataset (when adding noise). Default value is false (unchecked).<br /></div>
<div class="label"><strong>Decimal values:</strong> Allows to add decimal to new dataset (when adding noise). Default value is true (checked).<br /></div>
<div class="label"><strong>Emails:</strong> is the sheet which contains the emails to share the personalised dataset. This sheet must have the following format: name, last name and email from each student, per row. <br /></div>
<div class="label"><strong>Message: (optional)</strong> you can include a message to be added when sending the email.<br /></div>
</div>
</div>
</body>
</html>