Activity.js 43 KB

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