Activity.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. MWF.xDesktop.requireApp("process.ProcessDesigner", "Property", null, false);
  2. MWF.xApplication.process.ProcessDesigner.Activity = 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.routes = [];
  9. this.fromRoutes = [];
  10. // this.decisions = [];
  11. // this.fromDecisions = [];
  12. // this.fromRoutes = [];
  13. this.setType();
  14. this.setStyle();
  15. this.setSize();
  16. this.getPoint();
  17. this.selectedMultiStatus = false;
  18. this.positionLoaded = false;
  19. },
  20. setType: function(){
  21. this.type = "activity";
  22. this.data.type = "activity";
  23. },
  24. setStyle: function(){
  25. this.style = this.process.css.activity["default"];
  26. },
  27. setSize: function(){
  28. var size = MWF.getTextSize(this.data.name, this.style.text);
  29. this.width = size.x+38;
  30. this.width = this.width<100 ? 100: this.width;
  31. this.height = 40;
  32. },
  33. getPoint: function(){
  34. this.paperSize = $(this.paper.canvas).getParent().getSize();
  35. this.paperOriginalSize = {x: this.paperSize.x*0.99, y: this.paperSize.y*0.99};
  36. var height = this.paperSize.y;
  37. var width = this.paperSize.x;
  38. this.top = height/2;
  39. this.left = width/2;
  40. this.center = {x: this.left, y: this.top};
  41. this.point = {x: this.left-(this.width/2), y: this.top-(this.height/2)};
  42. },
  43. resetPoint: function(){
  44. this.center = {x: this.point.x + this.width/2, y: this.point.y + this.height/2};
  45. },
  46. checkUUID: function(){
  47. for (var i=0; i<this.routes.length; i++){
  48. delete this.process.routes[this.routes[i].data.id];
  49. delete this.process.routeDatas[this.routes[i].data.id];
  50. this.routes[i].data.id = this.process.checkUUIDs.pop().id;
  51. this.routes[i].data.process = this.process.process.id;
  52. this.setRouteData(this.routes[i].data.id, i);
  53. //this.data.routeList[i] = this.routes[i].data.id;
  54. this.routes[i].data.activity = this.routes[i].toActivity.data.id;
  55. this.process.routes[this.routes[i].data.id] = this.routes[i];
  56. this.process.routeDatas[this.routes[i].data.id] = this.routes[i].data;
  57. }
  58. },
  59. loaded: function(callback){
  60. if (this.positionLoaded){
  61. if (callback) callback();
  62. }
  63. },
  64. load : function(callback){
  65. if (this.process.isNewProcess){
  66. this.data.createTime = new Date().format('db');
  67. this.data.updateTime = new Date().format('db');
  68. }
  69. this.draw();
  70. this.setActivityPosition(function(){
  71. this.positionLoaded = true;
  72. this.loaded(callback);
  73. }.bind(this));
  74. this.setEvent();
  75. if (this.process.activityListNode) this.addToActivityList();
  76. // this.setPosition(100,100);
  77. },
  78. addToActivityList: function(){
  79. this.listItem = new MWF.APPPD.Activity.List(this);
  80. this.listItem.load();
  81. },
  82. create: function(point){
  83. this.point = point || {x: 100, y: 100};
  84. this.center = {"x": this.point.x+(this.width/2), "y": this.point.y+(this.height/2)};
  85. //this.center = center || {x: 100, y: 100};
  86. //this.point = {x: this.center.x-(this.width/2), y: this.center.y-(this.height/2)};
  87. this.draw();
  88. this.setEvent();
  89. if (this.process.activityListNode) this.addToActivityList();
  90. },
  91. setEvent: function(){
  92. if (!this.process.options.isView){
  93. this.set.drag(
  94. function(dx, dy, x, y, e){
  95. if (!e.rightClick){
  96. if (this.process.selectedActivitys.length){
  97. this.noselected = true;
  98. this.process.selectedActivitys.each(function(activity){
  99. activity.activityMove(dx, dy, x, y);
  100. });
  101. }else{
  102. this.activityMove(dx, dy, x, y);
  103. }
  104. }
  105. }.bind(this),
  106. function(x, y, e){
  107. if (!e.rightClick){
  108. if (this.process.selectedActivitys.length){
  109. this.process.selectedActivitys.each(function(activity){
  110. activity.activityMoveStart();
  111. });
  112. }else{
  113. this.activityMoveStart();
  114. }
  115. }
  116. }.bind(this),
  117. function(e){
  118. if (!e.rightClick){
  119. if (this.process.selectedActivitys.length){
  120. this.process.selectedActivitys.each(function(activity){
  121. activity.activityMoveEnd();
  122. });
  123. }else{
  124. this.activityMoveEnd();
  125. }
  126. }
  127. }.bind(this)
  128. );
  129. //this.set.drag(
  130. // function(dx, dy, x, y, e){}.bind(this),
  131. // function(x, y, e){}.bind(this),
  132. // function(e){}.bind(this)
  133. //);
  134. this.set.click(function(e){
  135. if (this.process.isCreateRoute){
  136. this.checkCreateRoute();
  137. }else{
  138. if (this.process.selectedActivitys.length){
  139. if (!this.noselected){
  140. if (this.process.currentSelected != this){
  141. this.selected();
  142. }
  143. }
  144. this.noselected = false;
  145. }
  146. }
  147. e.stopPropagation();
  148. }.bind(this));
  149. this.set.dblclick(function(){
  150. this.quickCreateRoute();
  151. }.bind(this));
  152. // this.set.mouseup(function(e){
  153. // }.bind(this));
  154. this.set.mousedown(function(e){
  155. if (this.process.isCreateRoute){
  156. this.checkCreateRoute();
  157. }else{
  158. if (!this.process.selectedActivitys.length){
  159. if (this.process.currentSelected != this){
  160. this.selected();
  161. }
  162. }
  163. }
  164. //this.checkCreateRoute();
  165. e.stopPropagation();
  166. }.bind(this));
  167. // this.shap.node.mousedown(function(e){
  168. // e.stop();
  169. // });
  170. // this.text.node.mousedown(function(e){
  171. // e.stop();
  172. // });
  173. // this.icon.node.mousedown(function(e){
  174. // e.stop();
  175. // });
  176. this.set.hover(this.mouseHover.bind(this), function(){
  177. if (this.process.isCreateRoute || this.process.isCopyRoute || this.process.isChangeRouteTo || this.process.isChangeRouteFrom){
  178. this.shap.attr(this.style.shap);
  179. }
  180. }.bind(this));
  181. this.set.mouseup(function(){
  182. this.mouseUp();
  183. }.bind(this));
  184. }
  185. },
  186. mouseHover: function(){
  187. if (this.process.isCreateRoute || this.process.isCopyRoute || this.process.isChangeRouteTo || this.process.isChangeRouteFrom){
  188. this.shap.attr({"stroke-width": "2"});
  189. }
  190. },
  191. mouseUp: function(){
  192. if (this.process.isChangeRouteTo){
  193. this.process.currentChangeRoute.setActivity(this, null);
  194. this.process.currentChangeRoute.isBack = false;
  195. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  196. this.process.currentChangeRoute.reload();
  197. this.process.isChangeRouteTo = false;
  198. this.process.currentChangeRoute = null;
  199. }
  200. if (this.process.isChangeRouteFrom){
  201. this.process.currentChangeRoute.setActivity(null, this);
  202. this.process.currentChangeRoute.isBack = false;
  203. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  204. this.process.currentChangeRoute.reload();
  205. this.process.isChangeRouteFrom = false;
  206. this.process.currentChangeRoute = null;
  207. }
  208. this.shap.attr(this.style.shap);
  209. },
  210. quickCreateRoute: function(){
  211. this.process.createRoute();
  212. this.process.routeCreateFromActivity(this);
  213. },
  214. checkCreateRoute: function(){
  215. if (this.process.isCreateRoute){
  216. var route = this.process.currentCreateRoute;
  217. if (!route.fromActivity){
  218. this.process.routeCreateFromActivity(this);
  219. }else{
  220. this.process.routeCreateToActivity(this);
  221. }
  222. }
  223. if (this.process.isCopyRoute){
  224. this.process.routeAddFromActivity(this);
  225. }
  226. },
  227. draw: function(){
  228. this.set = this.paper.set();
  229. this.shap = this.createShap();
  230. // this.shadow = this.careteShadow();
  231. this.text = this.createText();
  232. this.icon = this.createIcon();
  233. this.set.push(this.shadow, this.shap, this.text, this.icon);
  234. },
  235. redraw: function(){
  236. this.setSize();
  237. this.resetPoint();
  238. if (this.shap) this.redrawShap();
  239. if (this.text) this.redrawText();
  240. if (this.icon) this.redrawIcon();
  241. if (this.bBox) this.redrawBox();
  242. if (this.listItem) this.redrawListItem();
  243. this.redrawRoute();
  244. },
  245. careteShadow: function(){
  246. var shadow;
  247. shadow = this.shap.glow({
  248. "width": 10,
  249. "fill": true,
  250. "opacity": 0.2,
  251. "offsetx": 0,
  252. "offsety": 0,
  253. "color": "#aaa"
  254. });
  255. shadow.data("bind", this);
  256. return shadow;
  257. },
  258. createShap: function(){
  259. var shap;
  260. shap = this.paper.rectPath(this.point.x, this.point.y, this.width, this.height, this.style.shap.radius);
  261. shap.attr(this.style.shap);
  262. shap.data("bind", this);
  263. return shap;
  264. },
  265. createText: function(){
  266. var atts = this.getTextIconPoint();
  267. text = this.paper.text(atts.tatt.x, atts.tatt.y, this.data.name);
  268. text.attr(this.style.text);
  269. if (this.style.text.display=="none"){
  270. text.hide();
  271. }
  272. return text;
  273. },
  274. createIcon: function(){
  275. var atts = this.getTextIconPoint();
  276. var icon = this.paper.image(this.style.icon.src, atts.iatt.x, atts.iatt.y, 16, 16);
  277. icon.attr(this.style.icon.attr);
  278. return icon;
  279. },
  280. redrawShap: function(){
  281. var shapPath = MWFRaphael.getRectPath(this.point.x, this.point.y, this.width, this.height, this.style.shap.radius);
  282. this.shap.attr("path", shapPath);
  283. },
  284. redrawText: function(){
  285. var atts = this.getTextIconPoint();
  286. this.text.attr({
  287. "x": atts.tatt.x,
  288. "y": atts.tatt.y,
  289. "text": this.data.name
  290. });
  291. },
  292. redrawIcon: function(){
  293. var atts = this.getTextIconPoint();
  294. this.icon.attr({
  295. "x": atts.iatt.x,
  296. "y": atts.iatt.y
  297. });
  298. },
  299. redrawBox: function(){
  300. this.set.exclude(this.bBox);
  301. this.bBox.remove();
  302. this.bBox = null;
  303. var bBox = this.set.getBBox();
  304. this.bBox = this.paper.rectPath(bBox.x-3, bBox.y-3, bBox.width+6, bBox.height+6, 0);
  305. this.bBox.attr(this.process.css.activity.box);
  306. this.set.push(this.bBox);
  307. // var bBox = this.set.getBBox();
  308. // var boxPath = MWFRaphael.getRectPath(bBox.x-3, bBox.y-3, bBox.width+6, bBox.height+6, 0);
  309. // this.bBox.attr("path", boxPath);
  310. },
  311. redrawListItem: function(){
  312. var nameTd = this.listItem.row.tds[1];
  313. nameTd.set("text", this.data.name);
  314. },
  315. loadRoutes: function(){
  316. var routeIds = this.getRoutedata();
  317. routeIds.each(function(id){
  318. if (this.process.routes[id]){
  319. this.routes.push(this.process.routes[id]);
  320. this.process.routes[id].setActivity(null, this);
  321. this.process.routes[id].load();
  322. }
  323. }.bind(this));
  324. },
  325. getRoutedata: function(){
  326. if (!this.data.routeList) this.data.routeList = [];
  327. this.data.routeList = this.data.routeList.clean();
  328. return this.data.routeList;
  329. },
  330. setRouteData: function(id, i){
  331. var index = (i || i==0) ? i : null;
  332. if (!this.data.routeList) this.data.routeList = [];
  333. if (index!=null && index<=this.data.routeList.length){
  334. var idx = this.data.routeList.indexOf(id);
  335. if (idx==-1) this.data.routeList[index] = id;
  336. }else{
  337. if (this.data.routeList.indexOf(id)==-1) this.data.routeList.push(id);
  338. }
  339. },
  340. removeRouteData: function(id){
  341. if (!this.data.routeList) this.data.routeList = [];
  342. this.data.routeList.erase(id);
  343. },
  344. // loadDecisions: function(){
  345. // if (this.data.decisionIdList){
  346. // if (typeOf(this.data.decisionIdList).toLowerCase() == "array"){
  347. // this.data.decisionIdList.each(function(id){
  348. // var item = this.process.decisionDatas[id];
  349. // var decision = new MWF.PCDecision(item, this.process, this);
  350. // this.decisions.push(decision);
  351. // decision.load();
  352. // }.bind(this));
  353. // }else{
  354. // var item = this.process.decisionDatas[this.data.decisionIdList];
  355. // var decision = new MWF.PCDecision(item, this.process, this);
  356. // this.decisions.push(decision);
  357. // decision.load();
  358. // }
  359. // };
  360. // },
  361. redrawRoute: function(path){
  362. this.routes.each(function(route){
  363. route.reload(path,null);
  364. });
  365. this.fromRoutes.each(function(route){
  366. route.reload(null,path);
  367. });
  368. },
  369. activityMove: function(dx, dy, tox, toy){
  370. //var moveSet = this.set.clone();
  371. if (!this.set.isFront){
  372. this.set.toFront();
  373. this.set.isFront = true;
  374. }
  375. //this.paperSize = $(this.paper.canvas).getParent().getSize();
  376. if ((this.set.ox+dx)<0) dx = 0 - this.set.ox;
  377. if ((this.set.ox+dx+this.width)>this.paperSize.x){
  378. this.paperSize.x = this.set.ox+dx+this.width;
  379. this.paper.setSize(this.paperSize.x, this.paperSize.y);
  380. //alert("set width");
  381. $(this.paper.canvas).getParent().setStyle("width", ""+this.paperSize.x+"px");
  382. }
  383. //if ((this.set.ox+dx+this.width)<this.paperOriginalSize.x){
  384. // if (this.paperSize.x > this.paperOriginalSize.x){
  385. // this.paperSize.x = this.paperOriginalSize.x;
  386. // this.paper.setSize(this.paperOriginalSize.x, this.paperSize.y);
  387. // //alert("set width");
  388. // $(this.paper.canvas).getParent().setStyle("width", ""+this.paperSize.x+"px");
  389. // }
  390. //}
  391. if ((this.set.oy + dy)<0) dy = 0 - this.set.oy;
  392. if ((this.set.oy + dy+this.height)>this.paperSize.y){
  393. this.paperSize.y = this.set.oy + dy+this.height;
  394. this.paper.setSize(this.paperSize.x, this.paperSize.y);
  395. //alert("set height");
  396. $(this.paper.canvas).getParent().setStyle("height", ""+this.paperSize.y+"px");
  397. }
  398. //if ((this.set.oy + dy+this.height)<this.paperOriginalSize.y){
  399. // if (this.paperSize.y > this.paperOriginalSize.y){
  400. // this.paperSize.y = this.paperOriginalSize.y;
  401. // this.paper.setSize(this.paperSize.x, this.paperSize.y);
  402. // $(this.paper.canvas).getParent().setStyle("height", ""+this.paperSize.y+"px");
  403. // }
  404. //}
  405. // if (this.process.isGrid){
  406. var toX = Raphael.snapTo(10, this.set.ox + dx + this.width/2, 10);
  407. var toY = Raphael.snapTo(10, this.set.oy + dy + this.height/2, 10);
  408. dx = toX - this.set.ox - this.width/2;
  409. dy = toY - this.set.oy - this.height/2;
  410. // }
  411. // this.shap.transform("t"+dx+","+dy);
  412. // if (this.bBox) this.bBox.transform("t"+dx+","+dy);
  413. // var path = this.shap.attr("path");
  414. path = Raphael.transformPath(this.set.shapPath, "t"+dx+","+dy);
  415. this.shap.attr("path", path);
  416. //this.cloneMoveShap.attr("path", path);
  417. //
  418. //return ;
  419. // this.shap.transform("t0,0");
  420. if (this.bBox){
  421. // var boxPath = this.bBox.attr("path");
  422. var bBox = this.shap.getBBox();
  423. boxPath = MWFRaphael.getRectPath(bBox.x-3, bBox.y-3, bBox.width+6, bBox.height+6, 0);
  424. //boxPath = Raphael.transformPath(this.set.boxPath, "t"+dx+","+dy);
  425. this.bBox.attr("path", boxPath);
  426. // this.bBox.transform("t0,0");
  427. }
  428. this.point = {x: this.set.ox + dx, y: this.set.oy + dy};
  429. this.center = {x: this.set.ox + dx + this.width/2, y: this.set.oy + dy + this.height/2};
  430. var atts = this.getMoveTextIconPoint();
  431. this.text.attr(atts.tatt);
  432. this.icon.attr(atts.iatt);
  433. this.routes.each(function(route){
  434. if (this.process.selectedActivitys.indexOf(route.toActivity) != -1){
  435. route.corners.each(function(corner, idx){
  436. // var p = this.positionPoints[idx];
  437. var p = corner.data("point");
  438. var cx = p.x.toFloat()+dx.toFloat();
  439. var cy = p.y.toFloat()+dy.toFloat();
  440. var cornerPath = MWFRaphael.getRectPath(cx-2.5,cy-2.5, 5, 5, 0);
  441. corner.attr("path", cornerPath);
  442. route.positionPoints[idx] = {"x": cx, "y": cy};
  443. }.bind(this));
  444. }
  445. }.bind(this));
  446. this.set.movex = dx;
  447. this.set.movey = dy;
  448. // var path = this.shap.attr("path");
  449. // path = Raphael.transformPath(path, "t"+this.set.movex+","+this.set.movey);
  450. // this.redrawRoute(path);
  451. this.redrawRoute();
  452. this.paper.safari();
  453. },
  454. activityMoveStart: function(){
  455. this.set.isFront = false;
  456. var box = this.shap.getBBox();
  457. this.set.ox = box.x;
  458. this.set.oy = box.y;
  459. this.set.movex = 0;
  460. this.set.movey = 0;
  461. this.set.animate({
  462. "fill-opacity": .5
  463. },
  464. 500
  465. );
  466. this.set.shapPath = this.shap.attr("path");
  467. if (this.bBox) this.set.boxPath = this.bBox.attr("path")
  468. //this.cloneMoveShap = this.shap.clone();
  469. //
  470. //this.cloneMoveShap.animate({
  471. // "fill-opacity": .3
  472. // },
  473. // 200
  474. //);
  475. this.routes.each(function(route){
  476. if (this.process.selectedActivitys.indexOf(route.toActivity) != -1){
  477. route.corners.each(function(corner, idx){
  478. var p = route.positionPoints[idx];
  479. corner.data("point", p);
  480. }.bind(this));
  481. }
  482. }.bind(this));
  483. },
  484. activityMoveEnd: function(){
  485. this.center.x = this.center.x.toInt();
  486. this.center.y = this.center.y.toInt();
  487. this.data.position = this.center.x+","+this.center.y;
  488. this.set.animate({"fill-opacity": 1}, 500);
  489. // this.reSizePaper(this.center.x, this.center.y);
  490. // this.cloneMoveShap.remove();
  491. },
  492. setActivityPosition: function(callback){
  493. var x;
  494. var y;
  495. if (this.data.position){
  496. var tmp = this.data.position.split(/(?:,\s*){1}|(?:;\s*){1}/g);
  497. x = tmp[0];
  498. y = tmp[1];
  499. }else{
  500. // this.paperSize.x;
  501. // this.paperSize.y;
  502. var xi = Math.random();
  503. x = ((this.paperSize.x-300) * xi).toInt();
  504. var yi = Math.random();
  505. y = ((this.paperSize.y-300) * yi).toInt();
  506. this.data.position = x+","+y;
  507. }
  508. this.reSizePaper(x, y);
  509. this.setPosition(x.toFloat(), y.toFloat(), null, callback);
  510. },
  511. reSizePaper: function(x, y){
  512. //this.paperSize = $(this.paper.canvas).getParent().getSize();
  513. // if (x>this.paperSize.x) this.process.designer.paperNode.setStyle("height", x);
  514. // if (y>this.paperSize.y) this.process.designer.paperNode.setStyle("width", y);
  515. y = y.toFloat()+this.height.toFloat();
  516. x = x.toFloat()+this.width.toFloat();
  517. if (x>this.paperSize.x){
  518. this.paper.setSize(x*0.99, this.paperSize.y);
  519. $(this.paper.canvas).getParent().setStyle("width", ""+x+"px");
  520. this.paperSize.x = x;
  521. }
  522. if (y>this.paperSize.y){
  523. this.paper.setSize(this.paperSize.x*0.99, y);
  524. $(this.paper.canvas).getParent().setStyle("height", ""+y+"px");
  525. this.paperSize.y = y;
  526. }
  527. },
  528. setPosition: function(x, y, time, callback){
  529. x = x.toFloat();
  530. y = y.toFloat();
  531. if (!time) time = 300;
  532. var mx = x-(this.center.x.toFloat());
  533. var my = y-(this.center.y.toFloat());
  534. this.center = {x: x, y: y};
  535. this.point = {x: x-(this.width/2), y: y-(this.height/2)};
  536. var path = this.shap.attr("path");
  537. var path = Raphael.transformPath(path, "t"+mx+","+my);
  538. var atts = this.getTextIconPoint();
  539. this.shap.animate({"path": path}, time, "<>", callback);
  540. this.text.animate(atts.tatt, time, "<>");
  541. this.icon.animate(atts.iatt, time, "<>");
  542. // this.animateLine(time);
  543. },
  544. getTextIconPoint: function(){
  545. var t_att = {x: this.center.x+10, y: this.center.y};
  546. var i_att = {x: this.center.x-(this.width/2)+8, y: this.center.y-8};
  547. return {"tatt": t_att, "iatt": i_att};
  548. },
  549. getMoveTextIconPoint: function(){
  550. return this.getTextIconPoint();
  551. },
  552. showProperty: function(){
  553. if (!this.property){
  554. this.property = new MWF.APPPD.Activity.Property(this, {
  555. "onPostLoad": function(){
  556. this.property.show();
  557. }.bind(this)
  558. });
  559. this.property.load();
  560. }else{
  561. this.property.show();
  562. }
  563. },
  564. selectedMulti: function(){
  565. if (!this.bBox){
  566. var bBox = this.shap.getBBox();
  567. this.bBox = this.paper.rectPath(bBox.x-3, bBox.y-3, bBox.width+6, bBox.height+6, 0);
  568. this.bBox.attr(this.process.css.activity.box);
  569. this.set.push(this.bBox);
  570. }
  571. this.process.selectedActivitys.push(this);
  572. this.process.selectedActivityDatas.push(this.data);
  573. if (this.listItem) this.listItem.listUnSelected();
  574. if (this.property) this.property.hide();
  575. this.selectedMultiStatus = true;
  576. },
  577. unSelectedMulti: function(){
  578. if (this.bBox){
  579. this.set.exclude(this.bBox);
  580. this.bBox.remove();
  581. this.bBox = null;
  582. }
  583. this.selectedMultiStatus = false;
  584. },
  585. selected: function(){
  586. // if (this.process.jsonParse) {
  587. // window.setTimeout(function(){this.process.jsonParse.stopParseJson = true;}.bind(this), 1);
  588. // }
  589. try{
  590. this.process.designer.paperInNode.focus();
  591. }catch(e){};
  592. this.activitySelected();
  593. if (this.listItem) this.listItem.listSelected();
  594. // if (this.process.property) this.process.property.hide();
  595. window.setTimeout(function(){this.showProperty()}.bind(this), 10);
  596. // this.showQuickAction();
  597. },
  598. unSelected: function(){
  599. this.activityUnSelected();
  600. if (this.listItem) this.listItem.listUnSelected();
  601. if (this.property) this.property.hide();
  602. },
  603. showQuickAction: function(){
  604. this.getQuickActionJson(function(){
  605. this.quickActionJson.each(function(action, idx){
  606. var y = this.point.y-20;
  607. var x = this.point.x + (20*idx);
  608. var actionNode = this.paper.image(this.process.path+this.process.options.style+"/quickAction/"+action.icon, x, y, 16, 16);
  609. actionNode.toFront();
  610. //var actionNode = new Element("div", {
  611. // "styles": {
  612. // "top":this.center.y,
  613. // "left": this.center.x,
  614. // "height": "24px",
  615. // "width": "24px",
  616. // "position": "absolute",
  617. // "background-color": "red",
  618. // "z-index": "50000"
  619. // }
  620. //}).inject(this.process.designer.paperNode)
  621. }.bind(this));
  622. }.bind(this));
  623. },
  624. getQuickActionJson: function(callback){
  625. if (!this.quickActionJson){
  626. MWF.getJSON(this.process.path+"action.json", {
  627. "onSuccess": function(obj){
  628. var defaultActions = obj["default"];
  629. var myActions = obj[this.type];
  630. this.quickActionJson = defaultActions.concat(myActions);
  631. if (callback) callback();
  632. }.bind(this),
  633. "onerror": function(text){
  634. this.notice(text, "error");
  635. }.bind(this),
  636. "onRequestFailure": function(xhr){
  637. this.notice(xhr.responseText, "error");
  638. }.bind(this)
  639. });
  640. }else{
  641. if (callback) callback();
  642. }
  643. },
  644. activitySelected: function(){
  645. //if (this.process.currentSelected) this.process.currentSelected.unSelected();
  646. this.process.unSelectedAll();
  647. if (!this.bBox){
  648. var bBox = this.shap.getBBox();
  649. this.bBox = this.paper.rectPath(bBox.x-3, bBox.y-3, bBox.width+6, bBox.height+6, 0);
  650. this.bBox.attr(this.process.css.activity.box);
  651. this.set.push(this.bBox);
  652. }
  653. this.process.currentSelected = this;
  654. },
  655. activityUnSelected: function(){
  656. this.process.currentSelected = null;
  657. if (this.bBox){
  658. this.set.exclude(this.bBox);
  659. this.bBox.remove();
  660. this.bBox = null;
  661. }
  662. },
  663. addRouteData: function(id){
  664. if (this.data.routeList.indexOf(id)==-1) this.data.routeList.push(id);
  665. },
  666. destroy: function(){
  667. if (this.type=="begin"){
  668. this.process.begin = null;
  669. this.process.process.begin = null;
  670. }
  671. this.routes.each(function(r){
  672. r.destroy();
  673. });
  674. this.fromRoutes.each(function(r){
  675. r.destroy();
  676. });
  677. if (this.listItem){
  678. this.listItem.row.tr.destroy();
  679. }
  680. var activitys = {};
  681. for (aid in this.process[this.type+"s"]){
  682. if (aid!=this.data.id){
  683. activitys[aid] = this.process[this.type+"s"][aid];
  684. }else{
  685. this.process[this.type+"s"][aid] = null;
  686. }
  687. }
  688. this.process[this.type+"s"] = null;
  689. this.process[this.type+"s"] = activitys;
  690. this.process.activitys.erase(this);
  691. if (this.process.process[this.type+"List"]) this.process.process[this.type+"List"].erase(this.data);
  692. this.set.remove();
  693. }
  694. });
  695. MWF.APPPD.Activity.SingleRouter = new Class({
  696. Extends: MWF.APPPD.Activity,
  697. getRoutedata: function(){
  698. if (!this.data.route) this.data.route = "";
  699. return [this.data.route];
  700. },
  701. setRouteData: function(id){
  702. if (!this.data.route) this.data.route = "";
  703. this.data.route = id;
  704. },
  705. removeRouteData: function(id){
  706. this.data.route = "";
  707. },
  708. quickCreateRoute: function(){
  709. if (!this.routes.length){
  710. this.process.createRoute();
  711. this.process.routeCreateFromActivity(this);
  712. }
  713. },
  714. checkCreateRoute: function(){
  715. if (this.process.isCreateRoute){
  716. var route = this.process.currentCreateRoute;
  717. if (!route.fromActivity){
  718. if (!this.routes.length) this.process.routeCreateFromActivity(this);
  719. }else{
  720. this.process.routeCreateToActivity(this);
  721. }
  722. }
  723. if (this.process.isCopyRoute){
  724. if (!this.routes.length) this.process.routeAddFromActivity(this);
  725. }
  726. },
  727. mouseHover: function(){
  728. if (this.process.isCreateRoute){
  729. var route = this.process.currentCreateRoute;
  730. if (!route.fromActivity){
  731. if (!this.routes.length) this.shap.attr({"stroke-width": "2"});
  732. }else{
  733. this.shap.attr({"stroke-width": "2"});
  734. }
  735. }
  736. if (this.process.isChangeRouteTo){
  737. this.shap.attr({"stroke-width": "2"});
  738. }
  739. if (this.process.isChangeRouteFrom || this.process.isCopyRoute){
  740. if (!this.routes.length) this.shap.attr({"stroke-width": "2"});
  741. }
  742. },
  743. mouseUp: function(){
  744. if (this.process.isChangeRouteTo){
  745. this.process.currentChangeRoute.setActivity(this, null);
  746. this.process.currentChangeRoute.isBack = false;
  747. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  748. this.process.currentChangeRoute.reload();
  749. this.process.isChangeRouteTo = false;
  750. this.process.currentChangeRoute = null;
  751. }
  752. if (this.process.isChangeRouteFrom){
  753. if (!this.routes.length){
  754. this.process.currentChangeRoute.setActivity(null, this);
  755. this.process.currentChangeRoute.isBack = false;
  756. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  757. this.process.currentChangeRoute.reload();
  758. this.process.isChangeRouteFrom = false;
  759. this.process.currentChangeRoute = null;
  760. }
  761. }
  762. this.shap.attr(this.style.shap);
  763. },
  764. addRouteData: function(id){
  765. if (!this.data.route) this.data.route = id;
  766. }
  767. });
  768. MWF.APPPD.Activity.Circle = new Class({
  769. Extends: MWF.APPPD.Activity,
  770. setSize: function(){
  771. if (this.style.text.display=="none"){
  772. this.width = this.style.shap.width;
  773. this.height = this.style.shap.height;
  774. this.radius = this.style.shap.radius;
  775. }else{
  776. var size = MWF.getTextSize(this.data.name, this.style.text);
  777. this.radius = size.x/2+10;
  778. this.radius = this.radius<20 ? 20 : this.radius;
  779. this.width = this.height = this.radius*2;
  780. }
  781. },
  782. reSizePaper: function(x, y){
  783. //this.paperSize = $(this.paper.canvas).getParent().getSize();
  784. // if (x>this.paperSize.x) this.process.designer.paperNode.setStyle("height", x);
  785. // if (y>this.paperSize.y) this.process.designer.paperNode.setStyle("width", y);
  786. y = y.toFloat()+this.height.toFloat()/2;
  787. x = x.toFloat()+this.width.toFloat()/2;
  788. if (x>this.paperSize.x){
  789. this.paper.setSize(x*0.99, this.paperSize.y);
  790. $(this.paper.canvas).getParent().setStyle("width", ""+x+"px");
  791. this.paperSize.x = x;
  792. }
  793. if (y>this.paperSize.y){
  794. this.paper.setSize(this.paperSize.x*0.99, y);
  795. $(this.paper.canvas).getParent().setStyle("height", ""+y+"px");
  796. this.paperSize.y = y;
  797. }
  798. },
  799. resetPoint: function(){
  800. this.point = {x: this.center.x-this.width/2, y: this.center.y-this.height/2};
  801. },
  802. createShap: function(){
  803. var shap;
  804. shap = this.paper.circlePath(this.center.x, this.center.y, this.radius);
  805. shap.attr(this.style.shap);
  806. shap.data("bind", this);
  807. return shap;
  808. },
  809. redrawText: function(){
  810. return true;
  811. },
  812. redrawShap: function(){
  813. var shapPath = MWFRaphael.getCirclePath(this.center.x, this.center.y, this.radius);
  814. this.shap.attr("path", shapPath);
  815. },
  816. getOffset: function(){
  817. return {"tx": 6, "ty": 0, "ix": -8, "iy": -8};
  818. },
  819. getTextIconPoint: function(){
  820. var off = this.getOffset();
  821. if (this.style.text.display=="none"){
  822. var t_att = {x: this.center.x+off.tx, y: this.center.y+off.ty};
  823. var i_att = {x: this.center.x+off.ix, y: this.center.y+off.iy};
  824. return {"tatt": t_att, "iatt": i_att};
  825. }else{
  826. var t_att = {x: this.center.x+6, y: this.center.y};
  827. var i_att = {x: this.center.x-(this.width/2), y: this.center.y-8};
  828. return {"tatt": t_att, "iatt": i_att};
  829. }
  830. },
  831. getMoveOffset: function(){
  832. return {"tx": 6, "ty": 0, "ix": -9, "iy": -9};
  833. },
  834. getMoveTextIconPoint: function(){
  835. var off = this.getMoveOffset();
  836. if (this.style.text.display=="none"){
  837. var t_att = {x: this.center.x+off.tx, y: this.center.y+off.ty};
  838. var i_att = {x: this.center.x+off.ix, y: this.center.y+off.iy};
  839. return {"tatt": t_att, "iatt": i_att};
  840. }else{
  841. var t_att = {x: this.center.x+6, y: this.center.y};
  842. var i_att = {x: this.center.x-(this.width/2), y: this.center.y-8};
  843. return {"tatt": t_att, "iatt": i_att};
  844. }
  845. }
  846. });
  847. MWF.APPPD.Activity.Circle.SingleRouter = new Class({
  848. Extends: MWF.APPPD.Activity.Circle,
  849. getRoutedata: function(){
  850. if (!this.data.route) this.data.route = "";
  851. return [this.data.route];
  852. },
  853. setRouteData: function(id){
  854. if (!this.data.route) this.data.route = "";
  855. this.data.route = id;
  856. },
  857. removeRouteData: function(id){
  858. this.data.route = "";
  859. },
  860. quickCreateRoute: function(){
  861. if (!this.routes.length){
  862. this.process.createRoute();
  863. this.process.routeCreateFromActivity(this);
  864. }
  865. },
  866. checkCreateRoute: function(){
  867. if (this.process.isCreateRoute){
  868. var route = this.process.currentCreateRoute;
  869. if (!route.fromActivity){
  870. if (!this.routes.length) this.process.routeCreateFromActivity(this);
  871. }else{
  872. this.process.routeCreateToActivity(this);
  873. }
  874. }
  875. if (this.process.isCopyRoute){
  876. if (!this.routes.length) this.process.routeAddFromActivity(this);
  877. }
  878. },
  879. mouseHover: function(){
  880. if (this.process.isCreateRoute){
  881. var route = this.process.currentCreateRoute;
  882. if (!route.fromActivity){
  883. if (!this.routes.length) this.shap.attr({"stroke-width": "2"});
  884. }else{
  885. this.shap.attr({"stroke-width": "2"});
  886. }
  887. }
  888. if (this.process.isChangeRouteTo){
  889. this.shap.attr({"stroke-width": "2"});
  890. }
  891. if (this.process.isChangeRouteFrom || this.process.isCopyRoute){
  892. if (!this.routes.length) this.shap.attr({"stroke-width": "2"});
  893. }
  894. },
  895. mouseUp: function(){
  896. if (this.process.isChangeRouteTo){
  897. this.process.currentChangeRoute.setActivity(this, null);
  898. this.process.currentChangeRoute.isBack = false;
  899. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  900. this.process.currentChangeRoute.reload();
  901. this.process.isChangeRouteTo = false;
  902. this.process.currentChangeRoute = null;
  903. }
  904. if (this.process.isChangeRouteFrom){
  905. if (!this.routes.length){
  906. this.process.currentChangeRoute.setActivity(null, this);
  907. this.process.currentChangeRoute.isBack = false;
  908. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  909. this.process.currentChangeRoute.reload();
  910. this.process.isChangeRouteFrom = false;
  911. this.process.currentChangeRoute = null;
  912. }
  913. }
  914. this.shap.attr(this.style.shap);
  915. },
  916. addRouteData: function(id){
  917. if (!this.data.route) this.data.route = id;
  918. }
  919. });
  920. MWF.APPPD.Activity.Circle.NoRouter = new Class({
  921. Extends: MWF.APPPD.Activity.Circle,
  922. quickCreateRoute: function(){
  923. return false;
  924. },
  925. checkCreateRoute: function(){
  926. if (this.process.isCreateRoute){
  927. var route = this.process.currentCreateRoute;
  928. if (route.fromActivity){
  929. this.process.routeCreateToActivity(this);
  930. }
  931. }
  932. },
  933. mouseHover: function(){
  934. if (this.process.isCreateRoute){
  935. var route = this.process.currentCreateRoute;
  936. if (route.fromActivity){
  937. this.shap.attr({"stroke-width": "2"});
  938. }
  939. }
  940. if (this.process.isChangeRouteTo){
  941. this.shap.attr({"stroke-width": "2"});
  942. }
  943. },
  944. mouseUp: function(){
  945. if (this.process.isChangeRouteTo){
  946. this.process.currentChangeRoute.setActivity(this, null);
  947. this.process.currentChangeRoute.isBack = false;
  948. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  949. this.process.currentChangeRoute.reload();
  950. this.process.isChangeRouteTo = false;
  951. this.process.currentChangeRoute = null;
  952. }
  953. this.shap.attr(this.style.shap);
  954. },
  955. addRouteData: function(id){}
  956. });
  957. MWF.APPPD.Activity.Diamond = new Class({
  958. Extends: MWF.APPPD.Activity,
  959. setSize: function(){
  960. var size = MWF.getTextSize(this.data.name, this.style.text);
  961. this.width = size.x + 80;
  962. this.width = this.width<120 ? 120: this.width;
  963. this.height = this.width*0.4;
  964. },
  965. createShap: function(){
  966. var shap;
  967. shap = this.paper.diamond(this.point.x, this.point.y, this.width, this.height, this.style.shap.radiusX, this.style.shap.radiusY);
  968. shap.attr(this.style.shap);
  969. shap.data("bind", this);
  970. return shap;
  971. },
  972. redrawShap: function(){
  973. var shapPath = MWFRaphael.getDiamondPath(this.point.x, this.point.y, this.width, this.height, this.style.shap.radiusX, this.style.shap.radiusY);
  974. this.shap.attr("path", shapPath);
  975. },
  976. getTextIconPoint: function(){
  977. var t_att = {x: this.center.x+6, y: this.center.y+1};
  978. var i_att = {x: this.center.x-(this.width/2)+28, y: this.center.y-9};
  979. return {"tatt": t_att, "iatt": i_att};
  980. }
  981. });
  982. (function (){
  983. var Activity = function(extendClass, name){
  984. return new Class({
  985. Extends: extendClass,
  986. setType: function(){
  987. this.type = name;
  988. this.data.type = name;
  989. },
  990. setStyle: function(){
  991. this.style = this.process.css.activity[name];
  992. }
  993. });
  994. };
  995. MWF.APPPD.Activity.Begin = new Activity(MWF.APPPD.Activity.Circle.SingleRouter, "begin");
  996. MWF.APPPD.Activity.End = new Activity(MWF.APPPD.Activity.Circle.NoRouter, "end");
  997. MWF.APPPD.Activity.Cancel = new Activity(MWF.APPPD.Activity.Circle.NoRouter, "cancel");
  998. MWF.APPPD.Activity.Manual = new Activity(MWF.APPPD.Activity, "manual");
  999. MWF.APPPD.Activity.Condition = new Activity(MWF.APPPD.Activity.Diamond, "condition");
  1000. MWF.APPPD.Activity.Choice = new Activity(MWF.APPPD.Activity.Diamond, "choice");
  1001. MWF.APPPD.Activity.Split = new Activity(MWF.APPPD.Activity.Circle.SingleRouter, "split");
  1002. MWF.APPPD.Activity.Parallel = new Activity(MWF.APPPD.Activity.Circle, "parallel");
  1003. MWF.APPPD.Activity.Merge = new Activity(MWF.APPPD.Activity.Circle.SingleRouter, "merge");
  1004. MWF.APPPD.Activity.Embed = new Activity(MWF.APPPD.Activity.SingleRouter, "embed");
  1005. MWF.APPPD.Activity.Delay = new Activity(MWF.APPPD.Activity.Circle.SingleRouter, "delay");
  1006. MWF.APPPD.Activity.Invoke = new Activity(MWF.APPPD.Activity.SingleRouter, "invoke");
  1007. MWF.APPPD.Activity.Service = new Activity(MWF.APPPD.Activity.SingleRouter, "service");
  1008. MWF.APPPD.Activity.Agent = new Activity(MWF.APPPD.Activity.SingleRouter, "agent");
  1009. MWF.APPPD.Activity.Message = new Activity(MWF.APPPD.Activity.SingleRouter, "message");
  1010. })();
  1011. MWF.xApplication.process.ProcessDesigner.Activity.List = new Class({
  1012. initialize: function(activity){
  1013. this.activity = activity;
  1014. this.process = activity.process;
  1015. this.paper = this.activity.process.paper;
  1016. },
  1017. load: function(){
  1018. //this.activity.process.activityListNode
  1019. // this.listActivityNode = new Element("div",{
  1020. // "styles": this.process.css.listActivityNode
  1021. // });
  1022. // this.activityTable = new HtmlTable({
  1023. // "properties": {
  1024. // "width": "100%"
  1025. // }
  1026. // }).inject(this.listActivityNode);
  1027. var actionIcon = (this.activity.type=="begin") ? " " : "<img src=\""+"../x_component_process_ProcessDesigner/$Process/default/icon/copy.png"+"\" />";
  1028. this.row = this.process.activityTable.push([
  1029. {
  1030. "content": " ",
  1031. "properties": {
  1032. "styles": this.activity.style.listIcon
  1033. }
  1034. },
  1035. {
  1036. "content": this.activity.data.name,
  1037. "properties": {
  1038. "styles": this.process.css.list.listText
  1039. }
  1040. },
  1041. {
  1042. "content": actionIcon,
  1043. "properties": {
  1044. "styles": this.process.css.list.listIcon,
  1045. "events": {
  1046. "click": this.copyActivity.bind(this)
  1047. }
  1048. }
  1049. },
  1050. {
  1051. "content": "<img src=\""+"../x_component_process_ProcessDesigner/$Process/default/icon/delete.png"+"\" />",
  1052. "properties": {
  1053. "styles": this.process.css.list.listIcon,
  1054. "events": {
  1055. "click": this.deleteActivity.bind(this)
  1056. }
  1057. }
  1058. }
  1059. ]
  1060. );
  1061. this.row.tr.addEvent("click", function(){
  1062. this.activity.selected();
  1063. }.bind(this));
  1064. //this.listActivityNode.inject(this.activity.process.activityListNode);
  1065. //var activityTable = new Element("table").inject(this.listActivityNode);
  1066. },
  1067. copyActivity: function(){
  1068. this.process.copyActivity(this.activity);
  1069. },
  1070. deleteActivity: function(e){
  1071. this.process.deleteActivity(e, this.activity);
  1072. },
  1073. listSelected: function(){
  1074. if (this.process.currentListSelected) this.process.currentListSelected.listUnSelected();
  1075. this.row.tr.setStyles(this.process.css.list.listRowSelected);
  1076. this.process.currentListSelected = this;
  1077. //alert(this.process.currentSelected!=this.activity)
  1078. //if (this.process.currentSelected!=this.activity) this.activity.selected();
  1079. },
  1080. listUnSelected: function(){
  1081. this.process.currentListSelected = null;
  1082. this.row.tr.setStyles(this.process.css.list.listRow);
  1083. //if (this.process.currentSelected==this.activity) this.activity.unSelected();
  1084. }
  1085. });
  1086. MWF.xApplication.process.ProcessDesigner.Activity.Property = new Class({
  1087. Implements: [Options, Events],
  1088. Extends: MWF.APPPD.Property,
  1089. initialize: function(activity, options){
  1090. this.setOptions(options);
  1091. this.activity = activity;
  1092. this.process = activity.process;
  1093. this.paper = this.activity.process.paper;
  1094. this.data = activity.data;
  1095. this.htmlPath = "../x_component_process_ProcessDesigner/$Process/"+this.activity.type+".html";
  1096. },
  1097. setValue: function(name, value){
  1098. this.data[name] = value;
  1099. if (name=="name"){
  1100. if (!value) this.data[name] = MWF.APPPD.LP.unnamed;
  1101. this.activity.redraw();
  1102. }
  1103. }
  1104. });