forked from robicch/jQueryGantt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ganttGridEditor.js
727 lines (589 loc) · 24.7 KB
/
ganttGridEditor.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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
/*
Copyright (c) 2012-2017 Open Lab
Written by Roberto Bicchierai and Silvia Chelazzi http://roberto.open-lab.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
function GridEditor(master) {
this.master = master; // is the a GantEditor instance
var editorTabel = $.JST.createFromTemplate({}, "TASKSEDITHEAD");
if (!master.permissions.canSeeDep)
editorTabel.find(".requireCanSeeDep").hide();
this.gridified = $.gridify(editorTabel);
this.element = this.gridified.find(".gdfTable").eq(1);
}
GridEditor.prototype.fillEmptyLines = function () {
//console.debug("fillEmptyLines")
var factory = new TaskFactory();
var master = this.master;
//console.debug("GridEditor.fillEmptyLines");
var rowsToAdd = master.minRowsInEditor - this.element.find(".taskEditRow").length;
var empty=this.element.find(".emptyRow").length;
rowsToAdd=Math.max(rowsToAdd,empty>5?0:5-empty);
//fill with empty lines
for (var i = 0; i < rowsToAdd; i++) {
var emptyRow = $.JST.createFromTemplate({}, "TASKEMPTYROW");
if (!master.permissions.canSeeDep)
emptyRow.find(".requireCanSeeDep").hide();
//click on empty row create a task and fill above
emptyRow.click(function (ev) {
//console.debug("emptyRow.click")
var emptyRow = $(this);
//add on the first empty row only
if (!master.permissions.canWrite || !master.permissions.canAdd || emptyRow.prevAll(".emptyRow").length > 0)
return;
master.beginTransaction();
var lastTask;
var start = new Date().getTime();
var level = 0;
if (master.tasks[0]) {
start = master.tasks[0].start;
level = master.tasks[0].level + 1;
}
//fill all empty previouses
var cnt=0;
emptyRow.prevAll(".emptyRow").addBack().each(function () {
cnt++;
var ch = factory.build("tmp_fk" + new Date().getTime()+"_"+cnt, "", "", level, start, 1);
var task = master.addTask(ch);
lastTask = ch;
});
master.endTransaction();
if (lastTask.rowElement) {
//lastTask.rowElement.click(); removed R&S 22/03/2016 il click è bindato comunque
lastTask.rowElement.find("[name=name]").focus();//focus to "name" input
}
});
this.element.append(emptyRow);
}
};
GridEditor.prototype.addTask = function (task, row, hideIfParentCollapsed) {
//console.debug("GridEditor.addTask",task,row);
//var prof = new Profiler("editorAddTaskHtml");
//remove extisting row
this.element.find("[taskId=" + task.id + "]").remove();
var taskRow = $.JST.createFromTemplate(task, "TASKROW");
if (!this.master.permissions.canSeeDep)
taskRow.find(".requireCanSeeDep").hide();
if (!this.master.permissions.canSeePopEdit)
taskRow.find(".edit .teamworkIcon").hide();
//save row element on task
task.rowElement = taskRow;
this.bindRowEvents(task, taskRow);
if (typeof(row) != "number") {
var emptyRow = this.element.find(".emptyRow:first"); //tries to fill an empty row
if (emptyRow.length > 0)
emptyRow.replaceWith(taskRow);
else
this.element.append(taskRow);
} else {
var tr = this.element.find("tr.taskEditRow").eq(row);
if (tr.length > 0) {
tr.before(taskRow);
} else {
this.element.append(taskRow);
}
}
//[expand]
if (hideIfParentCollapsed) {
if (task.collapsed) taskRow.addClass('collapsed');
var collapsedDescendant = this.master.getCollapsedDescendant();
if (collapsedDescendant.indexOf(task) >= 0) taskRow.hide();
}
return taskRow;
};
GridEditor.prototype.refreshExpandStatus = function (task) {
//console.debug("refreshExpandStatus",task);
if (!task) return;
if (task.isParent()) {
task.rowElement.addClass("isParent");
} else {
task.rowElement.removeClass("isParent");
}
var par = task.getParent();
if (par && !par.rowElement.is("isParent")) {
par.rowElement.addClass("isParent");
}
};
GridEditor.prototype.refreshTaskRow = function (task) {
//console.debug("refreshTaskRow")
//var profiler = new Profiler("editorRefreshTaskRow");
var canWrite=this.master.permissions.canWrite && task.canWrite;
var row = task.rowElement;
row.find(".taskRowIndex").html(task.getRow() + 1);
row.find(".indentCell").css("padding-left", task.level * 10 + 18);
row.find("[name=name]").val(task.name);
row.find("[name=code]").val(task.code);
row.find("[status]").attr("status", task.status);
row.find("[name=duration]").val(task.duration);
row.find("[name=progress]").val(task.progress).prop("readonly",!canWrite || task.progressByWorklog==true);
row.find("[name=startIsMilestone]").prop("checked", task.startIsMilestone);
row.find("[name=start]").val(new Date(task.start).format()).updateOldValue().prop("readonly",!canWrite || task.depends || !task.canWrite && !this.master.permissions.canWrite ); // called on dates only because for other field is called on focus event
row.find("[name=endIsMilestone]").prop("checked", task.endIsMilestone);
row.find("[name=end]").val(new Date(task.end).format()).updateOldValue();
row.find("[name=depends]").val(task.depends);
row.find(".taskAssigs").html(task.getAssigsString());
//manage collapsed
if (task.collapsed)
row.addClass("collapsed");
else
row.removeClass("collapsed");
//Enhancing the function to perform own operations
this.master.element.trigger('gantt.task.afterupdate.event', task);
//profiler.stop();
};
GridEditor.prototype.redraw = function () {
//console.debug("GridEditor.prototype.redraw")
//var prof = new Profiler("ganttGridEditorRedraw");
for (var i = 0; i < this.master.tasks.length; i++) {
this.refreshTaskRow(this.master.tasks[i]);
}
// check if new empty rows are needed
if (this.master.fillWithEmptyLines)
this.fillEmptyLines();
//prof.stop()
};
GridEditor.prototype.reset = function () {
this.element.find("[taskid]").remove();
};
GridEditor.prototype.bindRowEvents = function (task, taskRow) {
var self = this;
//console.debug("bindRowEvents",this,this.master,this.master.permissions.canWrite, task.canWrite);
//bind row selection
taskRow.click(function (event) {
var row = $(this);
//console.debug("taskRow.click",row.attr("taskid"),event.target)
//var isSel = row.hasClass("rowSelected");
row.closest("table").find(".rowSelected").removeClass("rowSelected");
row.addClass("rowSelected");
//set current task
self.master.currentTask = self.master.getTask(row.attr("taskId"));
//move highlighter
self.master.gantt.synchHighlight();
//if offscreen scroll to element
var top = row.position().top;
if (top > self.element.parent().height()) {
row.offsetParent().scrollTop(top - self.element.parent().height() + 100);
} else if (top <= 40) {
row.offsetParent().scrollTop(row.offsetParent().scrollTop() - 40 + top);
}
});
if (this.master.permissions.canWrite && task.canWrite) {
self.bindRowInputEvents(task, taskRow);
} else { //cannot write: disable input
taskRow.find("input").prop("readonly", true);
taskRow.find("input:checkbox,select").prop("disabled", true);
}
if (!this.master.permissions.canSeeDep)
taskRow.find("[name=depends]").attr("readonly", true);
self.bindRowExpandEvents(task, taskRow);
if (this.master.permissions.canSeePopEdit) {
taskRow.find(".edit").click(function () {self.openFullEditor(task, false)});
taskRow.find(".taskAssigs").dblclick(function () {self.openFullEditor(task, true)});
}
};
GridEditor.prototype.bindRowExpandEvents = function (task, taskRow) {
var self = this;
//expand collapse
taskRow.find(".exp-controller").click(function () {
var el = $(this);
var taskId = el.closest("[taskid]").attr("taskid");
var task = self.master.getTask(taskId);
if (task.collapsed) {
self.master.expand(task,false);
} else {
self.master.collapse(task,false);
}
});
};
GridEditor.prototype.bindRowInputEvents = function (task, taskRow) {
var self = this;
//bind dateField on dates
taskRow.find(".date").each(function () {
var el = $(this);
el.click(function () {
var inp = $(this);
inp.dateField({
inputField: el,
callback: function (d) {
$(this).blur();
}
});
});
el.blur(function (date) {
var inp = $(this);
if (inp.isValueChanged()) {
if (!Date.isValid(inp.val())) {
alert(GanttMaster.messages["INVALID_DATE_FORMAT"]);
inp.val(inp.getOldValue());
} else {
var row = inp.closest("tr");
var taskId = row.attr("taskId");
var task = self.master.getTask(taskId);
var leavingField = inp.prop("name");
var dates = resynchDates(inp, row.find("[name=start]"), row.find("[name=startIsMilestone]"), row.find("[name=duration]"), row.find("[name=end]"), row.find("[name=endIsMilestone]"));
//console.debug("resynchDates",new Date(dates.start), new Date(dates.end),dates.duration)
//update task from editor
self.master.beginTransaction();
self.master.changeTaskDates(task, dates.start, dates.end);
self.master.endTransaction();
inp.updateOldValue(); //in order to avoid multiple call if nothing changed
}
}
});
});
//milestones checkbox
taskRow.find(":checkbox").click(function () {
var el = $(this);
var row = el.closest("tr");
var taskId = row.attr("taskId");
var task = self.master.getTask(taskId);
//update task from editor
var field = el.prop("name");
if (field == "startIsMilestone" || field == "endIsMilestone") {
self.master.beginTransaction();
//milestones
task[field] = el.prop("checked");
resynchDates(el, row.find("[name=start]"), row.find("[name=startIsMilestone]"), row.find("[name=duration]"), row.find("[name=end]"), row.find("[name=endIsMilestone]"));
self.master.endTransaction();
}
});
//binding on blur for task update (date exluded as click on calendar blur and then focus, so will always return false, its called refreshing the task row)
taskRow.find("input:text:not(.date)").focus(function () {
$(this).updateOldValue();
}).blur(function (event) {
var el = $(this);
var row = el.closest("tr");
var taskId = row.attr("taskId");
var task = self.master.getTask(taskId);
//update task from editor
var field = el.prop("name");
//console.debug("blur",field)
if (el.isValueChanged()) {
self.master.beginTransaction();
if (field == "depends") {
var oldDeps = task.depends;
task.depends = el.val();
// update links
var linkOK = self.master.updateLinks(task);
if (linkOK) {
//synchronize status from superiors states
var sups = task.getSuperiors();
/*
for (var i = 0; i < sups.length; i++) {
if (!sups[i].from.synchronizeStatus())
break;
}
*/
var oneFailed=false;
var oneUndefined=false;
var oneActive=false;
var oneSuspended=false;
for (var i = 0; i < sups.length; i++) {
oneFailed=oneFailed|| sups[i].from.status=="STATUS_FAILED";
oneUndefined=oneUndefined|| sups[i].from.status=="STATUS_UNDEFINED";
oneActive=oneActive|| sups[i].from.status=="STATUS_ACTIVE";
oneSuspended=oneSuspended|| sups[i].from.status=="STATUS_SUSPENDED";
}
if (oneFailed){
task.changeStatus("STATUS_FAILED")
} else if (oneUndefined){
task.changeStatus("STATUS_UNDEFINED")
} else if (oneActive){
task.changeStatus("STATUS_SUSPENDED")
} else if (oneSuspended){
task.changeStatus("STATUS_SUSPENDED")
} else {
task.changeStatus("STATUS_ACTIVE")
}
self.master.changeTaskDeps(task); //dates recomputation from dependencies
}
} else if (field == "duration") {
var dates = resynchDates(el, row.find("[name=start]"), row.find("[name=startIsMilestone]"), row.find("[name=duration]"), row.find("[name=end]"), row.find("[name=endIsMilestone]"));
self.master.changeTaskDates(task, dates.start, dates.end);
} else if (field == "name" && el.val() == "") { // remove unfilled task
var par = task.getParent();
task.deleteTask();
self.fillEmptyLines();
if (par) self.refreshExpandStatus(par);
self.master.gantt.synchHighlight();
} else if (field == "progress" ) {
task[field]=parseFloat(el.val())||0;
el.val(task[field]);
} else {
task[field] = el.val();
}
self.master.endTransaction();
} else if (field == "name" && el.val() == "") { // remove unfilled task even if not changed
if (task.getRow()!=0) {
var par = task.getParent();
task.deleteTask();
self.fillEmptyLines();
if (par) self.refreshExpandStatus(par);
self.master.gantt.synchHighlight();
}else {
el.oneTime(1,"foc",function(){$(this).focus()}); //
event.preventDefault();
//return false;
}
}
});
//cursor key movement
taskRow.find("input").keydown(function (event) {
var theCell = $(this);
var theTd = theCell.parent();
var theRow = theTd.parent();
var col = theTd.prevAll("td").length;
var ret = true;
if (!event.ctrlKey) {
switch (event.keyCode) {
case 37: //left arrow
if (!theCell.is(":text") || (!this.selectionEnd || this.selectionEnd == 0))
theTd.prev().find("input").focus();
break;
case 39: //right arrow
if (!theCell.is(":text") || (!this.selectionEnd || this.selectionEnd == this.value.length))
theTd.next().find("input").focus();
break;
case 38: //up arrow
//var prevRow = theRow.prev();
var prevRow = theRow.prevAll(":visible:first");
var td = prevRow.find("td").eq(col);
var inp = td.find("input");
if (inp.length > 0)
inp.focus();
break;
case 40: //down arrow
//var nextRow = theRow.next();
var nextRow = theRow.nextAll(":visible:first");
var td = nextRow.find("td").eq(col);
var inp = td.find("input");
if (inp.length > 0)
inp.focus();
else
nextRow.click(); //create a new row
break;
case 36: //home
break;
case 35: //end
break;
case 9: //tab
case 13: //enter
break;
}
}
return ret;
}).focus(function () {
$(this).closest("tr").click();
});
//change status
taskRow.find(".taskStatus").click(function () {
var el = $(this);
var tr = el.closest("[taskid]");
var taskId = tr.attr("taskid");
var task = self.master.getTask(taskId);
var changer = $.JST.createFromTemplate({}, "CHANGE_STATUS");
changer.find("[status=" + task.status + "]").addClass("selected");
changer.find(".taskStatus").click(function (e) {
e.stopPropagation();
var newStatus = $(this).attr("status");
changer.remove();
self.master.beginTransaction();
task.changeStatus(newStatus);
self.master.endTransaction();
el.attr("status", task.status);
});
el.oneTime(3000, "hideChanger", function () {
changer.remove();
});
el.after(changer);
});
};
GridEditor.prototype.openFullEditor = function (task, editOnlyAssig) {
var self = this;
if (!self.master.permissions.canSeePopEdit)
return;
var taskRow=task.rowElement;
//task editor in popup
var taskId = taskRow.attr("taskId");
//console.debug(task);
//make task editor
var taskEditor = $.JST.createFromTemplate(task, "TASK_EDITOR");
//hide task data if editing assig only
if (editOnlyAssig) {
taskEditor.find(".taskData").hide();
taskEditor.find(".assigsTableWrapper").height(455);
taskEditor.prepend("<h1>\""+task.name+"\"</h1>");
}
//got to extended editor
if (task.isNew()|| !self.master.permissions.canSeeFullEdit){
taskEditor.find("#taskFullEditor").remove();
} else {
taskEditor.bind("openFullEditor.gantt",function () {
window.location.href=contextPath+"/applications/teamwork/task/taskEditor.jsp?CM=ED&OBJID="+task.id;
});
}
taskEditor.find("#name").val(task.name);
taskEditor.find("#description").val(task.description);
taskEditor.find("#code").val(task.code);
taskEditor.find("#progress").val(task.progress ? parseFloat(task.progress) : 0).prop("readonly",task.progressByWorklog==true);
taskEditor.find("#progressByWorklog").prop("checked",task.progressByWorklog);
taskEditor.find("#status").val(task.status);
taskEditor.find("#type").val(task.typeId);
taskEditor.find("#type_txt").val(task.type);
taskEditor.find("#relevance").val(task.relevance);
//cvc_redraw(taskEditor.find(".cvcComponent"));
if (task.startIsMilestone)
taskEditor.find("#startIsMilestone").prop("checked", true);
if (task.endIsMilestone)
taskEditor.find("#endIsMilestone").prop("checked", true);
taskEditor.find("#duration").val(task.duration);
var startDate = taskEditor.find("#start");
startDate.val(new Date(task.start).format());
//start is readonly in case of deps
if (task.depends || !this.master.permissions.canWrite && !task.canWrite) {
startDate.attr("readonly", "true");
} else {
startDate.removeAttr("readonly");
}
taskEditor.find("#end").val(new Date(task.end).format());
//make assignments table
var assigsTable = taskEditor.find("#assigsTable");
assigsTable.find("[assId]").remove();
// loop on assignments
for (var i = 0; i < task.assigs.length; i++) {
var assig = task.assigs[i];
var assigRow = $.JST.createFromTemplate({task: task, assig: assig}, "ASSIGNMENT_ROW");
assigsTable.append(assigRow);
}
if (!self.master.permissions.canWrite || !task.canWrite) {
taskEditor.find("input,textarea").prop("readOnly", true);
taskEditor.find("input:checkbox,select").prop("disabled", true);
taskEditor.find("#saveButton").remove();
taskEditor.find(".button").addClass("disabled");
} else {
//bind dateField on dates, duration
taskEditor.find("#start,#end,#duration").click(function () {
var input = $(this);
if (input.is("[entrytype=DATE]")) {
input.dateField({
inputField: input,
callback: function (d) {$(this).blur();}
});
}
}).blur(function () {
var inp = $(this);
if (inp.validateField()) {
resynchDates(inp, taskEditor.find("[name=start]"), taskEditor.find("[name=startIsMilestone]"), taskEditor.find("[name=duration]"), taskEditor.find("[name=end]"), taskEditor.find("[name=endIsMilestone]"));
//workload computation
if (typeof(workloadDatesChanged)=="function")
workloadDatesChanged();
}
});
taskEditor.find("#startIsMilestone,#endIsMilestone").click(function () {
var inp = $(this);
resynchDates(inp, taskEditor.find("[name=start]"), taskEditor.find("[name=startIsMilestone]"), taskEditor.find("[name=duration]"), taskEditor.find("[name=end]"), taskEditor.find("[name=endIsMilestone]"));
});
//bind add assignment
var cnt=0;
taskEditor.find("#addAssig").click(function () {
cnt++;
var assigsTable = taskEditor.find("#assigsTable");
var assigRow = $.JST.createFromTemplate({task: task, assig: {id: "tmp_" + new Date().getTime()+"_"+cnt}}, "ASSIGNMENT_ROW");
assigsTable.append(assigRow);
$("#bwinPopupd").scrollTop(10000);
}).click();
//save task
taskEditor.bind("saveFullEditor.gantt",function () {
//console.debug("saveFullEditor");
var task = self.master.getTask(taskId); // get task again because in case of rollback old task is lost
self.master.beginTransaction();
task.name = taskEditor.find("#name").val();
task.description = taskEditor.find("#description").val();
task.code = taskEditor.find("#code").val();
task.progress = parseFloat(taskEditor.find("#progress").val());
//task.duration = parseInt(taskEditor.find("#duration").val()); //bicch rimosso perchè devono essere ricalcolata dalla start end, altrimenti sbaglia
task.startIsMilestone = taskEditor.find("#startIsMilestone").is(":checked");
task.endIsMilestone = taskEditor.find("#endIsMilestone").is(":checked");
task.type = taskEditor.find("#type_txt").val();
task.typeId = taskEditor.find("#type").val();
task.relevance = taskEditor.find("#relevance").val();
task.progressByWorklog= taskEditor.find("#progressByWorklog").is(":checked");
//set assignments
var cnt=0;
taskEditor.find("tr[assId]").each(function () {
var trAss = $(this);
var assId = trAss.attr("assId");
var resId = trAss.find("[name=resourceId]").val();
var resName = trAss.find("[name=resourceId_txt]").val(); // from smartcombo text input part
var roleId = trAss.find("[name=roleId]").val();
var effort = millisFromString(trAss.find("[name=effort]").val(),true);
//check if the selected resource exists in ganttMaster.resources
var res= self.master.getOrCreateResource(resId,resName);
//if resource is not found nor created
if (!res)
return;
//check if an existing assig has been deleted and re-created with the same values
var found = false;
for (var i = 0; i < task.assigs.length; i++) {
var ass = task.assigs[i];
if (assId == ass.id) {
ass.effort = effort;
ass.roleId = roleId;
ass.resourceId = res.id;
ass.touched = true;
found = true;
break;
} else if (roleId == ass.roleId && res.id == ass.resourceId) {
ass.effort = effort;
ass.touched = true;
found = true;
break;
}
}
if (!found && resId && roleId) { //insert
cnt++;
//console.debug("adding assig row:", assId,resId,resName,roleId,effort)
var ass = task.createAssignment("tmp_" + new Date().getTime()+"_"+cnt, resId, roleId, effort);
ass.touched = true;
}
});
//console.debug("task.assigs",task.assigs,task.assigs.length)
//remove untouched assigs
task.assigs = task.assigs.filter(function (ass) {
var ret = ass.touched;
delete ass.touched;
return ret;
});
//console.debug("task.assigs",task.assigs,task.assigs.length)
//change dates
task.setPeriod(Date.parseString(taskEditor.find("#start").val()).getTime(), Date.parseString(taskEditor.find("#end").val()).getTime() + (3600000 * 22));
//change status
task.changeStatus(taskEditor.find("#status").val());
if (self.master.endTransaction()) {
taskEditor.find(":input").updateOldValue();
closeBlackPopup();
}
});
}
taskEditor.attr("alertonchange","true");
var ndo = createModalPopup(800, 450).append(taskEditor);//.append("<div style='height:800px; background-color:red;'></div>")
//var ndo = createModalPopup(800, 650).append("<div style='height:300px; background-color:red;'></div>")
//workload computation
if (typeof(workloadDatesChanged)=="function")
workloadDatesChanged();
};