source: Dev/trunk/src/client/dojox/gantt/GanttProjectItem.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.6 KB
Line 
1define([
2        "./GanttTaskItem",
3        "dojo/_base/declare",
4        "./GanttProjectControl",
5        "dojo/domReady!"
6], function(GanttTaskItem, declare){
7        return declare("dojox.gantt.GanttProjectItem", [GanttTaskItem], {
8                constructor: function(configuration){
9                        //id is required
10                        this.id = configuration.id;
11                        this.name = configuration.name || this.id;
12                        this.startDate = configuration.startDate || new Date();
13                        this.parentTasks = [];
14                },
15                getTaskById: function(id){
16                        for(var i = 0; i < this.parentTasks.length; i++){
17                                var pTask = this.parentTasks[i];
18                                var task = this.getTaskByIdInTree(pTask, id);
19                                if(task){
20                                        return task;
21                                }
22                        }
23                        return null;
24                },
25                getTaskByIdInTree: function(parentTask, id){
26                        if(parentTask.id == id){
27                                return parentTask;
28                        }else{
29                                for(var i = 0; i < parentTask.cldTasks.length; i++){
30                                        var pcTask = parentTask.cldTasks[i];
31                                        if(pcTask.id == id){
32                                                return pcTask;
33                                        }
34                                        if(pcTask.cldTasks.length > 0){
35                                                if(pcTask.cldTasks.length > 0){
36                                                        var cTask = this.getTaskByIdInTree(pcTask, id);
37                                                        if(cTask){
38                                                                return cTask;
39                                                        }
40                                                }
41                                        }
42                                }
43                        }
44                        return null;
45                },
46                addTask: function(task){
47                        this.parentTasks.push(task);
48                        task.setProject(this);
49                },
50                deleteTask: function(id){
51                        var task = this.getTaskById(id);
52                        if(!task){return;}
53                        if(!task.parentTask){
54                                for(var i = 0; i < this.parentTasks.length; i++){
55                                        var pTask = this.parentTasks[i];
56                                        if(pTask.id == id){
57                                                if(pTask.nextParentTask){
58                                                        if(pTask.previousParentTask){
59                                                                pTask.previousParentTask.nextParentTask = pTask.nextParentTask;
60                                                                pTask.nextParentTask.previousParentTask = pTask.previousParentTask;
61                                                        }else{
62                                                                pTask.nextParentTask.previousParentTask = null;
63                                                        }
64                                                }else{
65                                                        if(pTask.previousParentTask){
66                                                                pTask.previousParentTask.nextParentTask = null;
67                                                        }
68                                                }
69                                                pTask = null;
70                                                this.parentTasks.splice(i, 1);
71                                                break;
72                                        }
73                                }
74                        }else{
75                                var parentTask = task.parentTask;
76                                for(var i = 0; i < parentTask.cldTasks.length; i++){
77                                        var pcTask = parentTask.cldTasks[i];
78                                        if(pcTask.id == id){
79                                                if(pcTask.nextChildTask){
80                                                        if(pcTask.previousChildTask){
81                                                                pcTask.previousChildTask.nextChildTask = pcTask.nextChildTask;
82                                                                pcTask.nextChildTask.previousChildTask = pcTask.previousChildTask;
83                                                        }else{
84                                                                pcTask.nextChildTask.previousChildTask = null;
85                                                        }
86                                                }else{
87                                                        if(pcTask.previousChildTask){
88                                                                pcTask.previousChildTask.nextChildTask = null;
89                                                        }
90                                                }
91                                                pcTask = null;
92                                                parentTask.cldTasks.splice(i, 1);
93                                                break;
94                                        }
95                                }
96                        }
97                }
98        });
99});
Note: See TracBrowser for help on using the repository browser.