Debian Codegraph @

dojox/gantt/GanttProjectControl.js

raw symbols SCIP
1 define([
2 "./GanttTaskItem",
3 "./GanttTaskControl",
4 "dijit/focus",
5 "dojo/_base/declare",
6 "dojo/_base/array",
7 "dojo/_base/lang",
8 "dojo/date/locale",
9 "dojo/request",
10 "dojo/on",
11 "dojo/dom",
12 "dojo/dom-class",
13 "dojo/dom-construct",
14 "dojo/dom-style",
15 "dojo/dom-attr",
16 "dojo/dom-geometry",
17 "dojo/keys",
18 "dojo/domReady!"
19 ], function(GanttTaskItem, GanttTaskControl, focus,
20 declare, arrayUtil, lang, locale, request, on,
21 dom, domClass, domConstruct, domStyle, domAttr, domGeometry, keys){
22 return declare("dojox.gantt.GanttProjectControl", [], {
23 constructor: function(ganttChart, projectItem){
24 this.project = projectItem;
25 this.ganttChart = ganttChart;
26 this.descrProject = null;
27 this.projectItem = null;
28 this.projectNameItem = null;
29 this.posY = 0;
30 this.posX = 0;
31 this.nextProject = null;
32 this.previousProject = null;
33 this.arrTasks = [];
34 this.percentage = 0;
35 this.duration = 0;
36 },
37 checkWidthProjectNameItem: function(){
38 if(this.projectNameItem.offsetWidth + this.projectNameItem.offsetLeft > this.ganttChart.maxWidthTaskNames){
39 var width = this.projectNameItem.offsetWidth + this.projectNameItem.offsetLeft - this.ganttChart.maxWidthTaskNames;
40 var countChar = Math.round(width / (this.projectNameItem.offsetWidth / this.projectNameItem.firstChild.length));
41 var pName = this.project.name.substring(0, this.projectNameItem.firstChild.length - countChar - 3);
42 pName += "...";
43 this.projectNameItem.innerHTML = pName;
44 }
45 },
46 refreshProjectItem: function(projectItem){
47 this.percentage = this.getPercentCompleted();
48 domStyle.set(projectItem, {
49 "left": this.posX + "px",
50 "width": this.duration * this.ganttChart.pixelsPerWorkHour + "px"
51 });
52 var tblProjectItem = projectItem.firstChild;
53 var width = this.duration * this.ganttChart.pixelsPerWorkHour;
54 tblProjectItem.width = ((width == 0) ? 1 : width) + "px";
55 tblProjectItem.style.width = ((width == 0) ? 1 : width) + "px";
56 var rowprojectItem = tblProjectItem.rows[0];
57 if(this.percentage != -1){
58 if(this.percentage != 0){
59 var cellprojectItem = rowprojectItem.firstChild;
60 cellprojectItem.width = this.percentage + "%";
61 var imageProgress = cellprojectItem.firstChild;
62 domStyle.set(imageProgress, {
63 width: (!this.duration ? 1 : (this.percentage * this.duration * this.ganttChart.pixelsPerWorkHour / 100)) + "px",
64 height: this.ganttChart.heightTaskItem + "px"
65 })
66 }
67 if(this.percentage != 100){
68 var cellprojectItem = rowprojectItem.lastChild;
69 cellprojectItem.width = (100 - this.percentage) + "%";
70 var imageProgress = cellprojectItem.firstChild;
71 domStyle.set(imageProgress, {
72 width: (!this.duration ? 1 : ((100 - this.percentage) * this.duration * this.ganttChart.pixelsPerWorkHour / 100)) + "px",
73 height: this.ganttChart.heightTaskItem + "px"
74 })
75 }
76 }else{
77 var cellprojectItem = rowprojectItem.firstChild;
78 cellprojectItem.width = "1px";
79 var imageProgress = cellprojectItem.firstChild;
80 domStyle.set(imageProgress, {
81 width: "1px",
82 height: this.ganttChart.heightTaskItem + "px"
83 })
84 }
85 var divTaskInfo = projectItem.lastChild;
86 var tblTaskInfo = divTaskInfo.firstChild;
87 domStyle.set(tblTaskInfo, {
88 height: this.ganttChart.heightTaskItem + "px",
89 width: (!this.duration ? 1 : (this.duration * this.ganttChart.pixelsPerWorkHour)) + "px"
90 });
91 var rowTaskInfo = tblTaskInfo.rows[0];
92 var cellTaskInfo = rowTaskInfo.firstChild;
93 cellTaskInfo.height = this.ganttChart.heightTaskItem + "px";
94 if(this.project.parentTasks.length == 0){
95 projectItem.style.display = "none";
96 }
97 return projectItem;
98 },
99 refreshDescrProject: function(divDesc){
100 var posX = (this.posX + this.duration * this.ganttChart.pixelsPerWorkHour + 10);
101 domStyle.set(divDesc, {
102 "left": posX + "px"
103 });
104 if(this.project.parentTasks.length == 0){
105 this.descrProject.style.visibility = 'hidden';
106 }
107 return divDesc;
108 },
109 postLoadData: function(){
110 //TODO e.g. project relative info...
111 },
112 refresh: function(){
113 this.posX = (this.project.startDate - this.ganttChart.startDate) / (60 * 60 * 1000) * this.ganttChart.pixelsPerHour;
114 this.refreshProjectItem(this.projectItem[0]);
115 this.refreshDescrProject(this.projectItem[0].nextSibling);
116 return this;
117 },
118 create: function(){
119 var containerTasks = this.ganttChart.contentData.firstChild;
120 this.posX = (this.project.startDate - this.ganttChart.startDate) / (60 * 60 * 1000) * this.ganttChart.pixelsPerHour;
121 if(this.previousProject){
122 if(this.previousProject.arrTasks.length > 0){
123 var lastChildTask = this.ganttChart.getLastChildTask(this.previousProject.arrTasks[this.previousProject.arrTasks.length - 1]);
124 this.posY = parseInt(lastChildTask.cTaskItem[0].style.top) + this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra;
125 }else{
126 this.posY = parseInt(this.previousProject.projectItem[0].style.top) + this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra;
127 }
128 }else{
129 this.posY = 6;
130 }
131 var containerNames = this.ganttChart.panelNames.firstChild;
132 this.projectNameItem = this.createProjectNameItem();
133 containerNames.appendChild(this.projectNameItem);
134 this.checkWidthProjectNameItem();
135 this.projectItem = [this.createProjectItem(), []];
136 containerTasks.appendChild(this.projectItem[0]);
137 containerTasks.appendChild(this.createDescrProject());
138 this.adjustPanelTime();
139 },
140 getTaskById: function(id){
141 for(var i = 0; i < this.arrTasks.length; i++){
142 var aTask = this.arrTasks[i];
143 var task = this.searchTaskInTree(aTask, id);
144 if(task){
145 return task;
146 }
147 }
148 return null;
149 },
150 searchTaskInTree: function(task, id){
151 if(task.taskItem.id == id){
152 return task;
153 }else{
154 for(var i = 0; i < task.childTask.length; i++){
155 var cTask = task.childTask[i];
156 if(cTask.taskItem.id == id){
157 return cTask;
158 }else{
159 if(cTask.childTask.length > 0){
160 var cTask = this.searchTaskInTree(cTask, id);
161 if(cTask){
162 return cTask;
163 }
164 }
165 }
166 }
167 }
168 return null;
169 },
170 shiftProjectItem: function(){
171 var posItemL = null;
172 var posItemR = null;
173 var posProjectItemL = parseInt(this.projectItem[0].style.left);
174 for(var i = 0; i < this.arrTasks.length; i++){
175 var aTask = this.arrTasks[i];
176 var tmpPosItemL = parseInt(aTask.cTaskItem[0].style.left);
177 var tmpPosItemR = parseInt(aTask.cTaskItem[0].style.left) + parseInt(aTask.cTaskItem[0].firstChild.firstChild.width);
178 if(!posItemL){
179 posItemL = tmpPosItemL;
180 }
181 if(!posItemR){
182 posItemR = tmpPosItemR;
183 }
184 if(posItemL > tmpPosItemL){
185 posItemL = tmpPosItemL;
186 }
187 if(posItemR < tmpPosItemR){
188 posItemR = tmpPosItemR;
189 }
190 }
191 if(posItemL != posProjectItemL){
192 this.project.startDate = new Date(this.ganttChart.startDate);
193 this.project.startDate.setHours(this.project.startDate.getHours() + (posItemL / this.ganttChart.pixelsPerHour));
194 }
195 this.projectItem[0].style.left = posItemL + "px";
196 this.resizeProjectItem(posItemR - posItemL);
197 this.duration = Math.round(parseInt(this.projectItem[0].firstChild.width) / (this.ganttChart.pixelsPerWorkHour));
198 this.shiftDescrProject();
199 this.adjustPanelTime();
200 },
201 adjustPanelTime: function(){
202 var projectItem = this.projectItem[0];
203 var width = parseInt(projectItem.style.left) + parseInt(projectItem.firstChild.style.width) + this.ganttChart.panelTimeExpandDelta;
204 width += this.descrProject.offsetWidth;
205 this.ganttChart.adjustPanelTime(width);
206 },
207 resizeProjectItem: function(width){
208 var percentage = this.percentage,
209 pItem = this.projectItem[0];
210 if(percentage > 0 && percentage < 100){
211 pItem.firstChild.style.width = width + "px";
212 pItem.firstChild.width = width + "px";
213 pItem.style.width = width + "px";
214 var firstRow = pItem.firstChild.rows[0];
215 firstRow.cells[0].firstChild.style.width = Math.round(width * percentage / 100) + "px";
216 firstRow.cells[0].firstChild.style.height = this.ganttChart.heightTaskItem + "px";
217 firstRow.cells[1].firstChild.style.width = Math.round(width * (100 - percentage) / 100) + "px";
218 firstRow.cells[1].firstChild.style.height = this.ganttChart.heightTaskItem + "px";
219 pItem.lastChild.firstChild.width = width + "px";
220 }else if(percentage == 0 || percentage == 100){
221 pItem.firstChild.style.width = width + "px";
222 pItem.firstChild.width = width + "px";
223 pItem.style.width = width + "px";
224 var firstRow = pItem.firstChild.rows[0];
225 firstRow.cells[0].firstChild.style.width = width + "px";
226 firstRow.cells[0].firstChild.style.height = this.ganttChart.heightTaskItem + "px";
227 pItem.lastChild.firstChild.width = width + "px";
228 }
229 },
230 shiftDescrProject: function(){
231 var posX = (parseInt(this.projectItem[0].style.left) + this.duration * this.ganttChart.pixelsPerWorkHour + 10);
232 this.descrProject.style.left = posX + "px";
233 this.descrProject.innerHTML = this.getDescStr();
234 },
235 showDescrProject: function(){
236 var posX = (parseInt(this.projectItem[0].style.left) + this.duration * this.ganttChart.pixelsPerWorkHour + 10);
237 this.descrProject.style.left = posX + "px";
238 this.descrProject.style.visibility = 'visible';
239 this.descrProject.innerHTML = this.getDescStr();
240 },
241 hideDescrProject: function(){
242 this.descrProject.style.visibility = 'hidden';
243 },
244 getDescStr: function(){
245 return this.duration/this.ganttChart.hsPerDay + " days, " + this.duration + " hours";
246 },
247 createDescrProject: function(){
248 var posX = (this.posX + this.duration * this.ganttChart.pixelsPerWorkHour + 10);
249 var divDesc = domConstruct.create("div", {
250 innerHTML: this.getDescStr(),
251 className: "ganttDescProject"
252 });
253 domStyle.set(divDesc, {
254 left: posX + "px",
255 top: this.posY + "px"
256 });
257 this.descrProject = divDesc;
258 if(this.project.parentTasks.length == 0){
259 this.descrProject.style.visibility = 'hidden';
260 }
261 return divDesc;
262 },
263 createProjectItem: function(){
264 this.percentage = this.getPercentCompleted();
265 this.duration = this.getDuration();
266 var projectItem = domConstruct.create("div", {
267 id: this.project.id,
268 className: "ganttProjectItem"
269 });
270 domStyle.set(projectItem, {
271 left: this.posX + "px",
272 top: this.posY + "px",
273 width: this.duration * this.ganttChart.pixelsPerWorkHour + "px"
274 });
275 var tblProjectItem = domConstruct.create("table", {
276 cellPadding: "0",
277 cellSpacing: "0",
278 className: "ganttTblProjectItem"
279 }, projectItem);
280 var width = this.duration * this.ganttChart.pixelsPerWorkHour;
281 tblProjectItem.width = ((width == 0) ? 1 : width) + "px";
282 tblProjectItem.style.width = ((width == 0) ? 1 : width) + "px";
283
284 var rowprojectItem = tblProjectItem.insertRow(tblProjectItem.rows.length);
285 if(this.percentage != -1){
286 if(this.percentage != 0){
287 var cellprojectItem = domConstruct.create("td", {
288 width: this.percentage + "%"
289 }, rowprojectItem);
290 cellprojectItem.style.lineHeight = "1px";
291 var imageProgress = domConstruct.create("div", {
292 className: "ganttImageProgressFilled"
293 }, cellprojectItem);
294 domStyle.set(imageProgress, {
295 width: (this.percentage * this.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px",
296 height: this.ganttChart.heightTaskItem + "px"
297 });
298 }
299 if(this.percentage != 100){
300 var cellprojectItem = domConstruct.create("td", {
301 width: (100 - this.percentage) + "%"
302 }, rowprojectItem);
303 cellprojectItem.style.lineHeight = "1px";
304 var imageProgress = domConstruct.create("div", {
305 className: "ganttImageProgressBg"
306 }, cellprojectItem);
307 domStyle.set(imageProgress, {
308 width: ((100 - this.percentage) * this.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px",
309 height: this.ganttChart.heightTaskItem + "px"
310 });
311 }
312 }else{
313 var cellprojectItem = domConstruct.create("td", {
314 width: "1px"
315 }, rowprojectItem);
316 cellprojectItem.style.lineHeight = "1px";
317 var imageProgress = domConstruct.create("div", {
318 className: "ganttImageProgressBg"
319 }, cellprojectItem);
320 domStyle.set(imageProgress, {
321 width: "1px",
322 height: this.ganttChart.heightTaskItem + "px"
323 });
324 }
325 var divTaskInfo = domConstruct.create("div", {className: "ganttDivTaskInfo"});
326 var tblTaskInfo = domConstruct.create("table", {
327 cellPadding: "0",
328 cellSpacing: "0",
329 height: this.ganttChart.heightTaskItem + "px",
330 width: ((this.duration * this.ganttChart.pixelsPerWorkHour == 0) ? 1 : this.duration * this.ganttChart.pixelsPerWorkHour) + "px"
331 }, divTaskInfo);
332 var rowTaskInfo = tblTaskInfo.insertRow(0);
333 domConstruct.create("td", {
334 align: "center",
335 vAlign: "top",
336 height: this.ganttChart.heightTaskItem + "px",
337 className: "ganttMoveInfo"
338 }, rowTaskInfo);
339 projectItem.appendChild(divTaskInfo);
340 if(this.project.parentTasks.length == 0){
341 projectItem.style.display = "none";
342 }
343 return projectItem;
344 },
345 createProjectNameItem: function(){
346 var divName = domConstruct.create("div", {
347 className: "ganttProjectNameItem",
348 innerHTML: this.project.name,
349 title: this.project.name
350 });
351 domStyle.set(divName, {
352 left: "5px",
353 top: this.posY + "px"
354 });
355 domAttr.set(divName, "tabIndex", 0);
356 if(this.ganttChart.isShowConMenu){
357 this.ganttChart._events.push(
358 on(divName, "mouseover", lang.hitch(this, function(event){
359 domClass.add(divName, "ganttProjectNameItemHover");
360 clearTimeout(this.ganttChart.menuTimer);
361 this.ganttChart.tabMenu.clear();
362 this.ganttChart.tabMenu.show(event.target, this);
363 }))
364 );
365 this.ganttChart._events.push(
366 on(divName, "keydown", lang.hitch(this, function(event){
367 if(event.keyCode == keys.ENTER){
368 this.ganttChart.tabMenu.clear();
369 this.ganttChart.tabMenu.show(event.target, this);
370 }
371 if(this.ganttChart.tabMenu.isShow && (event.keyCode == keys.LEFT_ARROW || event.keyCode == keys.RIGHT_ARROW)){
372 focus(this.ganttChart.tabMenu.menuPanel.firstChild.rows[0].cells[0]);
373 }
374 if(this.ganttChart.tabMenu.isShow && event.keyCode == keys.ESCAPE){
375 this.ganttChart.tabMenu.hide();
376 }
377 }))
378 );
379 this.ganttChart._events.push(
380 on(divName, "mouseout", lang.hitch(this, function(){
381 domClass.remove(divName, "ganttProjectNameItemHover");
382 clearTimeout(this.ganttChart.menuTimer);
383 this.ganttChart.menuTimer = setTimeout(lang.hitch(this, function(){
384 this.ganttChart.tabMenu.hide();
385 }), 200);
386 }))
387 );
388 this.ganttChart._events.push(
389 on(this.ganttChart.tabMenu.menuPanel, "mouseover", lang.hitch(this, function(){
390 clearTimeout(this.ganttChart.menuTimer);
391 }))
392 );
393 this.ganttChart._events.push(
394 on(this.ganttChart.tabMenu.menuPanel, "keydown", lang.hitch(this, function(){
395 if(this.ganttChart.tabMenu.isShow && event.keyCode == keys.ESCAPE){
396 this.ganttChart.tabMenu.hide();
397 }
398 }))
399 );
400 this.ganttChart._events.push(
401 on(this.ganttChart.tabMenu.menuPanel, "mouseout", lang.hitch(this, function(){
402 clearTimeout(this.ganttChart.menuTimer);
403 this.ganttChart.menuTimer = setTimeout(lang.hitch(this, function(){
404 this.ganttChart.tabMenu.hide();
405 }), 200);
406 }))
407 );
408 }
409 return divName;
410 },
411 getPercentCompleted: function(){
412 var sum = 0;
413 arrayUtil.forEach(this.project.parentTasks, function(ppTask){
414 sum += parseInt(ppTask.percentage);
415 }, this);
416 if(this.project.parentTasks.length != 0){
417 return Math.round(sum / this.project.parentTasks.length);
418 }else{
419 return -1;
420 }
421 },
422 getDuration: function(){
423 var duration = 0, tmpDuration = 0;
424 if(this.project.parentTasks.length > 0){
425 arrayUtil.forEach(this.project.parentTasks, function(ppTask){
426 tmpDuration = ppTask.duration * 24 / this.ganttChart.hsPerDay + (ppTask.startTime - this.ganttChart.startDate) / (60 * 60 * 1000);
427 if(tmpDuration > duration){
428 duration = tmpDuration;
429 }
430 }, this);
431 return ((duration - this.posX) / 24) * this.ganttChart.hsPerDay;
432 }else{
433 return 0;
434 }
435 },
436 deleteTask: function(id){
437 var task = this.getTaskById(id);
438 if(task){
439 this.deleteChildTask(task);
440 this.ganttChart.checkPosition();
441 }
442 },
443 setName: function(name){
444 if(name){
445 this.project.name = name;
446 this.projectNameItem.innerHTML = name;
447 this.projectNameItem.title = name;
448 this.checkWidthProjectNameItem();
449
450 this.descrProject.innerHTML = this.getDescStr();
451 this.adjustPanelTime();
452 }
453 },
454 setPercentCompleted: function(percentage){
455 percentage = parseInt(percentage);
456 if(isNaN(percentage) || percentage > 100 || percentage < 0){
457 return false;
458 }
459 var prow = this.projectItem[0].firstChild.rows[0],
460 rc0 = prow.cells[0], rc1 = prow.cells[1];
461 if((percentage > 0) && (percentage < 100) && (this.percentage > 0) && (this.percentage < 100)){
462 rc0.width = parseInt(percentage) + "%";
463 rc0.firstChild.style.width = (percentage * this.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px";
464 rc1.width = (100 - parseInt(percentage)) + "%";
465 rc1.firstChild.style.width = ((100 - percentage) * this.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px";
466 }else if(((percentage == 0) || (percentage == 100)) && (this.percentage > 0) && (this.percentage < 100)){
467 if(percentage == 0){
468 rc0.parentNode.removeChild(rc0);
469 rc1.width = 100 + "%";
470 rc1.firstChild.style.width = this.duration * this.ganttChart.pixelsPerWorkHour + "px";
471 }else if(percentage == 100){
472 rc1.parentNode.removeChild(rc1);
473 rc0.width = 100 + "%";
474 rc0.firstChild.style.width = this.duration * this.ganttChart.pixelsPerWorkHour + "px";
475 }
476 }else if(((percentage == 0) || (percentage == 100)) && ((this.percentage == 0) || (this.percentage == 100))){
477 if((percentage == 0) && (this.percentage == 100)){
478 domClass.remove(rc0.firstChild, "ganttImageProgressFilled");
479 domClass.add(rc0.firstChild, "ganttImageProgressBg");
480 }else if((percentage == 100) && (this.percentage == 0)){
481 domClass.remove(rc0.firstChild, "ganttImageProgressBg");
482 domClass.add(rc0.firstChild, "ganttImageProgressFilled");
483 }
484 }else if(((percentage > 0) || (percentage < 100)) && ((this.percentage == 0) || (this.percentage == 100))){
485 rc0.parentNode.removeChild(rc0);
486 var cellprojectItem = domConstruct.create("td", {
487 width: percentage + "%"
488 }, prow);
489 cellprojectItem.style.lineHeight = "1px";
490 var imageProgress = domConstruct.create("div", {
491 className: "ganttImageProgressFilled"
492 }, cellprojectItem);
493 domStyle.set(imageProgress, {
494 width: (percentage * this.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px",
495 height: this.ganttChart.heightTaskItem + "px"
496 });
497 cellprojectItem = domConstruct.create("td", {
498 width: (100 - percentage) + "%"
499 }, prow);
500 cellprojectItem.style.lineHeight = "1px";
501 imageProgress = domConstruct.create("div", {
502 className: "ganttImageProgressBg"
503 }, cellprojectItem);
504 domStyle.set(imageProgress, {
505 width: ((100 - percentage) * this.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px",
506 height: this.ganttChart.heightTaskItem + "px"
507 });
508 }else if(this.percentage == -1){
509 if(percentage == 100){
510 domClass.remove(rc0.firstChild, "ganttImageProgressBg");
511 domClass.add(rc0.firstChild, "ganttImageProgressFilled");
512 }else if(percentage < 100 && percentage > 0){
513 rc0.parentNode.removeChild(rc0);
514 var cellprojectItem = domConstruct.create("td", {
515 width: percentage + "%"
516 }, prow);
517 cellprojectItem.style.lineHeight = "1px";
518 imageProgress = domConstruct.create("div", {
519 className: "ganttImageProgressFilled"
520 }, cellprojectItem);
521 domStyle.set(imageProgress, {
522 width: (percentage * this.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px",
523 height: this.ganttChart.heightTaskItem + "px"
524 });
525 cellprojectItem = domConstruct.create("td", {
526 width: (100 - percentage) + "%"
527 }, prow);
528 cellprojectItem.style.lineHeight = "1px";
529 imageProgress = domConstruct.create("div", {
530 className: "ganttImageProgressBg"
531 }, cellprojectItem);
532 domStyle.set(imageProgress, {
533 width: ((100 - percentage) * this.duration * this.ganttChart.pixelsPerWorkHour) / 100 + "px",
534 height: this.ganttChart.heightTaskItem + "px"
535 });
536 }
537 }
538 this.percentage = percentage;
539 this.descrProject.innerHTML = this.getDescStr();
540 return true;
541 },
542 deleteChildTask: function(task){
543 if(task){
544 var tItem0 = task.cTaskItem[0], tNameItem0 = task.cTaskNameItem[0],
545 tItem1 = task.cTaskItem[1], tNameItem1 = task.cTaskNameItem[1],
546 tNameItem2 = task.cTaskNameItem[2];
547 if(tItem0.style.display == "none"){
548 this.ganttChart.openTree(task.parentTask);
549 }
550 //delete of connecting lines
551 if(task.childPredTask.length > 0){
552 for(var i = 0; i < task.childPredTask.length; i++){
553 var cpTask = task.childPredTask[i];
554 for(var t = 0; t < cpTask.cTaskItem[1].length; t++){
555 cpTask.cTaskItem[1][t].parentNode.removeChild(cpTask.cTaskItem[1][t]);
556 }
557 cpTask.cTaskItem[1] = [];
558 cpTask.predTask = null;
559 }
560 }
561 //delete child task
562 if(task.childTask.length > 0){
563 while(task.childTask.length > 0){
564 this.deleteChildTask(task.childTask[0]);
565 }
566 }
567 //shift tasks
568 var rowHeight = this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra;
569 if(tItem0.style.display != "none"){
570 task.shiftCurrentTasks(task, -rowHeight);
571 }
572 //delete object task
573 this.project.deleteTask(task.taskItem.id);
574 //delete div and connecting lines from contentData
575 if(tItem0){
576 tItem0.parentNode.removeChild(tItem0);
577 }
578 task.descrTask.parentNode.removeChild(task.descrTask);
579 if(tItem1.length > 0){
580 for(var j = 0; j < tItem1.length; j++){
581 tItem1[j].parentNode.removeChild(tItem1[j]);
582 }
583 }
584 //delete div and connecting lines from panelName
585 if(tNameItem0){
586 tNameItem0.parentNode.removeChild(tNameItem0);
587 }
588 if(task.cTaskNameItem[1]){
589 for(var j = 0; j < tNameItem1.length; j++){
590 tNameItem1[j].parentNode.removeChild(tNameItem1[j]);
591 }
592 }
593 if(tNameItem2 && tNameItem2.parentNode){
594 tNameItem2.parentNode.removeChild(tNameItem2);
595 }
596 if(task.taskIdentifier){
597 task.taskIdentifier.parentNode.removeChild(task.taskIdentifier);
598 task.taskIdentifier = null;
599 }
600 //delete object task
601 if(task.parentTask){
602 if(task.previousChildTask){
603 if(task.nextChildTask){
604 task.previousChildTask.nextChildTask = task.nextChildTask;
605 }else{
606 task.previousChildTask.nextChildTask = null;
607 }
608 }
609 var parentTask = task.parentTask;
610 for(var i = 0; i < parentTask.childTask.length; i++){
611 if(parentTask.childTask[i].taskItem.id == task.taskItem.id){
612 parentTask.childTask[i] = null;
613 parentTask.childTask.splice(i, 1);
614 break;
615 }
616 }
617 if(parentTask.childTask.length == 0){
618 if(parentTask.cTaskNameItem[2]){
619 parentTask.cTaskNameItem[2].parentNode.removeChild(parentTask.cTaskNameItem[2]);
620 parentTask.cTaskNameItem[2] = null;
621 }
622 }
623 }else{
624 if(task.previousParentTask){
625 if(task.nextParentTask){
626 task.previousParentTask.nextParentTask = task.nextParentTask;
627 }else{
628 task.previousParentTask.nextParentTask = null;
629 }
630 }
631 var project = task.project;
632 for(var i = 0; i < project.arrTasks.length; i++){
633 if(project.arrTasks[i].taskItem.id == task.taskItem.id){
634 project.arrTasks.splice(i, 1);
635 }
636 }
637 }
638 if(task.predTask){
639 var predTask = task.predTask;
640 for(var i = 0; i < predTask.childPredTask.length; i++){
641 if(predTask.childPredTask[i].taskItem.id == task.taskItem.id){
642 predTask.childPredTask[i] = null;
643 predTask.childPredTask.splice(i, 1);
644 }
645 }
646 }
647 if(task.project.arrTasks.length != 0){
648 task.project.shiftProjectItem();
649 }else{
650 task.project.projectItem[0].style.display = "none";
651 this.hideDescrProject();
652 }
653 this.ganttChart.contentDataHeight -= this.ganttChart.heightTaskItemExtra + this.ganttChart.heightTaskItem;
654 }
655 },
656
657 insertTask: function(id, name, startTime, duration, percentage, previousTaskId, taskOwner, parentTaskId){
658 var task = null;
659 var _task = null;
660 if(this.project.getTaskById(id)){
661 return false;
662 }
663 if((!duration) || (duration < this.ganttChart.minWorkLength)){
664 duration = this.ganttChart.minWorkLength;
665 }
666 if((!name) || (name == "")){
667 name = id;
668 }
669 if((!percentage) || (percentage == "")){
670 percentage = 0;
671
672 }else{
673 percentage = parseInt(percentage);
674 if(percentage < 0 || percentage > 100){
675 return false;
676 }
677 }
678 var sortRequired = false;
679 if((parentTaskId) && (parentTaskId != "")){
680 var parentTask = this.project.getTaskById(parentTaskId);
681 if(!parentTask){
682 return false;
683 }
684 startTime = startTime || parentTask.startTime;
685 if(startTime < parentTask.startTime){
686 return false;
687 }
688 task = new GanttTaskItem({
689 id: id,
690 name: name,
691 startTime: startTime,
692 duration: duration,
693 percentage: percentage,
694 previousTaskId: previousTaskId,
695 taskOwner: taskOwner
696 });
697 if(!this.ganttChart.checkPosParentTask(parentTask, task)){
698 return false;
699 }
700 task.parentTask = parentTask;
701 var _parentTask = this.getTaskById(parentTask.id);
702 var isHide = false;
703 if(_parentTask.cTaskItem[0].style.display == "none"){
704 isHide = true;
705 }else if(_parentTask.cTaskNameItem[2]){
706 if(!_parentTask.isExpanded){
707 isHide = true;
708 }
709 }
710 if(isHide){
711 if(_parentTask.childTask.length == 0){
712 this.ganttChart.openTree(_parentTask.parentTask);
713 }else{
714 this.ganttChart.openTree(_parentTask);
715 }
716 }
717 if(previousTaskId != ""){
718 var predTask = this.project.getTaskById(previousTaskId);
719 if(!predTask){
720 return false;
721 }
722 if(predTask.parentTask){
723 if(predTask.parentTask.id != task.parentTask.id){
724 return false;
725 }
726 }else{
727 return false;
728 }
729 if(!this.ganttChart.checkPosPreviousTask(predTask, task)){
730 this.ganttChart.correctPosPreviousTask(predTask, task);
731 }
732 task.previousTask = predTask;
733 }
734 var isAdd = false;
735 if(sortRequired) for(var i = 0; i < parentTask.cldTasks.length; i++){
736 if(task.startTime < parentTask.cldTasks[i].startTime){
737 parentTask.cldTasks.splice(i, 0, task);
738 if(i > 0){
739 parentTask.cldTasks[i - 1].nextChildTask = parentTask.cldTasks[i];
740 parentTask.cldTasks[i].previousChildTask = parentTask.cldTasks[i - 1];
741 }
742 if(parentTask.cldTasks[i + 1]){
743 parentTask.cldTasks[i + 1].previousChildTask = parentTask.cldTasks[i];
744 parentTask.cldTasks[i].nextChildTask = parentTask.cldTasks[i + 1];
745 }
746 isAdd = true;
747 break;
748 }
749 }
750 if(!isAdd){
751 if(parentTask.cldTasks.length > 0){
752 parentTask.cldTasks[parentTask.cldTasks.length - 1].nextChildTask = task;
753 task.previousChildTask = parentTask.cldTasks[parentTask.cldTasks.length - 1];
754 }
755 parentTask.cldTasks.push(task);
756 }
757 if(parentTask.cldTasks.length == 1){
758 _parentTask.cTaskNameItem[2] = _parentTask.createTreeImg();
759 }
760 _task = new GanttTaskControl(task, this, this.ganttChart);
761 _task.create();
762 if(task.nextChildTask) _task.nextChildTask = _task.project.getTaskById(task.nextChildTask.id);
763 _task.adjustPanelTime();
764 var rowHeight = this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra;
765 _task.shiftCurrentTasks(_task, rowHeight);//23
766 }else{
767 startTime = startTime || this.project.startDate;
768 task = new GanttTaskItem({
769 id: id,
770 name: name,
771 startTime: startTime,
772 duration: duration,
773 percentage: percentage,
774 previousTaskId: previousTaskId,
775 taskOwner: taskOwner
776 });
777 if(task.startTime <= this.ganttChart.startDate){
778 return false;
779 }
780 if(previousTaskId != ""){
781 var predTask = this.project.getTaskById(previousTaskId);
782 if(!predTask){
783 return false;
784 }
785 if(!this.ganttChart.checkPosPreviousTask(predTask, task)){
786 this.ganttChart.correctPosPreviousTask(predTask, task);
787 }
788 if(predTask.parentTask){
789 return false;
790 }
791 task.previousTask = predTask;
792 }
793 var isAdd = false;
794 if(sortRequired){
795 for(var i = 0; i < this.project.parentTasks.length; i++){
796 var ppTask = this.project.parentTasks[i];
797 if(startTime < ppTask.startTime){
798 this.project.parentTasks.splice(i, 0, task);
799 if(i > 0){
800 this.project.parentTasks[i - 1].nextParentTask = task;
801 task.previousParentTask = this.project.parentTasks[i - 1];
802 }
803 if(this.project.parentTasks[i + 1]){
804 this.project.parentTasks[i + 1].previousParentTask = task;
805 task.nextParentTask = this.project.parentTasks[i + 1];
806 }
807 isAdd = true;
808 break;
809 }
810 }
811 }
812 if(!isAdd){
813 if(this.project.parentTasks.length > 0){
814 this.project.parentTasks[this.project.parentTasks.length - 1].nextParentTask = task;
815 task.previousParentTask = this.project.parentTasks[this.project.parentTasks.length - 1];
816 }
817 this.project.parentTasks.push(task);
818 }
819 _task = new GanttTaskControl(task, this, this.ganttChart);
820 _task.create();
821 if(task.nextParentTask) _task.nextParentTask = _task.project.getTaskById(task.nextParentTask.id);
822 _task.adjustPanelTime();
823 this.arrTasks.push(_task);
824 var rowHeight = this.ganttChart.heightTaskItem + this.ganttChart.heightTaskItemExtra;
825 _task.shiftCurrentTasks(_task, rowHeight);
826 this.projectItem[0].style.display = "inline";
827 this.setPercentCompleted(this.getPercentCompleted());
828 this.shiftProjectItem();
829 this.showDescrProject();
830 }
831 this.ganttChart.checkHeighPanelTasks();
832 this.ganttChart.checkPosition();
833 return _task;
834 },
835 shiftNextProject: function(project, height){
836 if(project.nextProject){
837 project.nextProject.shiftProject(height);
838 this.shiftNextProject(project.nextProject, height);
839 }
840 },
841 shiftProject: function(height){
842 this.posY = this.posY + height;
843 this.projectItem[0].style.top = parseInt(this.projectItem[0].style.top) + height + "px";
844 this.descrProject.style.top = parseInt(this.descrProject.style.top) + height + "px";
845 this.projectNameItem.style.top = parseInt(this.projectNameItem.style.top) + height + "px";
846 if(this.arrTasks.length > 0){
847 this.shiftNextParentTask(this.arrTasks[0], height);
848 }
849 },
850 shiftTask: function(task, height){
851 task.posY = task.posY + height;
852 var tNameItem0 = task.cTaskNameItem[0], tNameItem1 = task.cTaskNameItem[1], tNameItem2 = task.cTaskNameItem[2],
853 tItem1 = task.cTaskItem[1];
854 tNameItem0.style.top = parseInt(tNameItem0.style.top) + height + "px";
855 if(tNameItem2){
856 tNameItem2.style.top = parseInt(tNameItem2.style.top) + height + "px";
857 }
858 if(task.parentTask){
859 tNameItem1[0].style.top = parseInt(tNameItem1[0].style.top) + height + "px";
860 tNameItem1[1].style.top = parseInt(tNameItem1[1].style.top) + height + "px";
861 }
862 task.cTaskItem[0].style.top = parseInt(task.cTaskItem[0].style.top) + height + "px";
863 task.descrTask.style.top = parseInt(task.descrTask.style.top) + height + "px";
864 if(tItem1[0]){
865 tItem1[0].style.top = parseInt(tItem1[0].style.top) + height + "px";
866 tItem1[1].style.top = parseInt(tItem1[1].style.top) + height + "px";
867 tItem1[2].style.top = parseInt(tItem1[2].style.top) + height + "px";
868 }
869 },
870 shiftNextParentTask: function(task, height){
871 this.shiftTask(task, height);
872 this.shiftChildTasks(task, height);
873 if(task.nextParentTask){
874 this.shiftNextParentTask(task.nextParentTask, height);
875 }
876 },
877 shiftChildTasks: function(task, height){
878 arrayUtil.forEach(task.childTask, function(cTask){
879 this.shiftTask(cTask, height);
880 if(cTask.childTask.length > 0){
881 this.shiftChildTasks(cTask, height);
882 }
883 }, this);
884 }
885 });
886 });