GanttTaskItem.js 51 KB

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