GanttProjectItem.js 33 KB

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