source: Dev/branches/rest-dojo-ui/client/dojox/gantt/GanttTaskItem.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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