Debian Codegraph @

dojox/gantt/GanttTaskControl.js

raw symbols SCIP
1 define([
2 "dijit/focus",
3 "dojo/_base/declare",
4 "dojo/_base/array",
5 "dojo/_base/lang",
6 "dojo/date/locale",
7 "dojo/request",
8 "dojo/on",
9 "dojo/dom",
10 "dojo/dom-class",
11 "dojo/dom-construct",
12 "dojo/dom-style",
13 "dojo/dom-attr",
14 "dojo/dom-geometry",
15 "dojo/keys",
16 "dojo/domReady!"
17 ], function(focus, declare, arrayUtil, lang, locale, request, on,
18 dom, domClass, domConstruct, domStyle, domAttr, domGeometry, keys){
19 return declare("dojox.gantt.GanttTaskControl", [], {
20 constructor: function(taskInfo, project, chart){
21 this.ganttChart = chart;
22 this.project = project;
23 this.taskItem = taskInfo;
24 //control variables
25 this.checkMove = false;
26 this.checkResize = false;
27 this.moveChild = false;
28 this.maxPosXMove = -1;
29 this.minPosXMove = -1;
30 this.maxWidthResize = -1;
31 this.minWidthResize = -1;
32 this.posX = 0;
33 this.posY = 0;
34 this.mouseX = 0;
35 this.taskItemWidth = 0;
36 this.isHide = false;
37 this.hideTasksHeight = 0;
38 this.isExpanded = true;
39 this.descrTask = null;
40 this.cTaskItem = null;
41 this.cTaskNameItem = null;
42 this.parentTask = null;
43 this.predTask = null;
44 this.childTask = [];
45 this.childPredTask = [];
46 this.nextChildTask = null;
47 this.previousChildTask = null;
48 this.nextParentTask = null;
49 this.previousParentTask = null;
50 },
51 createConnectingLinesPN: function(){
52 var arrConnectingLinesNames = [];
53 var lineVerticalLeft = domConstruct.create("div", {
54 innerHTML: " ",
55 className: "ganttTaskLineVerticalLeft"
56 }, this.ganttChart.panelNames.firstChild);
57 var cTaskName = this.cTaskNameItem[0], pcTaskName = this.parentTask.cTaskNameItem[0];
58 domStyle.set(lineVerticalLeft, {
59 height: (cTaskName.offsetTop - pcTaskName.offsetTop) + "px",
60 top: (pcTaskName.offsetTop + 5) + "px",
61 left: (pcTaskName.offsetLeft - 9) + "px"
62 });
63 var LineHorizontalLeft = domConstruct.create("div", {
64 noShade: true,
65 color: "#000000",
66 className: "ganttTaskLineHorizontalLeft"
67 }, this.ganttChart.panelNames.firstChild);
68 domStyle.set(LineHorizontalLeft, {
69 left: (pcTaskName.offsetLeft - 9) + "px",
70 top: (cTaskName.offsetTop + 5) + "px",
71 height: "1px",
72 width: (cTaskName.offsetLeft - pcTaskName.offsetLeft + 4) + "px"
73 });
74 arrConnectingLinesNames.push(lineVerticalLeft);
75 arrConnectingLinesNames.push(LineHorizontalLeft);
76 return arrConnectingLinesNames;
77 },
78 createConnectingLinesDS: function(){
79 var contentData = this.ganttChart.contentData.firstChild;
80 var arrLines = [];
81 var arrowImg = domConstruct.create("div", {
82 className: "ganttImageArrow"
83 });
84 //vertical line
85 var lineVerticalRight = document.createElement("div");
86 //horizontal line
87 var lineHorizontal = document.createElement("div");
88 var posXPreviousTask = domStyle.get(this.predTask.cTaskItem[0], "left");
89 var posYPreviousTask = domStyle.get(this.predTask.cTaskItem[0], "top");
90 var posXChildTask = domStyle.get(this.cTaskItem[0], "left");
91 var posYChildTask = this.posY + 2;
92 //width task item
93 var widthPreviousTask = parseInt(this.predTask.cTaskItem[0].firstChild.firstChild.width);
94 if(posYPreviousTask < posYChildTask){
95 domClass.add(lineVerticalRight, "ganttTaskLineVerticalRight");
96 domStyle.set(lineVerticalRight, {
97 height: (posYChildTask - this.ganttChart.heightTaskItem / 2 - posYPreviousTask - 3) + "px",
98 width: "1px",
99 left: (posXPreviousTask + widthPreviousTask - 20) + "px",
100 top: (posYPreviousTask + this.ganttChart.heightTaskItem) + "px"
101 });
102 domClass.add(lineHorizontal, "ganttTaskLineHorizontal");
103 domStyle.set(lineHorizontal, {
104 width: (15 + (posXChildTask - (widthPreviousTask + posXPreviousTask))) + "px",
105 left: (posXPreviousTask + widthPreviousTask - 20) + "px",
106 top: (posYChildTask + 2) + "px"
107 });
108 domClass.add(arrowImg, "ganttTaskArrowImg");
109 domStyle.set(arrowImg, {
110 left: (posXChildTask - 7) + "px",
111 top: (posYChildTask - 1) + "px"
112 });
113 }else{
114 domClass.add(lineVerticalRight, "ganttTaskLineVerticalRightPlus");
115 domStyle.set(lineVerticalRight, {
116 height: (posYPreviousTask + 2 - posYChildTask) + "px",
117 width: "1px",
118 left: (posXPreviousTask + widthPreviousTask - 20) + "px",
119 top: (posYChildTask + 2) + "px"
120 });
121 domClass.add(lineHorizontal, "ganttTaskLineHorizontalPlus");
122 domStyle.set(lineHorizontal, {
123 width: (15 + (posXChildTask - (widthPreviousTask + posXPreviousTask))) + "px",
124 left: (posXPreviousTask + widthPreviousTask - 20) + "px",
125 top: (posYChildTask + 2) + "px"
126 });
127 domClass.add(arrowImg, "ganttTaskArrowImgPlus");
128 domStyle.set(arrowImg, {
129 left: (posXChildTask - 7) + "px",
130 top: (posYChildTask - 1) + "px"
131 });
132 }
133 contentData.appendChild(lineVerticalRight);
134 contentData.appendChild(lineHorizontal);
135 contentData.appendChild(arrowImg);
136 arrLines.push(lineVerticalRight);
137 arrLines.push(arrowImg);
138 arrLines.push(lineHorizontal);
139 return arrLines;
140 },
141 showChildTasks: function(task, isOpen){
142 if(isOpen){
143 for(var i = 0; i < task.childTask.length; i++){
144 var cTask = task.childTask[i],
145 cTaskItem0 = cTask.cTaskItem[0], cTaskName0 = cTask.cTaskNameItem[0],
146 cTaskItem1 = cTask.cTaskItem[1], cTaskName1 = cTask.cTaskNameItem[1],
147 cTaskName2 = cTask.cTaskNameItem[2];
148 if(cTaskItem0.style.display == "none"){
149 cTaskItem0.style.display = "inline";
150 cTaskName0.style.display = "inline";
151 cTask.showDescTask();
152 task.isHide = false;
153 if(cTaskName2){
154 cTaskName2.style.display = "inline";
155 isOpen = cTask.isExpanded;
156 }
157 for(var k = 0; k < cTaskItem1.length; k++){
158 cTaskItem1[k].style.display = "inline";
159 }
160 for(var k = 0; k < cTaskName1.length; k++){
161 cTaskName1[k].style.display = "inline";
162 }
163 (cTask.taskIdentifier) && (cTask.taskIdentifier.style.display = "inline");
164 this.hideTasksHeight += this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra;
165 if(cTask.childTask.length > 0){
166 this.showChildTasks(cTask, isOpen);
167 }
168 }
169 }
170 }
171 },
172 hideChildTasks: function(task){
173 for(var i = 0; i < task.childTask.length; i++){
174 var cTask = task.childTask[i],
175 cTaskItem0 = cTask.cTaskItem[0], cTaskName0 = cTask.cTaskNameItem[0],
176 cTaskItem1 = cTask.cTaskItem[1], cTaskName1 = cTask.cTaskNameItem[1],
177 cTaskName2 = cTask.cTaskNameItem[2];
178 if(cTaskItem0.style.display != "none"){
179 cTaskItem0.style.display = "none";
180 cTaskName0.style.display = "none";
181 cTask.hideDescTask();
182 task.isHide = true;
183 if(cTaskName2){
184 cTaskName2.style.display = "none";
185 }
186 for(var k = 0; k < cTaskItem1.length; k++){
187 cTaskItem1[k].style.display = "none";
188 }
189 for(var k = 0; k < cTaskName1.length; k++){
190 cTaskName1[k].style.display = "none";
191 }
192 (cTask.taskIdentifier) && (cTask.taskIdentifier.style.display = "none");
193 this.hideTasksHeight += (this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra);
194 if(cTask.childTask.length > 0){
195 this.hideChildTasks(cTask);
196 }
197 }
198 }
199 },
200 shiftCurrentTasks: function(task, height){
201 this.shiftNextTask(this, height);
202 task.project.shiftNextProject(task.project, height);
203 },
204 shiftTask: function(task, height){
205 task.posY = task.posY + height;
206 var taskItem0 = task.cTaskItem[0], taskName0 = task.cTaskNameItem[0],
207 taskItem1 = task.cTaskItem[1], taskName1 = task.cTaskNameItem[1],
208 taskName2 = task.cTaskNameItem[2];
209 taskName0.style.top = parseInt(taskName0.style.top) + height + "px";
210 if(taskName2){
211 taskName2.style.top = parseInt(taskName2.style.top) + height + "px";
212 }
213 if(task.parentTask){
214 if(parseInt(this.cTaskNameItem[0].style.top) > parseInt(task.parentTask.cTaskNameItem[0].style.top) &&
215 (taskName1[0].style.display != "none")){
216 taskName1[0].style.height = parseInt(taskName1[0].style.height) + height + "px";
217 }else{
218 taskName1[0].style.top = parseInt(taskName1[0].style.top) + height + "px";
219 }
220 taskName1[1].style.top = parseInt(taskName1[1].style.top) + height + "px";
221 }
222 taskItem0.style.top = parseInt(taskItem0.style.top) + height + "px";
223 task.descrTask.style.top = parseInt(task.descrTask.style.top) + height + "px";
224 if(task.predTask){
225 if(((parseInt(this.cTaskItem[0].style.top) > parseInt(task.predTask.cTaskItem[0].style.top)) ||
226 (this.cTaskItem[0].id == task.predTask.taskItem.id)) &&
227 taskItem1[0].style.display != "none"){
228 taskItem1[0].style.height = parseInt(taskItem1[0].style.height) + height + "px";
229 }else{
230 taskItem1[0].style.top = parseInt(taskItem1[0].style.top) + height + "px";
231 }
232 taskItem1[1].style.top = parseInt(taskItem1[1].style.top) + height + "px";
233 taskItem1[2].style.top = parseInt(taskItem1[2].style.top) + height + "px";
234 }
235 },
236 shiftNextTask: function(task, height){
237 if(task.nextChildTask){
238 this.shiftTask(task.nextChildTask, height);
239 this.shiftChildTask(task.nextChildTask, height);
240 this.shiftNextTask(task.nextChildTask, height);
241 }else if(task.parentTask){
242 this.shiftNextTask(task.parentTask, height);
243 }else if(task.nextParentTask){
244 this.shiftTask(task.nextParentTask, height);
245 this.shiftChildTask(task.nextParentTask, height);
246 this.shiftNextTask(task.nextParentTask, height);
247 }
248 },
249 shiftChildTask: function(task, height){
250 arrayUtil.forEach(task.childTask, function(cTask){
251 this.shiftTask(cTask, height);
252 if(cTask.childTask.length > 0){
253 this.shiftChildTask(cTask, height);
254 }
255 }, this);
256 },
257 endMove: function(){
258 var cTask0 = this.cTaskItem[0];
259 var width = domStyle.get(cTask0, "left") - this.posX;
260 var startTime = this.getDateOnPosition(domStyle.get(cTask0, "left"));
261 startTime = this.checkPos(startTime);
262 if(this.checkMove){
263 width = this.ganttChart.getPosOnDate(startTime) - this.posX;
264 this.moveCurrentTaskItem(width, this.moveChild);
265 this.project.shiftProjectItem();
266 }
267 this.checkMove = false;
268 this.posX = 0;
269 this.maxPosXMove = -1;
270 this.minPosXMove = -1;
271 cTask0.childNodes[1].firstChild.rows[0].cells[0].innerHTML = "";
272 this.adjustPanelTime();
273 if(this.ganttChart.resource){
274 this.ganttChart.resource.refresh();
275 }
276 },
277 checkPos: function(startTime){
278 var cTask0 = this.cTaskItem[0];
279 var h = startTime.getHours();
280 if(h >= 12){
281 startTime.setDate(startTime.getDate() + 1);
282 startTime.setHours(0);
283 if((parseInt(cTask0.firstChild.firstChild.width) + this.ganttChart.getPosOnDate(startTime) > this.maxPosXMove) && (this.maxPosXMove != -1)){
284 startTime.setDate(startTime.getDate() - 1);
285 startTime.setHours(0);
286 }
287 }else if((h < 12) && (h != 0)){
288 startTime.setHours(0);
289 if((this.ganttChart.getPosOnDate(startTime) < this.minPosXMove)){
290 startTime.setDate(startTime.getDate() + 1);
291 }
292 }
293 cTask0.style.left = this.ganttChart.getPosOnDate(startTime) + "px";
294 return startTime;
295 },
296 getMaxPosPredChildTaskItem: function(){
297 var posPredChildTaskItem = 0;
298 var nextPosPredChildTaskItem = 0;
299 for(var i = 0; i < this.childPredTask.length; i++){
300 nextPosPredChildTaskItem = this.getMaxPosPredChildTaskItemInTree(this.childPredTask[i]);
301 if(nextPosPredChildTaskItem > posPredChildTaskItem){
302 posPredChildTaskItem = nextPosPredChildTaskItem;
303 }
304 }
305 return posPredChildTaskItem;
306 },
307 getMaxPosPredChildTaskItemInTree: function(task){
308 var cTask0 = task.cTaskItem[0];
309 var currentPos = parseInt(cTask0.firstChild.firstChild.width) + domStyle.get(cTask0, "left");
310 var posPredChildTaskItem = 0;
311 var nextPosPredChildTaskItem = 0;
312 arrayUtil.forEach(task.childPredTask, function(cpTask){
313 nextPosPredChildTaskItem = this.getMaxPosPredChildTaskItemInTree(cpTask);
314 if(nextPosPredChildTaskItem > posPredChildTaskItem){
315 posPredChildTaskItem = nextPosPredChildTaskItem;
316 }
317 }, this);
318 return posPredChildTaskItem > currentPos ? posPredChildTaskItem : currentPos;
319 },
320 moveCurrentTaskItem: function(width, moveChild){
321 var taskItem = this.cTaskItem[0];
322 this.taskItem.startTime = new Date(this.ganttChart.startDate);
323 this.taskItem.startTime.setHours(this.taskItem.startTime.getHours() + (parseInt(taskItem.style.left) / this.ganttChart.pixelsPerHour));
324 this.showDescTask();
325 var cTask1 = this.cTaskItem[1];
326 if(cTask1.length > 0){
327 cTask1[2].style.width = parseInt(cTask1[2].style.width) + width + "px";
328 cTask1[1].style.left = parseInt(cTask1[1].style.left) + width + "px";
329 }
330 arrayUtil.forEach(this.childTask, function(cTask){
331 if(!cTask.predTask){
332 this.moveChildTaskItems(cTask, width, moveChild);
333 }
334 }, this);
335 arrayUtil.forEach(this.childPredTask, function(cpTask){
336 this.moveChildTaskItems(cpTask, width, moveChild);
337 }, this);
338 },
339 moveChildTaskItems: function(task, width, moveChild){
340 var taskItem = task.cTaskItem[0];
341 if(moveChild){
342 taskItem.style.left = parseInt(taskItem.style.left) + width + "px";
343 task.adjustPanelTime();
344 task.taskItem.startTime = new Date(this.ganttChart.startDate);
345 task.taskItem.startTime.setHours(task.taskItem.startTime.getHours() + (parseInt(taskItem.style.left) / this.ganttChart.pixelsPerHour));
346 var ctItem = task.cTaskItem[1];
347 arrayUtil.forEach(ctItem, function(item){
348 item.style.left = parseInt(item.style.left) + width + "px";
349 }, this);
350 arrayUtil.forEach(task.childTask, function(cTask){
351 if(!cTask.predTask){
352 this.moveChildTaskItems(cTask, width, moveChild);
353 }
354 }, this);
355 arrayUtil.forEach(task.childPredTask, function(cpTask){
356 this.moveChildTaskItems(cpTask, width, moveChild);
357 }, this);
358 }else{
359 var ctItem = task.cTaskItem[1];
360 if(ctItem.length > 0){
361 var item0 = ctItem[0], item2 = ctItem[2];
362 item2.style.left = parseInt(item2.style.left) + width + "px";
363 item2.style.width = parseInt(item2.style.width) - width + "px";
364 item0.style.left = parseInt(item0.style.left) + width + "px";
365 }
366 }
367 task.moveDescTask();
368 },
369 adjustPanelTime: function(){
370 var taskItem = this.cTaskItem[0];
371 var width = parseInt(taskItem.style.left) + parseInt(taskItem.firstChild.firstChild.width) + this.ganttChart.panelTimeExpandDelta;
372 width += this.descrTask.offsetWidth;
373 this.ganttChart.adjustPanelTime(width);
374 },
375 getDateOnPosition: function(position){
376 var date = new Date(this.ganttChart.startDate);
377 date.setHours(date.getHours() + (position / this.ganttChart.pixelsPerHour));
378 return date;
379 },
380 moveItem: function(event){
381 var pageX = event.screenX;
382 var posTaskItem = (this.posX + (pageX - this.mouseX));
383 var widthTaskItem = parseInt(this.cTaskItem[0].childNodes[0].firstChild.width);
384 var posTaskItemR = posTaskItem + widthTaskItem;
385 if(this.checkMove){
386 if(((this.minPosXMove <= posTaskItem)) &&
387 ((posTaskItemR <= this.maxPosXMove) || (this.maxPosXMove == -1))){
388 this.moveTaskItem(posTaskItem);
389 }
390 }
391 },
392 moveTaskItem: function(posX){
393 var cTask = this.cTaskItem[0];
394 cTask.style.left = posX + "px";
395 cTask.childNodes[1].firstChild.rows[0].cells[0].innerHTML = this.getDateOnPosition(posX).getDate() + '.' + (this.getDateOnPosition(posX).getMonth() + 1) + '.' + this.getDateOnPosition(posX).getUTCFullYear();
396 },
397 resizeItem: function(event){
398 if(this.checkResize){
399 var mouseX = event.screenX;
400 var widthTaskItem = this.taskItemWidth + (mouseX - this.mouseX);
401 if(widthTaskItem >= this.taskItemWidth){
402 if((widthTaskItem <= this.maxWidthResize) || (this.maxWidthResize == -1)){
403 this.resizeTaskItem(widthTaskItem);
404 }else if((this.maxWidthResize != -1) && (widthTaskItem > this.maxWidthResize)){
405 this.resizeTaskItem(this.maxWidthResize);
406 }
407 }else if(widthTaskItem <= this.taskItemWidth){
408 if(widthTaskItem >= this.minWidthResize){
409 this.resizeTaskItem(widthTaskItem);
410 }else if(widthTaskItem < this.minWidthResize){
411 this.resizeTaskItem(this.minWidthResize);
412 }
413 }
414 }
415 },
416 resizeTaskItem: function(width){
417 var taskItem = this.cTaskItem[0];
418 var countHours = Math.round(width / this.ganttChart.pixelsPerWorkHour);
419 var trow = taskItem.childNodes[0].firstChild.rows[0],
420 rc0 = trow.cells[0], rc1 = trow.cells[1];
421 rc0 && (rc0.firstChild.style.width = parseInt(rc0.width) * width / 100 + "px");
422 rc1 && (rc1.firstChild.style.width = parseInt(rc1.width) * width / 100 + "px");
423 taskItem.childNodes[0].firstChild.width = width + "px";
424 taskItem.childNodes[1].firstChild.width = width + "px";
425 //resize info
426 this.cTaskItem[0].childNodes[1].firstChild.rows[0].cells[0].innerHTML = countHours;
427 var tcNode2 = taskItem.childNodes[2];
428 tcNode2.childNodes[0].style.width = width + "px";
429 tcNode2.childNodes[1].style.left = width - 10 + "px";
430 },
431 endResizeItem: function(){
432 var taskItem = this.cTaskItem[0];
433 if((this.taskItemWidth != parseInt(taskItem.childNodes[0].firstChild.width))){
434 var posXL = taskItem.offsetLeft;
435 var posXR = taskItem.offsetLeft + parseInt(taskItem.childNodes[0].firstChild.width);
436 this.taskItem.duration = Math.round((posXR - posXL) / this.ganttChart.pixelsPerWorkHour);
437 if(this.childPredTask.length > 0){
438 for(var j = 0; j < this.childPredTask.length; j++){
439 var cpctItem = this.childPredTask[j].cTaskItem[1],
440 item0 = cpctItem[0], item2 = cpctItem[2], tcNode0 = taskItem.childNodes[0];
441 item2.style.width = parseInt(item2.style.width) - (parseInt(tcNode0.firstChild.width) - this.taskItemWidth) + "px";
442 item2.style.left = parseInt(item2.style.left) + (parseInt(tcNode0.firstChild.width) - this.taskItemWidth) + "px";
443 item0.style.left = parseInt(item0.style.left) + (parseInt(tcNode0.firstChild.width) - this.taskItemWidth) + "px";
444 }
445 }
446 }
447 this.cTaskItem[0].childNodes[1].firstChild.rows[0].cells[0].innerHTML = "";
448 this.checkResize = false;
449 this.taskItemWidth = 0;
450 this.mouseX = 0;
451 this.showDescTask();
452 this.project.shiftProjectItem();
453 this.adjustPanelTime();
454 if(this.ganttChart.resource){
455 this.ganttChart.resource.refresh();
456 }
457 },
458 startMove: function(event){
459 this.moveChild = event.ctrlKey;
460 this.mouseX = event.screenX;
461 this.getMoveInfo();
462 this.checkMove = true;
463 this.hideDescTask();
464 },
465 showDescTask: function(){
466 var posX = (parseInt(this.cTaskItem[0].style.left) + this.taskItem.duration * this.ganttChart.pixelsPerWorkHour + 10);
467 this.descrTask.style.left = posX + "px";
468 this.descrTask.innerHTML = this.objKeyToStr(this.getTaskOwner());
469 this.descrTask.style.visibility = 'visible';
470 },
471 hideDescTask: function(){
472 domStyle.set(this.descrTask, "visibility", "hidden");
473 },
474 buildResourceInfo: function(resourceInfo){
475 if(this.childTask && this.childTask.length > 0){
476 for(var i = 0; i < this.childTask.length; i++){
477 var cTask = this.childTask[i];
478 cTask.buildResourceInfo(resourceInfo);
479 }
480 }
481 if(lang.trim(this.taskItem.taskOwner).length > 0){
482 var owners = this.taskItem.taskOwner.split(";");
483 for(var i = 0; i < owners.length; i++){
484 var o = owners[i];
485 if(lang.trim(o).length <= 0){
486 continue;
487 }
488 resourceInfo[o] ? (resourceInfo[o].push(this)) : (resourceInfo[o] = [this]);
489 }
490 }
491 },
492 objKeyToStr: function(obj, delm){
493 var returnStr = "";
494 delm = delm || " ";
495 if(obj){
496 for(var key in obj){
497 returnStr += delm + key;
498 }
499 }
500 return returnStr;
501 },
502 getTaskOwner: function(){
503 var tOwner = {};
504 if(lang.trim(this.taskItem.taskOwner).length > 0){
505 var owners = this.taskItem.taskOwner.split(";");
506 for(var i = 0; i < owners.length; i++){
507 var o = owners[i];
508 tOwner[o] = 1;
509 }
510 }
511 arrayUtil.forEach(this.childTask, function(ctask){
512 lang.mixin(tOwner, ctask.getTaskOwner());
513 }, this);
514 return tOwner;
515 },
516 moveDescTask: function(){
517 var posX = (parseInt(this.cTaskItem[0].style.left) + this.taskItem.duration * this.ganttChart.pixelsPerWorkHour + 10);
518 this.descrTask.style.left = posX + "px";
519 },
520 getMoveInfo: function(){
521 this.posX = parseInt(this.cTaskItem[0].style.left);
522 var widthTaskItem = parseInt(this.cTaskItem[0].childNodes[0].firstChild.width);
523 var posParentTaskItem = !this.parentTask ? 0 : parseInt(this.parentTask.cTaskItem[0].style.left);
524 var posPredTaskItem = !this.predTask ? 0 : parseInt(this.predTask.cTaskItem[0].style.left) + parseInt(this.predTask.cTaskItem[0].childNodes[0].firstChild.width);
525 var widthParentTaskItem = !this.parentTask ? 0 : parseInt(this.parentTask.cTaskItem[0].childNodes[0].firstChild.width);
526
527 var childPredPosX = 0;
528 var childParentPosX = 0;
529 var childParentPosXR = 0;
530 if(this.childPredTask.length > 0){
531 var posChildTaskItem = null;
532 arrayUtil.forEach(this.childPredTask, function(cpTask){
533 if((!posChildTaskItem) || ((posChildTaskItem) && (posChildTaskItem > parseInt(cpTask.cTaskItem[0].style.left)))){
534 posChildTaskItem = parseInt(cpTask.cTaskItem[0].style.left);
535 }
536 }, this);
537 childPredPosX = posChildTaskItem;
538 }
539 if(this.childTask.length > 0){
540 var posChildTaskItemR = null;
541 arrayUtil.forEach(this.childTask, function(cTask){
542 if((!posChildTaskItemR) || ((posChildTaskItemR) && (posChildTaskItemR > (parseInt(cTask.cTaskItem[0].style.left))))){
543 posChildTaskItemR = parseInt(cTask.cTaskItem[0].style.left);
544 }
545 }, this);
546 childParentPosXR = posChildTaskItemR;
547 var posChildTaskItem = null;
548 arrayUtil.forEach(this.childTask, function(cTask){
549 if((!posChildTaskItem) || ((posChildTaskItem)
550 && (posChildTaskItem < (parseInt(cTask.cTaskItem[0].style.left) + parseInt(cTask.cTaskItem[0].firstChild.firstChild.width))))){
551 posChildTaskItem = parseInt(cTask.cTaskItem[0].style.left) + parseInt(cTask.cTaskItem[0].firstChild.firstChild.width);
552 }
553 }, this);
554 childParentPosX = posChildTaskItem;
555 }
556 if(!this.moveChild){
557 if(this.childPredTask.length > 0){
558 if(this.maxPosXMove < childPredPosX) this.maxPosXMove = childPredPosX;
559 }
560 if(this.childTask.length > 0){
561 if((this.childPredTask.length > 0) && (this.maxPosXMove - widthTaskItem) > childParentPosXR){
562 this.maxPosXMove = this.maxPosXMove - ((this.maxPosXMove - widthTaskItem) - childParentPosXR);
563 }
564 if(!(this.childPredTask.length > 0)){
565 this.maxPosXMove = childParentPosXR + widthTaskItem;
566 }
567 this.minPosXMove = (childParentPosX - widthTaskItem);
568 }
569 if(posParentTaskItem > 0){
570 if((!(this.childPredTask.length > 0)) && (this.childTask.length > 0)){
571 if(this.maxPosXMove > posParentTaskItem + widthParentTaskItem){
572 this.maxPosXMove = posParentTaskItem + widthParentTaskItem;
573 }
574 }
575 if(this.minPosXMove <= posParentTaskItem){
576 this.minPosXMove = posParentTaskItem;
577 }
578 if((!(this.childTask.length > 0)) && (!(this.childPredTask.length > 0))){
579 this.maxPosXMove = posParentTaskItem + widthParentTaskItem;
580 }else if((!(this.childTask.length > 0)) && (this.childPredTask.length > 0)){
581 if((posParentTaskItem + widthParentTaskItem) > posPredTaskItem){
582 this.maxPosXMove = childPredPosX;
583 }
584 }
585 }
586 if(posPredTaskItem > 0){
587 if(this.minPosXMove <= posPredTaskItem){
588 this.minPosXMove = posPredTaskItem;
589 }
590 }
591 if((posPredTaskItem == 0) && (posParentTaskItem == 0)){
592 if(this.minPosXMove <= this.ganttChart.initialPos){
593 this.minPosXMove = this.ganttChart.initialPos;
594 }
595 }
596 }else{
597 if((posParentTaskItem > 0) && (posPredTaskItem == 0)){
598 this.minPosXMove = posParentTaskItem;
599 this.maxPosXMove = posParentTaskItem + widthParentTaskItem;
600 }else if((posParentTaskItem == 0) && (posPredTaskItem == 0)){
601 this.minPosXMove = this.ganttChart.initialPos;
602 this.maxPosXMove = -1;
603 }else if((posParentTaskItem > 0) && (posPredTaskItem > 0)){
604 this.minPosXMove = posPredTaskItem;
605 this.maxPosXMove = posParentTaskItem + widthParentTaskItem;
606 }else if((posParentTaskItem == 0) && (posPredTaskItem > 0)){
607 this.minPosXMove = posPredTaskItem;
608 this.maxPosXMove = -1;
609 }
610 if((this.parentTask) && (this.childPredTask.length > 0)){
611 var posChildTaskItem = this.getMaxPosPredChildTaskItem(this);
612 var posParentTaskItem = parseInt(this.parentTask.cTaskItem[0].style.left) + parseInt(this.parentTask.cTaskItem[0].firstChild.firstChild.width);
613 this.maxPosXMove = this.posX + widthTaskItem + posParentTaskItem - posChildTaskItem;
614 }
615 }
616 },
617 startResize: function(event){
618 this.mouseX = event.screenX;
619 this.getResizeInfo();
620 this.hideDescTask();
621 this.checkResize = true;
622 this.taskItemWidth = parseInt(this.cTaskItem[0].firstChild.firstChild.width);
623 },
624 getResizeInfo: function(){
625 var cTask = this.cTaskItem[0];
626 var posParentTaskItem = !this.parentTask ? 0 : parseInt(this.parentTask.cTaskItem[0].style.left);
627 var widthParentTaskItem = !this.parentTask ? 0 : parseInt(this.parentTask.cTaskItem[0].childNodes[0].firstChild.width);
628 var posTaskItem = parseInt(cTask.style.left);
629 var childPredPosX = 0;
630 var childParentPosX = 0;
631 if(this.childPredTask.length > 0){
632 var posChildTaskItem = null;
633 arrayUtil.forEach(this.childPredTask, function(cpTask){
634 if((!posChildTaskItem) || ((posChildTaskItem) && (posChildTaskItem > parseInt(cpTask.cTaskItem[0].style.left)))){
635 posChildTaskItem = parseInt(cpTask.cTaskItem[0].style.left);
636 }
637 }, this);
638 childPredPosX = posChildTaskItem;
639 }
640 if(this.childTask.length > 0){
641 var posChildTaskItem = null;
642 arrayUtil.forEach(this.childTask, function(cTask){
643 if((!posChildTaskItem) || ((posChildTaskItem) && (posChildTaskItem < (parseInt(cTask.cTaskItem[0].style.left) + parseInt(cTask.cTaskItem[0].firstChild.firstChild.width))))){
644 posChildTaskItem = parseInt(cTask.cTaskItem[0].style.left) + parseInt(cTask.cTaskItem[0].firstChild.firstChild.width);
645 }
646 }, this);
647 childParentPosX = posChildTaskItem;
648 }
649 this.minWidthResize = this.ganttChart.pixelsPerDay;
650 if(this.childTask.length > 0){
651 this.minWidthResize = childParentPosX - posTaskItem;
652 }
653 if((this.childPredTask.length > 0) && (!this.parentTask)){
654 this.maxWidthResize = childPredPosX - posTaskItem;
655 }else if((this.childPredTask.length > 0) && (this.parentTask)){
656 var w1 = posParentTaskItem + widthParentTaskItem - posTaskItem;
657 var w2 = childPredPosX - posTaskItem;
658 this.maxWidthResize = Math.min(w1, w2);
659 }else if((this.childPredTask.length == 0) && (this.parentTask)){
660 this.maxWidthResize = posParentTaskItem + widthParentTaskItem - posTaskItem;
661 }
662 },
663 createTaskItem: function(){
664 this.posX = this.ganttChart.getPosOnDate(this.taskItem.startTime);
665 var itemControl = domConstruct.create("div", {
666 id: this.taskItem.id,
667 className: "ganttTaskItemControl"
668 });
669 domStyle.set(itemControl, {
670 left: this.posX + "px",
671 top: this.posY + "px"
672 });
673 var divTaskItem = domConstruct.create("div", {className: "ganttTaskDivTaskItem"}, itemControl);
674 var tblTaskItem = domConstruct.create("table", {
675 cellPadding: "0",
676 cellSpacing: "0",
677 width: this.taskItem.duration * this.ganttChart.pixelsPerWorkHour + "px",
678 className: "ganttTaskTblTaskItem"
679 }, divTaskItem);
680 var rowTblTask = tblTaskItem.insertRow(tblTaskItem.rows.length);
681 if(this.taskItem.percentage != 0){
682 var cellTblTask = domConstruct.create("td", {
683 height: this.ganttChart.heightTaskItem + "px",
684 width: this.taskItem.percentage + "%"
685 }, rowTblTask);
686 cellTblTask.style.lineHeight = "1px";
687 var imageProgress = domConstruct.create("div", {
688 className: "ganttImageTaskProgressFilled"
689 }, cellTblTask);
690 domStyle.set(imageProgress, {
691 width: (this.taskItem.percentage * this.taskItem.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px",
692 height: this.ganttChart.heightTaskItem + "px"
693 });
694 }
695 if(this.taskItem.percentage != 100){
696 var cellTblTask = domConstruct.create("td", {
697 height: this.ganttChart.heightTaskItem + "px",
698 width: (100 - this.taskItem.percentage) + "%"
699 }, rowTblTask);
700 cellTblTask.style.lineHeight = "1px";
701 var imageProgressFill = domConstruct.create("div", {
702 className: "ganttImageTaskProgressBg"
703 }, cellTblTask);
704 domStyle.set(imageProgressFill, {
705 width: ((100 - this.taskItem.percentage) * this.taskItem.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px",
706 height: this.ganttChart.heightTaskItem + "px"
707 });
708 }
709 if(this.ganttChart.isContentEditable){
710 var divTaskInfo = domConstruct.create("div", {className: "ganttTaskDivTaskInfo"}, itemControl);
711 var tblTaskInfo = domConstruct.create("table", {
712 cellPadding: "0",
713 cellSpacing: "0",
714 height: this.ganttChart.heightTaskItem + "px",
715 width: this.taskItem.duration * this.ganttChart.pixelsPerWorkHour + "px"
716 }, divTaskInfo);
717 var rowTaskInfo = tblTaskInfo.insertRow(0);
718 var cellTaskInfo = domConstruct.create("td", {
719 align: "center",
720 vAlign: "top",
721 height: this.ganttChart.heightTaskItem + "px",
722 className: "ganttMoveInfo"
723 }, rowTaskInfo);
724 var divTaskName = domConstruct.create("div", {className: "ganttTaskDivTaskName"}, itemControl);
725 var divMove = domConstruct.create("div", {}, divTaskName);
726 domConstruct.create("input", {
727 className: "ganttTaskDivMoveInput",
728 type: "text"
729 }, divMove);
730 domStyle.set(divMove, {
731 background: "#000000",
732 opacity: 0
733 });
734 domStyle.set(divMove, {
735 height: this.ganttChart.heightTaskItem + "px",
736 width: this.taskItem.duration * this.ganttChart.pixelsPerWorkHour + "px"
737 });
738 //Creation resize area
739 var divResize = domConstruct.create("div", {className: "ganttTaskDivResize"}, divTaskName);
740 domConstruct.create("input", {
741 className: "ganttTaskDivResizeInput",
742 type: "text"
743 }, divResize);
744 domStyle.set(divResize, {
745 left: (this.taskItem.duration * this.ganttChart.pixelsPerWorkHour - 10) + "px",
746 height: this.ganttChart.heightTaskItem + "px",
747 width: "10px"
748 });
749 this.ganttChart._events.push(
750 on(divMove, "mousedown", lang.hitch(this, function(event){
751 //start move
752 this.moveMoveConn = on(document, "mousemove", lang.hitch(this, function(e){
753 this.checkMove && this.moveItem(e);
754 }));
755 this.moveUpConn = on(document, "mouseup", lang.hitch(this, function(){
756 if(this.checkMove){
757 this.endMove();
758 this.ganttChart.isMoving = false;
759 document.body.releaseCapture && document.body.releaseCapture();
760 this.moveMoveConn.remove();
761 this.moveUpConn.remove();
762 }
763 }));
764 this.startMove(event);
765 this.ganttChart.isMoving = true;
766 document.body.setCapture && document.body.setCapture(false);
767 }))
768 );
769 this.ganttChart._events.push(
770 on(divMove, "mouseover", lang.hitch(this, function(event){
771 event.target && (event.target.style.cursor = "move");
772 }))
773 );
774 this.ganttChart._events.push(
775 on(divMove, "mouseout", lang.hitch(this, function(event){
776 event.target.style.cursor = "";
777 }))
778 );
779 this.ganttChart._events.push(
780 on(divResize, "mousedown", lang.hitch(this, function(event){
781 //start resize
782 this.resizeMoveConn = on(document, "mousemove", lang.hitch(this, function(e){
783 this.checkResize && this.resizeItem(e);
784 }));
785 this.resizeUpConn = on(document, "mouseup", lang.hitch(this, function(){
786 if(this.checkResize){
787 this.endResizeItem();
788 this.ganttChart.isResizing = false;
789 document.body.releaseCapture && document.body.releaseCapture();
790 this.resizeMoveConn.remove();
791 this.resizeUpConn.remove();
792 }
793 }));
794 this.startResize(event);
795 this.ganttChart.isResizing = true;
796 document.body.setCapture && document.body.setCapture(false);
797 }))
798 );
799 this.ganttChart._events.push(
800 on(divResize, "mouseover", lang.hitch(this, function(event){
801 (!this.ganttChart.isMoving) && (!this.ganttChart.isResizing) && event.target && (event.target.style.cursor = "e-resize");
802 }))
803 );
804 this.ganttChart._events.push(
805 on(divResize, "mouseout", lang.hitch(this, function(event){
806 !this.checkResize && event.target && (event.target.style.cursor = "");
807 }))
808 );
809 }
810 return itemControl;
811 },
812 createTaskNameItem: function(){
813 var divName = domConstruct.create("div", {
814 id: this.taskItem.id,
815 className: "ganttTaskTaskNameItem",
816 title: this.taskItem.name + ", id: " + this.taskItem.id + " ",
817 innerHTML: this.taskItem.name
818 });
819 domStyle.set(divName, "top", this.posY + "px");
820 domAttr.set(divName, "tabIndex", 0);
821 if(this.ganttChart.isShowConMenu){
822 this.ganttChart._events.push(
823 on(divName, "mouseover", lang.hitch(this, function(event){
824 domClass.add(divName, "ganttTaskTaskNameItemHover");
825 clearTimeout(this.ganttChart.menuTimer);
826 this.ganttChart.tabMenu.clear();
827 this.ganttChart.tabMenu.show(event.target, this);
828 }))
829 );
830 this.ganttChart._events.push(
831 on(divName, "keydown", lang.hitch(this, function(event){
832 if(event.keyCode == keys.ENTER){
833 this.ganttChart.tabMenu.clear();
834 this.ganttChart.tabMenu.show(event.target, this);
835 }
836 if(this.ganttChart.tabMenu.isShow && (event.keyCode == keys.LEFT_ARROW || event.keyCode == keys.RIGHT_ARROW)){
837 focus(this.ganttChart.tabMenu.menuPanel.firstChild.rows[0].cells[0]);
838 }
839 if(this.ganttChart.tabMenu.isShow && event.keyCode == keys.ESCAPE){
840 this.ganttChart.tabMenu.hide();
841 }
842 }))
843 );
844 this.ganttChart._events.push(
845 on(divName, "mouseout", lang.hitch(this, function(){
846 domClass.remove(divName, "ganttTaskTaskNameItemHover");
847 clearTimeout(this.ganttChart.menuTimer);
848 this.ganttChart.menuTimer = setTimeout(lang.hitch(this, function(){
849 this.ganttChart.tabMenu.hide();
850 }), 200);
851 }))
852 );
853 this.ganttChart._events.push(
854 on(this.ganttChart.tabMenu.menuPanel, "mouseover", lang.hitch(this, function(){
855 clearTimeout(this.ganttChart.menuTimer);
856 }))
857 );
858 this.ganttChart._events.push(
859 on(this.ganttChart.tabMenu.menuPanel, "keydown", lang.hitch(this, function(event){
860 if(this.ganttChart.tabMenu.isShow && event.keyCode == keys.ESCAPE){
861 this.ganttChart.tabMenu.hide();
862 }
863 }))
864 );
865 this.ganttChart._events.push(
866 on(this.ganttChart.tabMenu.menuPanel, "mouseout", lang.hitch(this, function(){
867 clearTimeout(this.ganttChart.menuTimer);
868 this.ganttChart.menuTimer = setTimeout(lang.hitch(this, function(){
869 this.ganttChart.tabMenu.hide();
870 }), 200);
871 }))
872 );
873 }
874 return divName;
875 },
876 createTaskDescItem: function(){
877 var posX = (this.posX + this.taskItem.duration * this.ganttChart.pixelsPerWorkHour + 10);
878 var divDesc = domConstruct.create("div", {
879 innerHTML: this.objKeyToStr(this.getTaskOwner()),
880 className: "ganttTaskDescTask"
881 });
882 domStyle.set(divDesc, {
883 left: posX + "px",
884 top: this.posY + "px"
885 });
886 return this.descrTask = divDesc;
887 },
888 checkWidthTaskNameItem: function(){
889 if(this.cTaskNameItem[0].offsetWidth + this.cTaskNameItem[0].offsetLeft > this.ganttChart.maxWidthTaskNames){
890 var width = this.cTaskNameItem[0].offsetWidth + this.cTaskNameItem[0].offsetLeft - this.ganttChart.maxWidthTaskNames;
891 var countChar = Math.round(width / (this.cTaskNameItem[0].offsetWidth / this.cTaskNameItem[0].firstChild.length));
892 var tName = this.taskItem.name.substring(0, this.cTaskNameItem[0].firstChild.length - countChar - 3);
893 tName += "...";
894 this.cTaskNameItem[0].innerHTML = tName;
895 }
896 },
897 refreshTaskItem: function(itemControl){
898 this.posX = this.ganttChart.getPosOnDate(this.taskItem.startTime);
899 domStyle.set(itemControl, {
900 "left": this.posX + "px"
901 });
902 var divTaskItem = itemControl.childNodes[0];
903 var tblTaskItem = divTaskItem.firstChild;
904 tblTaskItem.width = (!this.taskItem.duration ? 1 : this.taskItem.duration * this.ganttChart.pixelsPerWorkHour) + "px";
905 var rowTblTask = tblTaskItem.rows[0];
906 if(this.taskItem.percentage != 0){
907 var cellTblTask = rowTblTask.firstChild;
908 cellTblTask.height = this.ganttChart.heightTaskItem + "px";
909 cellTblTask.width = this.taskItem.percentage + "%";
910 cellTblTask.style.lineHeight = "1px";
911 var imageProgress = cellTblTask.firstChild;
912 domStyle.set(imageProgress, {
913 width: (!this.taskItem.duration ? 1 : (this.taskItem.percentage * this.taskItem.duration * this.ganttChart.pixelsPerWorkHour / 100)) + "px",
914 height: this.ganttChart.heightTaskItem + "px"
915 });
916 }
917 if(this.taskItem.percentage != 100){
918 var cellTblTask = rowTblTask.lastChild;
919 cellTblTask.height = this.ganttChart.heightTaskItem + "px";
920 cellTblTask.width = (100 - this.taskItem.percentage) + "%";
921 cellTblTask.style.lineHeight = "1px";
922 var imageProgressFill = cellTblTask.firstChild;
923 domStyle.set(imageProgressFill, {
924 width: (!this.taskItem.duration ? 1 : ((100 - this.taskItem.percentage) * this.taskItem.duration * this.ganttChart.pixelsPerWorkHour / 100)) + "px",
925 height: this.ganttChart.heightTaskItem + "px"
926 });
927 }
928 if(this.ganttChart.isContentEditable){
929 var divTaskInfo = itemControl.childNodes[1];
930 var tblTaskInfo = divTaskInfo.firstChild;
931 tblTaskInfo.height = this.ganttChart.heightTaskItem + "px";
932 tblTaskInfo.width = (!this.taskItem.duration ? 1 : (this.taskItem.duration * this.ganttChart.pixelsPerWorkHour)) + "px";
933 var rowTaskInfo = tblTaskInfo.rows[0];
934 var cellTaskInfo = rowTaskInfo.firstChild;
935 cellTaskInfo.height = this.ganttChart.heightTaskItem + "px";
936 var divTaskName = itemControl.childNodes[2];
937 var divMove = divTaskName.firstChild;
938 divMove.style.height = this.ganttChart.heightTaskItem + "px";
939 divMove.style.width = (!this.taskItem.duration ? 1 : (this.taskItem.duration * this.ganttChart.pixelsPerWorkHour)) + "px";
940 //Creation resize area
941 var divResize = divTaskName.lastChild;
942 domStyle.set(divResize, {
943 "left": (this.taskItem.duration * this.ganttChart.pixelsPerWorkHour - 10) + "px"
944 });
945 divResize.style.height = this.ganttChart.heightTaskItem + "px";
946 divResize.style.width = "10px";
947 }
948 return itemControl;
949 },
950 refreshTaskDesc: function(divDesc){
951 var posX = (this.posX + this.taskItem.duration * this.ganttChart.pixelsPerWorkHour + 10);
952 domStyle.set(divDesc, {
953 "left": posX + "px"
954 });
955 return divDesc;
956 },
957 refreshConnectingLinesDS: function(arrLines){
958 var arrowImg = arrLines[1];
959 var lineVerticalRight = arrLines[0];
960 //horizontal line
961 var lineHorizontal = arrLines[2];
962 var posXPreviousTask = domStyle.get(this.predTask.cTaskItem[0], "left");
963 var posYPreviousTask = domStyle.get(this.predTask.cTaskItem[0], "top");
964 var posXChildTask = domStyle.get(this.cTaskItem[0], "left");
965 var posYChildTask = this.posY + 2;
966 //width task item
967
968 var widthPreviousTask = parseInt(this.predTask.cTaskItem[0].firstChild.firstChild.width);
969 if(posYPreviousTask < posYChildTask){
970 domStyle.set(lineVerticalRight, {
971 "height": (posYChildTask - this.ganttChart.heightTaskItem / 2 - posYPreviousTask - 3) + "px",
972 "left": (posXPreviousTask + widthPreviousTask - 20) + "px"
973 });
974 domStyle.set(lineHorizontal, {
975 "width": (15 + (posXChildTask - (widthPreviousTask + posXPreviousTask))) + "px",
976 "left": (posXPreviousTask + widthPreviousTask - 20) + "px"
977 });
978
979 domStyle.set(arrowImg, {
980 "left": (posXChildTask - 7) + "px"
981 });
982 }else{
983 domStyle.set(lineVerticalRight, {
984 "height": (posYPreviousTask + 2 - posYChildTask) + "px",
985 "left": (posXPreviousTask + widthPreviousTask - 20) + "px"
986 });
987 domStyle.set(lineHorizontal, {
988 "width": (15 + (posXChildTask - (widthPreviousTask + posXPreviousTask))) + "px",
989 "left": (posXPreviousTask + widthPreviousTask - 20) + "px"
990 });
991 domStyle.set(arrowImg, {
992 "left": (posXChildTask - 7) + "px"
993 });
994 }
995 return arrLines;
996 },
997 postLoadData: function(){
998 //TODO e.g. task relative info...
999 },
1000 refresh: function(){
1001 if(this.childTask && this.childTask.length > 0){
1002 arrayUtil.forEach(this.childTask, function(cTask){
1003 cTask.refresh();
1004 }, this);
1005 }
1006 //creation task item
1007 this.refreshTaskItem(this.cTaskItem[0]);
1008 this.refreshTaskDesc(this.cTaskItem[0].nextSibling);
1009 //Create Connecting Lines
1010
1011 if(this.taskItem.previousTask && this.predTask){
1012 this.refreshConnectingLinesDS(this.cTaskItem[1]);
1013 }
1014 return this;
1015 },
1016 create: function(){
1017 var containerTasks = this.ganttChart.contentData.firstChild;
1018
1019 var previousTask = this.taskItem.previousTask;
1020 var parentTask = this.taskItem.parentTask;
1021 var isCParentTask = (this.taskItem.cldTasks.length > 0);
1022 this.cTaskItem = [];
1023 this.cTaskNameItem = [];
1024 //creation arrTasks
1025 if(!parentTask){
1026 if(this.taskItem.previousParentTask){
1027 this.previousParentTask = this.project.getTaskById(this.taskItem.previousParentTask.id);
1028 var lastChildTask = this.ganttChart.getLastChildTask(this.previousParentTask);
1029 this.posY = parseInt(lastChildTask.cTaskItem[0].style.top)
1030 + this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra;
1031 this.previousParentTask.nextParentTask = this;
1032 }else{
1033 this.posY = parseInt(this.project.projectItem[0].style.top)
1034 + this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra;
1035 }
1036 }
1037 if(parentTask){
1038 var task = this.project.getTaskById(this.taskItem.parentTask.id);
1039 this.parentTask = task;
1040
1041 if(this.taskItem.previousChildTask){
1042 this.previousChildTask = this.project.getTaskById(this.taskItem.previousChildTask.id);
1043 var lastChildTask = this.ganttChart.getLastChildTask(this.previousChildTask);
1044 this.posY = domStyle.get(lastChildTask.cTaskItem[0], "top")
1045 + this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra;
1046 this.previousChildTask.nextChildTask = this;
1047 }else{
1048 this.posY = domStyle.get(task.cTaskItem[0], "top")
1049 + this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra;
1050 }
1051 task.childTask.push(this);
1052 }
1053 if(previousTask){
1054 var task = this.project.getTaskById(previousTask.id);
1055 this.predTask = task;
1056 task.childPredTask.push(this);
1057 }
1058 //creation task item
1059 this.cTaskItem.push(this.createTaskItem());
1060 containerTasks.appendChild(this.cTaskItem[0]);
1061 if(this.ganttChart.panelNames){
1062 this.cTaskNameItem.push(this.createTaskNameItem());
1063 this.ganttChart.panelNames.firstChild.appendChild(this.cTaskNameItem[0]);
1064 }
1065 containerTasks.appendChild(this.createTaskDescItem());
1066 //Create Connecting Lines
1067 var arrConnectingLines = [];
1068 if(previousTask){
1069 arrConnectingLines = this.createConnectingLinesDS();
1070 }
1071 this.cTaskItem.push(arrConnectingLines);
1072 if(this.ganttChart.panelNames){
1073 //Create Connecting Lines
1074 var arrConnectingLinesNames = [];
1075 if(parentTask){
1076 this.cTaskNameItem[0].style.left = domStyle.get(this.parentTask.cTaskNameItem[0], "left") + 15 + "px";
1077 arrConnectingLinesNames = this.createConnectingLinesPN();
1078 }
1079 this.checkWidthTaskNameItem();
1080 //Identifier
1081 this.checkPosition();
1082 var treeImg = null;
1083 if(isCParentTask){
1084 treeImg = this.createTreeImg();
1085 }
1086 this.cTaskNameItem.push(arrConnectingLinesNames);
1087 this.cTaskNameItem.push(treeImg);
1088 }
1089 this.adjustPanelTime();
1090 return this;
1091 },
1092 checkPosition: function(){
1093 //task name position: check Task Identifier
1094 if(!this.ganttChart.withTaskId){
1095 return;
1096 }
1097 var pos = domGeometry.getMarginBox(this.cTaskNameItem[0], true);
1098 if(this.taskIdentifier){
1099 if(this.childTask && this.childTask.length > 0){
1100 arrayUtil.forEach(this.childTask, function(cTask){
1101 cTask.checkPosition();
1102 }, this);
1103 }
1104 domStyle.set(this.taskIdentifier, {
1105 "left": (pos.l + pos.w + 4) + "px",
1106 "top": (pos.t - 1) + "px"
1107 });
1108 }else{
1109 this.taskIdentifier = domConstruct.create("div", {
1110 id: "TaskId_" + this.taskItem.id,
1111 className: "ganttTaskIdentifier",
1112 title: this.taskItem.id,
1113 innerHTML: this.taskItem.id
1114 }, this.cTaskNameItem[0].parentNode);
1115 domStyle.set(this.taskIdentifier, {
1116 left: (pos.l + pos.w + 4) + "px",
1117 top: (pos.t - 1) + "px"
1118 });
1119 }
1120 },
1121 createTreeImg: function(){
1122 var treeImg = domConstruct.create("div", {
1123 id: this.taskItem.id,
1124 className: "ganttImageTreeCollapse"
1125 });
1126 domAttr.set(treeImg, "tabIndex", 0);
1127 arrayUtil.forEach(["click", "keydown"], function(e){
1128 this.ganttChart._events.push(
1129 on(treeImg, e, lang.hitch(this, function(evt){
1130 if(e == "keydown" && evt.keyCode != keys.ENTER){ return; }
1131 if(this.isExpanded){
1132 domClass.remove(treeImg, "ganttImageTreeCollapse");
1133 domClass.add(treeImg, "ganttImageTreeExpand");
1134 this.isExpanded = false;
1135 this.hideChildTasks(this);
1136 this.shiftCurrentTasks(this, -this.hideTasksHeight);
1137 this.ganttChart.checkPosition();
1138 }else{
1139 domClass.remove(treeImg, "ganttImageTreeExpand");
1140 domClass.add(treeImg, "ganttImageTreeCollapse");
1141 this.isExpanded = true;
1142 this.shiftCurrentTasks(this, this.hideTasksHeight);
1143 this.showChildTasks(this, true);
1144 this.hideTasksHeight = 0;
1145 this.ganttChart.checkPosition();
1146 }
1147 }))
1148 );
1149 }, this);
1150 this.ganttChart.panelNames.firstChild.appendChild(treeImg);
1151 domClass.add(treeImg, "ganttTaskTreeImage");
1152 domStyle.set(treeImg, {
1153 left: (domStyle.get(this.cTaskNameItem[0], "left") - 12) + "px",
1154 top: (domStyle.get(this.cTaskNameItem[0], "top") + 3) + "px"
1155 });
1156 return treeImg;
1157 },
1158 setPreviousTask: function(previousTaskId){
1159 if(previousTaskId == ""){
1160 this.clearPredTask();
1161 }else{
1162 var task = this.taskItem;
1163 if(task.id == previousTaskId){
1164 return false;
1165 }
1166 var predTaskObj = this.project.getTaskById(previousTaskId);
1167 if(!predTaskObj){
1168 return false;
1169 }
1170 var predTask = predTaskObj.taskItem;
1171 var a1 = predTask.parentTask == null, a2 = task.parentTask == null;
1172 if(a1 && !a2 || !a1 && a2 || !a1 && !a2 && (predTask.parentTask.id != task.parentTask.id)){
1173 return false;
1174 }
1175 //check time
1176 var startTime = task.startTime.getTime(),
1177 pest = predTask.startTime.getTime(),
1178 pdur = predTask.duration * 24 * 60 * 60 * 1000 / predTaskObj.ganttChart.hsPerDay;
1179 if((pest+pdur) > startTime){
1180 return false;
1181 }
1182 // remove current connection
1183 this.clearPredTask();
1184 if(!this.ganttChart.checkPosPreviousTask(predTask, task)){
1185 this.ganttChart.correctPosPreviousTask(predTask, task, this);
1186 }
1187 task.previousTaskId = previousTaskId;
1188 task.previousTask = predTask;
1189 this.predTask = predTaskObj;
1190 predTaskObj.childPredTask.push(this);
1191 this.cTaskItem[1] = this.createConnectingLinesDS();
1192 }
1193 return true;
1194 },
1195 clearPredTask: function(){
1196 if(this.predTask){
1197 var ch = this.predTask.childPredTask;
1198 for(var i = 0; i < ch.length; i++){
1199 if(ch[i] == this){
1200 ch.splice(i, 1);
1201 break;
1202 }
1203 }
1204 for(var i = 0; i < this.cTaskItem[1].length; i++){
1205 this.cTaskItem[1][i].parentNode.removeChild(this.cTaskItem[1][i]);
1206 }
1207 this.cTaskItem[1] = [];
1208 this.taskItem.previousTaskId = null;
1209 this.taskItem.previousTask = null;
1210 this.predTask = null;
1211 }
1212 },
1213 setStartTime: function(startTime, shiftChild){
1214 this.moveChild = shiftChild;
1215 this.getMoveInfo();
1216 var pos = this.ganttChart.getPosOnDate(startTime);
1217 if((parseInt(this.cTaskItem[0].firstChild.firstChild.width) + pos > this.maxPosXMove) && (this.maxPosXMove != -1)){
1218 this.maxPosXMove = -1;
1219 this.minPosXMove = -1;
1220 return false;
1221 }
1222 if(pos < this.minPosXMove){
1223 this.maxPosXMove = -1;
1224 this.minPosXMove = -1;
1225 return false;
1226 }
1227 this.cTaskItem[0].style.left = pos;
1228 var width = pos - this.posX;
1229 this.moveCurrentTaskItem(width, shiftChild);
1230 this.project.shiftProjectItem();
1231 this.descrTask.innerHTML = this.objKeyToStr(this.getTaskOwner());
1232 this.adjustPanelTime();
1233 this.posX = 0;
1234 this.maxPosXMove = -1;
1235 this.minPosXMove = -1;
1236 return true;
1237 },
1238 setDuration: function(duration){
1239 this.getResizeInfo();
1240 var width = this.ganttChart.getWidthOnDuration(duration);
1241 if((width > this.maxWidthResize) && (this.maxWidthResize != -1)){
1242 return false;
1243 }else if(width < this.minWidthResize){
1244 return false;
1245 }else{
1246 this.taskItemWidth = parseInt(this.cTaskItem[0].firstChild.firstChild.width);
1247 this.resizeTaskItem(width);
1248 this.endResizeItem();
1249 this.descrTask.innerHTML = this.objKeyToStr(this.getTaskOwner());
1250 return true;
1251 }
1252 },
1253 setTaskOwner: function(owner){
1254 owner = (owner == null || owner == undefined) ? "" : owner;
1255 this.taskItem.taskOwner = owner;
1256 this.descrTask.innerHTML = this.objKeyToStr(this.getTaskOwner());
1257 return true;
1258 },
1259 setPercentCompleted: function(percentage){
1260 percentage = parseInt(percentage);
1261 if(isNaN(percentage) || percentage > 100 || percentage < 0){
1262 return false;
1263 }
1264 var trow = this.cTaskItem[0].childNodes[0].firstChild.rows[0],
1265 rc0 = trow.cells[0], rc1 = trow.cells[1];
1266 if((percentage != 0) && (percentage != 100)){
1267 if((this.taskItem.percentage != 0) && (this.taskItem.percentage != 100)){
1268 rc0.width = percentage + "%";
1269 rc1.width = 100 - percentage + "%";
1270 }else if((this.taskItem.percentage == 0) || (this.taskItem.percentage == 100)){
1271 rc0.parentNode.removeChild(rc0);
1272 var cellTblTask = domConstruct.create("td", {
1273 height: this.ganttChart.heightTaskItem + "px",
1274 width: percentage + "%"
1275 }, trow);
1276 cellTblTask.style.lineHeight = "1px";
1277 var imageProgressFill = domConstruct.create("div", {
1278 className: "ganttImageTaskProgressFilled"
1279 }, cellTblTask);
1280 domStyle.set(imageProgressFill, {
1281 width: (percentage * this.taskItem.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px",
1282 height: this.ganttChart.heightTaskItem + "px"
1283 });
1284
1285 cellTblTask = domConstruct.create("td", {
1286 height: this.ganttChart.heightTaskItem + "px",
1287 width: (100 - percentage) + "%"
1288 }, trow);
1289 cellTblTask.style.lineHeight = "1px";
1290 imageProgressFill = domConstruct.create("div", {
1291 className: "ganttImageTaskProgressBg"
1292 }, cellTblTask);
1293 domStyle.set(imageProgressFill, {
1294 width: ((100 - percentage) * this.taskItem.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px",
1295 height: this.ganttChart.heightTaskItem + "px"
1296 });
1297 }
1298 }else if(percentage == 0){
1299 if((this.taskItem.percentage != 0) && (this.taskItem.percentage != 100)){
1300 rc0.parentNode.removeChild(rc0);
1301 rc1.width = 100 + "%";
1302 }else{
1303 domClass.remove(rc0.firstChild, "ganttImageTaskProgressFilled");
1304 domClass.add(rc0.firstChild, "ganttImageTaskProgressBg");
1305 }
1306 }else if(percentage == 100){
1307 if((this.taskItem.percentage != 0) && (this.taskItem.percentage != 100)){
1308 rc1.parentNode.removeChild(rc1);
1309 rc0.width = 100 + "%";
1310 }else{
1311 domClass.remove(rc0.firstChild, "ganttImageTaskProgressBg");
1312 domClass.add(rc0.firstChild, "ganttImageTaskProgressFilled");
1313 }
1314 }
1315 this.taskItem.percentage = percentage;
1316 this.taskItemWidth = parseInt(this.cTaskItem[0].firstChild.firstChild.width);
1317 this.resizeTaskItem(this.taskItemWidth);
1318 this.endResizeItem();
1319 this.descrTask.innerHTML = this.objKeyToStr(this.getTaskOwner());
1320 return true;
1321 },
1322 setName: function(name){
1323 if(name){
1324 this.taskItem.name = name;
1325 this.cTaskNameItem[0].innerHTML = name;
1326 this.cTaskNameItem[0].title = name;
1327 this.checkWidthTaskNameItem();
1328 this.checkPosition();
1329 this.descrTask.innerHTML = this.objKeyToStr(this.getTaskOwner());
1330 this.adjustPanelTime();
1331 }
1332 }
1333 });
1334 });