ProcessDiagramGenerator.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. /**
  2. * Class to generate an image based the diagram interchange information in a
  3. * BPMN 2.0 process.
  4. *
  5. * @author (Javascript) Dmitry Farafonov
  6. */
  7. var ProcessDiagramGenerator = {
  8. options: {},
  9. processDiagramCanvas: [],
  10. activityDrawInstructions:{},
  11. processDiagrams: {},
  12. diagramBreadCrumbs: null,
  13. init: function(){
  14. // start event
  15. this.activityDrawInstructions["startEvent"] = function(){
  16. var activityImpl = this.activity;
  17. var processDiagramCanvas = this.processDiagramCanvas;
  18. processDiagramCanvas.setConextObject(activityImpl);
  19. processDiagramCanvas.drawNoneStartEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  20. };
  21. // start timer event
  22. this.activityDrawInstructions["startTimerEvent"] = function(){
  23. var activityImpl = this.activity;
  24. var processDiagramCanvas = this.processDiagramCanvas;
  25. processDiagramCanvas.setConextObject(activityImpl);
  26. var isInterrupting = activityImpl.getProperty("isInterrupting");
  27. processDiagramCanvas.drawTimerStartEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, activityImpl.getProperty("name"));
  28. };
  29. // start event
  30. this.activityDrawInstructions["messageStartEvent"] = function(){
  31. var activityImpl = this.activity;
  32. var processDiagramCanvas = this.processDiagramCanvas;
  33. processDiagramCanvas.setConextObject(activityImpl);
  34. var isInterrupting = activityImpl.getProperty("isInterrupting");
  35. processDiagramCanvas.drawMessageStartEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, activityImpl.getProperty("name"));
  36. };
  37. // start signal event
  38. this.activityDrawInstructions["startSignalEvent"] = function(){
  39. var activityImpl = this.activity;
  40. var processDiagramCanvas = this.processDiagramCanvas;
  41. processDiagramCanvas.setConextObject(activityImpl);
  42. var isInterrupting = activityImpl.getProperty("isInterrupting");
  43. processDiagramCanvas.drawSignalStartEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, activityImpl.getProperty("name"));
  44. };
  45. // start multiple event
  46. this.activityDrawInstructions["startMultipleEvent"] = function(){
  47. var activityImpl = this.activity;
  48. var processDiagramCanvas = this.processDiagramCanvas;
  49. processDiagramCanvas.setConextObject(activityImpl);
  50. var isInterrupting = activityImpl.getProperty("isInterrupting");
  51. processDiagramCanvas.drawMultipleStartEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, activityImpl.getProperty("name"));
  52. };
  53. // signal catch
  54. this.activityDrawInstructions["intermediateSignalCatch"] = function(){
  55. var activityImpl = this.activity;
  56. var processDiagramCanvas = this.processDiagramCanvas;
  57. processDiagramCanvas.setConextObject(activityImpl);
  58. var isInterrupting = activityImpl.getProperty("isInterrupting");
  59. processDiagramCanvas.drawCatchingSignalEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, null);
  60. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  61. if (label)
  62. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  63. };
  64. // message catch
  65. this.activityDrawInstructions["intermediateMessageCatch"] = function(){
  66. var activityImpl = this.activity;
  67. var processDiagramCanvas = this.processDiagramCanvas;
  68. processDiagramCanvas.setConextObject(activityImpl);
  69. var isInterrupting = activityImpl.getProperty("isInterrupting");
  70. processDiagramCanvas.drawCatchingMessageEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, null);
  71. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  72. if (label)
  73. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  74. };
  75. // multiple catch
  76. this.activityDrawInstructions["intermediateMultipleCatch"] = function(){
  77. var activityImpl = this.activity;
  78. var processDiagramCanvas = this.processDiagramCanvas;
  79. processDiagramCanvas.setConextObject(activityImpl);
  80. var isInterrupting = activityImpl.getProperty("isInterrupting");
  81. processDiagramCanvas.drawCatchingMultipleEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, null);
  82. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  83. if (label)
  84. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  85. };
  86. // signal throw
  87. this.activityDrawInstructions["intermediateSignalThrow"] = function(){
  88. var activityImpl = this.activity;
  89. var processDiagramCanvas = this.processDiagramCanvas;
  90. processDiagramCanvas.setConextObject(activityImpl);
  91. processDiagramCanvas.drawThrowingSignalEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), activityImpl.getProperty("name"));
  92. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  93. if (label)
  94. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  95. };
  96. // message throw
  97. this.activityDrawInstructions["intermediateMessageThrow"] = function(){
  98. var activityImpl = this.activity;
  99. var processDiagramCanvas = this.processDiagramCanvas;
  100. processDiagramCanvas.setConextObject(activityImpl);
  101. processDiagramCanvas.drawThrowingMessageEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), activityImpl.getProperty("name"));
  102. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  103. if (label)
  104. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  105. };
  106. // multiple throw
  107. this.activityDrawInstructions["intermediateMultipleThrow"] = function(){
  108. var activityImpl = this.activity;
  109. var processDiagramCanvas = this.processDiagramCanvas;
  110. processDiagramCanvas.setConextObject(activityImpl);
  111. processDiagramCanvas.drawThrowingMultipleEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), activityImpl.getProperty("name"));
  112. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  113. if (label)
  114. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  115. };
  116. // none throw
  117. this.activityDrawInstructions["intermediateThrowEvent"] = function() {
  118. var activityImpl = this.activity;
  119. var processDiagramCanvas = this.processDiagramCanvas;
  120. processDiagramCanvas.setConextObject(activityImpl);
  121. processDiagramCanvas.drawThrowingNoneEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), activityImpl.getProperty("name"));
  122. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  123. if (label)
  124. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  125. };
  126. // end event
  127. this.activityDrawInstructions["endEvent"] = function(){
  128. var activityImpl = this.activity;
  129. var processDiagramCanvas = this.processDiagramCanvas;
  130. processDiagramCanvas.setConextObject(activityImpl);
  131. processDiagramCanvas.drawNoneEndEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  132. };
  133. // error end event
  134. this.activityDrawInstructions["errorEndEvent"] = function(){
  135. var activityImpl = this.activity;
  136. var processDiagramCanvas = this.processDiagramCanvas;
  137. processDiagramCanvas.setConextObject(activityImpl);
  138. processDiagramCanvas.drawErrorEndEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), null);
  139. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  140. if (label)
  141. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  142. };
  143. // message end event
  144. this.activityDrawInstructions["messageEndEvent"] = function(){
  145. var activityImpl = this.activity;
  146. var processDiagramCanvas = this.processDiagramCanvas;
  147. processDiagramCanvas.setConextObject(activityImpl);
  148. processDiagramCanvas.drawMessageEndEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), null);
  149. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  150. if (label)
  151. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  152. };
  153. // signal end event
  154. this.activityDrawInstructions["signalEndEvent"] = function(){
  155. var activityImpl = this.activity;
  156. var processDiagramCanvas = this.processDiagramCanvas;
  157. processDiagramCanvas.setConextObject(activityImpl);
  158. processDiagramCanvas.drawSignalEndEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), null);
  159. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  160. if (label)
  161. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  162. };
  163. // multiple end event
  164. this.activityDrawInstructions["multipleEndEvent"] = function(){
  165. var activityImpl = this.activity;
  166. var processDiagramCanvas = this.processDiagramCanvas;
  167. processDiagramCanvas.setConextObject(activityImpl);
  168. processDiagramCanvas.drawMultipleEndEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), null);
  169. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  170. if (label)
  171. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  172. };
  173. // terminate end event
  174. this.activityDrawInstructions["terminateEndEvent"] = function(){
  175. var activityImpl = this.activity;
  176. var processDiagramCanvas = this.processDiagramCanvas;
  177. processDiagramCanvas.setConextObject(activityImpl);
  178. processDiagramCanvas.drawTerminateEndEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  179. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  180. if (label)
  181. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  182. };
  183. // error start event
  184. this.activityDrawInstructions["errorStartEvent"] = function(){
  185. var activityImpl = this.activity;
  186. var processDiagramCanvas = this.processDiagramCanvas;
  187. processDiagramCanvas.setConextObject(activityImpl);
  188. processDiagramCanvas.drawErrorStartEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), activityImpl.getProperty("name"));
  189. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  190. if (label)
  191. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  192. };
  193. // task
  194. this.activityDrawInstructions["task"] = function(){
  195. var activityImpl = this.activity;
  196. var processDiagramCanvas = this.processDiagramCanvas;
  197. processDiagramCanvas.setConextObject(activityImpl);
  198. // TODO:
  199. //console.error("task is not implemented yet");
  200. /*
  201. var activityImpl = this;
  202. processDiagramCanvas.drawTask(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), thickBorder);
  203. */
  204. };
  205. // user task
  206. this.activityDrawInstructions["userTask"] = function(){
  207. var activityImpl = this.activity;
  208. var processDiagramCanvas = this.processDiagramCanvas;
  209. processDiagramCanvas.setConextObject(activityImpl);
  210. processDiagramCanvas.drawUserTask(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  211. };
  212. // script task
  213. this.activityDrawInstructions["scriptTask"] = function(){
  214. var activityImpl = this.activity;
  215. var processDiagramCanvas = this.processDiagramCanvas;
  216. processDiagramCanvas.setConextObject(activityImpl);
  217. processDiagramCanvas.drawScriptTask(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  218. };
  219. // service task
  220. this.activityDrawInstructions["serviceTask"] = function(){
  221. var activityImpl = this.activity;
  222. var processDiagramCanvas = this.processDiagramCanvas;
  223. processDiagramCanvas.setConextObject(activityImpl);
  224. processDiagramCanvas.drawServiceTask(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  225. };
  226. // receive task
  227. this.activityDrawInstructions["receiveTask"] = function(){
  228. var activityImpl = this.activity;
  229. var processDiagramCanvas = this.processDiagramCanvas;
  230. processDiagramCanvas.setConextObject(activityImpl);
  231. processDiagramCanvas.drawReceiveTask(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  232. };
  233. // send task
  234. this.activityDrawInstructions["sendTask"] = function(){
  235. var activityImpl = this.activity;
  236. var processDiagramCanvas = this.processDiagramCanvas;
  237. processDiagramCanvas.setConextObject(activityImpl);
  238. processDiagramCanvas.drawSendTask(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  239. };
  240. // manual task
  241. this.activityDrawInstructions["manualTask"] = function(){
  242. var activityImpl = this.activity;
  243. var processDiagramCanvas = this.processDiagramCanvas;
  244. processDiagramCanvas.setConextObject(activityImpl);
  245. processDiagramCanvas.drawManualTask(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  246. };
  247. // businessRuleTask task
  248. this.activityDrawInstructions["businessRuleTask"] = function(){
  249. var activityImpl = this.activity;
  250. var processDiagramCanvas = this.processDiagramCanvas;
  251. processDiagramCanvas.setConextObject(activityImpl);
  252. processDiagramCanvas.drawBusinessRuleTask(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  253. };
  254. // exclusive gateway
  255. this.activityDrawInstructions["exclusiveGateway"] = function(){
  256. var activityImpl = this.activity;
  257. var processDiagramCanvas = this.processDiagramCanvas;
  258. processDiagramCanvas.setConextObject(activityImpl);
  259. processDiagramCanvas.drawExclusiveGateway(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  260. };
  261. // inclusive gateway
  262. this.activityDrawInstructions["inclusiveGateway"] = function(){
  263. var activityImpl = this.activity;
  264. var processDiagramCanvas = this.processDiagramCanvas;
  265. processDiagramCanvas.setConextObject(activityImpl);
  266. processDiagramCanvas.drawInclusiveGateway(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  267. };
  268. // parallel gateway
  269. this.activityDrawInstructions["parallelGateway"] = function(){
  270. var activityImpl = this.activity;
  271. var processDiagramCanvas = this.processDiagramCanvas;
  272. processDiagramCanvas.setConextObject(activityImpl);
  273. processDiagramCanvas.drawParallelGateway(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  274. };
  275. // eventBasedGateway
  276. this.activityDrawInstructions["eventBasedGateway"] = function(){
  277. var activityImpl = this.activity;
  278. var processDiagramCanvas = this.processDiagramCanvas;
  279. processDiagramCanvas.setConextObject(activityImpl);
  280. processDiagramCanvas.drawEventBasedGateway(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  281. };
  282. // Boundary timer
  283. this.activityDrawInstructions["boundaryTimer"] = function(){
  284. var activityImpl = this.activity;
  285. var processDiagramCanvas = this.processDiagramCanvas;
  286. processDiagramCanvas.setConextObject(activityImpl);
  287. var isInterrupting = activityImpl.getProperty("isInterrupting");
  288. processDiagramCanvas.drawCatchingTimerEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, null);
  289. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  290. if (label)
  291. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  292. };
  293. // Boundary catch error
  294. this.activityDrawInstructions["boundaryError"] = function(){
  295. var activityImpl = this.activity;
  296. var processDiagramCanvas = this.processDiagramCanvas;
  297. processDiagramCanvas.setConextObject(activityImpl);
  298. var isInterrupting = activityImpl.getProperty("isInterrupting");
  299. processDiagramCanvas.drawCatchingErrorEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, null);
  300. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  301. if (label)
  302. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  303. };
  304. // Boundary signal event
  305. this.activityDrawInstructions["boundarySignal"] = function(){
  306. var activityImpl = this.activity;
  307. var processDiagramCanvas = this.processDiagramCanvas;
  308. processDiagramCanvas.setConextObject(activityImpl);
  309. var isInterrupting = activityImpl.getProperty("isInterrupting");
  310. processDiagramCanvas.drawCatchingSignalEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, null);
  311. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  312. if (label)
  313. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  314. };
  315. // Boundary message event
  316. this.activityDrawInstructions["boundaryMessage"] = function(){
  317. var activityImpl = this.activity;
  318. var processDiagramCanvas = this.processDiagramCanvas;
  319. processDiagramCanvas.setConextObject(activityImpl);
  320. var isInterrupting = activityImpl.getProperty("isInterrupting");
  321. processDiagramCanvas.drawCatchingMessageEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, null);
  322. var label = ProcessDiagramGenerator.getActivitiLabel(activityImpl);
  323. if (label)
  324. processDiagramCanvas.drawLabel(label.text, label.x, label.y, label.width, label.height);
  325. };
  326. // timer catch event
  327. this.activityDrawInstructions["intermediateTimer"] = function(){
  328. var activityImpl = this.activity;
  329. var processDiagramCanvas = this.processDiagramCanvas;
  330. processDiagramCanvas.setConextObject(activityImpl);
  331. var isInterrupting = null;
  332. processDiagramCanvas.drawCatchingTimerEvent(activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight(), isInterrupting, activityImpl.getProperty("name"));
  333. };
  334. // subprocess
  335. this.activityDrawInstructions["subProcess"] = function(){
  336. var activityImpl = this.activity;
  337. var processDiagramCanvas = this.processDiagramCanvas;
  338. // TODO:
  339. processDiagramCanvas.setConextObject(activityImpl);
  340. var isExpanded = activityImpl.getProperty("isExpanded");
  341. var isTriggeredByEvent = activityImpl.getProperty("triggeredByEvent");
  342. if(isTriggeredByEvent == undefined) {
  343. isTriggeredByEvent = true;
  344. }
  345. // TODO: check why isTriggeredByEvent = true when undefined
  346. isTriggeredByEvent = false;
  347. if (isExpanded != undefined && isExpanded == false) {
  348. processDiagramCanvas.drawCollapsedSubProcess(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(),
  349. activityImpl.getWidth(), activityImpl.getHeight(), isTriggeredByEvent);
  350. } else {
  351. processDiagramCanvas.drawExpandedSubProcess(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(),
  352. activityImpl.getWidth(), activityImpl.getHeight(), isTriggeredByEvent);
  353. }
  354. //console.error("subProcess is not implemented yet");
  355. };
  356. // call activity
  357. this.activityDrawInstructions["callActivity"] = function(){
  358. var activityImpl = this.activity;
  359. var processDiagramCanvas = this.processDiagramCanvas;
  360. processDiagramCanvas.setConextObject(activityImpl);
  361. processDiagramCanvas.drawCollapsedCallActivity(activityImpl.getProperty("name"), activityImpl.getX(), activityImpl.getY(), activityImpl.getWidth(), activityImpl.getHeight());
  362. };
  363. $(document).ready(function(){
  364. // Protect right click on SVG elements (and on canvas too)
  365. document.body.oncontextmenu = function(event) {
  366. if (window.event.srcElement.tagName == "shape" || window.event.srcElement.tagName == "DIV" && window.event.srcElement.parentElement.className == "diagram") {
  367. // IE DIAGRAM CANVAS OR SHAPE DETECTED!
  368. return false;
  369. }
  370. return (!Object.isSVGElement(window.event.srcElement));
  371. };
  372. });
  373. },
  374. getActivitiLabel:function(activityImpl){
  375. /*
  376. TODO: Label object should be in activityImpl and looks like:
  377. {
  378. x: 250,
  379. y: 250,
  380. width: 80,
  381. height: 30
  382. }
  383. And then:
  384. if (!activityImpl.label)
  385. return null;
  386. var label = activityImpl.label;
  387. label.text = activityImpl.name;
  388. return label;
  389. */
  390. // But now default label for all events is:
  391. return {
  392. text: activityImpl.getProperty("name"),
  393. x: activityImpl.getX() + .5 + activityImpl.getWidth()/2,
  394. y: activityImpl.getY() + .5 + activityImpl.getHeight() + ICON_PADDING,
  395. width: 100,
  396. height: 0
  397. };
  398. },
  399. generateDiagram: function(processDefinitionDiagramLayout){
  400. // Init canvas
  401. var processDefinitionId = processDefinitionDiagramLayout.processDefinition.id;
  402. //console.log("Init canvas ", processDefinitionId);
  403. if (this.getProcessDiagram(processDefinitionId) != undefined) {
  404. // TODO: may be reset canvas if exists.. Or just show
  405. //console.log("ProcessDiagram '" + processDefinitionId + "' is already generated. Just show it.");
  406. return;
  407. }
  408. var processDiagram = this.initProcessDiagramCanvas(processDefinitionDiagramLayout);
  409. var processDiagramCanvas = processDiagram.diagramCanvas;
  410. // Draw pool shape, if process is participant in collaboration
  411. if(processDefinitionDiagramLayout.participantProcess != undefined) {
  412. //console.log("Draw pool shape");
  413. var pProc = processDefinitionDiagramLayout.participantProcess;
  414. processDiagramCanvas.drawPoolOrLane(pProc.x, pProc.y, pProc.width, pProc.height, pProc.name);
  415. }
  416. var laneSets = processDefinitionDiagramLayout.laneSets;
  417. var activities = processDefinitionDiagramLayout.activities;
  418. var sequenceFlows = processDefinitionDiagramLayout.sequenceFlows;
  419. pb1.set('value', 0);
  420. var cnt = 0;
  421. if (laneSets)
  422. for(var i in laneSets) {
  423. cnt += laneSets[i].lanes.length;
  424. }
  425. if (activities)
  426. cnt += activities.length;
  427. if (sequenceFlows)
  428. cnt += sequenceFlows.length;
  429. var step = (cnt>0)? 100/cnt : 0;
  430. var progress = 0;
  431. //console.log("progress bar step: ", step);
  432. var task1 = new $.AsyncQueue();
  433. // Draw lanes
  434. task1.add(function (task1) {
  435. if (!laneSets) laneSets = [];
  436. //console.log("> draw lane sets, count:", laneSets.length)
  437. });
  438. for(var i in laneSets) {
  439. var laneSet = laneSets[i];
  440. //laneSet.id, laneSet.name
  441. task1.add(laneSet.lanes,function (task1, lane) {
  442. progress += step;
  443. pb1.set('value', parseInt(progress));
  444. //console.log("--> laneId: " + lane.name + ", name: " + lane.name);
  445. processDiagramCanvas.drawPoolOrLane(lane.x, lane.y, lane.width, lane.height, lane.name);
  446. });
  447. }
  448. // Draw activities
  449. task1.add(function (task1) {
  450. if (!activities) activities = [];
  451. //console.log("> draw activities, count:", activities.length)
  452. });
  453. var activitiesLength = activities.length;
  454. task1.add(activities,function (task1, activityJson) {
  455. var activity = new ActivityImpl(activityJson);
  456. activitiesLength --;
  457. progress += step;
  458. pb1.set('value', parseInt(progress));
  459. //console.log(activitiesLength, "--> activityId: " + activity.getId() + ", name: " + activity.getProperty("name"));
  460. ProcessDiagramGenerator.drawActivity(processDiagramCanvas, activity);
  461. });
  462. // Draw sequence-flows
  463. task1.add(function (task1) {
  464. if (!sequenceFlows) sequenceFlows = [];
  465. //console.log("> draw sequence flows, count:", sequenceFlows.length)
  466. });
  467. var flowsLength = sequenceFlows.length;
  468. task1.add(sequenceFlows,function (task1, flow) {
  469. var waypoints = [];
  470. for(var j in flow.xPointArray) {
  471. waypoints[j] = {x: flow.xPointArray[j], y: flow.yPointArray[j]};
  472. }
  473. var isDefault = flow.isDefault;
  474. var isConditional = flow.isConditional;
  475. var isHighLighted = flow.isHighLighted;
  476. // TODO: add source and destination for sequence flows in REST
  477. // parse for test
  478. var f = flow.flow;
  479. var matches = f.match(/\((.*)\)--.*-->\((.*)\)/);
  480. var sourceActivityId, destinationActivityId;
  481. if (matches != null) {
  482. sourceActivityId = matches[1];
  483. destinationActivityId = matches[2];
  484. }
  485. flow.sourceActivityId = sourceActivityId;
  486. flow.destinationActivityId = destinationActivityId;
  487. //
  488. flowsLength--;
  489. progress += step;
  490. pb1.set('value', parseInt(progress));
  491. //console.log(flowsLength, "--> flow: " + flow.flow);
  492. processDiagramCanvas.setConextObject(flow);
  493. processDiagramCanvas.drawSequenceflow(waypoints, isConditional, isDefault, isHighLighted);
  494. });
  495. task1.onComplete(function(){
  496. if (progress<100)
  497. pb1.set('value', 100);
  498. //console.log("COMPLETE!!!");
  499. //console.timeEnd('generateDiagram');
  500. });
  501. task1.run();
  502. },
  503. getProcessDiagram: function (processDefinitionId) {
  504. return this.processDiagrams[processDefinitionId];
  505. },
  506. initProcessDiagramCanvas: function (processDefinitionDiagramLayout) {
  507. var minX = 0;
  508. var maxX = 0;
  509. var minY = 0;
  510. var maxY = 0;
  511. if(processDefinitionDiagramLayout.participantProcess != undefined) {
  512. var pProc = processDefinitionDiagramLayout.participantProcess;
  513. minX = pProc.x;
  514. maxX = pProc.x + pProc.width;
  515. minY = pProc.y;
  516. maxY = pProc.y + pProc.height;
  517. }
  518. var activities = processDefinitionDiagramLayout.activities;
  519. for(var i in activities) {
  520. var activityJson = activities[i];
  521. var activity = new ActivityImpl(activityJson);
  522. // width
  523. if (activity.getX() + activity.getWidth() > maxX) {
  524. maxX = activity.getX() + activity.getWidth();
  525. }
  526. if (activity.getX() < minX) {
  527. minX = activity.getX();
  528. }
  529. // height
  530. if (activity.getY() + activity.getHeight() > maxY) {
  531. maxY = activity.getY() + activity.getHeight();
  532. }
  533. if (activity.getY() < minY) {
  534. minY = activity.getY();
  535. }
  536. }
  537. var sequenceFlows = processDefinitionDiagramLayout.sequenceFlows;
  538. for(var i in sequenceFlows) {
  539. var flow = sequenceFlows[i];
  540. var waypoints = [];
  541. for(var j in flow.xPointArray) {
  542. waypoints[j] = {x: flow.xPointArray[j], y: flow.yPointArray[j]};
  543. // width
  544. if (waypoints[j].x > maxX) {
  545. maxX = waypoints[j].x;
  546. }
  547. if (waypoints[j].x < minX) {
  548. minX = waypoints[j].x;
  549. }
  550. // height
  551. if (waypoints[j].y > maxY) {
  552. maxY = waypoints[j].y;
  553. }
  554. if (waypoints[j].y < minY) {
  555. minY = waypoints[j].y;
  556. }
  557. }
  558. }
  559. var laneSets = processDefinitionDiagramLayout.laneSets;
  560. for(var i in laneSets) {
  561. var laneSet = laneSets[i];
  562. //laneSet.id, laneSet.name
  563. for(var j in laneSet.lanes) {
  564. var lane = laneSet.lanes[j];
  565. // width
  566. if (lane.x + lane.width > maxX) {
  567. maxX = lane.x + lane.width;
  568. }
  569. if (lane.x < minX) {
  570. minX = lane.x;
  571. }
  572. // height
  573. if (lane.y + lane.height > maxY) {
  574. maxY = lane.y + lane.height;
  575. }
  576. if (lane.y < minY) {
  577. minY = lane.y;
  578. }
  579. }
  580. }
  581. var diagramCanvas = new ProcessDiagramCanvas();
  582. if (diagramCanvas) {
  583. // create div in diagramHolder
  584. var diagramHolder = document.getElementById(this.options.diagramHolderId);
  585. if (!diagramHolder)
  586. throw {msg: "Diagram holder not found", error: "diagramHolderNotFound"};
  587. var div = document.createElement("DIV");
  588. div.id = processDefinitionDiagramLayout.processDefinition.id;
  589. div.className = "diagram";
  590. diagramHolder.appendChild(div);
  591. diagramCanvas.init(maxX + 20, maxY + 20, processDefinitionDiagramLayout.processDefinition.id);
  592. this.processDiagrams[processDefinitionDiagramLayout.processDefinition.id] = {
  593. processDefinitionDiagramLayout: processDefinitionDiagramLayout,
  594. diagramCanvas: diagramCanvas
  595. };
  596. }
  597. return this.getProcessDiagram(processDefinitionDiagramLayout.processDefinition.id);
  598. //return new DefaultProcessDiagramCanvas(maxX + 10, maxY + 10, minX, minY);
  599. },
  600. drawActivity: function(processDiagramCanvas, activity, highLightedActivities) {
  601. var type = activity.getProperty("type");
  602. var drawInstruction = this.activityDrawInstructions[type];
  603. if (drawInstruction != null) {
  604. drawInstruction.apply({processDiagramCanvas:processDiagramCanvas, activity:activity});
  605. } else {
  606. //console.error("no drawInstruction for " + type + ": ", activity);
  607. }
  608. // Actually draw the markers
  609. if (activity.getProperty("multiInstance") != undefined || activity.getProperty("collapsed") != undefined) {
  610. //console.log(activity.getProperty("name"), activity.properties);
  611. var multiInstanceSequential = (activity.getProperty("multiInstance") == "sequential");
  612. var multiInstanceParallel = (activity.getProperty("multiInstance") == "parrallel");
  613. var collapsed = activity.getProperty("collapsed");
  614. processDiagramCanvas.drawActivityMarkers(activity.getX(), activity.getY(), activity.getWidth(), activity.getHeight(),
  615. multiInstanceSequential, multiInstanceParallel, collapsed);
  616. }
  617. /*
  618. processDiagramCanvas.drawActivityMarkers(activity.getX(), activity.getY(), activity.getWidth(), activity.getHeight(), multiInstanceSequential,
  619. multiInstanceParallel, collapsed);
  620. */
  621. // TODO: Draw highlighted activities if they are present
  622. },
  623. setHighLights: function(highLights){
  624. if (highLights.processDefinitionId == undefined) {
  625. //console.error("Process instance " + highLights.processInstanceId + " doesn't exist");
  626. return;
  627. }
  628. var processDiagram = this.getProcessDiagram(highLights.processDefinitionId);
  629. if (processDiagram == undefined) {
  630. //console.error("Process diagram " + highLights.processDefinitionId + " not found");
  631. return;
  632. }
  633. var processDiagramCanvas = processDiagram.diagramCanvas;
  634. // TODO: remove highLightes from all activities before set new highLight
  635. for (var i in highLights.activities) {
  636. var activityId = highLights.activities[i];
  637. processDiagramCanvas.highLightActivity(activityId);
  638. }
  639. // TODO: remove highLightes from all flows before set new highLight
  640. for (var i in highLights.flows) {
  641. var flowId = highLights.flows[i];
  642. var object = processDiagramCanvas.g.getById(flowId);
  643. var flow = object.data("contextObject");
  644. flow.isHighLighted = true;
  645. processDiagramCanvas.highLightFlow(flowId);
  646. }
  647. },
  648. drawHighLights: function(processInstanceId) {
  649. // Load highLights for the processInstanceId
  650. /*
  651. var url = Lang.sub(this.options.processInstanceHighLightsUrl, {processInstanceId: processInstanceId});
  652. $.ajax({
  653. url: url,
  654. type: 'GET',
  655. dataType: 'json',
  656. cache: false,
  657. async: true,
  658. }).done(function(data) {
  659. var highLights = data;
  660. if (!highLights) {
  661. console.log("highLights not found");
  662. return;
  663. }
  664. console.log("highLights[" + highLights.processDefinitionId + "][" + processInstanceId + "]: ", highLights);
  665. ProcessDiagramGenerator.setHighLights(highLights);
  666. }).fail(function(jqXHR, textStatus){
  667. console.log('Get HighLights['+processDefinitionId+'] failure: ', textStatus, jqXHR);
  668. });
  669. */
  670. ActivitiRest.getHighLights(processInstanceId, this._drawHighLights);
  671. },
  672. _drawHighLights: function() {
  673. var highLights = this.highLights;
  674. ProcessDiagramGenerator.setHighLights(highLights);
  675. },
  676. // Load processDefinition
  677. drawDiagram: function(processDefinitionId) {
  678. // Hide all diagrams
  679. var diagrams = $("#" + this.options.diagramHolderId + " div.diagram");
  680. diagrams.addClass("hidden");
  681. // If processDefinitionId doesn't contain ":" then it's a "processDefinitionKey", not an id.
  682. // Get process definition by key
  683. if (processDefinitionId.indexOf(":") < 0) {
  684. ActivitiRest.getProcessDefinitionByKey(processDefinitionId, this._drawDiagram);
  685. } else {
  686. this._drawDiagram.apply({processDefinitionId: processDefinitionId});
  687. }
  688. },
  689. _drawDiagram: function() {
  690. var processDefinitionId = this.processDefinitionId;
  691. ProcessDiagramGenerator.addBreadCrumbsItem(processDefinitionId);
  692. // Check if processDefinition is already loaded and rendered
  693. var processDiagram = ProcessDiagramGenerator.getProcessDiagram(processDefinitionId);
  694. if (processDiagram != undefined && processDiagram != null) {
  695. //console.log("Process diagram " + processDefinitionId + " is already loaded");
  696. //return;
  697. var diagram = document.getElementById(processDefinitionId);
  698. $(diagram).removeClass("hidden");
  699. // Regenerate image
  700. var processDefinitionDiagramLayout = processDiagram.processDefinitionDiagramLayout;
  701. ProcessDiagramGenerator.generateDiagram(processDefinitionDiagramLayout);
  702. return;
  703. }
  704. //console.time('loadDiagram');
  705. // Load processDefinition
  706. ActivitiRest.getProcessDefinition(processDefinitionId, ProcessDiagramGenerator._generateDiagram);
  707. },
  708. _generateDiagram: function() {
  709. var processDefinitionDiagramLayout = this.processDefinitionDiagramLayout;
  710. //console.log("process-definition-diagram-layout["+processDefinitionDiagramLayout.processDefinition.id+"]: ", processDefinitionDiagramLayout);
  711. //console.timeEnd('loadDiagram');
  712. //console.time('generateDiagram');
  713. pb1.set('value', 0);
  714. ProcessDiagramGenerator.generateDiagram(processDefinitionDiagramLayout);
  715. },
  716. getProcessDefinitionByKey: function(processDefinitionKey) {
  717. var url = Lang.sub(this.options.processDefinitionByKeyUrl, {processDefinitionKey: processDefinitionKey});
  718. var processDefinition;
  719. $.ajax({
  720. url: url,
  721. type: 'POST',
  722. dataType: 'json',
  723. cache: false,
  724. async: false
  725. }).done(function(data) {
  726. //console.log("ajax returned data");
  727. //console.log("ajax returned data:", data);
  728. processDefinition = data;
  729. if (!processDefinition) {
  730. //console.error("Process definition '" + processDefinitionKey + "' not found");
  731. }
  732. }).fail(function(jqXHR, textStatus){
  733. //console.error('Get diagram layout['+processDefinitionKey+'] failure: ', textStatus, jqXHR);
  734. });
  735. if (processDefinition) {
  736. //console.log("Get process definition by key '" + processDefinitionKey + "': ", processDefinition.id);
  737. return processDefinition;
  738. } else {
  739. return null;
  740. }
  741. },
  742. addBreadCrumbsItem: function(processDefinitionId){
  743. var TPL_UL_CONTAINER = '<ul></ul>',
  744. TPL_LI_CONTAINER = '<li id="{id}", processDefinitionId="{processDefinitionId}"><span>{name}</span></li>';
  745. if (!this.diagramBreadCrumbs)
  746. this.diagramBreadCrumbs = $("#" + this.options.diagramBreadCrumbsId);
  747. if (!this.diagramBreadCrumbs) return;
  748. var ul = this.diagramBreadCrumbs.find("ul");
  749. //console.log("ul: ", ul);
  750. if (ul.size() == 0) {
  751. ul = $(TPL_UL_CONTAINER);
  752. this.diagramBreadCrumbs.append(ul);
  753. }
  754. var liListOld = ul.find("li");
  755. //console.warn("liListOld", liListOld);
  756. // TODO: if there is any items after current then remove that before adding new item (m.b. it is a duplicate)
  757. var currentBreadCrumbsItemId = this.currentBreadCrumbsItemId;
  758. found = false;
  759. liListOld.each(
  760. function(index, item) {
  761. //console.warn("item:", $(this));
  762. if (!found && currentBreadCrumbsItemId == $(this).attr("id")) {
  763. found = true;
  764. return;
  765. }
  766. if (found) {
  767. //console.warn("remove ", $(this).attr("id"));
  768. $(this).remove();
  769. }
  770. }
  771. );
  772. var liListNew = ul.find("li");
  773. //console.log("liListNew size: ", liListNew.size());
  774. var values = {
  775. id: 'breadCrumbsItem_' + liListNew.size(),
  776. processDefinitionId: processDefinitionId,
  777. name: processDefinitionId
  778. };
  779. var tpl = Lang.sub(TPL_LI_CONTAINER, values);
  780. //console.log("tpl: ", tpl);
  781. ul.append(tpl);
  782. var li = ul.find("#" + values.id);
  783. //console.warn("li:", li);
  784. $('#' + values.id).on('click', this._breadCrumbsItemClick);
  785. ul.find("li").removeClass("selected");
  786. li.attr("num", liListNew.size());
  787. li.addClass("selected");
  788. this.currentBreadCrumbsItemId = li.attr("id");
  789. },
  790. _breadCrumbsItemClick: function(){
  791. var li = $(this),
  792. id = li.attr("id"),
  793. processDefinitionId = li.attr("processDefinitionId");
  794. //console.warn("_breadCrumbsItemClick: ", id, ", processDefinitionId: ", processDefinitionId);
  795. var ul = ProcessDiagramGenerator.diagramBreadCrumbs.one("ul");
  796. ul.find("li").removeClass("selected");
  797. li.addClass("selected");
  798. ProcessDiagramGenerator.currentBreadCrumbsItemId = li.attr("id");
  799. // Hide all diagrams
  800. var diagrams = $("#"+ProcessDiagramGenerator.options.diagramHolderId+" div.diagram");
  801. diagrams.addClass("hidden");
  802. var processDiagram = ProcessDiagramGenerator.getProcessDiagram(processDefinitionId);
  803. var diagram = document.getElementById(processDefinitionId);
  804. if (!diagram) return;
  805. $(diagram).removeClass("hidden");
  806. // Regenerate image
  807. var processDefinitionDiagramLayout = processDiagram.processDefinitionDiagramLayout;
  808. ProcessDiagramGenerator.generateDiagram(processDefinitionDiagramLayout);
  809. },
  810. showFlowInfo: function(flow){
  811. var diagramInfo = $("#" + this.options.diagramInfoId);
  812. if (!diagramInfo) return;
  813. var values = {
  814. flow: flow.flow,
  815. isDefault: (flow.isDefault)? "true":"",
  816. isConditional: (flow.isConditional)? "true":"",
  817. isHighLighted: (flow.isHighLighted)? "true":"",
  818. sourceActivityId: flow.sourceActivityId,
  819. destinationActivityId: flow.destinationActivityId
  820. };
  821. var TPL_FLOW_INFO = '<div>{flow}</div>'
  822. + '<div><b>sourceActivityId</b>: {sourceActivityId}</div>'
  823. + '<div><b>destinationActivityId</b>: {destinationActivityId}</div>'
  824. + '<div><b>isDefault</b>: {isDefault}</div>'
  825. + '<div><b>isConditional</b>: {isConditional}</div>'
  826. + '<div><b>isHighLighted</b>: {isHighLighted}</div>';
  827. var tpl = Lang.sub(TPL_FLOW_INFO, values);
  828. //console.log("info: ", tpl);
  829. diagramInfo.html(tpl);
  830. },
  831. showActivityInfo: function(activity){
  832. var diagramInfo = $("#" + this.options.diagramInfoId);
  833. if (!diagramInfo) return;
  834. var values = {
  835. activityId: activity.getId(),
  836. name: activity.getProperty("name"),
  837. type: activity.getProperty("type")
  838. };
  839. var TPL_ACTIVITY_INFO = ''
  840. + '<div><b>activityId</b>: {activityId}</div>'
  841. + '<div><b>name</b>: {name}</div>'
  842. + '<div><b>type</b>: {type}</div>';
  843. var TPL_CALLACTIVITY_INFO = ''
  844. + '<div><b>collapsed</b>: {collapsed}</div>'
  845. + '<div><b>processDefinitonKey</b>: {processDefinitonKey}</div>';
  846. var template = TPL_ACTIVITY_INFO;
  847. if (activity.getProperty("type") == "callActivity") {
  848. values.collapsed = activity.getProperty("collapsed");
  849. values.processDefinitonKey = activity.getProperty("processDefinitonKey");
  850. template += TPL_CALLACTIVITY_INFO;
  851. } else if (activity.getProperty("type") == "callActivity") {
  852. }
  853. var tpl = Lang.sub(template, values);
  854. //console.log("info: ", tpl);
  855. diagramInfo.html(tpl);
  856. },
  857. hideInfo: function(){
  858. var diagramInfo = $("#" + this.options.diagramInfoId);
  859. if (!diagramInfo) return;
  860. diagramInfo.html("");
  861. },
  862. vvoid: function(){}
  863. };
  864. var Lang = {
  865. SUBREGEX: /\{\s*([^\|\}]+?)\s*(?:\|([^\}]*))?\s*\}/g,
  866. UNDEFINED: 'undefined',
  867. isUndefined: function(o) {
  868. return typeof o === Lang.UNDEFINED;
  869. },
  870. sub: function(s, o) {
  871. return ((s.replace) ? s.replace(Lang.SUBREGEX, function(match, key) {
  872. return (!Lang.isUndefined(o[key])) ? o[key] : match;
  873. }) : s);
  874. }
  875. };
  876. if (Lang.isUndefined(console)) {
  877. console = { log: function() {}, warn: function() {}, error: function() {}};
  878. }
  879. ProcessDiagramGenerator.init();