Activity.js 43 KB

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