Route.js 43 KB

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