Route.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. MWF.xDesktop.requireApp("process.ProcessDesigner", "Property", null, false);
  2. MWF.xApplication.process.ProcessDesigner.Route = new Class({
  3. initialize: function (data, process) {
  4. this.data = data;
  5. this.process = process;
  6. this.paper = this.process.paper;
  7. this.loaded = false;
  8. this.l1 = 8;
  9. this.l2 = 12;
  10. this.aj = 25;
  11. this.corners = [];
  12. this.toSelf = false;
  13. this.isLineEvent = false;
  14. this.isTextEvent = false;
  15. this.isSetEvent = false;
  16. this.isArrowEvent = false;
  17. this.isPointEvent = false;
  18. this.checked = false;
  19. this.isBack = false;
  20. this.isBrokenLine = false;
  21. this.tmpbeginPoint = null;
  22. this.tmpEndPoint = null;
  23. this.toActivity = this.getNextActivity();
  24. this.positionPoints = this.getRoutePoint();
  25. if (!this.process.options.isView) {
  26. this.listItem = new MWF.APPPD.Route.List(this);
  27. this.listItem.load();
  28. }
  29. },
  30. getRoutePoint: function () {
  31. var points = [];
  32. if (this.data.track) {
  33. var pointArr = this.data.track.split(/\s+/g);
  34. pointArr.each(function (p) {
  35. var pArr = p.split(/(?:,\s*){1}|(?:;\s*){1}/g);
  36. points.push({"x": pArr[0], "y": pArr[1]});
  37. }.bind(this));
  38. }
  39. return points;
  40. },
  41. reload: function (fromPath, toPath) {
  42. if (this.toActivity && this.fromActivity) {
  43. if (this.toActivity.data.id == this.fromActivity.data.id) {
  44. this.toSelf = true;
  45. } else {
  46. this.toSelf = false;
  47. }
  48. }
  49. // this.positionPoints = this.getRoutePoint();
  50. this.getPoint(fromPath, toPath);
  51. this.redraw();
  52. },
  53. load: function (fromActivity) {
  54. if (this.process.isNewProcess) {
  55. this.data.createTime = new Date().format('db');
  56. this.data.updateTime = new Date().format('db');
  57. }
  58. if (fromActivity) this.fromActivity = fromActivity;
  59. if (this.toActivity && this.fromActivity) {
  60. if (this.toActivity.data.id == this.fromActivity.data.id) {
  61. this.toSelf = true;
  62. } else {
  63. this.toSelf = false;
  64. }
  65. }
  66. this.getPoint();
  67. this.draw();
  68. this.loaded = true;
  69. },
  70. setActivity: function (toActivity, fromActivity) {
  71. if (toActivity) {
  72. if (this.toActivity) {
  73. this.toActivity.fromRoutes.erase(this);
  74. }
  75. this.toActivity = toActivity;
  76. this.data.activity = this.toActivity.data.id;
  77. this.data.activityType = this.toActivity.data.type;
  78. if (this.toActivity.fromRoutes.indexOf(this) == -1) this.toActivity.fromRoutes.push(this);
  79. }
  80. if (fromActivity) {
  81. if (this.fromActivity) {
  82. this.fromActivity.routes.erase(this);
  83. this.fromActivity.removeRouteData(this.data.id);
  84. // this.fromActivity.data.routeList.erase(this.data.id);
  85. }
  86. this.fromActivity = fromActivity;
  87. if (this.data.id) this.fromActivity.addRouteData(this.data.id);
  88. if (this.fromActivity.routes.indexOf(this) == -1) this.fromActivity.routes.push(this);
  89. }
  90. },
  91. getNextActivity: function () {
  92. var id = this.data.activity;
  93. var type = this.data.activityType;
  94. if (type) {
  95. if (type.toLowerCase() == "begin") {
  96. if (this.process.begin.data.id == id) {
  97. this.process.begin.fromRoutes.push(this);
  98. return this.process.begin;
  99. }
  100. } else {
  101. var activity = this.process[type + "s"][id];
  102. if (activity) {
  103. if (activity.fromRoutes.indexOf(this) == -1) activity.fromRoutes.push(this);
  104. return activity;
  105. }
  106. }
  107. }
  108. return null;
  109. },
  110. redraw: function () {
  111. if (this.beginPoint && this.endPoint) {
  112. if (this.set) {
  113. //this.set.show();
  114. //this.set.clear();
  115. } else {
  116. this.set = this.paper.set();
  117. }
  118. if (this.point) {
  119. this.point.show();
  120. this.point.attr("path", MWFRaphael.getCirclePath(this.beginPoint.x, this.beginPoint.y, 3));
  121. } else {
  122. this.point = this.paper.circlePath(this.beginPoint.x, this.beginPoint.y, 3);
  123. this.point.attr(this.process.css.route.decision.normal);
  124. this.set.push(this.point);
  125. }
  126. if (this.line) {
  127. this.line.show();
  128. this.line.attr("path", this.getLinePath());
  129. } else {
  130. this.line = this.paper.path(this.getLinePath());
  131. this.line.toBack();
  132. this.line.attr(this.process.css.route.line.normal);
  133. this.set.push(this.line);
  134. }
  135. this.line.toBack();
  136. if (this.text) {
  137. this.text.show();
  138. var p = this.getTextPoint();
  139. this.text.attr({
  140. "text": this.data.name || MWF.APPPD.LP.unnamed,
  141. "x": p.x,
  142. "y": p.y
  143. });
  144. } else {
  145. this.text = this.createText();
  146. this.set.push(this.text);
  147. }
  148. if (this.arrow) {
  149. this.arrow.show();
  150. var beginPoint = (this.positionPoints.length) ? this.positionPoints[this.positionPoints.length - 1] : this.beginPoint;
  151. this.arrow.attr("path", MWFRaphael.getArrowPath(beginPoint, this.endPoint, this.l1, this.l2, this.aj));
  152. } else {
  153. this.arrow = this.createArrow();
  154. this.arrow.attr(this.process.css.route.arrow.normal);
  155. this.set.push(this.arrow);
  156. }
  157. if (this.set) {
  158. this.set.attr({"transform": ""});
  159. if (this.checked) {
  160. if (this.process.currentSelected == this) {
  161. this.point.attr(this.process.css.route.decision.selected);
  162. this.line.attr(this.process.css.route.line.selected);
  163. this.arrow.attr(this.process.css.route.arrow.selected);
  164. this.text.attr(this.process.css.route.linetext.selected);
  165. } else {
  166. this.point.attr(this.process.css.route.decision.normal);
  167. this.line.attr(this.process.css.route.line.normal);
  168. this.arrow.attr(this.process.css.route.arrow.normal);
  169. this.text.attr(this.process.css.route.linetext.normal);
  170. }
  171. } else {
  172. this.point.attr(this.process.css.route.decision["no-checked"]);
  173. this.line.attr(this.process.css.route.line["no-checked"]);
  174. this.arrow.attr(this.process.css.route.arrow["no-checked"]);
  175. this.text.attr(this.process.css.route.linetext["no-checked"]);
  176. }
  177. if (this.isBack) {
  178. this.set.toBack();
  179. } else {
  180. this.set.toFront();
  181. }
  182. }
  183. } else {
  184. if (this.point) this.point.hide();
  185. if (this.line) this.line.hide();
  186. if (this.arrow) this.arrow.hide();
  187. if (this.set) this.set.hide();
  188. }
  189. this.setListItemData();
  190. this.setEvent();
  191. },
  192. draw: function () {
  193. if (this.beginPoint && this.endPoint) {
  194. this.point = this.paper.circlePath(this.beginPoint.x, this.beginPoint.y, 3);
  195. this.point.attr(this.process.css.route.decision.normal);
  196. this.line = this.paper.path(this.getLinePath());
  197. this.line.toBack();
  198. this.line.attr(this.process.css.route.line.normal);
  199. this.text = this.createText();
  200. this.arrow = this.createArrow();
  201. this.arrow.attr(this.process.css.route.arrow.normal);
  202. this.set = this.paper.set();
  203. this.set.push(this.point, this.line, this.arrow, this.text);
  204. this.point.data("bind", this);
  205. this.line.data("bind", this);
  206. this.arrow.data("bind", this);
  207. this.text.data("bind", this);
  208. if (!this.toSelf) {
  209. this.positionPoints.each(function (p, idx) {
  210. this.createCorner(p, idx);
  211. }.bind(this));
  212. }
  213. if (this.checked) {
  214. if (this.process.currentSelected == this) {
  215. this.point.attr(this.process.css.route.decision.selected);
  216. this.line.attr(this.process.css.route.line.selected);
  217. this.arrow.attr(this.process.css.route.arrow.selected);
  218. this.text.attr(this.process.css.route.linetext.selected);
  219. } else {
  220. this.point.attr(this.process.css.route.decision.normal);
  221. this.line.attr(this.process.css.route.line.normal);
  222. this.arrow.attr(this.process.css.route.arrow.normal);
  223. this.text.attr(this.process.css.route.linetext.normal);
  224. }
  225. } else {
  226. this.point.attr(this.process.css.route.decision["no-checked"]);
  227. this.line.attr(this.process.css.route.line["no-checked"]);
  228. this.arrow.attr(this.process.css.route.arrow["no-checked"]);
  229. this.text.attr(this.process.css.route.linetext["no-checked"]);
  230. }
  231. if (this.isBack) {
  232. this.set.toBack();
  233. } else {
  234. this.set.toFront();
  235. }
  236. } else {
  237. if (this.point) this.point.hide();
  238. if (this.line) this.line.hide();
  239. if (this.arrow) this.arrow.hide();
  240. if (this.text) this.text.hide();
  241. if (this.set) this.set.hide();
  242. }
  243. this.setEvent();
  244. },
  245. setEvent: function () {
  246. if (this.set) {
  247. if (!this.isSetEvent) {
  248. this.set.mousedown(function (e) {
  249. this.selected();
  250. //this.process.unSelectedEvent = false;
  251. e.stopPropagation();
  252. }.bind(this));
  253. this.set.click(function (e) {
  254. e.stopPropagation();
  255. }.bind(this));
  256. this.isSetEvent = true;
  257. }
  258. ;
  259. }
  260. if (this.line) {
  261. if (!this.isLineEvent) {
  262. this.line.mousedown(function (e) {
  263. if (!this.toSelf) {
  264. var offsetP = MWF.getOffset(e);
  265. this.checkBrokenLineBegin(offsetP.offsetX, offsetP.offsetY);
  266. //this.checkBrokenLineBegin(e.clientX, e.clientY);
  267. }
  268. }.bind(this));
  269. this.isLineEvent = true;
  270. }
  271. ;
  272. }
  273. ;
  274. if (this.arrow) {
  275. if (!this.isArrowEvent) {
  276. this.arrow.drag(
  277. function (dx, dy, x, y, e) {
  278. this.arrowMove(dx, dy, x, y.e);
  279. }.bind(this),
  280. function () {
  281. this.arrowMoveStart();
  282. }.bind(this),
  283. function () {
  284. this.arrowMoveEnd();
  285. }.bind(this)
  286. );
  287. this.arrow.hover(function () {
  288. var beginPoint = this.beginPoint;
  289. if (this.positionPoints.length) {
  290. beginPoint = this.positionPoints[this.positionPoints.length - 1];
  291. }
  292. beginPoint.x = beginPoint.x.toFloat();
  293. beginPoint.y = beginPoint.y.toFloat();
  294. var path = MWFRaphael.getArrowPath(beginPoint, this.endPoint, 20, 30, this.aj);
  295. this.arrow.attr("path", path);
  296. }.bind(this), function () {
  297. var beginPoint = this.beginPoint;
  298. if (this.positionPoints.length) {
  299. beginPoint = this.positionPoints[this.positionPoints.length - 1];
  300. }
  301. beginPoint.x = beginPoint.x.toFloat();
  302. beginPoint.y = beginPoint.y.toFloat();
  303. var path = MWFRaphael.getArrowPath(beginPoint, this.endPoint, this.l1, this.l2, this.aj);
  304. this.arrow.attr("path", path);
  305. }.bind(this));
  306. }
  307. this.isArrowEvent = true;
  308. }
  309. ;
  310. if (this.point) {
  311. if (!this.isPointEvent) {
  312. this.point.drag(
  313. function (dx, dy, x, y, e) {
  314. this.pointMove(dx, dy, x, y.e);
  315. }.bind(this),
  316. function () {
  317. this.pointMoveStart();
  318. }.bind(this),
  319. function () {
  320. this.pointMoveEnd();
  321. }.bind(this)
  322. );
  323. this.point.hover(function () {
  324. var path = MWFRaphael.getCirclePath(this.beginPoint.x, this.beginPoint.y, 8);
  325. this.point.attr("path", path);
  326. }.bind(this), function () {
  327. var path = MWFRaphael.getCirclePath(this.beginPoint.x, this.beginPoint.y, 3);
  328. this.point.attr("path", path);
  329. }.bind(this));
  330. }
  331. this.isPointEvent = true;
  332. }
  333. ;
  334. if (this.text) {
  335. if (!this.isTextEvent) {
  336. this.text.drag(
  337. function (dx, dy, x, y) {
  338. this.textMove(dx, dy, x, y);
  339. }.bind(this),
  340. function () {
  341. this.textMoveStart();
  342. }.bind(this),
  343. function () {
  344. this.textMoveEnd();
  345. }.bind(this)
  346. );
  347. this.isTextEvent = true;
  348. }
  349. }
  350. ;
  351. },
  352. arrowMoveStart: function () {
  353. this.arrow.data("originalPoint", {
  354. "x": this.endPoint.x,
  355. "y": this.endPoint.y
  356. });
  357. // this.arrow.toBack();
  358. // if (this.line) this.line.toBack();
  359. this.process.isChangeRouteTo = true;
  360. this.process.currentChangeRoute = this;
  361. },
  362. arrowMove: function (dx, dy, x, y) {
  363. this.isBack = true;
  364. var p = this.arrow.data("originalPoint");
  365. this.endPoint = {
  366. "x": p.x + dx - 6,
  367. "y": p.y + dy - 6
  368. };
  369. this.redraw();
  370. },
  371. arrowMoveEnd: function () {
  372. this.isBack = false;
  373. if (this.process.isChangeRouteTo) {
  374. this.endPoint = this.arrow.data("originalPoint");
  375. this.redraw();
  376. this.process.isChangeRouteTo = false;
  377. this.process.currentChangeRoute = null;
  378. }
  379. //this.arrow.toFront();
  380. if (this.line) this.line.toFront();
  381. },
  382. pointMoveStart: function () {
  383. this.point.data("originalPoint", {
  384. "x": this.beginPoint.x,
  385. "y": this.beginPoint.y
  386. });
  387. //this.point.toBack();
  388. //if (this.line) this.line.toBack();
  389. this.process.isChangeRouteFrom = true;
  390. this.process.currentChangeRoute = this;
  391. },
  392. pointMove: function (dx, dy, x, y) {
  393. if (dx > 10 || dy > 10) this.isBack = true;
  394. var p = this.point.data("originalPoint");
  395. this.beginPoint = {
  396. "x": p.x + dx - 4,
  397. "y": p.y + dy - 4
  398. };
  399. this.redraw();
  400. },
  401. pointMoveEnd: function () {
  402. this.isBack = false;
  403. if (this.process.isChangeRouteFrom) {
  404. this.beginPoint = this.point.data("originalPoint");
  405. this.redraw();
  406. this.process.isChangeRouteFrom = false;
  407. this.process.currentChangeRoute = null;
  408. }
  409. //this.point.toFront();
  410. if (this.line) this.line.toFront();
  411. },
  412. cornerBrokenLineBegin: function (e, corner) {
  413. if (!this.process.isCreateRoute) {
  414. // var x = e.layerX;
  415. // var y = e.layerY;
  416. var offsetP = MWF.getOffset(e);
  417. var x = offsetP.offsetX;
  418. var y = offsetP.offsetY;
  419. var idx = this.corners.indexOf(corner);
  420. if (idx != -1) {
  421. this.process.brokenLineBeginMousemoveBind = function (e) {
  422. this.doBeginBrokenLine(e, x, y, idx - 1, corner, true);
  423. }.bind(this);
  424. this.process.brokenLineMouseupBind = function () {
  425. this.endBrokenLine();
  426. }.bind(this);
  427. this.paper.canvas.addEvent("mousemove", this.process.brokenLineBeginMousemoveBind);
  428. this.paper.canvas.addEvent("mouseup", this.process.brokenLineMouseupBind);
  429. }
  430. }
  431. },
  432. checkBrokenLineBegin: function (x, y) {
  433. if (!this.process.isCreateRoute) {
  434. var movePointIndex = this.getNearIndex(this.positionPoints, {"x": x, "y": y});
  435. if (movePointIndex === null) {
  436. var idx = this.getCornerPointIndex(x, y);
  437. this.process.brokenLineBeginMousemoveBind = function (e) {
  438. this.doBeginBrokenLine(e, x, y, idx);
  439. }.bind(this);
  440. this.process.brokenLineMouseupBind = function () {
  441. this.endBrokenLine();
  442. }.bind(this);
  443. this.paper.canvas.addEvent("mousemove", this.process.brokenLineBeginMousemoveBind);
  444. this.paper.canvas.addEvent("mouseup", this.process.brokenLineMouseupBind);
  445. } else {
  446. }
  447. }
  448. ;
  449. },
  450. getCornerPointIndex: function (x, y) {
  451. cornerPointIndex = -1;
  452. var tmpLong = 500000;
  453. if (this.positionPoints.length) {
  454. var tmpArr = this.positionPoints.concat(this.endPoint);
  455. tmpArr.unshift(this.beginPoint);
  456. for (var i = 0; i < tmpArr.length - 1; i++) {
  457. var p1 = tmpArr[i];
  458. var p2 = tmpArr[i + 1];
  459. var n = MWFRaphael.getMinDistance({"x": x, "y": y}, p1, p2).h;
  460. if (n < tmpLong) {
  461. tmpLong = n;
  462. cornerPointIndex = i - 1;
  463. }
  464. }
  465. ;
  466. }
  467. ;
  468. return cornerPointIndex;
  469. },
  470. getNearIndex: function (pList, p) {
  471. for (var i = 0; i < pList.length; i++) {
  472. var tmpp = pList[i];
  473. var lineP = {"x": tmpp.x.toFloat(), "y": tmpp.y.toFloat()};
  474. var tmp = MWFRaphael.getPointDistance(p, lineP);
  475. if (tmp <= 8) {
  476. return i;
  477. }
  478. }
  479. return null;
  480. },
  481. endBrokenLine: function () {
  482. this.process.isBrokenLine = false;
  483. if (this.removeCorner) {
  484. this.corners.splice(this.removeCorner.idx + 1, 1);
  485. this.removeCorner.corner.remove();
  486. this.positionPoints.splice(this.removeCorner.idx + 1, 1);
  487. this.removeCorner = null;
  488. }
  489. this.isBrokenLine = false;
  490. this.data.track = this.positionPointsToString();
  491. this.paper.canvas.removeEvent("mouseup", this.process.brokenLineMouseupBind);
  492. this.paper.canvas.removeEvent("mousemove", this.process.brokenLineBeginMousemoveBind);
  493. this.paper.canvas.removeEvent("mousemove", this.process.brokenLineMousemoveBind);
  494. },
  495. positionPointsToString: function () {
  496. var arr = [];
  497. this.positionPoints.each(function (p) {
  498. arr.push(p.x + "," + p.y);
  499. });
  500. return arr.join(" ");
  501. },
  502. doBeginBrokenLine: function (e, x, y, idx, corner, noCreateP) {
  503. var p1 = this.positionPoints[idx] || this.beginPoint;
  504. var p2 = this.positionPoints[idx + 2] || this.endPoint;
  505. var offsetP = MWF.getOffset(e.event);
  506. var n = MWFRaphael.getMinDistance({
  507. "x": offsetP.offsetX,
  508. "y": offsetP.offsetY
  509. }, p1, p2).h;
  510. if (n > 6) {
  511. this.process.isBrokenLine = true;
  512. this.isBrokenLine = true;
  513. if (!corner || this.removeCorner) {
  514. if (!noCreateP) this.positionPoints.splice(idx + 1, 0, {
  515. "x": offsetP.offsetX,
  516. "y": offsetP.offsetY
  517. });
  518. if (this.removeCorner) {
  519. corner = this.removeCorner.corner;
  520. this.removeCorner = null;
  521. } else {
  522. corner = this.createCorner(this.positionPoints[idx + 1], idx + 1);
  523. }
  524. }
  525. corner.attr(this.process.css.route.corner["default"]);
  526. this.paper.canvas.removeEvent("mousemove", this.process.brokenLineBeginMousemoveBind);
  527. this.reload();
  528. this.process.brokenLineMousemoveBind = function (e) {
  529. this.doBrokenLine(e, idx, corner);
  530. }.bind(this);
  531. this.paper.canvas.addEvent("mousemove", this.process.brokenLineMousemoveBind);
  532. }
  533. ;
  534. },
  535. doBrokenLine: function (e, idx, corner) {
  536. var offsetP = MWF.getOffset(e.event);
  537. var toX = offsetP.offsetX;
  538. var toY = offsetP.offsetY;
  539. // if (this.process.isGrid){
  540. toX = Raphael.snapTo(10, toX, 10);
  541. toY = Raphael.snapTo(10, toY, 10);
  542. // }
  543. var p1 = this.positionPoints[idx] || this.beginPoint;
  544. var p2 = this.positionPoints[idx + 2] || this.endPoint;
  545. var offset = MWFRaphael.getMinDistance({"x": toX, "y": toY}, p1, p2);
  546. var off = offset.h;
  547. if (off < 6) {
  548. this.removeCorner = {"corner": corner, "idx": idx};
  549. corner.attr("path", MWFRaphael.getRectPath((offset.p.x.toFloat()) - 2.5, (offset.p.y.toFloat()) - 2.5, 5, 5, 0));
  550. if (this.positionPoints[idx + 1]) this.positionPoints[idx + 1].x = offset.p.x;
  551. if (this.positionPoints[idx + 1]) this.positionPoints[idx + 1].y = offset.p.y;
  552. this.reload();
  553. this.process.brokenLineBeginMousemoveBind = function (e) {
  554. this.doBeginBrokenLine(e, toX, toY, idx, null, true);
  555. }.bind(this);
  556. this.paper.canvas.removeEvent("mousemove", this.process.brokenLineMousemoveBind);
  557. this.paper.canvas.addEvent("mousemove", this.process.brokenLineBeginMousemoveBind);
  558. } else {
  559. if (Math.abs(p1.x - toX) < 5) toX = p1.x;
  560. if (Math.abs(p1.y - toY) < 5) toY = p1.y;
  561. if (Math.abs(p2.x - toX) < 5) toX = p2.x;
  562. if (Math.abs(p2.y - toY) < 5) toY = p2.y;
  563. var path = MWFRaphael.getRectPath(toX - 2.5, toY - 2.5, 5, 5, 0);
  564. corner.attr("path", path);
  565. if (this.positionPoints[idx + 1]) this.positionPoints[idx + 1].x = toX;
  566. if (this.positionPoints[idx + 1]) this.positionPoints[idx + 1].y = toY;
  567. this.reload();
  568. }
  569. },
  570. selected: function () {
  571. this.process.unSelectedAll();
  572. if (this.line) this.line.attr(this.process.css.route.line.selected);
  573. if (this.point) this.point.attr(this.process.css.route.decision.selected);
  574. if (this.arrow) this.arrow.attr(this.process.css.route.arrow.selected);
  575. if (this.text) this.text.attr(this.process.css.route.linetext.selected);
  576. this.corners.each(function (corner) {
  577. corner.show();
  578. });
  579. this.process.currentSelected = this;
  580. if (this.listItem) this.listItem.selected();
  581. this.set.toFront();
  582. this.showProperty();
  583. },
  584. unSelected: function () {
  585. if (this.checked) {
  586. this.point.attr(this.process.css.route.decision.normal);
  587. this.line.attr(this.process.css.route.line.normal);
  588. this.arrow.attr(this.process.css.route.arrow.normal);
  589. this.text.attr(this.process.css.route.linetext.normal);
  590. } else {
  591. this.point.attr(this.process.css.route.decision["no-checked"]);
  592. this.line.attr(this.process.css.route.line["no-checked"]);
  593. this.arrow.attr(this.process.css.route.arrow["no-checked"]);
  594. this.text.attr(this.process.css.route.linetext["no-checked"]);
  595. }
  596. this.corners.each(function (corner) {
  597. corner.hide();
  598. });
  599. this.process.currentSelected = null;
  600. if (this.listItem) this.listItem.unSelected();
  601. if (this.property) this.property.hide();
  602. },
  603. textMove: function (dx, dy, x, y) {
  604. var x = (this.text.moveX.toFloat()) + parseFloat(dx);
  605. var y = (this.text.moveY.toFloat()) + parseFloat(dy);
  606. var dp = this.getDefaultTextPoint();
  607. var d = MWFRaphael.getPointDistance(dp, {"x": x, "y": y});
  608. if (d < 5) {
  609. this.text.attr({
  610. "x": dp.x,
  611. "y": dp.y
  612. });
  613. } else {
  614. this.text.attr({
  615. "x": x,
  616. "y": y
  617. });
  618. }
  619. },
  620. textMoveStart: function () {
  621. this.text.moveX = this.text.attr("x");
  622. this.text.moveY = this.text.attr("y");
  623. },
  624. textMoveEnd: function () {
  625. var x = this.text.attr("x");
  626. var y = this.text.attr("y");
  627. var dp = this.getDefaultTextPoint();
  628. var d = MWFRaphael.getPointDistance(dp, {"x": x, "y": y});
  629. if (d < 5) {
  630. this.data.position = "";
  631. } else {
  632. this.data.position = x + "," + y;
  633. }
  634. },
  635. getLinePath: function () {
  636. var path = "";
  637. if (this.beginPoint && this.endPoint) {
  638. path = "M" + this.beginPoint.x + "," + this.beginPoint.y;
  639. this.positionPoints.each(function (p, idx) {
  640. var p0;
  641. var p2;
  642. if (idx == 0) {
  643. p0 = this.beginPoint;
  644. } else {
  645. p0 = this.positionPoints[idx - 1];
  646. }
  647. if (this.positionPoints[idx + 1]) {
  648. p2 = this.positionPoints[idx + 1];
  649. } else {
  650. p2 = this.endPoint;
  651. }
  652. p.x = p.x.toFloat();
  653. p.y = p.y.toFloat();
  654. var minus1 = MWFRaphael.getMinus(Math.abs(p.x - p0.x), Math.abs(p.y - p0.y), 12);
  655. var minus2 = MWFRaphael.getMinus(Math.abs(p.x - p2.x), Math.abs(p.y - p2.y), 12);
  656. var qp0 = null;
  657. var qp2 = null;
  658. if (p.x >= p0.x && p.y >= p0.y) {
  659. qp0 = {"x": p.x - minus1.x, "y": p.y - minus1.y};
  660. } else if (p.x <= p0.x && p.y <= p0.y) {
  661. qp0 = {"x": p.x + minus1.x, "y": p.y + minus1.y};
  662. } else if (p.x >= p0.x && p.y <= p0.y) {
  663. qp0 = {"x": p.x - minus1.x, "y": p.y + minus1.y};
  664. } else if (p.x <= p0.x && p.y >= p0.y) {
  665. qp0 = {"x": p.x + minus1.x, "y": p.y - minus1.y};
  666. }
  667. if (p.x >= p2.x && p.y >= p2.y) {
  668. qp2 = {"x": p.x - minus2.x, "y": p.y - minus2.y};
  669. } else if (p.x <= p2.x && p.y <= p2.y) {
  670. qp2 = {"x": p.x + minus2.x, "y": p.y + minus2.y};
  671. } else if (p.x >= p2.x && p.y <= p2.y) {
  672. qp2 = {"x": p.x - minus2.x, "y": p.y + minus2.y};
  673. } else if (p.x <= p2.x && p.y >= p2.y) {
  674. qp2 = {"x": p.x + minus2.x, "y": p.y - minus2.y};
  675. }
  676. path += "L" + qp0.x + "," + qp0.y;
  677. path += "Q" + p.x + ", " + p.y + ", " + qp2.x + "," + qp2.y;
  678. }.bind(this));
  679. path += "L" + this.endPoint.x + "," + this.endPoint.y;
  680. }
  681. return path;
  682. },
  683. getDefaultTextPoint: function () {
  684. var x = "";
  685. var y = "";
  686. if (this.toSelf) {
  687. x = this.positionPoints[2].x + (this.positionPoints[1].x - this.positionPoints[2].x) / 2;
  688. y = this.positionPoints[2].y - 8;
  689. } else {
  690. var p1 = this.beginPoint;
  691. var p2 = this.endPoint;
  692. if (this.positionPoints[0]) p2 = this.positionPoints[0];
  693. var xoff = (p2.x.toFloat() - p1.x.toFloat()) * 0.4;
  694. var yoff = (p2.y.toFloat() - p1.y.toFloat()) * 0.4;
  695. x = p1.x.toFloat() + xoff;
  696. y = p1.y.toFloat() + yoff;
  697. }
  698. return {"x": x, "y": y};
  699. },
  700. getTextPoint: function () {
  701. var x = "";
  702. var y = "";
  703. if (this.data.position) {
  704. var pArr = this.data.position.split(/(?:,\s*){1}|(?:;\s*){1}/g);
  705. x = pArr[0];
  706. y = pArr[1];
  707. } else {
  708. var p = this.getDefaultTextPoint();
  709. x = p.x;
  710. y = p.y;
  711. }
  712. return {"x": x, "y": y};
  713. },
  714. createText: function () {
  715. var text = null;
  716. if (this.beginPoint && this.endPoint) {
  717. var p = this.getTextPoint();
  718. text = this.paper.text(p.x, p.y, this.data.name || MWF.APPPD.LP.unnamed);
  719. text.attr(this.process.css.route.linetext.normal);
  720. return text;
  721. }
  722. },
  723. createArrow: function () {
  724. var beginPoint = this.beginPoint;
  725. if (this.positionPoints.length) {
  726. beginPoint = this.positionPoints[this.positionPoints.length - 1];
  727. }
  728. beginPoint.x = beginPoint.x.toFloat();
  729. beginPoint.y = beginPoint.y.toFloat();
  730. return this.paper.arrow(beginPoint, this.endPoint, this.l1, this.l2, this.aj);
  731. },
  732. createCorner: function (p, idx) {
  733. var corner = this.paper.rectPath((p.x.toFloat()) - 2.5, (p.y.toFloat()) - 2.5, 5, 5, 0);
  734. corner.data("position", p);
  735. corner.attr(this.process.css.route.corner["default"]);
  736. corner.hide();
  737. this.corners.splice(idx, 0, corner);
  738. corner.mousedown(function (e) {
  739. this.cornerBrokenLineBegin(e, corner);
  740. }.bind(this));
  741. this.set.push(corner);
  742. return corner;
  743. },
  744. getPoint: function (fromPath, toPath) {
  745. var fromActivityPath = fromPath;
  746. if (this.fromActivity) {
  747. if (!fromActivityPath) fromActivityPath = this.fromActivity.shap.attr("path");
  748. }
  749. var toActivityPath = toPath;
  750. if (this.toActivity) {
  751. if (!toActivityPath) toActivityPath = this.toActivity.shap.attr("path");
  752. }
  753. if (fromActivityPath && toActivityPath) {
  754. this.checked = true;
  755. if (this.toSelf) {
  756. var p1x = this.fromActivity.center.x + this.fromActivity.width;
  757. var p1y = this.fromActivity.center.y;
  758. var p2x = this.fromActivity.center.x + this.fromActivity.width;
  759. var p2y = this.fromActivity.center.y - this.fromActivity.height;
  760. var p3x = this.fromActivity.center.x;
  761. var p3y = this.fromActivity.center.y - this.fromActivity.height;
  762. this.positionPoints = [];
  763. this.positionPoints.push({"x": p1x, "y": p1y});
  764. this.positionPoints.push({"x": p2x, "y": p2y});
  765. this.positionPoints.push({"x": p3x, "y": p3y});
  766. this.beginPoint = {
  767. "x": this.fromActivity.center.x + this.fromActivity.width / 2,
  768. "y": this.fromActivity.center.y
  769. };
  770. this.endPoint = {
  771. "x": this.fromActivity.center.x,
  772. "y": this.fromActivity.center.y - this.fromActivity.height / 2
  773. };
  774. } else {
  775. var beginLinePath;
  776. var endLinePath;
  777. if (this.positionPoints[0]) {
  778. beginLinePath = "M" + this.fromActivity.center.x + "," + this.fromActivity.center.y + "L" + this.positionPoints[0].x + "," + this.positionPoints[0].y;
  779. var p = this.positionPoints[this.positionPoints.length - 1];
  780. endLinePath = "M" + p.x + "," + p.y + "L" + this.toActivity.center.x + "," + this.toActivity.center.y;
  781. } else {
  782. beginLinePath = "M" + this.fromActivity.center.x + "," + this.fromActivity.center.y + "L" + this.toActivity.center.x + "," + this.toActivity.center.y;
  783. endLinePath = "M" + this.fromActivity.center.x + "," + this.fromActivity.center.y + "L" + this.toActivity.center.x + "," + this.toActivity.center.y;
  784. }
  785. var decisionPoints = Raphael.pathIntersection(beginLinePath, fromActivityPath);
  786. var endPoints = Raphael.pathIntersection(endLinePath, toActivityPath);
  787. this.beginPoint = decisionPoints[0];
  788. this.endPoint = endPoints[0];
  789. }
  790. }
  791. if (!fromActivityPath && toActivityPath) {
  792. this.checked = false;
  793. var decisionY;
  794. var decisionX;
  795. if (this.tmpBeginPoint) {
  796. decisionY = this.tmpBeginPoint.y.toFloat();
  797. decisionX = this.tmpBeginPoint.x.toFloat();
  798. } else {
  799. decisionY = this.toActivity.center.y.toFloat() - 500;
  800. decisionX = this.toActivity.center.x.toFloat();
  801. }
  802. var endLinePath = "M" + decisionX + "," + decisionY + "L" + this.toActivity.center.x + "," + this.toActivity.center.y;
  803. var endPoints = Raphael.pathIntersection(endLinePath, toActivityPath);
  804. this.endPoint = endPoints[0];
  805. this.beginPoint = this.tmpBeginPoint || {"x": this.endPoint.x, "y": this.endPoint.y - 30};
  806. this.tmpBeginPoint = null;
  807. }
  808. if (fromActivityPath && !toActivityPath) {
  809. this.checked = false;
  810. var endY;
  811. var endX;
  812. if (this.tmpEndPoint) {
  813. endY = this.tmpEndPoint.y.toFloat();
  814. endX = this.tmpEndPoint.x.toFloat();
  815. } else {
  816. endY = this.fromActivity.center.y.toFloat() + 500;
  817. endX = this.fromActivity.center.x.toFloat();
  818. }
  819. var beginLinePath = "M" + this.fromActivity.center.x + "," + this.fromActivity.center.y + "L" + endX + "," + endY;
  820. var decisionPoints = Raphael.pathIntersection(beginLinePath, fromActivityPath);
  821. this.beginPoint = decisionPoints[0];
  822. this.endPoint = this.tmpEndPoint || {"x": this.beginPoint.x, "y": this.beginPoint.y + 30};
  823. this.tmpEndPoint = null;
  824. }
  825. if (!fromActivityPath && !toActivityPath) {
  826. this.checked = false;
  827. this.beginPoint = {"x": 10, "y": 10};
  828. this.endPoint = {"x": 10, "y": 30};
  829. }
  830. },
  831. setListItemData: function () {
  832. if (this.listItem) {
  833. var routeName = this.data.name || MWF.APPPD.LP.unnamed;
  834. var name = "";
  835. if (this.toActivity) {
  836. name = this.toActivity.data.name;
  837. if (!name) name = MWF.APPPD.LP.unnamed;
  838. } else {
  839. name = MWF.APPPD.LP.unknow;
  840. }
  841. this.listItem.row.tds[1].set("text", routeName + " (to " + name + ")");
  842. }
  843. },
  844. destroy: function () {
  845. if (this.fromActivity) {
  846. this.fromActivity.removeRouteData(this.data.id);
  847. // if (this.fromActivity.data.routeList){
  848. // this.fromActivity.data.routeList.erase(this.data.id);
  849. // }
  850. this.fromActivity.routes.erase(this);
  851. }
  852. if (this.listItem) {
  853. this.listItem.row.tr.destroy();
  854. }
  855. var routes = {};
  856. var routeDatas = {};
  857. for (rid in this.process.routes) {
  858. if (rid != this.data.id) {
  859. routes[rid] = this.process.routes[rid];
  860. routeDatas[rid] = this.process.routeDatas[rid];
  861. } else {
  862. this.process.routes[rid] = null;
  863. this.process.routeDatas[rid] = null;
  864. }
  865. }
  866. this.process.routes = null;
  867. this.process.routeDatas = null;
  868. this.process.routes = routes;
  869. this.process.routeDatas = routeDatas;
  870. this.process.process.routeList.erase(this.data);
  871. this.set.remove();
  872. },
  873. showProperty: function () {
  874. if (!this.property) {
  875. this.property = new MWF.APPPD.Route.Property(this, {
  876. "onPostLoad": function () {
  877. this.property.show();
  878. }.bind(this)
  879. });
  880. this.property.load();
  881. } else {
  882. this.property.show();
  883. }
  884. },
  885. _setEditProperty: function (name, input, oldValue) {
  886. if (name === "passExpired" || name === "passSameTarget") {
  887. if (this.data[name]) {
  888. if (this.fromActivity) {
  889. this.fromActivity.routes.each(function(route){
  890. if (route.data.id !== this.data.id) {
  891. if (route.data[name]) {
  892. route.data[name] = false;
  893. if (route.property){
  894. var node = route.property.propertyContent.getElementById(route.data.id+name);
  895. if (node) node.getElements("input")[1].set("checked", true);
  896. }
  897. }
  898. }
  899. }.bind(this));
  900. }
  901. }
  902. }
  903. }
  904. });
  905. MWF.xApplication.process.ProcessDesigner.Route.List = new Class({
  906. initialize: function(route){
  907. this.route = route;
  908. this.process = route.process;
  909. this.paper = this.route.paper;
  910. },
  911. load: function(){
  912. var routeName = this.route.data.name || MWF.APPPD.LP.unnamed;
  913. var name = "";
  914. if (this.route.toActivity){
  915. name = this.route.toActivity.data.name;
  916. if (!name) name = MWF.APPPD.LP.unnamed;
  917. } else {
  918. name = MWF.APPPD.LP.unknow;
  919. }
  920. this.row = this.process.routeTable.push([
  921. {
  922. "content": " ",
  923. "properties": {
  924. "styles": this.process.css.route.icon
  925. }
  926. },
  927. {
  928. "content": routeName+" (to "+name+")",
  929. "properties": {
  930. "styles": this.process.css.list.listText
  931. }
  932. },
  933. {
  934. "content": "<img src=\""+"/x_component_process_ProcessDesigner/$Process/default/icon/copy.png"+"\" />",
  935. "properties": {
  936. "styles": this.process.css.list.listIcon,
  937. "events": {
  938. "click": this.copyRoute.bind(this)
  939. }
  940. }
  941. },
  942. {
  943. "content": "<img src=\""+"/x_component_process_ProcessDesigner/$Process/default/icon/delete.png"+"\" />",
  944. "properties": {
  945. "styles": this.process.css.list.listIcon,
  946. "events": {
  947. "click": this.deleteRoute.bind(this)
  948. }
  949. }
  950. }
  951. ]
  952. );
  953. this.row.tr.addEvent("click", function(){
  954. this.listSelected();
  955. }.bind(this));
  956. },
  957. copyRoute: function(){
  958. this.process.copyRoute(this.route);
  959. },
  960. deleteRoute: function(e){
  961. this.process.deleteRoute(e, this.route);
  962. },
  963. selected: function(){
  964. if (this.process.currentListSelected) this.process.currentListSelected.listUnSelected();
  965. this.row.tr.setStyles(this.process.css.list.listRowSelected);
  966. this.process.currentListSelected = this;
  967. },
  968. unSelected: function(){
  969. this.process.currentListSelected = null;
  970. this.row.tr.setStyles(this.process.css.list.listRow);
  971. },
  972. listSelected: function(){
  973. this.route.selected();
  974. },
  975. listUnSelected: function(){
  976. this.route.unSelected();
  977. }
  978. });
  979. MWF.xApplication.process.ProcessDesigner.Route.Property = new Class({
  980. Implements: [Options, Events],
  981. Extends: MWF.APPPD.Property,
  982. initialize: function(route, options){
  983. this.setOptions(options);
  984. this.route = route;
  985. this.process = route.process;
  986. this.paper = this.process.paper;
  987. this.data = route.data;
  988. this.htmlPath = "/x_component_process_ProcessDesigner/$Process/route.html";
  989. },
  990. setValue: function(name, value){
  991. this.data[name] = value;
  992. if (name=="name"){
  993. if (!value) this.data[name] = MWF.APPPD.LP.unnamed;
  994. this.route.reload();
  995. }
  996. },
  997. show: function(){
  998. if (!this.process.options.isView){
  999. if (!this.propertyContent){
  1000. this.propertyContent = new Element("div", {"styles": {"overflow": "hidden"}}).inject(this.process.propertyListNode);
  1001. this.process.panel.propertyTabPage.showTabIm();
  1002. this.JsonTemplate = new MWF.widget.JsonTemplate(this.data, this.htmlString);
  1003. this.propertyContent.set("html", this.JsonTemplate.load());
  1004. this.process.panel.data = this.data;
  1005. this.loadRouteCondition();
  1006. this.setEditNodeEvent();
  1007. this.setEditNodeStyles(this.propertyContent);
  1008. this.loadPropertyTab();
  1009. this.loadPersonInput();
  1010. this.loadScriptInput();
  1011. this.loadScriptText();
  1012. this.loadConditionInput();
  1013. this.loadFormSelect();
  1014. }else{
  1015. this.propertyContent.setStyle("display", "block");
  1016. }
  1017. }
  1018. },
  1019. loadRouteCondition: function(){
  1020. var routeConditionNode = this.propertyContent.getElement(".MWFRouteCondition");
  1021. var type = this.route.fromActivity.type;
  1022. if (type=="choice" || type=="condition" || type=="parallel"){
  1023. if (!routeConditionNode){
  1024. routeConditionNode = new Element("div.MWFTab", {
  1025. "title": MWF.APPPD.LP.condition,
  1026. "html": "<div class=\"MWFScriptText\" name=\"scriptText\"></div>"
  1027. }).inject(this.propertyContent.getFirst());
  1028. }
  1029. }else{
  1030. if (routeConditionNode) routeConditionNode.destroy();
  1031. }
  1032. }
  1033. //loadScriptText: function(){
  1034. // var node = this.propertyContent.getElement(".MWFScriptText");
  1035. // if (node){
  1036. // MWF.require("MWF.xApplication.process.ProcessDesigner.widget.ScriptText", function(){
  1037. // var _self = this;
  1038. // // scriptNodes.each(function(node){
  1039. // var data = (_self.route.fromActivity.data.extension) ? JSON.decode(_self.route.fromActivity.data.extension) : {};
  1040. // var code = (data[_self.route.data.id]) || "";
  1041. //
  1042. // var script = new MWF.xApplication.process.ProcessDesigner.widget.ScriptText(node, code, this.process.designer, {
  1043. // "maskNode": this.process.designer.content,
  1044. // "onChange": function(code){
  1045. // var id = _self.route.data.id;
  1046. // data[id] = code;
  1047. // var jsonString = JSON.encode(data);
  1048. // _self.route.fromActivity.data.extension = jsonString;
  1049. // _self.route.fromActivity.data.scriptText = "return this.library.choiceRoute('"+encodeURIComponent(jsonString)+"');";
  1050. // }
  1051. // });
  1052. // //this.setScriptItems(script, node);
  1053. // // }.bind(this));
  1054. // }.bind(this));
  1055. // }
  1056. //}
  1057. });