-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
574 lines (436 loc) · 16.3 KB
/
deploy.js
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
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
$(document).ready(function(){
if ($('#restrictionshide').val()!='parent'){
$('#restrictions').text($('#restrictionshide').val());
}
$("#ReviewerYes").click( function(){
if( $(this).is(':checked') ){
$("#ReviewerNo").attr('checked', false);
}
});
$("#ReviewerNo").click( function(){
if( $(this).is(':checked') ){
$("#ReviewerYes").attr('checked', false);
}
});
$("#confirmationYes").click( function(){
if( $(this).is(':checked') ){
$("#confirmationNo").attr('checked', false);
}
});
$("#confirmationNo").click( function(){
if( $(this).is(':checked') ){
$("#confirmationYes").attr('checked', false);
}
});
})
function getFile(){
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() +1;
//var day = date.getDay();
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
<<<<<<< HEAD
var timestamp = month+ "/"+day+"/"+year+", "+hour+":"+minute;
=======
var timestamp = month+ "/"+day+"/"+year+", "+hour+":"+minute+':'+minute;
>>>>>>> a32b1107a54a996ad8f8f1892ca0c590d574b191
//'<tr><td>8/19/2011 16:23:30</td><td>colintest</td><td>[email protected]</td><td>colin</td><td>1</td><td>non</td><td>yes</td><td>yes</td><td>yes</td><td>yes</td><td></td><td></td><td></td></tr>'
var filedata = '<tr><td>'+timestamp+'</td><td>'+value('folder')+'</td><td>'+value('researchEmail')+'</td><td>'+value('researchName')+'</td><td>'+
value('targetNumber')+'</td><td>'+value('rulename')+'</td><td>'+value('restrictions')+'</td><td>'+value('restrictionsComments')+'</td><td>'+getCheckBoxVal('ReviewerYes')+'</td><td>'+getCheckBoxVal('studyComplete')+
'</td><td>'+getCheckBoxVal('Virtual')+'</td><td>'+getCheckBoxVal('necessary')+'</td><td>'+getCheckBoxVal('approved')+'</td><td>'+
value('experimentFile')+'</td><td>'+getCheckBoxVal('confirmationYes')+'</td><td>'+value('comments')+'</td></tr>';
// var filedata= '\t\t\t'+'Submission Form for: '+$('#researchName').val()+'\t\t\t\r\n\r\n'+
// 'Researcher name: '+$('#researchName').val()+'\r\n'+
// 'Researcher email address: '+$('#researchEmail').val() + '\r\n'+
// 'Study folder location : '+$('#folder').val() + '\r\n'+
// 'Name of experiment file: '+$('#experimentFile').val()+'\r\n'+
// 'Target number of completed study sessions: '+$('#targetNumber').val() + '\r\n'+
// 'Participant restrictions' +$('#restrictions').val() + '\r\n'+
// 'This study has been approved by the appropriate IRB: yes:'+getCheckBoxVal('approved')+ '\r\n'+
// 'All items on "Study Testing" and "Study Approval" from Project Implicit Study Development Checklist completed yes: '+getCheckBoxVal('studyComplete')+'\r\n'+
// 'My study folder on dev2 includes ZERO files that arent necessary for the study: yes: '+getCheckBoxVal('necessary')+'\r\n'+
// 'Study approved by a User Experience Reviewer: yes: '+getCheckBoxVal('ReviewerYes')+ ' no: '+getCheckBoxVal('ReviewerNo')+'\r\n'+
// 'If you are building this study for another researcher (e.g. a contract study), has the researcher received the standard final launch confirmation email and confirmed that the study is ready to be launched? Yes: '+getCheckBoxVal('confirmationYes')+
// ' no: '+getCheckBoxVal('confirmationNo')+'\r\n'+
// 'Study submitted to the Virtual Lab: yes: '+getCheckBoxVal('Virtual')+'\r\n'+
// 'additional comments: '+ $('#comments').val()+'\r\n';
return filedata;
}
function value(field){
var value;
if (field==='restrictions'){
value = $('#'+field).text();
if (value==='' || value===undefined || value===null){
value= ' ';
}
}else{
value = $('#'+field).val();
if (value==='' || value===undefined || value===null){
value= ' ';
}
console.log(value);
}
if (value==='parent') return 'None';
return value;
}
/**
* Get true or false if the box was checked
*
* @param {box} check Box id
*
*/
function getCheckBoxVal(box){
var res = $('#'+box).attr('checked') ? "Yes" : "No";
return res;
}
/**
* Insert new file.
*
* @param {File} fileData File object to read data from.
* @param {Function} callback Function to call when the request is complete.
*/
function setParametersInURL(){
var a = document.getElementById("rulaTableAnch");
var url = 'ruletable.html';
var ruletable = window.open(url, "Rule Generator", "width=1100,height=900,scrollbars=yes");
}
function validate(){
var notFilled = '';
var mistake=false;
$('#researchName_error').css("visibility","hidden");
$('#researchEmail_error').css("visibility","hidden");
$('#folder_error').css("visibility","hidden");
$('#experimentFile_error').css("visibility","hidden");
$('#ReviewerYes_error').css("visibility","hidden");
$('#confirmationYes_error').css("visibility","hidden");
$('#targetNumber_error').css("visibility","hidden");
$('#approved_error').css("visibility","hidden");
$('#studyComplete_error').css("visibility","hidden");
$('#necessary_error').css("visibility","hidden");
$('#Virtual_error').css("visibility","hidden");
if (!($("#researchName").val())){
notfilled = "Researcher name is not filled";
$('#researchName_error').css("visibility","visible");
mistake=true;
}
if (!($('#researchEmail').val())){
notfilled = "Researcher mail is not filled";
mistake=true;
$('#researchEmail_error').css("visibility","visible");
}
if (!($('#folder').val())){
notfilled = "Researcher folder is not filled";
mistake=true;
$('#folder_error').css("visibility","visible");
}
if (!($('#experimentFile').val())){
notfilled = "Name of experiment file is not filled";
mistake=true;
$('#experimentFile_error').css("visibility","visible");
}
if (!($('#targetNumber').val())){
notfilled = "Name of experiment file is not filled";
mistake=true;
$('#targetNumber_error').css("visibility","visible");
}
if (!($('#approved').attr('checked'))){
notfilled = "Name of experiment file is not filled";
mistake=true;
$('#approved_error').css("visibility","visible");
}
if (!($('#studyComplete').attr('checked'))){
notfilled = "Name of experiment file is not filled";
mistake=true;
$('#studyComplete_error').css("visibility","visible");
}
if (!($('#necessary').attr('checked'))){
notfilled = "Name of experiment file is not filled";
mistake=true;
$('#necessary_error').css("visibility","visible");
}
if (!($('#Virtual').attr('checked'))){
notfilled = "Name of experiment file is not filled";
mistake=true;
$('#Virtual_error').css("visibility","visible");
}
if (!($('#ReviewerYes').attr('checked'))){
if (!($('#ReviewerNo').attr('checked'))){
notfilled = "Name of experiment file is not filled";
mistake=true;
$('#ReviewerYes_error').css("visibility","visible");
}
}
if (!($('#confirmationYes').attr('checked'))){
if (!($('#confirmationNo').attr('checked'))){
notfilled = "Name of experiment file is not filled";
mistake=true;
$('#confirmationYes_error').css("visibility","visible");
}
}
return mistake;
}
function clearAnchor(){
$('#hide').val('parent');
$('#rulename').val('parent');
$('#restrictionshide').val('parent');
$('#restrictions').text('None');
}
function clearForm(){
$('#researchName').val('');
$('#researchEmail').val('');
$('#folder').val('');
$('#experimentFile').val('');
//$('#restrictions').val('None');
$('#targetNumber').val('');
$('#restrictions').text('None');
$('#comments').val('');
$('#restrictionsComments').val('None');
//hidden
$('#hide').val('parent');
$('#rulename').val('parent');
$('#restrictionshide').val('parent');
//checkbox
$('#ReviewerYes').removeAttr('checked');
$('#ReviewerNo').removeAttr('checked');
$('#confirmationNo').removeAttr('checked');
$('#Virtual').removeAttr('checked');
$('#confirmationYes').removeAttr('checked');
$('#approved').removeAttr('checked');
$('#studyComplete').removeAttr('checked');
$('#necessary').removeAttr('checked');
}
function processForm(){
if (validate()){
alert('Some of the fields above were not filled');
return;
}
var msg1 ={};
var msg2={
success: true,
text :'No Rule File'
};
<<<<<<< HEAD
//var url="/implicit/rules";//on implicit
var url="/implicit/rules";//for local
var msgurl = "/ruleGenerator/msg.html";//for local
//var msgurl = "/implicit/user/bgoldenberg/ruleGenerator/msg.html";//on implicit
var xml = $('#hide' ).val();
var name = $('#researchName').val();
//var ruleName = $('#rulename').val();
var path = $('#folder').val();
var index = path.lastIndexOf("/") + 1;
var length = path.length;
var filename = path.substr(index,length);
if (filename=='') {
var folders = path.split("/");
var size = folders.length;
filename = folders[size-2];
}
var ruleName = filename+'.rules';
if (xml!='parent'){
$('#rulename').val(ruleName);
}else{
$('#rulename').val('None');
}
var text = getFile();
if (xml!='parent'){
sendToServer(xml,path,ruleName,url,msg2,'false');
}
if (msg2.success===false && msg2.text==='File was not saved, a file with this name already exist on the server.'){
$('#ruleModel').modal('show');
$('#overwriteB').on('click',function(){
//alert('click');
$('#ruleModel').modal('hide');
sendToServer(xml,path,ruleName,url,msg2,'true');
if (msg2.success!=false){
sendFormToServer(name,text,msg1,url);
window.location.assign(msgurl+'?success1='+msg1.success+'&msg1='+msg1.text+'&success2='+msg2.success+'&msg2='+msg2.text);
}
});
$('#overwriteClose').on('click',function(){
$('#ruleModel').modal('hide');
});
}else{
if (msg2.success!=false){
sendFormToServer(name,text,msg1,url);
window.location.assign(msgurl+'?success1='+msg1.success+'&msg1='+msg1.text+'&success2='+msg2.success+'&msg2='+msg2.text);
}else{
$('#folderModel').modal('show');
$('#OkClose').on('click',function(){
$('#folderModel').modal('hide');
});
//msg1.sucess=false;
//msg1.text = "Deploy Form Was not Sent because there was a problem saving the rule file. "
}
}
}
function sendFormToServer(name,text,msg1,url){
var timeStamp = Math.round(+new Date()/1000);
var data={};
//data.path='/user/'+'bgoldenberg';
data.path='/forms/checklistold.html';
data.FileName =name+timeStamp;
console.log('name: '+data.FileName+ ', folder: '+data.path);
data.xml = text;
data.submit='true';
data.realPath = '';
console.log(text);
$.ajax({
type: 'POST',
url: url,
data: JSON.stringify(data),
success: function(result) {
var res = result.length;
if(res === 3){
//alert('File was saved successfully.');
msg1.success=true;
msg1.text = "The Deploy form was sent successfully ";
}else{
//alert('File was not saved on our servers, check your study folder name.');
msg1.success=false;
msg1.text = "There was a problem sending the deploy form";
}
},
fail: function(jqXHR, textStatus, errorThrown){
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
alert('fail');
},
dataType: 'text',
async:false
});
}
//send rule file
function sendToServer(xml,path,name,url,msg2,overwrite){
=======
var url="/implicit/rules";
//var msgurl = "/ruleGenerator/msg.html";
var msgurl = "/implicit/user/bgoldenberg/ruleGenerator/msg.html";
var text = getFile();
var xml = $('#hide' ).val();
var name = $('#researchName').val();
var ruleName = $('#rulename').val();
var path = $('#folder').val();
if (xml!='parent'){
sendToServer(xml,path,ruleName,url,msg2);
}
if (msg2.success!=false){
var timeStamp = Math.round(+new Date()/1000);
var data={};
//data.path='/user/'+'bgoldenberg';
data.path='/forms/checklist.html';
data.FileName =name+timeStamp;
console.log('name: '+data.FileName+ ', folder: '+data.path);
data.xml = text;
data.submit='true';
data.realPath = '';
console.log(text);
$.ajax({
type: 'POST',
url: url,
data: JSON.stringify(data),
success: function(result) {
var res = result.length;
if(res === 3){
//alert('File was saved successfully.');
msg1.success=true;
msg1.text = "The Deploy form was sent successfully ";
}else{
//alert('File was not saved on our servers, check your study folder name.');
msg1.success=false;
msg1.text = "There was a problem sending the deploy form";
}
},
fail: function(jqXHR, textStatus, errorThrown){
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
alert('fail');
},
dataType: 'text',
async:false
});
}else{
msg1.sucess=false;
msg1.text = "Deploy Form Was not Sent because there was a problem saving the rule file. "
}
window.location.assign(msgurl+'?success1='+msg1.success+'&msg1='+msg1.text+'&success2='+msg2.success+'&msg2='+msg2.text);
}
//send rule file
function sendToServer(xml,path,name,url,msg2){
>>>>>>> a32b1107a54a996ad8f8f1892ca0c590d574b191
var data={};
//var path = this.params.folder;
data.path='/user/'+path;
data.FileName =name;
data.submit='false';
data.realPath = '';
console.log('name: '+data.FileName+ ', folder: '+data.path);
data.xml = xml;
<<<<<<< HEAD
data.overwrite = overwrite;
=======
>>>>>>> a32b1107a54a996ad8f8f1892ca0c590d574b191
console.log(xml);
$.ajax({
type: 'POST',
url: url,
data: JSON.stringify(data),
success: function(result) {
var res = result.length;
if(res === 3){
//alert('File was saved successfully.');
msg2.success=true;
msg2.text = "File was saved successfully, on: "+path+'/'+name;
}else{
if (res=== 4){
msg2.success=false;
msg2.text = "File was not saved, a file with this name already exist on the server.";
}else{
msg2.success =false;
//alert('File was not saved on our servers, check your study folder name.');
<<<<<<< HEAD
msg2.text = 'Study Folder was not Found, check your study folder name.';
=======
msg2.text = 'File was not saved on our servers, check your study folder name.';
>>>>>>> a32b1107a54a996ad8f8f1892ca0c590d574b191
}
}
},
fail: function(jqXHR, textStatus, errorThrown){
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
alert('fail');
},
dataType: 'text',
async:false
});
<<<<<<< HEAD
}
=======
}
// $.post(this.url,JSON.stringify(data),function(data){
// // alert(data);
// alert('success');
// },"html").fail(function ( jqXHR, textStatus, errorThrown){
// console.log(jqXHR);
// console.log(textStatus);
// console.log(errorThrown);
// alert('fail');
// });
// promise.fail(function(){
// //$('.alert').alert();
// //$('.alert').show();
// alert('File was not saved on our servers, check your study folder name.');
// // $('#Errormodal').modal('toggle');
// });
// // }).fail( function(xhr, textStatus, errorThrown) {
// // alert(xhr.responseText);}
// promise.done(function(){
// alert('File was saved successfully.');
// });
>>>>>>> a32b1107a54a996ad8f8f1892ca0c590d574b191