Activity_bak.js 37 KB

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