Activity.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  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. this.activitySelected();
  590. if (this.listItem) this.listItem.listSelected();
  591. // if (this.process.property) this.process.property.hide();
  592. window.setTimeout(function(){this.showProperty()}.bind(this), 10);
  593. // this.showQuickAction();
  594. },
  595. unSelected: function(){
  596. this.activityUnSelected();
  597. if (this.listItem) this.listItem.listUnSelected();
  598. if (this.property) this.property.hide();
  599. },
  600. showQuickAction: function(){
  601. this.getQuickActionJson(function(){
  602. this.quickActionJson.each(function(action, idx){
  603. var y = this.point.y-20;
  604. var x = this.point.x + (20*idx);
  605. var actionNode = this.paper.image(this.process.path+this.process.options.style+"/quickAction/"+action.icon, x, y, 16, 16);
  606. actionNode.toFront();
  607. //var actionNode = new Element("div", {
  608. // "styles": {
  609. // "top":this.center.y,
  610. // "left": this.center.x,
  611. // "height": "24px",
  612. // "width": "24px",
  613. // "position": "absolute",
  614. // "background-color": "red",
  615. // "z-index": "50000"
  616. // }
  617. //}).inject(this.process.designer.paperNode)
  618. }.bind(this));
  619. }.bind(this));
  620. },
  621. getQuickActionJson: function(callback){
  622. if (!this.quickActionJson){
  623. MWF.getJSON(this.process.path+"action.json", {
  624. "onSuccess": function(obj){
  625. var defaultActions = obj["default"];
  626. var myActions = obj[this.type];
  627. this.quickActionJson = defaultActions.concat(myActions);
  628. if (callback) callback();
  629. }.bind(this),
  630. "onerror": function(text){
  631. this.notice(text, "error");
  632. }.bind(this),
  633. "onRequestFailure": function(xhr){
  634. this.notice(xhr.responseText, "error");
  635. }.bind(this)
  636. });
  637. }else{
  638. if (callback) callback();
  639. }
  640. },
  641. activitySelected: function(){
  642. //if (this.process.currentSelected) this.process.currentSelected.unSelected();
  643. this.process.unSelectedAll();
  644. if (!this.bBox){
  645. var bBox = this.shap.getBBox();
  646. this.bBox = this.paper.rectPath(bBox.x-3, bBox.y-3, bBox.width+6, bBox.height+6, 0);
  647. this.bBox.attr(this.process.css.activity.box);
  648. this.set.push(this.bBox);
  649. }
  650. this.process.currentSelected = this;
  651. },
  652. activityUnSelected: function(){
  653. this.process.currentSelected = null;
  654. if (this.bBox){
  655. this.set.exclude(this.bBox);
  656. this.bBox.remove();
  657. this.bBox = null;
  658. }
  659. },
  660. addRouteData: function(id){
  661. if (this.data.routeList.indexOf(id)==-1) this.data.routeList.push(id);
  662. },
  663. destroy: function(){
  664. if (this.type=="begin"){
  665. this.process.begin = null;
  666. this.process.process.begin = null;
  667. }
  668. this.routes.each(function(r){
  669. r.destroy();
  670. });
  671. this.fromRoutes.each(function(r){
  672. r.destroy();
  673. });
  674. if (this.listItem){
  675. this.listItem.row.tr.destroy();
  676. }
  677. var activitys = {};
  678. for (aid in this.process[this.type+"s"]){
  679. if (aid!=this.data.id){
  680. activitys[aid] = this.process[this.type+"s"][aid];
  681. }else{
  682. this.process[this.type+"s"][aid] = null;
  683. }
  684. }
  685. this.process[this.type+"s"] = null;
  686. this.process[this.type+"s"] = activitys;
  687. this.process.activitys.erase(this);
  688. if (this.process.process[this.type+"List"]) this.process.process[this.type+"List"].erase(this.data);
  689. this.set.remove();
  690. }
  691. });
  692. MWF.APPPD.Activity.SingleRouter = new Class({
  693. Extends: MWF.APPPD.Activity,
  694. getRoutedata: function(){
  695. if (!this.data.route) this.data.route = "";
  696. return [this.data.route];
  697. },
  698. setRouteData: function(id){
  699. if (!this.data.route) this.data.route = "";
  700. this.data.route = id;
  701. },
  702. removeRouteData: function(id){
  703. this.data.route = "";
  704. },
  705. quickCreateRoute: function(){
  706. if (!this.routes.length){
  707. this.process.createRoute();
  708. this.process.routeCreateFromActivity(this);
  709. }
  710. },
  711. checkCreateRoute: function(){
  712. if (this.process.isCreateRoute){
  713. var route = this.process.currentCreateRoute;
  714. if (!route.fromActivity){
  715. if (!this.routes.length) this.process.routeCreateFromActivity(this);
  716. }else{
  717. this.process.routeCreateToActivity(this);
  718. }
  719. }
  720. if (this.process.isCopyRoute){
  721. if (!this.routes.length) this.process.routeAddFromActivity(this);
  722. }
  723. },
  724. mouseHover: function(){
  725. if (this.process.isCreateRoute){
  726. var route = this.process.currentCreateRoute;
  727. if (!route.fromActivity){
  728. if (!this.routes.length) this.shap.attr({"stroke-width": "2"});
  729. }else{
  730. this.shap.attr({"stroke-width": "2"});
  731. }
  732. }
  733. if (this.process.isChangeRouteTo){
  734. this.shap.attr({"stroke-width": "2"});
  735. }
  736. if (this.process.isChangeRouteFrom || this.process.isCopyRoute){
  737. if (!this.routes.length) this.shap.attr({"stroke-width": "2"});
  738. }
  739. },
  740. mouseUp: function(){
  741. if (this.process.isChangeRouteTo){
  742. this.process.currentChangeRoute.setActivity(this, null);
  743. this.process.currentChangeRoute.isBack = false;
  744. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  745. this.process.currentChangeRoute.reload();
  746. this.process.isChangeRouteTo = false;
  747. this.process.currentChangeRoute = null;
  748. }
  749. if (this.process.isChangeRouteFrom){
  750. if (!this.routes.length){
  751. this.process.currentChangeRoute.setActivity(null, this);
  752. this.process.currentChangeRoute.isBack = false;
  753. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  754. this.process.currentChangeRoute.reload();
  755. this.process.isChangeRouteFrom = false;
  756. this.process.currentChangeRoute = null;
  757. }
  758. }
  759. this.shap.attr(this.style.shap);
  760. },
  761. addRouteData: function(id){
  762. if (!this.data.route) this.data.route = id;
  763. }
  764. });
  765. MWF.APPPD.Activity.Circle = new Class({
  766. Extends: MWF.APPPD.Activity,
  767. setSize: function(){
  768. if (this.style.text.display=="none"){
  769. this.width = this.style.shap.width;
  770. this.height = this.style.shap.height;
  771. this.radius = this.style.shap.radius;
  772. }else{
  773. var size = MWF.getTextSize(this.data.name, this.style.text);
  774. this.radius = size.x/2+10;
  775. this.radius = this.radius<20 ? 20 : this.radius;
  776. this.width = this.height = this.radius*2;
  777. }
  778. },
  779. reSizePaper: function(x, y){
  780. //this.paperSize = $(this.paper.canvas).getParent().getSize();
  781. // if (x>this.paperSize.x) this.process.designer.paperNode.setStyle("height", x);
  782. // if (y>this.paperSize.y) this.process.designer.paperNode.setStyle("width", y);
  783. y = y.toFloat()+this.height.toFloat()/2;
  784. x = x.toFloat()+this.width.toFloat()/2;
  785. if (x>this.paperSize.x){
  786. this.paper.setSize(x*0.99, this.paperSize.y);
  787. $(this.paper.canvas).getParent().setStyle("width", ""+x+"px");
  788. this.paperSize.x = x;
  789. }
  790. if (y>this.paperSize.y){
  791. this.paper.setSize(this.paperSize.x*0.99, y);
  792. $(this.paper.canvas).getParent().setStyle("height", ""+y+"px");
  793. this.paperSize.y = y;
  794. }
  795. },
  796. resetPoint: function(){
  797. this.point = {x: this.center.x-this.width/2, y: this.center.y-this.height/2};
  798. },
  799. createShap: function(){
  800. var shap;
  801. shap = this.paper.circlePath(this.center.x, this.center.y, this.radius);
  802. shap.attr(this.style.shap);
  803. shap.data("bind", this);
  804. return shap;
  805. },
  806. redrawText: function(){
  807. return true;
  808. },
  809. redrawShap: function(){
  810. var shapPath = MWFRaphael.getCirclePath(this.center.x, this.center.y, this.radius);
  811. this.shap.attr("path", shapPath);
  812. },
  813. getOffset: function(){
  814. return {"tx": 6, "ty": 0, "ix": -8, "iy": -8};
  815. },
  816. getTextIconPoint: function(){
  817. var off = this.getOffset();
  818. if (this.style.text.display=="none"){
  819. var t_att = {x: this.center.x+off.tx, y: this.center.y+off.ty};
  820. var i_att = {x: this.center.x+off.ix, y: this.center.y+off.iy};
  821. return {"tatt": t_att, "iatt": i_att};
  822. }else{
  823. var t_att = {x: this.center.x+6, y: this.center.y};
  824. var i_att = {x: this.center.x-(this.width/2), y: this.center.y-8};
  825. return {"tatt": t_att, "iatt": i_att};
  826. }
  827. },
  828. getMoveOffset: function(){
  829. return {"tx": 6, "ty": 0, "ix": -9, "iy": -9};
  830. },
  831. getMoveTextIconPoint: function(){
  832. var off = this.getMoveOffset();
  833. if (this.style.text.display=="none"){
  834. var t_att = {x: this.center.x+off.tx, y: this.center.y+off.ty};
  835. var i_att = {x: this.center.x+off.ix, y: this.center.y+off.iy};
  836. return {"tatt": t_att, "iatt": i_att};
  837. }else{
  838. var t_att = {x: this.center.x+6, y: this.center.y};
  839. var i_att = {x: this.center.x-(this.width/2), y: this.center.y-8};
  840. return {"tatt": t_att, "iatt": i_att};
  841. }
  842. }
  843. });
  844. MWF.APPPD.Activity.Circle.SingleRouter = new Class({
  845. Extends: MWF.APPPD.Activity.Circle,
  846. getRoutedata: function(){
  847. if (!this.data.route) this.data.route = "";
  848. return [this.data.route];
  849. },
  850. setRouteData: function(id){
  851. if (!this.data.route) this.data.route = "";
  852. this.data.route = id;
  853. },
  854. removeRouteData: function(id){
  855. this.data.route = "";
  856. },
  857. quickCreateRoute: function(){
  858. if (!this.routes.length){
  859. this.process.createRoute();
  860. this.process.routeCreateFromActivity(this);
  861. }
  862. },
  863. checkCreateRoute: function(){
  864. if (this.process.isCreateRoute){
  865. var route = this.process.currentCreateRoute;
  866. if (!route.fromActivity){
  867. if (!this.routes.length) this.process.routeCreateFromActivity(this);
  868. }else{
  869. this.process.routeCreateToActivity(this);
  870. }
  871. }
  872. if (this.process.isCopyRoute){
  873. if (!this.routes.length) this.process.routeAddFromActivity(this);
  874. }
  875. },
  876. mouseHover: function(){
  877. if (this.process.isCreateRoute){
  878. var route = this.process.currentCreateRoute;
  879. if (!route.fromActivity){
  880. if (!this.routes.length) this.shap.attr({"stroke-width": "2"});
  881. }else{
  882. this.shap.attr({"stroke-width": "2"});
  883. }
  884. }
  885. if (this.process.isChangeRouteTo){
  886. this.shap.attr({"stroke-width": "2"});
  887. }
  888. if (this.process.isChangeRouteFrom || this.process.isCopyRoute){
  889. if (!this.routes.length) this.shap.attr({"stroke-width": "2"});
  890. }
  891. },
  892. mouseUp: function(){
  893. if (this.process.isChangeRouteTo){
  894. this.process.currentChangeRoute.setActivity(this, null);
  895. this.process.currentChangeRoute.isBack = false;
  896. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  897. this.process.currentChangeRoute.reload();
  898. this.process.isChangeRouteTo = false;
  899. this.process.currentChangeRoute = null;
  900. }
  901. if (this.process.isChangeRouteFrom){
  902. if (!this.routes.length){
  903. this.process.currentChangeRoute.setActivity(null, this);
  904. this.process.currentChangeRoute.isBack = false;
  905. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  906. this.process.currentChangeRoute.reload();
  907. this.process.isChangeRouteFrom = false;
  908. this.process.currentChangeRoute = null;
  909. }
  910. }
  911. this.shap.attr(this.style.shap);
  912. },
  913. addRouteData: function(id){
  914. if (!this.data.route) this.data.route = id;
  915. }
  916. });
  917. MWF.APPPD.Activity.Circle.NoRouter = new Class({
  918. Extends: MWF.APPPD.Activity.Circle,
  919. quickCreateRoute: function(){
  920. return false;
  921. },
  922. checkCreateRoute: function(){
  923. if (this.process.isCreateRoute){
  924. var route = this.process.currentCreateRoute;
  925. if (route.fromActivity){
  926. this.process.routeCreateToActivity(this);
  927. }
  928. }
  929. },
  930. mouseHover: function(){
  931. if (this.process.isCreateRoute){
  932. var route = this.process.currentCreateRoute;
  933. if (route.fromActivity){
  934. this.shap.attr({"stroke-width": "2"});
  935. }
  936. }
  937. if (this.process.isChangeRouteTo){
  938. this.shap.attr({"stroke-width": "2"});
  939. }
  940. },
  941. mouseUp: function(){
  942. if (this.process.isChangeRouteTo){
  943. this.process.currentChangeRoute.setActivity(this, null);
  944. this.process.currentChangeRoute.isBack = false;
  945. this.process.currentChangeRoute.positionPoints = this.process.currentChangeRoute.getRoutePoint();
  946. this.process.currentChangeRoute.reload();
  947. this.process.isChangeRouteTo = false;
  948. this.process.currentChangeRoute = null;
  949. }
  950. this.shap.attr(this.style.shap);
  951. },
  952. addRouteData: function(id){}
  953. });
  954. MWF.APPPD.Activity.Diamond = new Class({
  955. Extends: MWF.APPPD.Activity,
  956. setSize: function(){
  957. var size = MWF.getTextSize(this.data.name, this.style.text);
  958. this.width = size.x + 80;
  959. this.width = this.width<120 ? 120: this.width;
  960. this.height = this.width*0.4;
  961. },
  962. createShap: function(){
  963. var shap;
  964. shap = this.paper.diamond(this.point.x, this.point.y, this.width, this.height, this.style.shap.radiusX, this.style.shap.radiusY);
  965. shap.attr(this.style.shap);
  966. shap.data("bind", this);
  967. return shap;
  968. },
  969. redrawShap: function(){
  970. var shapPath = MWFRaphael.getDiamondPath(this.point.x, this.point.y, this.width, this.height, this.style.shap.radiusX, this.style.shap.radiusY);
  971. this.shap.attr("path", shapPath);
  972. },
  973. getTextIconPoint: function(){
  974. var t_att = {x: this.center.x+6, y: this.center.y+1};
  975. var i_att = {x: this.center.x-(this.width/2)+28, y: this.center.y-9};
  976. return {"tatt": t_att, "iatt": i_att};
  977. }
  978. });
  979. (function (){
  980. var Activity = function(extendClass, name){
  981. return new Class({
  982. Extends: extendClass,
  983. setType: function(){
  984. this.type = name;
  985. this.data.type = name;
  986. },
  987. setStyle: function(){
  988. this.style = this.process.css.activity[name];
  989. }
  990. });
  991. };
  992. MWF.APPPD.Activity.Begin = new Activity(MWF.APPPD.Activity.Circle.SingleRouter, "begin");
  993. MWF.APPPD.Activity.End = new Activity(MWF.APPPD.Activity.Circle.NoRouter, "end");
  994. MWF.APPPD.Activity.Cancel = new Activity(MWF.APPPD.Activity.Circle.NoRouter, "cancel");
  995. MWF.APPPD.Activity.Manual = new Activity(MWF.APPPD.Activity, "manual");
  996. MWF.APPPD.Activity.Condition = new Activity(MWF.APPPD.Activity.Diamond, "condition");
  997. MWF.APPPD.Activity.Choice = new Activity(MWF.APPPD.Activity.Diamond, "choice");
  998. MWF.APPPD.Activity.Split = new Activity(MWF.APPPD.Activity.Circle.SingleRouter, "split");
  999. MWF.APPPD.Activity.Parallel = new Activity(MWF.APPPD.Activity.Circle, "parallel");
  1000. MWF.APPPD.Activity.Merge = new Activity(MWF.APPPD.Activity.Circle.SingleRouter, "merge");
  1001. MWF.APPPD.Activity.Embed = new Activity(MWF.APPPD.Activity.SingleRouter, "embed");
  1002. MWF.APPPD.Activity.Delay = new Activity(MWF.APPPD.Activity.Circle.SingleRouter, "delay");
  1003. MWF.APPPD.Activity.Invoke = new Activity(MWF.APPPD.Activity.SingleRouter, "invoke");
  1004. MWF.APPPD.Activity.Service = new Activity(MWF.APPPD.Activity.SingleRouter, "service");
  1005. MWF.APPPD.Activity.Agent = new Activity(MWF.APPPD.Activity.SingleRouter, "agent");
  1006. MWF.APPPD.Activity.Message = new Activity(MWF.APPPD.Activity.SingleRouter, "message");
  1007. })();
  1008. MWF.xApplication.process.ProcessDesigner.Activity.List = new Class({
  1009. initialize: function(activity){
  1010. this.activity = activity;
  1011. this.process = activity.process;
  1012. this.paper = this.activity.process.paper;
  1013. },
  1014. load: function(){
  1015. //this.activity.process.activityListNode
  1016. // this.listActivityNode = new Element("div",{
  1017. // "styles": this.process.css.listActivityNode
  1018. // });
  1019. // this.activityTable = new HtmlTable({
  1020. // "properties": {
  1021. // "width": "100%"
  1022. // }
  1023. // }).inject(this.listActivityNode);
  1024. var actionIcon = (this.activity.type=="begin") ? " " : "<img src=\""+"/x_component_process_ProcessDesigner/$Process/default/icon/copy.png"+"\" />";
  1025. this.row = this.process.activityTable.push([
  1026. {
  1027. "content": " ",
  1028. "properties": {
  1029. "styles": this.activity.style.listIcon
  1030. }
  1031. },
  1032. {
  1033. "content": this.activity.data.name,
  1034. "properties": {
  1035. "styles": this.process.css.list.listText
  1036. }
  1037. },
  1038. {
  1039. "content": actionIcon,
  1040. "properties": {
  1041. "styles": this.process.css.list.listIcon,
  1042. "events": {
  1043. "click": this.copyActivity.bind(this)
  1044. }
  1045. }
  1046. },
  1047. {
  1048. "content": "<img src=\""+"/x_component_process_ProcessDesigner/$Process/default/icon/delete.png"+"\" />",
  1049. "properties": {
  1050. "styles": this.process.css.list.listIcon,
  1051. "events": {
  1052. "click": this.deleteActivity.bind(this)
  1053. }
  1054. }
  1055. }
  1056. ]
  1057. );
  1058. this.row.tr.addEvent("click", function(){
  1059. this.activity.selected();
  1060. }.bind(this));
  1061. //this.listActivityNode.inject(this.activity.process.activityListNode);
  1062. //var activityTable = new Element("table").inject(this.listActivityNode);
  1063. },
  1064. copyActivity: function(){
  1065. this.process.copyActivity(this.activity);
  1066. },
  1067. deleteActivity: function(e){
  1068. this.process.deleteActivity(e, this.activity);
  1069. },
  1070. listSelected: function(){
  1071. if (this.process.currentListSelected) this.process.currentListSelected.listUnSelected();
  1072. this.row.tr.setStyles(this.process.css.list.listRowSelected);
  1073. this.process.currentListSelected = this;
  1074. //alert(this.process.currentSelected!=this.activity)
  1075. //if (this.process.currentSelected!=this.activity) this.activity.selected();
  1076. },
  1077. listUnSelected: function(){
  1078. this.process.currentListSelected = null;
  1079. this.row.tr.setStyles(this.process.css.list.listRow);
  1080. //if (this.process.currentSelected==this.activity) this.activity.unSelected();
  1081. }
  1082. });
  1083. MWF.xApplication.process.ProcessDesigner.Activity.Property = new Class({
  1084. Implements: [Options, Events],
  1085. Extends: MWF.APPPD.Property,
  1086. initialize: function(activity, options){
  1087. this.setOptions(options);
  1088. this.activity = activity;
  1089. this.process = activity.process;
  1090. this.paper = this.activity.process.paper;
  1091. this.data = activity.data;
  1092. this.htmlPath = "/x_component_process_ProcessDesigner/$Process/"+this.activity.type+".html";
  1093. },
  1094. setValue: function(name, value){
  1095. this.data[name] = value;
  1096. if (name=="name"){
  1097. if (!value) this.data[name] = MWF.APPPD.LP.unnamed;
  1098. this.activity.redraw();
  1099. }
  1100. }
  1101. });