-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntest.js
626 lines (539 loc) · 18.1 KB
/
runtest.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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
// $Id: addedit.js,v 1.15 2005/04/08 03:49:15 ajdonnison Exp $
var calendarField = '';
var calWin = null;
function setMilestoneEndDate(checked){
if(checked){
document.datesFrm.end_date.value = document.datesFrm.start_date.value;
document.datesFrm.task_end_date.value = document.datesFrm.task_start_date.value;
}
}
/**
setTasksStartDate sets new task's start date value which is maximum end date of all dependend tasks
to do: date format should be taken from config
*/
function setTasksStartDate(form, datesForm) {
var td = form.task_dependencies.length -1;
var max_date = new Date("1970", "01", "01");
var max_id = -1;
if (form.set_task_start_date.checked == true) {
//build array of task dependencies
for (td; td > -1; td--) {
var i = form.task_dependencies.options[td].value;
var val = projTasksWithEndDates[i][0]; //format 05/03/2004
var sdate = new Date(val.substring(6,10),val.substring(3,5)-1, val.substring(0,2));
if (sdate > max_date) {
max_date = sdate;
max_id = i;
}
}
//check end date of parent task
// Why? Parent task is for updating dynamics or angle icon
if ( 0 && form.task_parent.options.selectedIndex!=0) {
var i = form.task_parent.options[form.task_parent.options.selectedIndex].value;
var val = projTasksWithEndDates[i][0]; //format 05/03/2004
var sdate = new Date(val.substring(6,10),val.substring(3,5)-1, val.substring(0,2));
if (sdate > max_date) {
max_date = sdate;
max_id = i;
}
}
if (max_id != -1) {
var hour = projTasksWithEndDates[max_id][1];
var minute = projTasksWithEndDates[max_id][2];
datesForm.start_date.value = projTasksWithEndDates[max_id][0];
datesForm.start_hour.value = hour;
datesForm.start_minute.value = minute;
var d = projTasksWithEndDates[max_id][0];
//hardcoded date format Ymd
datesForm.task_start_date.value = d.substring(6,10) + "" + d.substring(3,5) + "" + d.substring(0,2);
}
setAMPM(datesForm.start_hour);
}
}
function popContacts() {
window.open('./index.php?m=public&a=contact_selector&dialog=1&call_back=setContacts&selected_contacts_id='+selected_contacts_id, 'contacts','height=600,width=400,resizable,scrollbars=yes');
}
function popCalendar( field ){
calendarField = field;
unittest_cal = document.getElementById('unittest_' + field.name);
idate = unittest_cal.value;
window.open( 'index.php?m=public&a=calendar&dialog=1&callback=setCalendar&date=' + idate, 'calwin', 'top=250,left=250,width=251, height=220, scollbars=false' );
}
/**
* @param string Input date in the format YYYYMMDD
* @param string Formatted date
*/
function setCalendar( idate, fdate ) {
fld_date = document.getElementById('task_' + calendarField.name);
calendarField.value = fdate;
fld_date.value = idate;
// set end date automatically with start date if start date is after end date
e_date = document.getElementById('task_' + 'end_date');
e_fdate = document.getElementById('end_date');
if (calendarField.name == 'start_date') {
if( e_fdate.value < idate) {
e_date.value = idate;
e_fdate.value = fdate;
}
}
}
function setContacts(contact_id_string){
if(!contact_id_string){
contact_id_string = "";
}
task_contacts = document.getElementById('task_contacts');
task_contacts.value = contact_id_string;
selected_contacts_id = contact_id_string;
}
function submitIt(form){
if (form.task_name.value.length < 3) {
alert( task_name_msg );
form.task_name.focus();
return false;
}
// Check the sub forms
for (var i = 0; i < subForm.length; i++) {
if (!subForm[i].check())
return false;
// Save the subform, this may involve seeding this form
// with data
subForm[i].save();
}
form.submit();
}
function addUser(form) {
var fl = form.resources.length -1;
var au = form.assigned.length -1;
//gets value of percentage assignment of selected resource
var perc = form.percentage_assignment.options[form.percentage_assignment.selectedIndex].value;
var users = "x";
//build array of assiged users
for (au; au > -1; au--) {
users = users + "," + form.assigned.options[au].value + ","
}
//Pull selected resources and add them to list
for (fl; fl > -1; fl--) {
if (form.resources.options[fl].selected && users.indexOf( "," + form.resources.options[fl].value + "," ) == -1) {
t = form.assigned.length
opt = new Option( form.resources.options[fl].text+" ["+perc+"%]", form.resources.options[fl].value);
form.hperc_assign.value += form.resources.options[fl].value+"="+perc+";";
form.assigned.options[t] = opt
}
}
}
function removeUser(form) {
fl = form.assigned.length -1;
for (fl; fl > -1; fl--) {
if (form.assigned.options[fl].selected) {
//remove from hperc_assign
var selValue = form.assigned.options[fl].value;
var re = ".*("+selValue+"=[0-9]*;).*";
var hiddenValue = form.hperc_assign.value;
if (hiddenValue) {
var b = hiddenValue.match(re);
if (b[1]) {
hiddenValue = hiddenValue.replace(b[1], '');
}
form.hperc_assign.value = hiddenValue;
form.assigned.options[fl] = null;
}
//alert(form.hperc_assign.value);
}
}
}
//Check to see if None has been selected.
function checkForTaskDependencyNone(obj){
var td = obj.length -1;
for (td; td > -1; td--) {
if(obj.options[td].value==task_id){
clearExceptFor(obj, task_id);
break;
}
}
}
//If None has been selected, remove the existing entries.
function clearExceptFor(obj, id){
var td = obj.length -1;
for (td; td > -1; td--) {
if(obj.options[td].value != id){
obj.options[td]=null;
}
}
}
function addTaskDependency(form, datesForm) {
var at = form.all_tasks.length -1;
var td = form.task_dependencies.length -1;
var tasks = "x";
//Check to see if None is currently in the dependencies list, and if so, remove it.
if(td>=0 && form.task_dependencies.options[0].value==task_id){
form.task_dependencies.options[0] = null;
td = form.task_dependencies.length -1;
}
//build array of task dependencies
for (td; td > -1; td--) {
tasks = tasks + "," + form.task_dependencies.options[td].value + ","
}
//Pull selected resources and add them to list
for (at; at > -1; at--) {
if (form.all_tasks.options[at].selected && tasks.indexOf( "," + form.all_tasks.options[at].value + "," ) == -1) {
t = form.task_dependencies.length
opt = new Option( form.all_tasks.options[at].text, form.all_tasks.options[at].value );
form.task_dependencies.options[t] = opt
}
}
checkForTaskDependencyNone(form.task_dependencies);
setTasksStartDate(form, datesForm);
}
function removeTaskDependency(form, datesForm) {
td = form.task_dependencies.length -1;
for (td; td > -1; td--) {
if (form.task_dependencies.options[td].selected) {
form.task_dependencies.options[td] = null;
}
}
setTasksStartDate(form, datesForm);
}
function setAMPM( field) {
ampm_field = document.getElementById(field.name + "_ampm");
if (ampm_field) {
if ( field.value > 11 ){
ampm_field.value = "pm";
} else {
ampm_field.value = "am";
}
}
}
var hourMSecs = 3600*1000;
/**
* no comment needed
*/
function isInArray(myArray, intValue) {
for (var i = 0; i < myArray.length; i++) {
if (myArray[i] == intValue) {
return true;
}
}
return false;
}
/**
* @modify_reason calculating duration does not include time information and cal_working_days stored in config.php
*/
function calcDuration(f) {
var int_st_date = new String(f.task_start_date.value + f.start_hour.value + f.start_minute.value);
var int_en_date = new String(f.task_end_date.value + f.end_hour.value + f.end_minute.value);
var sDate = new Date(int_st_date.substring(0,4),(int_st_date.substring(4,6)-1),int_st_date.substring(6,8), int_st_date.substring(8,10), int_st_date.substring(10,12));
var eDate = new Date(int_en_date.substring(0,4),(int_en_date.substring(4,6)-1),int_en_date.substring(6,8), int_en_date.substring(8,10), int_en_date.substring(10,12));
var s = Date.UTC(int_st_date.substring(0,4),(int_st_date.substring(4,6)-1),int_st_date.substring(6,8), int_st_date.substring(8,10), int_st_date.substring(10,12));
var e = Date.UTC(int_en_date.substring(0,4),(int_en_date.substring(4,6)-1),int_en_date.substring(6,8), int_en_date.substring(8,10), int_en_date.substring(10,12));
var durn = (e - s) / hourMSecs; //hours absolute diff start and end
//now we should subtract non-working days from durn variable
var duration = durn / 24;
var weekendDays = 0;
var myDate = new Date(int_st_date.substring(0,4), (int_st_date.substring(4,6)-1),int_st_date.substring(6,8), int_st_date.substring(8,10));
for (var i = 0; i < duration; i++) {
//var myDate = new Date(int_st_date.substring(0,4), (int_st_date.substring(4,6)-1),int_st_date.substring(6,8), int_st_date.substring(8,10));
var myDay = myDate.getDate();
if ( !isInArray(working_days, myDate.getDay()) ) {
weekendDays++;
}
myDate.setDate(myDay + 1);
}
//alert('h'+weekendDays);
//alert(durn);
//calculating correct durn value
durn = durn - weekendDays*24; // total hours minus non-working days (work day hours)
// check if the last day is a weekendDay
// if so we subtracted some hours too much before,
// we have to fill up the last working day until cal_day_start + daily_working_hours
if ( !isInArray(working_days, eDate.getDay()) && eDate.getHours() != cal_day_start) {
durn = durn + Math.max(0, (cal_day_start + daily_working_hours - eDate.getHours()));
}
//could be 1 or 24 (based on TaskDurationType value)
var durnType = parseFloat(f.task_duration_type.value);
durn /= durnType;
//alert(durn);
if (durnType == 1){
// durn is absolute weekday hours
// Hours worked on the first day
var first_day_hours = cal_day_end - sDate.getHours();
if (first_day_hours > daily_working_hours)
first_day_hours = daily_working_hours;
// Hours worked on the last day
var last_day_hours = eDate.getHours() - cal_day_start;
if (last_day_hours > daily_working_hours)
last_day_hours = daily_working_hours;
// Total partial day hours
var partial_day_hours = first_day_hours + last_day_hours;
// Full work days
var full_work_days = (durn - partial_day_hours) / 24;
// Total working hours
durn = Math.floor(full_work_days) * daily_working_hours + partial_day_hours;
// check if the last day is a weekendDay
// if so we subtracted some hours too much before,
// we have to fill up the last working day until cal_day_start + daily_working_hours
if ( !isInArray(working_days, eDate.getDay()) && eDate.getHours() != cal_day_start) {
durn = durn + Math.max(0, (cal_day_start + daily_working_hours - eDate.getHours()));
}
} else if (durnType == 24 ) {
//we should talk about working days so task duration equals 41 hrs means 6 (NOT 5) days!!!
if (durn > Math.round(durn))
durn++;
}
if ( s > e )
alert( 'End date is before start date!');
else
f.task_duration.value = Math.round(durn);
}
/**
* Get the end of the previous working day
*/
function prev_working_day( dateObj ) {
while ( ! isInArray(working_days, dateObj.getDay()) || dateObj.getHours() < cal_day_start ||
( dateObj.getHours() == cal_day_start && dateObj.getMinutes() == 0 ) ){
dateObj.setDate(dateObj.getDate()-1);
dateObj.setHours( cal_day_end );
dateObj.setMinutes( 0 );
}
return dateObj;
}
/**
* Get the start of the next working day
*/
function next_working_day( dateObj ) {
while ( ! isInArray(working_days, dateObj.getDay()) || dateObj.getHours() >= cal_day_end ) {
dateObj.setDate(dateObj.getDate()+1);
dateObj.setHours( cal_day_start );
dateObj.setMinutes( 0 );
}
return dateObj;
}
/**
* @modify reason calcFinish does not use time info and working_days array
*/
function calcFinish(f) {
//var int_st_date = new String(f.task_start_date.value);
var int_st_date_time = new String(f.task_start_date.value + f.start_hour.value + f.start_minute.value);
var int_st_date = int_st_date_time;
var e = new Date(int_st_date_time.substring(0,4),(int_st_date_time.substring(4,6)-1),int_st_date_time.substring(6,8), int_st_date_time.substring(8,10), int_st_date_time.substring(10,12));
// The task duration
var durn = parseFloat(f.task_duration.value);//hours
var durnType = parseFloat(f.task_duration_type.value); //1 or 24
//temporary variables
var inc = durn;
var hoursToAddToLastDay = 0;
var hoursToAddToFirstDay = durn;
var fullWorkingDays = 0;
// calculate the number of non-working days
var k = 7 - working_days.length;
// jump over to the first working day
for (var i = 0; i < k; i++){
if ( !isInArray(working_days, e.getDay()) ) {
e.setDate(e.getDate() + 1);
}
}
if ( durnType==24 ) {
fullWorkingDays = Math.ceil(inc);
e.setMinutes( 0 );
// Include start day as a working day (if it is one)
if ( isInArray(working_days, e.getDay()) ) fullWorkingDays--;
for (var i = 0; i < fullWorkingDays; i++)
{
e.setDate(e.getDate() + 1);
if ( !isInArray(working_days, e.getDay()) ) i--;
}
f.end_hour.value = f.start_hour.value;
} else {
hoursToAddToFirstDay = inc;
if ( e.getHours() + inc > cal_day_end )
hoursToAddToFirstDay = cal_day_end - e.getHours();
if ( hoursToAddToFirstDay > workHours )
hoursToAddToFirstDay = workHours;
inc -= hoursToAddToFirstDay;
hoursToAddToLastDay = inc % workHours;
fullWorkingDays = Math.round((inc - hoursToAddToLastDay) / workHours);
if (hoursToAddToLastDay <= 0)
e.setHours(e.getHours()+hoursToAddToFirstDay);
else
{
e.setHours(cal_day_start+hoursToAddToLastDay);
e.setDate(e.getDate() + 1);
}
e.setMinutes( 0 );
// boolean for setting later if we just found a non-working day
// and therefore do not have to add a day in the next loop
// (which would have caused to not respecting multiple non-working days after each other)
var g = false;
for (var i = 0; i < Math.ceil(fullWorkingDays); i++){
if (!g) {
e.setDate(e.getDate() + 1);
}
g = false;
// calculate overriden non-working days
if ( !isInArray(working_days, e.getDay()) ) {
e.setDate(e.getDate() + 1);
i--;
g = true;
}
}
f.end_hour.value = (e.getHours() < 10 ? "0"+e.getHours() : e.getHours());
}
var tz1 = "";
var tz2 = "";
if ( e.getDate() < 10 ) tz1 = "0";
if ( (e.getMonth()+1) < 10 ) tz2 = "0";
f.task_end_date.value = e.getUTCFullYear()+tz2+(e.getMonth()+1)+tz1+e.getDate();
//f.end_date.value = tz2+(e.getMonth()+1)+"/"+tz1+e.getDate()+"/"+e.getUTCFullYear(); // MM/DD/YY
//f.end_date.value = tz1+e.getDate()+"/"+tz2+(e.getMonth()+1)+"/"+e.getUTCFullYear(); // DD/MM/YY
var url = 'index.php?m=public&a=date_format&dialog=1&field='+f.name+'.end_date&date=' + f.task_end_date.value;
thread = window.frames['thread']; //document.getElementById('thread');
thread.location = url;
setAMPM(f.end_hour);
}
function changeRecordType(value){
// if the record type is changed, then hide everything
hideAllRows();
// and how only those fields needed for the current type
eval("show"+task_types[value]+"();");
}
var subForm = new Array();
function FormDefinition(id, form, check, save) {
this.id = id;
this.form = form;
this.checkHandler = check;
this.saveHandler = save;
this.check = fd_check;
this.save = fd_save;
this.submit = fd_submit;
this.seed = fd_seed;
}
function fd_check()
{
if (this.checkHandler) {
return this.checkHandler(this.form);
} else {
return true;
}
}
function fd_save()
{
if (this.saveHandler) {
var copy_list = this.saveHandler(this.form);
return copyForm(this.form, document.editFrm, copy_list);
} else {
return this.form.submit();
}
}
function fd_submit()
{
if (this.saveHandler)
this.saveHandler(this.form);
return this.form.submit();
}
function fd_seed()
{
return copyForm(document.editFrm, this.form);
}
// Sub-form specific functions.
function checkDates(form) {
if (can_edit_time_information && check_task_dates) {
if (!form.task_start_date.value) {
alert( task_start_msg );
form.task_start_date.focus();
return false;
}
if (!form.task_end_date.value) {
alert( task_end_msg );
form.task_end_date.focus();
return false;
}
}
return true;
}
function copyForm(form, to, extras) {
// Grab all of the elements in the form, and copy them
// to the main form. Do not copy hidden fields.
var h = new HTMLex;
for (var i = 0; i < form.elements.length; i++) {
var elem = form.elements[i];
if (elem.type == 'hidden') {
// If we have anything in the extras array we check to see if we
// need to copy it across
if (!extras)
continue;
var found = false;
for (var j = 0; j < extras.length; j++) {
if (extras[j] == elem.name) {
found = true;
break;
}
}
if (! found)
continue;
}
// Determine the node type, and determine the current value
switch (elem.type) {
case 'text':
case 'textarea':
case 'hidden':
to.appendChild(h.addHidden(elem.name, elem.value));
break;
case 'select-one':
if (elem.options.length > 0)
to.appendChild(h.addHidden(elem.name, elem.options[elem.selectedIndex].value));
break;
case 'select-multiple':
var sel = to.appendChild(h.addSelect(elem.name, false, true));
for (var x = 0; x < elem.options.length; x++) {
if (elem.options[x].selected) {
sel.appendChild(h.addOption(elem.options[x].value, '', true));
}
}
break;
case 'radio':
case 'checkbox':
if (elem.checked) {
to.appendChild(h.addHidden(elem.name, elem.value));
}
break;
}
}
return true;
}
function saveDates(form) {
if (can_edit_time_information) {
if ( form.task_start_date.value.length > 0 ) {
form.task_start_date.value += form.start_hour.value + form.start_minute.value;
}
if ( form.task_end_date.value.length > 0 ) {
form.task_end_date.value += form.end_hour.value + form.end_minute.value;
}
}
return new Array('task_start_date', 'task_end_date');
}
function saveDepend(form) {
var dl = form.task_dependencies.length -1;
hd = form.hdependencies;
hd.value = "";
for (dl; dl > -1; dl--){
hd.value = "," + hd.value +","+ form.task_dependencies.options[dl].value;
}
return new Array('hdependencies');;
}
function checkDetail(form) {
return true;
}
function saveDetail(form) {
return null;
}
function checkResource(form) {
return true;
}
function saveResource(form) {
var fl = form.assigned.length -1;
ha = form.hassign;
ha.value = "";
for (fl; fl > -1; fl--){
ha.value = "," + ha.value +","+ form.assigned.options[fl].value;
}
return new Array('hassign', 'hperc_assign');
}