Process.js 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.process = MWF.xApplication.process || {};
  3. MWF.xApplication.process.ProcessDesigner = MWF.xApplication.process.ProcessDesigner || {};
  4. MWF.APPPD = MWF.xApplication.process.ProcessDesigner;
  5. MWF.require("MWF.widget.Common", null, false);
  6. MWF.xDesktop.requireApp("process.ProcessDesigner", "lp."+MWF.language, null, false);
  7. MWF.xDesktop.requireApp("process.ProcessDesigner", "Property", null, false);
  8. MWF.xDesktop.requireApp("process.ProcessDesigner", "Activity", null, false);
  9. MWF.xDesktop.requireApp("process.ProcessDesigner", "Route", null, false);
  10. MWF.xApplication.process.ProcessDesigner.Process = new Class({
  11. Extends: MWF.widget.Common,
  12. Implements: [Options, Events],
  13. options: {
  14. "style": "default",
  15. "isView": false
  16. },
  17. initialize: function(paper, process, designer, options){
  18. this.setOptions(options);
  19. this.path = "../x_component_process_ProcessDesigner/$Process/";
  20. this.cssPath = "../x_component_process_ProcessDesigner/$Process/"+this.options.style+"/css.wcss";
  21. this._loadCss();
  22. this.designer = designer;
  23. this.process = process;
  24. this.process.projectionData = (process.project) ? JSON.parse(process.project) : null;
  25. this.paper = paper;
  26. if(this.designer.application) this.process.applicationName = this.designer.application.name;
  27. if(this.designer.application) this.process.application = this.designer.application.id;
  28. // if(this.designer.category) this.process.processCategory = this.designer.category.data.id;
  29. // this.process.starterMode = "assign";
  30. this.activityTemplates = null;
  31. this.routeTemplates = null;
  32. //activity list
  33. this.begin = null;
  34. this.ends = {};
  35. this.cancels={};
  36. this.manuals = {};
  37. this.conditions = {};
  38. this.choices = {};
  39. this.splits = {};
  40. this.parallels = {};
  41. this.merges = {};
  42. this.embeds = {};
  43. this.delays = {};
  44. this.invokes = {};
  45. this.services = {};
  46. this.agents = {};
  47. this.messages = {};
  48. this.activitys=[];
  49. this.selectedActivitys = [];
  50. this.selectedActivityDatas = [];
  51. this.scripts = {};
  52. this.routes = {};
  53. this.routeDatas = {};
  54. this.isGrid = true;
  55. //activity loaded
  56. this.loadedBegin = false;
  57. this.loadedEnds = false;
  58. this.loadedCancels = false;
  59. this.loadedConditions = false;
  60. this.loadedChoices = false;
  61. this.loadedManuals = false;
  62. this.loadedSplits = false;
  63. this.loadedParallels = false;
  64. this.loadedMerges = false;
  65. this.loadedEmbeds = false;
  66. this.loadedDelays = false;
  67. this.loadedInvokes = false;
  68. this.loadedServices = false;
  69. this.loadedAgents = false;
  70. this.loadedMessages = false;
  71. this.isCreateRoute = false;
  72. this.currentCreateRoute = null;
  73. this.isCopyRoute = false;
  74. this.currentCopyRoute = null;
  75. this.isBrokenLine = false;
  76. this.isChangeRouteTo = false;
  77. this.isChangeRouteFrom = false;
  78. this.currentChangeRoute = null;
  79. this.unSelectedEvent = true;
  80. this.panel = null;
  81. this.property = null;
  82. // this.isFocus = false;
  83. this.isNewProcess = (this.process.id) ? false : true;
  84. },
  85. load : function(){
  86. // if (this.isNewProcess){
  87. // this.process.createTime = new Date().format('db');
  88. // this.process.updateTime = new Date().format('db');
  89. // }
  90. this.createPropertyPanel();
  91. this.loadProcessActivitys(function(){
  92. // this.loadProcessActivitys();
  93. this.loadProcessRoutes();
  94. this.loadActivityRoutes();
  95. this.loadProcessScripts();
  96. this.checkLoadRoutes();
  97. if (this.isNewProcess) this.checkUUID();
  98. this.fireEvent("postLoad");
  99. }.bind(this));
  100. this.setEvent();
  101. this.setMenu();
  102. this.showProperty();
  103. this.showEditionInfor();
  104. },
  105. checkLoadRoutes: function(){
  106. Object.each(this.routes, function(route){
  107. if (!route.loaded) route.load();
  108. });
  109. },
  110. checkUUID: function(){
  111. //新流程, 此处处理所有元素的id
  112. this.process.isNewProcess = true;
  113. var idCount = (this.process.begin) ? 2 : 1;
  114. idCount += (this.process.endList) ? this.process.endList.length : 0;
  115. idCount += (this.process.manualList) ? this.process.manualList.length : 0;
  116. idCount += (this.process.conditionList) ? this.process.conditionList.length : 0;
  117. idCount += (this.process.choiceList) ? this.process.choiceList.length : 0;
  118. idCount += (this.process.parallelList) ? this.process.parallelList.length : 0;
  119. idCount += (this.process.splitList) ? this.process.splitList.length : 0;
  120. idCount += (this.process.mergeList) ? this.process.mergeList.length : 0;
  121. idCount += (this.process.embedList) ? this.process.embedList.length : 0;
  122. idCount += (this.process.invokeList) ? this.process.invokeList.length : 0;
  123. idCount += (this.process.cancelList) ? this.process.cancelList.length : 0;
  124. idCount += (this.process.delayList) ? this.process.delayList.length : 0;
  125. idCount += (this.process.messageList) ? this.process.messageList.length : 0;
  126. idCount += (this.process.serviceList) ? this.process.serviceList.length : 0;
  127. idCount += (this.process.routeList) ? this.process.routeList.length : 0;
  128. this.designer.actions.getId(idCount, function(ids){
  129. this.checkUUIDs = ids.data;
  130. //流程ID
  131. this.process.id = this.checkUUIDs.pop().id;
  132. this.process.createTime = new Date().format('db');
  133. this.process.updateTime = new Date().format('db');
  134. for (var i=0; i<this.activitys.length; i++){
  135. if (this.activitys[i].type!="begin"){
  136. delete this[this.activitys[i].type+"s"][this.activitys[i].data.id];
  137. }
  138. this.activitys[i].data.id = this.checkUUIDs.pop().id;
  139. this.activitys[i].data.process = this.process.id;
  140. if (this.activitys[i].type!="begin"){
  141. this[this.activitys[i].type+"s"][this.activitys[i].data.id] = this.activitys[i];
  142. }
  143. }
  144. for (var i=0; i<this.activitys.length; i++){
  145. this.activitys[i].checkUUID();
  146. }
  147. }.bind(this));
  148. },
  149. loadProcessScripts: function(){
  150. if (this.process.scriptList){
  151. this.process.scriptList.each(function(script){
  152. this.scripts[script.id] = script;
  153. }.bind(this));
  154. }
  155. },
  156. setStyle: function(style){
  157. this.options.style = style;
  158. this.reload(this.process);
  159. },
  160. reload: function(process){
  161. debugger;
  162. //this.process = process;
  163. this.panel.destroy();
  164. this.paper.clear();
  165. this.initialize(this.paper, process, this.designer, this.options);
  166. this.createPropertyPanel();
  167. //return false;
  168. this.loadProcessActivitys(function(){
  169. this.loadProcessRoutes();
  170. this.loadActivityRoutes();
  171. this.checkLoadRoutes();
  172. // this.loadProcessRoutes();
  173. // this.loadProcessDecisions();
  174. // this.loadActivityDecisions();
  175. }.bind(this));
  176. this.showProperty();
  177. this.showEditionInfor();
  178. if (process && this.designer.options.id != process.id){
  179. var app = layout.desktop.apps["process.ProcessDesigner"+this.designer.options.id];
  180. if (app){
  181. delete layout.desktop.apps["process.ProcessDesigner"+this.designer.options.id];
  182. this.designer.appId = "process.ProcessDesigner"+process.id;
  183. layout.desktop.apps[this.designer.appId] = this.designer;
  184. }
  185. this.designer.setOptions({"id": process.id});
  186. }
  187. },
  188. setEvent: function(){
  189. this.paper.canvas.addEvent("selectstart", function(e){e.preventDefault();e.stopPropagation();});
  190. if (!this.options.isView){
  191. this.paper.canvas.addEvent("click", function(e){
  192. if (this.unSelectedEvent){
  193. if (this.currentSelected || this.selectedActivitys.length) this.unSelected(e);
  194. }else{
  195. this.unSelectedEvent = true;
  196. }
  197. }.bind(this));
  198. this.paper.canvas.addEvent("mousedown", function(e){
  199. this.checkCreateRoute(e);
  200. this.checkSelectMulti(e);
  201. }.bind(this));
  202. }
  203. //this.paper.canvas.addEvents({
  204. // "blur": function(){this.isFocus = false;}.bind(this),
  205. // "focus": function(){this.isFocus = true;}.bind(this)
  206. //});
  207. },
  208. checkSelectMulti: function(e){
  209. if (!e.rightClick){
  210. var x = e.event.offsetX;
  211. var y = e.event.offsetY;
  212. var els = this.paper.getElementsByPoint(x, y);
  213. if (!els.length){
  214. if (!this.isCreateRoute && !this.isCopyRoute){
  215. this.checkSelectMultiMouseMoveBind = function(e){
  216. this.checkSelectMultiMouseMove(e, {"x": x, "y": y});
  217. }.bind(this);
  218. this.checkSelectMultiMouseUpBind = function(e){
  219. this.checkSelectMultiStop(e, {"x": x, "y": y});
  220. }.bind(this);
  221. this.paper.canvas.addEvent("mousemove", this.checkSelectMultiMouseMoveBind);
  222. this.paper.canvas.addEvent("mouseup", this.checkSelectMultiMouseUpBind);
  223. }
  224. }
  225. }
  226. },
  227. unSelectedAll: function(){
  228. if (this.currentSelected) this.currentSelected.unSelected();
  229. this.property.hide();
  230. this.selectedActivitys.each(function(a){
  231. a.unSelectedMulti();
  232. });
  233. this.selectedActivitys = [];
  234. this.selectedActivityDatas = [];
  235. },
  236. checkSelectMultiMouseMove: function(e, p){
  237. var pMove = {"x": e.event.offsetX, "y": e.event.offsetY};
  238. if (MWFRaphael.getPointDistance(p,pMove)>8){
  239. this.paper.canvas.removeEvent("mousemove", this.checkSelectMultiMouseMoveBind);
  240. if (!this.isCreateRoute && !this.isCopyRoute && !this.isBrokenLine && !this.isChangeRouteTo && !this.isChangeRouteFrom){
  241. var x = Math.min(p.x, pMove.x);
  242. var y = Math.min(p.y, pMove.y);
  243. var width = Math.abs(pMove.x-p.x);
  244. var height = Math.abs(pMove.y-p.y);
  245. var selectBox = this.paper.rect(x, y, width, height, 0).attr({
  246. "fill": "#a8caec",
  247. "stroke": "#3399ff",
  248. "stroke-width": "0.8",
  249. "fill-opacity": 0.5
  250. });
  251. this.beginSelectMultiMouseMoveBind = function(e){
  252. this.beginSelectMultiMouseMove(e, p, selectBox);
  253. }.bind(this);
  254. this.endSelectMultiMouseMoveBind = function(e){
  255. return this.endSelectMulti(e, p, selectBox);
  256. }.bind(this);
  257. this.unSelectedAll();
  258. this.paper.canvas.addEvent("mousemove", this.beginSelectMultiMouseMoveBind);
  259. this.paper.canvas.addEvent("mouseup", this.endSelectMultiMouseMoveBind);
  260. }
  261. }
  262. },
  263. checkSelectMultiStop: function(){
  264. this.paper.canvas.removeEvent("mousemove", this.checkSelectMultiMouseMoveBind);
  265. },
  266. beginSelectMultiMouseMove: function(e, p, rect){
  267. var pMove = {"x": e.event.offsetX, "y": e.event.offsetY};
  268. var x = Math.min(p.x, pMove.x);
  269. var y = Math.min(p.y, pMove.y);
  270. var width = Math.abs(pMove.x-p.x);
  271. var height = Math.abs(pMove.y-p.y);
  272. // rect.attr("path", MWFRaphael.getRectPath(x, y, width, height, 0));
  273. rect.attr({
  274. //"path", MWFRaphael.getRectPath(x, y, width, height, 0)
  275. "x": x,
  276. "y": y,
  277. "width": width,
  278. "height": height
  279. });
  280. this.checkSelectActivity(e, p, rect);
  281. },
  282. endSelectMulti: function(e, p, rect){
  283. rect.remove();
  284. if (this.selectedActivityDatas.length){
  285. this.panel.data = this.selectedActivityDatas;
  286. }
  287. this.paper.canvas.removeEvent("mousemove", this.beginSelectMultiMouseMoveBind);
  288. this.paper.canvas.removeEvent("mouseup", this.endSelectMultiMouseMoveBind);
  289. if (this.selectedActivitys.length){
  290. this.unSelectedEvent = false;
  291. window.setTimeout(function(){this.unSelectedEvent = true;}.bind(this), 300);
  292. }
  293. return false;
  294. },
  295. checkSelectActivity: function(e, p, rect){
  296. var pMove = {"x": e.event.offsetX, "y": e.event.offsetY};
  297. var x = Math.min(p.x, pMove.x);
  298. var y = Math.min(p.y, pMove.y);
  299. var toX = Math.max(p.x, pMove.x);
  300. var toY = Math.max(p.y, pMove.y);
  301. this.activitys.each(function(activity){
  302. var ax = activity.center.x;
  303. var ay = activity.center.y;
  304. if (ax>x && ax<toX && ay>y && ay<toY){
  305. if (!activity.selectedMultiStatus) activity.selectedMulti();
  306. }else{
  307. this.selectedActivitys.erase(activity);
  308. this.selectedActivityDatas.erase(activity.data);
  309. activity.unSelectedMulti();
  310. }
  311. }.bind(this));
  312. if (this.selectedActivityDatas.length){
  313. if (this.property) this.property.showMultiActivity(this.selectedActivitys);
  314. this.panel.propertyTabPage.showTabIm();
  315. this.panel.data = this.selectedActivityDatas;
  316. }else{
  317. this.unSelectedAll();
  318. this.showProperty();
  319. }
  320. },
  321. showProperty: function(){
  322. if (!this.property){
  323. this.property = new MWF.APPPD.Process.Property(this, {
  324. "onPostLoad": function(){
  325. this.property.show();
  326. }.bind(this)
  327. });
  328. this.property.load();
  329. }else{
  330. this.property.show();
  331. }
  332. // this.isFocus = true;
  333. },
  334. showEditionInfor: function(){
  335. if (this.process.edition){
  336. if (this.designer.processEditionNode){
  337. this.designer.processEditionNode.removeEvents("click");
  338. if (this.process.editionEnable){
  339. this.designer.processEditionNode.set("text", this.designer.lp.enable);
  340. this.designer.processEditionNode.addClass("mainColor_bg");
  341. }else{
  342. this.designer.processEditionNode.set("text", this.designer.lp.notEnable);
  343. this.designer.processEditionNode.removeClass("mainColor_bg");
  344. this.designer.processEditionNode.addEvent("click", function(e){
  345. this.enableCurrentEdition(e);
  346. }.bind(this));
  347. }
  348. }
  349. if (this.designer.processEditionInforNode){
  350. var text = this.designer.lp.currentEdition+": <span class='mainColor_color'>"+this.process.editionNumber+"</span> "+this.designer.lp.editionUpdate+": <span class='mainColor_color'>"+o2.name.cn(this.process.lastUpdatePerson)+" ("+this.process.updateTime+")</span>";
  351. this.designer.processEditionInforNode.set("html", text);
  352. this.designer.processEditionInforNode.addEvent("click", function(e){
  353. this.listEdition(e);
  354. }.bind(this));
  355. }
  356. }
  357. },
  358. enableCurrentEdition: function(e){
  359. var _self = this;
  360. this.designer.confirm("infor", e, this.designer.lp.edition_list.enabledProcessTitle, {"html": this.designer.lp.edition_list.enabledProcessInfor}, 600, 120, function(){
  361. _self.save(function(){
  362. var actions = o2.Actions.load("x_processplatform_assemble_designer").ProcessAction;
  363. actions.enableProcess(this.process.id, function(json){
  364. actions.get(this.process.id, function(json){
  365. this.reload(json.data);
  366. }.bind(this))
  367. }.bind(this));
  368. }.bind(_self));
  369. this.close();
  370. },function(){this.close();})
  371. },
  372. unSelected: function(e){
  373. //var els = this.paper.getElementsByPoint(e.event.layerX, e.event.layerY);
  374. var els = this.paper.getElementsByPoint(e.event.offsetX, e.event.offsetY);
  375. if (!els.length){
  376. this.unSelectedAll();
  377. this.showProperty();
  378. // if (this.currentSelected){
  379. // this.currentSelected.unSelected();
  380. // }
  381. }
  382. },
  383. setMenu: function(){
  384. MWF.require("MWF.widget.Menu", function(){
  385. this.menu = new MWF.widget.Menu(this.paper.canvas, {
  386. "onQueryShow": function(e){
  387. //var obj = this.getPointElement(e.event.layerX, e.event.layerY);
  388. var obj = this.getPointElement(e.event.offsetX, e.event.offsetY);
  389. switch (obj.type){
  390. case "activity":
  391. this.addActivityMenu(obj.bind);
  392. break;
  393. case "route":
  394. this.addRouteMenu(obj.bind);
  395. break;
  396. default:
  397. this.addProcessMenu();
  398. };
  399. }.bind(this)
  400. });
  401. this.menu.load();
  402. }.bind(this));
  403. },
  404. addPublicMenu: function(bind, newRoute){
  405. var newRouteFun = newRoute;
  406. if (!newRouteFun) newRouteFun = this.createRoute.bind(this);
  407. this.menu.addMenuItem(MWF.APPPD.LP.menu.newRoute, "click", newRouteFun, this.designer.path+""+this.options.style+"/toolbarIcon/"+"newRouter.gif");
  408. if (!this.newActivityMenu){
  409. MWF.require("MWF.widget.Menu", null, false);
  410. this.newActivityMenu = new MWF.widget.Menu(this.paper.canvas, {"event": null});
  411. this.newActivityMenu.load();
  412. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.manual, "click", this.createManualActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"manual.gif");
  413. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.condition, "click", this.createConditionActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"condition.gif");
  414. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.auto, "click", this.createAutoActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"auto.gif");
  415. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.split, "click", this.createSplitActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"split.gif");
  416. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.merge, "click", this.createMergeActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"merge.gif");
  417. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.embed, "click", this.createEmbedActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"embed.gif");
  418. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.invoke, "click", this.createInvokesActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"invoke.gif");
  419. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.begin, "click", this.createBeginActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"begin.gif");
  420. this.newActivityMenu.addMenuItem(MWF.APPPD.LP.menu.newActivityType.end, "click", this.createEndActivity.bind(this), this.designer.path+""+this.designer.options.style+"/toolbarIcon/"+"end.gif");
  421. }
  422. this.menu.addMenuMenu(MWF.APPPD.LP.menu.newActivity, this.designer.path+""+this.options.style+"/toolbarIcon/"+"newActivity.gif", this.newActivityMenu);
  423. },
  424. addActivityMenu: function(bind){
  425. this.menu.clearItems();
  426. var newRoute = function(){bind.quickCreateRoute();};
  427. this.addPublicMenu(bind, newRoute);
  428. this.menu.addMenuLine();
  429. this.menu.addMenuItem(MWF.APPPD.LP.menu.copyActivity, "click", function(e){this.copyActivity(bind);}.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"copy.png");
  430. this.menu.addMenuLine();
  431. this.menu.addMenuItem(MWF.APPPD.LP.menu.deleteActivity, "click", function(e){this.deleteActivity(e, bind);}.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"deleteActivity.gif");
  432. },
  433. addRouteMenu: function(bind){
  434. this.menu.clearItems();
  435. this.addPublicMenu();
  436. this.menu.addMenuLine();
  437. this.menu.addMenuItem(MWF.APPPD.LP.menu.deleteRoute, "click", function(e){this.deleteRoute(e, bind);}.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"deleteRouter.gif");
  438. },
  439. addProcessMenu: function(){
  440. var process = this;
  441. this.menu.clearItems();
  442. this.addPublicMenu();
  443. this.menu.addMenuLine();
  444. this.menu.addMenuItem(MWF.APPPD.LP.menu.saveProcess, "click", this.save.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"save.gif");
  445. this.menu.addMenuItem(MWF.APPPD.LP.menu.saveProcessNew, "click", this.saveNew.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"saveNew.gif", true);
  446. this.menu.addMenuLine();
  447. if (this.isGrid){
  448. this.menu.addMenuItem(MWF.APPPD.LP.menu.hideGrid, "click", function(){process.switchGrid(this);}, this.designer.path+""+this.options.style+"/toolbarIcon/"+"gridding.gif");
  449. }else{
  450. this.menu.addMenuItem(MWF.APPPD.LP.menu.showGrid, "click", function(){process.switchGrid(this);}, this.designer.path+""+this.options.style+"/toolbarIcon/"+"gridding.gif");
  451. }
  452. this.menu.addMenuLine();
  453. this.menu.addMenuItem(MWF.APPPD.LP.menu.checkProcess, "click", this.checkProcess.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"checkProcess.gif", true);
  454. this.menu.addMenuItem(MWF.APPPD.LP.menu.exportProcess, "click", this.exportProcess.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"processExplode.gif", true);
  455. this.menu.addMenuLine();
  456. this.menu.addMenuItem(MWF.APPPD.LP.menu.printProcess, "click", this.printProcess.bind(this), this.designer.path+""+this.options.style+"/toolbarIcon/"+"print.gif", true);
  457. },
  458. saveNew: function(e){
  459. //unrealized
  460. this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100);
  461. //layout.notice("error", {x: "right", y:"top"}, MWF.APPPD.LP.unrealized);
  462. },
  463. checkProcess: function(e){
  464. //unrealized
  465. this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100);
  466. },
  467. exportProcess: function(e){
  468. //unrealized
  469. this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100);
  470. },
  471. printProcess: function(e){
  472. //unrealized
  473. this.designer.alert("error", e, "", MWF.APPPD.LP.unrealized, 220, 100);
  474. },
  475. saveNewEdition: function(e){
  476. if (this.process.isNewProcess){
  477. this.save();
  478. }else{
  479. var node = new Element("div", {"styles":this.designer.css.saveNewEditionNode});
  480. var inforNode = new Element("div", {"html":this.designer.lp.upgradeInfor}).inject(node);
  481. var descriptionNode = new Element("div", {"styles": this.designer.css.editionDescriptionNode}).inject(node);
  482. var descriptionTitleNode = new Element("div", {"styles": this.designer.css.descriptionTitleNode, "text": this.designer.lp.editionDiscription}).inject(descriptionNode);
  483. var descriptionTextAreaNode = new Element("textarea", {"styles": this.designer.css.descriptionTextAreaNode}).inject(descriptionNode);
  484. var _self = this;
  485. o2.DL.open({
  486. "content": node,
  487. "title": this.designer.lp.upgradeConfirm,
  488. "offset": {"y": -100},
  489. "height": 340,
  490. "width": 580,
  491. "buttonList": [{
  492. "type": "ok",
  493. "text": this.designer.lp.ok,
  494. "action": function(){
  495. var textarea = this.content.getElement("textarea");
  496. var discription = textarea.get("value");
  497. if (!discription) {
  498. _self.designer.notice(_self.designer.lp.inputDiscription, "error", descriptionNode);
  499. }else{
  500. var checkbox = this.content.getElement("input");
  501. var enable = (!!checkbox && checkbox.get("checked"));
  502. _self.doSaveNewEdition(enable, discription);
  503. this.close();
  504. }
  505. }
  506. },{
  507. "type": "cancel",
  508. "text": this.designer.lp.cancel,
  509. "action": function(){
  510. this.close();
  511. }
  512. }]
  513. });
  514. // var _self = this;
  515. // this.designer.confirm("infor", e, this.designer.lp.upgradeConfirm, {"html": this.designer.lp.upgradeInfor}, 520, 210, function(){
  516. // var checkbox = this.content.getElement("input");
  517. // var enable = (!!checkbox && checkbox.get("checked"));
  518. // _self.doSaveNewEdition(enable);
  519. // this.close();
  520. // }, function(){
  521. // this.close();
  522. // });
  523. }
  524. },
  525. doSaveNewEdition: function(enable, description){
  526. debugger;
  527. var process = Object.clone(this.process);
  528. process.editionDes = description;
  529. var oldIds = [];
  530. oldIds.push(process.id);
  531. if (process.begin) oldIds.push(process.begin.id);
  532. if (process.endList) process.endList.each(function(a){oldIds.push(a.id);});
  533. if (process.agentList) process.agentList.each(function(a){oldIds.push(a.id);});
  534. if (process.manualList) process.manualList.each(function(a){oldIds.push(a.id);});
  535. if (process.conditionList) process.conditionList.each(function(a){oldIds.push(a.id);});
  536. if (process.choiceList) process.choiceList.each(function(a){oldIds.push(a.id);});
  537. if (process.parallelList) process.parallelList.each(function(a){oldIds.push(a.id);});
  538. if (process.splitList) process.splitList.each(function(a){oldIds.push(a.id);});
  539. if (process.mergeList) process.mergeList.each(function(a){oldIds.push(a.id);});
  540. if (process.embedList) process.embedList.each(function(a){oldIds.push(a.id);});
  541. if (process.invokeList) process.invokeList.each(function(a){oldIds.push(a.id);});
  542. if (process.cancelList) process.cancelList.each(function(a){oldIds.push(a.id);});
  543. if (process.delayList) process.delayList.each(function(a){oldIds.push(a.id);});
  544. if (process.messageList) process.messageList.each(function(a){oldIds.push(a.id);});
  545. if (process.serviceList) process.serviceList.each(function(a){oldIds.push(a.id);});
  546. if (process.routeList) process.routeList.each(function(a){oldIds.push(a.id);});
  547. var actions = o2.Actions.load("x_processplatform_assemble_designer");
  548. this.designer.actions.getId(oldIds.length, function(ids) {
  549. var checkUUIDs = ids.data;
  550. var processStr = JSON.encode(process);
  551. oldIds.each(function(oid, i){
  552. var reg = new RegExp(oid, "ig");
  553. processStr = processStr.replace(reg, checkUUIDs[i].id);
  554. }.bind(this));
  555. process = JSON.decode(processStr);
  556. actions.ProcessAction.upgrade(this.process.id, process, function(json){
  557. var processId = json.data.id;
  558. if (enable){
  559. actions.ProcessAction.enableProcess(processId, function(processJson){
  560. actions.ProcessAction.get(processId, function(processJson){
  561. this.reload(processJson.data);
  562. }.bind(this))
  563. }.bind(this))
  564. }else{
  565. actions.ProcessAction.get(processId, function(processJson){
  566. this.reload(processJson.data);
  567. }.bind(this))
  568. }
  569. }.bind(this));
  570. }.bind(this));
  571. },
  572. listEdition: function(){
  573. if (this.process.edition){
  574. if (!this.editionListDlg){
  575. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.EditionList", function(){
  576. this.editionListDlg = new MWF.xApplication.process.ProcessDesigner.widget.EditionList(this.process.application, this.process.edition, this);
  577. this.editionListDlg.load();
  578. }.bind(this));
  579. }else{
  580. this.editionListDlg.show();
  581. }
  582. }else{
  583. this.designer.notice("infor", this.designer.lp.save_process);
  584. }
  585. },
  586. listEditionDlg: function(editionList){
  587. //var node = new Element("div", )
  588. },
  589. switchGrid: function(item){
  590. if (this.isGrid){
  591. this.hideGrid();
  592. }else{
  593. this.showGrid();
  594. }
  595. },
  596. showGrid: function(){
  597. this.designer.paperNode.setStyle("background-image", "url("+MWF.defaultPath+"/process/ProcessChart/$Process/"+this.options.style+"/griddingbg.gif)");
  598. // if (this.GridSet){
  599. // this.GridSet.show();
  600. // }else{
  601. // var paperSize = $(this.paper.canvas).getParent().getSize();
  602. // this.GridSet = this.paper.set();
  603. // for (var i=20; i<paperSize.x; i=i+20){
  604. // var lineV = this.paper.path("M"+i+",0L"+i+","+paperSize.y).attr({
  605. // "stroke": "#ccc",
  606. // "stroke-dasharray": ".",
  607. // "stroke-width": 1
  608. // });
  609. // lineV.toBack();
  610. // this.GridSet.push(lineV);
  611. // }
  612. // for (var j=20; j<paperSize.y; j=j+20){
  613. // var lineL = this.paper.path("M0,"+j+"L"+paperSize.x+","+j).attr({
  614. // "stroke": "#ccc",
  615. // "stroke-dasharray": ".",
  616. // "stroke-width": 1
  617. // });
  618. // lineL.toBack();
  619. // this.GridSet.push(lineL);
  620. // }
  621. // }
  622. this.isGrid = true;
  623. },
  624. hideGrid: function(){
  625. this.designer.paperNode.setStyle("background-image", "");
  626. // if (this.GridSet){
  627. // this.GridSet.hide();
  628. // }
  629. this.isGrid = false;
  630. },
  631. getPointElement: function(x, y){
  632. var els = this.paper.getElementsByPoint(x, y);
  633. var bindObject = null;
  634. var bindType = "none";
  635. if (els.length){
  636. for (var i=0; i<els.length; i++){
  637. var bind = els[i].data("bind");
  638. if (bind){
  639. if (instanceOf(bind, MWF.APPPD.Activity)){
  640. bindObject = bind;
  641. bindType = "activity";
  642. break;
  643. }
  644. if (instanceOf(bind, MWF.APPPD.Route)){
  645. bindObject = bind;
  646. bindType = "route";
  647. }
  648. };
  649. }
  650. }
  651. return {"bind": bindObject, "type": bindType};
  652. },
  653. // loadProcessDecisions: function(){
  654. // if (this.process.decisionList){
  655. // this.process.decisionList.each(function(d){
  656. // this.decisionDatas[d.id] = d;
  657. // }.bind(this));
  658. // }
  659. // },
  660. loadActivityRoutes: function(){
  661. this.activitys.each(function(activity){
  662. activity.loadRoutes();
  663. });
  664. },
  665. // loadActivityDecisions: function(){
  666. // if (this.begin) this.begin.loadDecisions();
  667. // for (a in this.ends){
  668. // this.ends[a].loadDecisions();
  669. // };
  670. // for (a in this.manuals){
  671. // this.manuals[a].loadDecisions();
  672. // };
  673. // for (a in this.autos){
  674. // this.autos[a].loadDecisions();
  675. // };
  676. // for (a in this.conditions){
  677. // this.conditions[a].loadDecisions();
  678. // };
  679. // for (a in this.embeds){
  680. // this.embeds[a].loadDecisions();
  681. // };
  682. // for (a in this.invokes){
  683. // this.invokes[a].loadDecisions();
  684. // };
  685. // },
  686. loadProcessRoutes: function(){
  687. this.process.routeList.each(function(item){
  688. this.routes[item.id] = new MWF.APPPD.Route(item, this);
  689. this.routeDatas[item.id] = item;
  690. // this.routes[item.id].load();
  691. }.bind(this));
  692. },
  693. createPropertyPanel: function(){
  694. if (!this.options.isView){
  695. this.panel = new MWF.APPPD.Process.Panel(this);
  696. this.panel.load();
  697. }
  698. },
  699. loadedActivitys: function(callback){
  700. if (this.loadedBegin && this.loadedEnds && this.loadedCancels && this.loadedConditions && this.loadedChoices && this.loadedSplits && this.loadedParallels && this.loadedMerges && this.loadedManuals && this.loadedEmbeds && this.loadedDelays && this.loadedInvokes && this.loadedServices && this.loadedAgents && this.loadedMessages){
  701. if (callback) callback();
  702. }
  703. },
  704. loadProcessActivitys: function(callback){
  705. this.loadBegin(function(){this.loadedBegin = true; this.loadedActivitys(callback);}.bind(this));
  706. this.loadEndList(function(){this.loadedEnds = true; this.loadedActivitys(callback);}.bind(this));
  707. this.loadCancelList(function(){this.loadedCancels = true; this.loadedActivitys(callback);}.bind(this));
  708. this.loadManualList(function(){this.loadedManuals = true; this.loadedActivitys(callback);}.bind(this));
  709. this.loadConditionList(function(){this.loadedConditions = true; this.loadedActivitys(callback);}.bind(this));
  710. this.loadChoiceList(function(){this.loadedChoices = true; this.loadedActivitys(callback);}.bind(this));
  711. this.loadSplitList(function(){this.loadedSplits = true; this.loadedActivitys(callback);}.bind(this));
  712. this.loadParallelList(function(){this.loadedParallels = true; this.loadedActivitys(callback);}.bind(this));
  713. this.loadMergeList(function(){this.loadedMerges = true; this.loadedActivitys(callback);}.bind(this));
  714. this.loadEmbedList(function(){this.loadedEmbeds = true; this.loadedActivitys(callback);}.bind(this));
  715. this.loadDelayList(function(){this.loadedDelays = true; this.loadedActivitys(callback);}.bind(this));
  716. this.loadInvokeList(function(){this.loadedInvokes = true; this.loadedActivitys(callback);}.bind(this));
  717. this.loadServiceList(function(){this.loadedServices = true; this.loadedActivitys(callback);}.bind(this));
  718. this.loadAgentList(function(){this.loadedAgents = true; this.loadedActivitys(callback);}.bind(this));
  719. this.loadMessageList(function(){this.loadedMessages = true; this.loadedActivitys(callback);}.bind(this));
  720. },
  721. loadBegin: function(callback){
  722. var data = this.process["begin"];
  723. if (data){
  724. this.begin = new MWF.APPPD.Activity.Begin(data, this);
  725. this.begin.load(callback);
  726. }else{
  727. if (callback) callback();;
  728. }
  729. this.activitys.push(this.begin);
  730. },
  731. loadEndList: function(callback){
  732. this.loadActivitys("End", "endList", this.ends, callback);
  733. },
  734. loadCancelList: function(callback){
  735. this.loadActivitys("Cancel", "cancelList", this.cancels, callback);
  736. },
  737. loadManualList: function(callback){
  738. this.loadActivitys("Manual", "manualList", this.manuals, callback);
  739. },
  740. loadConditionList: function(callback){
  741. this.loadActivitys("Condition", "conditionList", this.conditions, callback);
  742. },
  743. loadChoiceList: function(callback){
  744. this.loadActivitys("Choice", "choiceList", this.choices, callback);
  745. },
  746. loadSplitList: function(callback){
  747. this.loadActivitys("Split", "splitList", this.splits, callback);
  748. },
  749. loadParallelList: function(callback){
  750. this.loadActivitys("Parallel", "parallelList", this.parallels, callback);
  751. },
  752. loadMergeList: function(callback){
  753. this.loadActivitys("Merge", "mergeList", this.merges, callback);
  754. },
  755. loadEmbedList: function(callback){
  756. this.loadActivitys("Embed", "embedList", this.embeds, callback);
  757. },
  758. loadDelayList: function(callback){
  759. this.loadActivitys("Delay", "delayList", this.delays, callback);
  760. },
  761. loadInvokeList: function(callback){
  762. this.loadActivitys("Invoke", "invokeList", this.invokes, callback);
  763. },
  764. loadServiceList: function(callback){
  765. this.loadActivitys("Service", "serviceList", this.services, callback);
  766. },
  767. loadAgentList: function(callback){
  768. this.loadActivitys("Agent", "agentList", this.agents, callback);
  769. },
  770. loadMessageList: function(callback){
  771. this.loadActivitys("Message", "messageList", this.messages, callback);
  772. },
  773. loadActivitys: function(c, p, children, callback){
  774. var datas = this.process[p];
  775. if (datas){
  776. var count = datas.length;
  777. var loadedCount = 0;
  778. if (count){
  779. datas.each(function(data){
  780. this.loadActivity(c, data, children, function(){
  781. loadedCount++;
  782. if (loadedCount==count){
  783. if (callback) callback();
  784. }
  785. }.bind(this));
  786. }.bind(this));
  787. }else{
  788. if (callback) callback();
  789. }
  790. }else{
  791. if (callback) callback();
  792. }
  793. },
  794. loadActivity: function(c, data, children, callback){
  795. activity = new MWF.APPPD.Activity[c](data, this);
  796. activity.load(callback);
  797. if (c==="begin"){
  798. this.begin = activity;
  799. }else{
  800. children[data.id] = activity;
  801. }
  802. this.activitys.push(activity);
  803. },
  804. destroy: function(){
  805. this.paper.remove();
  806. },
  807. checkActivityEmptyRouteList: function(activitys){
  808. if (activitys && activitys.length){
  809. activitys.each(function(a){
  810. if (a.routeList) a.routeList = a.routeList.filter(function(n){return !!n;});
  811. });
  812. }
  813. },
  814. checkEmptyRouteList: function(){
  815. this.checkActivityEmptyRouteList(this.process.endList);
  816. this.checkActivityEmptyRouteList(this.process.cancelList);
  817. this.checkActivityEmptyRouteList(this.process.manualList);
  818. this.checkActivityEmptyRouteList(this.process.conditionList);
  819. this.checkActivityEmptyRouteList(this.process.choiceList);
  820. this.checkActivityEmptyRouteList(this.process.splitList);
  821. this.checkActivityEmptyRouteList(this.process.parallelList);
  822. this.checkActivityEmptyRouteList(this.process.mergeList);
  823. this.checkActivityEmptyRouteList(this.process.embedList);
  824. this.checkActivityEmptyRouteList(this.process.delayList);
  825. this.checkActivityEmptyRouteList(this.process.invokeList);
  826. this.checkActivityEmptyRouteList(this.process.serviceList);
  827. this.checkActivityEmptyRouteList(this.process.agentList);
  828. this.checkActivityEmptyRouteList(this.process.messageList);
  829. },
  830. save: function(callback){
  831. if (!this.isSave){
  832. this.isSave = true;
  833. //check empty routeList
  834. this.checkEmptyRouteList();
  835. var reload = !!this.process.isNewProcess;
  836. this.designer.actions.saveProcess(this.process, function(responseJSON){
  837. this.isSave = false;
  838. this.process.isNewProcess = false;
  839. this.designer.notice(MWF.APPPD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"} );
  840. this.isNewProcess = false;
  841. this.designer.options.id = responseJSON.data.id;
  842. if (reload){
  843. this.designer.actions.getProcess(responseJSON.data.id, function(json){
  844. this.reload(json.data);
  845. if (callback) callback();
  846. }.bind(this));
  847. }else{
  848. if (callback) callback();
  849. }
  850. }.bind(this), function(xhr, text, error){
  851. this.isSave = false;
  852. var errorText = error+":"+text;
  853. if (xhr) errorText = xhr.responseText;
  854. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  855. }.bind(this));
  856. }else{
  857. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
  858. }
  859. //this.process
  860. },
  861. getActivityTemplate: function(callback){
  862. if (this.activityTemplates){
  863. if (callback) callback();
  864. }else{
  865. var activityTemplateUrl = this.path+"activity.json";
  866. var r = new Request.JSON({
  867. url: activityTemplateUrl,
  868. secure: false,
  869. async: false,
  870. method: "get",
  871. noCache: true,
  872. onSuccess: function(responseJSON, responseText){
  873. this.activityTemplates = responseJSON;
  874. if (callback) callback();
  875. }.bind(this),
  876. onError: function(text, error){
  877. alert(error);
  878. }
  879. });
  880. r.send();
  881. }
  882. },
  883. getRouteTemplates: function(callback){
  884. if (this.routeTemplates){
  885. if (callback) callback();
  886. }else{
  887. var routeTemplateUrl = this.path+"route.json";
  888. var r = new Request.JSON({
  889. url: routeTemplateUrl,
  890. secure: false,
  891. async: false,
  892. method: "get",
  893. noCache: true,
  894. onSuccess: function(responseJSON, responseText){
  895. this.routeTemplates = responseJSON;
  896. if (callback) callback();
  897. }.bind(this),
  898. onError: function(text, error){
  899. alert(error);
  900. }
  901. });
  902. r.send();
  903. }
  904. },
  905. createActivity: function(d, c, position){
  906. if (d=="begin"){
  907. if (this.begin){
  908. this.designer.notice(MWF.APPPD.LP.notice["one_begin"], "error", null, {x: "right", y:"top"});
  909. return false;
  910. }
  911. }
  912. var activity = null;
  913. this.getActivityTemplate(function(){
  914. var activityData = Object.clone(this.activityTemplates[d]);
  915. //MWF.require("MWF.widget.UUID", function(){
  916. //activityData.id = (new MWF.widget.UUID()).toString();
  917. this.designer.actions.getUUID(function(id){activityData.id = id;});
  918. activityData.process = this.process.id;
  919. activityData.createTime = new Date().format('db');
  920. activityData.updateTime = new Date().format('db');
  921. activityData.position = position.x+","+position.y;
  922. activity = new MWF.APPPD.Activity[c](activityData, this);
  923. activity.create(position);
  924. if (d=="begin"){
  925. this.begin = activity;
  926. this.process.begin = activityData;
  927. }else{
  928. this[d+"s"][activityData.id] = activity;
  929. if (!this.process[d+"List"]){
  930. this.process[d+"List"] = [];
  931. }
  932. this.process[d+"List"].push(activityData);
  933. }
  934. this.activitys.push(activity);
  935. // }.bind(this));
  936. }.bind(this));
  937. return activity;
  938. },
  939. createManualActivity: function(){
  940. this.createActivity("manual", "Manual");
  941. },
  942. createConditionActivity: function(){
  943. this.createActivity("condition", "Condition");
  944. },
  945. createAutoActivity: function(){
  946. this.createActivity("auto", "Auto");
  947. },
  948. createSplitActivity: function(){
  949. this.createActivity("split", "Split");
  950. },
  951. createMergeActivity: function(){
  952. this.createActivity("merge", "Merge");
  953. },
  954. createEmbedActivity: function(){
  955. this.createActivity("embed", "Embed");
  956. },
  957. createInvokesActivity: function(){
  958. this.createActivity("invoke", "Invoke");
  959. },
  960. createBeginActivity: function(){
  961. this.createActivity("begin", "Begin");
  962. },
  963. createEndActivity: function(){
  964. this.createActivity("end", "End");
  965. },
  966. createRoute: function(){
  967. if (!this.isCopyRoute && !this.isCreateRoute){
  968. this.getRouteTemplates(function(){
  969. var routerData = Object.clone(this.routeTemplates.route);
  970. //routerData.id = this.designer.actions.getUUID();
  971. this.designer.actions.getUUID(function(id){routerData.id = id;});
  972. routerData.process = this.process.id;
  973. routerData.createTime = new Date().format('db');
  974. routerData.updateTime = new Date().format('db');
  975. var route = new MWF.APPPD.Route(routerData, this);
  976. route.isBack = true;
  977. route.load();
  978. route.set.toBack();
  979. this.beginRouteCreate(route);
  980. }.bind(this));
  981. }
  982. },
  983. beginRouteCreate: function(route){
  984. this.isCreateRoute = true;
  985. this.currentCreateRoute = route;
  986. this.designer.setToolBardisabled("createRoute");
  987. //route.set.toFront();
  988. this.routeCreateFromMouseMoveBind = function(e){
  989. this.routeCreateFromMouseMove(e);
  990. }.bind(this);
  991. this.paper.canvas.addEvent("mousemove", this.routeCreateFromMouseMoveBind);
  992. },
  993. routeCreateFromMouseMove: function(e){
  994. //var x = e.event.layerX.toFloat();
  995. //var y = e.event.layerY.toFloat();
  996. var x = e.event.offsetX.toFloat();
  997. var y = e.event.offsetY.toFloat();
  998. var dx = x - this.currentCreateRoute.beginPoint.x-5;
  999. var dy = y - this.currentCreateRoute.beginPoint.y+5;
  1000. this.currentCreateRoute.set.transform("t"+dx+","+dy);
  1001. },
  1002. routeCreateFromActivity: function(activity){
  1003. this.paper.canvas.removeEvent("mousemove", this.routeCreateFromMouseMoveBind);
  1004. var route = this.currentCreateRoute;
  1005. route.setActivity(null, activity);
  1006. route.reload();
  1007. this.routeCreateToMouseMoveBind = function(e){
  1008. this.routeCreateToMouseMove(e);
  1009. }.bind(this);
  1010. this.paper.canvas.addEvent("mousemove", this.routeCreateToMouseMoveBind);
  1011. },
  1012. routeCreateToMouseMove: function(e){
  1013. //var x = e.event.layerX.toFloat();
  1014. //var y = e.event.layerY.toFloat();
  1015. var x = e.event.offsetX.toFloat();
  1016. var y = e.event.offsetY.toFloat();
  1017. var route = this.currentCreateRoute;
  1018. route.tmpEndPoint = {"x": x-3, "y": y-3};
  1019. route.reload();
  1020. },
  1021. routeCreateToActivity: function(activity){
  1022. this.paper.canvas.removeEvent("mousemove", this.routeCreateToMouseMoveBind);
  1023. var route = this.currentCreateRoute;
  1024. route.tmpEndPoint = null;
  1025. route.tmpBeginPoint = null;
  1026. route.setActivity(activity, null);
  1027. route.isBack = false;
  1028. route.reload();
  1029. activity.shap.attr(activity.style.shap);
  1030. this.endRouteCreate();
  1031. },
  1032. endRouteCreate: function(){
  1033. var route = this.currentCreateRoute;
  1034. route.selected();
  1035. this.isCreateRoute = false;
  1036. this.currentCreateRoute = null;
  1037. route.setListItemData();
  1038. this.designer.setToolBardisabled("decision");
  1039. this.setNewRouteProcessData(route);
  1040. },
  1041. setNewRouteProcessData: function(route){
  1042. this.routes[route.data.id] = route;
  1043. this.process.routeList.push(route.data);
  1044. route.fromActivity.setRouteData(route.data.id);
  1045. // if (!route.fromActivity.data.routeList) route.fromActivity.data.routeList = [];
  1046. // route.fromActivity.data.routeList.push(route.data.id);
  1047. route.data.activity = route.toActivity.data.id;
  1048. route.data.activityType = route.toActivity.type;
  1049. },
  1050. routeCreateCancel: function(){
  1051. var route = this.currentCreateRoute;
  1052. if (route.fromActivity){
  1053. route.fromActivity.routes.erase(route);
  1054. }
  1055. route.destroy();
  1056. delete route;
  1057. this.isCreateRoute = false;
  1058. this.currentCreateRoute = null;
  1059. if (this.routeCreateFromMouseMoveBind) this.paper.canvas.removeEvent("mousemove", this.routeCreateFromMouseMoveBind);
  1060. if (this.routeCreateToMouseMoveBind) this.paper.canvas.removeEvent("mousemove", this.routeCreateToMouseMoveBind);
  1061. },
  1062. checkCreateRoute: function(e){
  1063. if (this.isCreateRoute || this.isCopyRoute){
  1064. if (e.rightClick){
  1065. if (this.isCreateRoute){
  1066. this.routeCreateCancel();
  1067. }
  1068. if (this.isCopyRoute){
  1069. this.routeAddCancel();
  1070. }
  1071. }
  1072. if (this.menu) this.menu.pause(1);
  1073. }
  1074. },
  1075. clearSelected: function(){
  1076. this.begin.unSelectActivity();
  1077. for (a in this.ends) this.ends[a].unSelected();
  1078. for (a in this.conditions) this.conditions[a].unSelected();
  1079. for (a in this.autos) this.autos[a].unSelected();
  1080. for (a in this.manuals) this.manuals[a].unSelected();
  1081. for (a in this.embeds) this.embeds[a].unSelected();
  1082. for (a in this.invokes) this.invokes[a].unSelected();
  1083. },
  1084. copyRoute: function(route){
  1085. if (!this.isCopyRoute && !this.isCreateRoute){
  1086. var newRouteData = Object.clone(route.data);
  1087. //newRouteData.id = Raphael.createUUID();
  1088. //newRouteData.id = this.designer.actions.getUUID();
  1089. this.designer.actions.getUUID(function(id){newRouteData.id = id;});
  1090. var route = new MWF.APPPD.Route(newRouteData, this);
  1091. route.load();
  1092. route.isBack = true;
  1093. this.isCopyRoute = true;
  1094. this.currentCopyRoute = route;
  1095. this.beginRouteCopy(route);
  1096. }
  1097. },
  1098. beginRouteCopy: function(route){
  1099. this.routeCopyMouseMoveBind = function(e){
  1100. this.copyRouteMouseMove(e, route);
  1101. }.bind(this);
  1102. this.paper.canvas.addEvent("mousemove", this.routeCopyMouseMoveBind);
  1103. },
  1104. copyRouteMouseMove: function(e, route){
  1105. route.tmpBeginPoint = {"x": e.event.offsetX-5, "y": e.event.offsetY-5};
  1106. route.reload();
  1107. },
  1108. routeAddFromActivity: function(activity){
  1109. var route = this.currentCopyRoute;
  1110. this.paper.canvas.removeEvent("mousemove", this.routeCopyMouseMoveBind);
  1111. route.setActivity(null, activity);
  1112. route.isBack = false;
  1113. route.reload();
  1114. activity.shap.attr(activity.style.shap);
  1115. this.endRouteCopy();
  1116. },
  1117. endRouteCopy: function(){
  1118. var route = this.currentCopyRoute;
  1119. route.selected();
  1120. this.isCopyRoute = false;
  1121. this.currentCopyRoute = null;
  1122. route.setListItemData();
  1123. this.designer.setToolBardisabled("decision");
  1124. this.setCopyRouteProcessData(route);
  1125. },
  1126. routeAddCancel: function(){
  1127. var route = this.currentCopyRoute;
  1128. route.destroy();
  1129. delete route;
  1130. this.isCopyRoute = false;
  1131. this.currentCopyRoute = null;
  1132. if (this.routeAddMouseMoveBind) this.paper.canvas.removeEvent("mousemove", this.routeAddMouseMoveBind);
  1133. },
  1134. setCopyRouteProcessData: function(route){
  1135. this.process.routeList.push(route.data);
  1136. route.fromActivity.setRouteData(route.data.id);
  1137. // if (!route.fromActivity.data.routeList) route.fromActivity.data.routeList = [];
  1138. // route.fromActivity.data.routeList.push(route.data.id);
  1139. this.routeDatas[route.data.id] = route.data;
  1140. },
  1141. deleteRoute: function(e, route){
  1142. var _self = this;
  1143. this.designer.shortcut = false;
  1144. this.designer.confirm("warn", e, MWF.APPPD.LP.notice.deleteRouteTitle, MWF.APPPD.LP.notice.deleteRoute, 300, 120, function(){
  1145. route.destroy();
  1146. delete route;
  1147. _self.designer.shortcut = true;
  1148. this.close();
  1149. }, function(){
  1150. _self.designer.shortcut = true;
  1151. this.close();
  1152. }, null);
  1153. },
  1154. copyActivity: function(activity){
  1155. var activityData = Object.clone(activity.data);
  1156. var type = activity.type;
  1157. var c = type.capitalize();
  1158. //activityData.id = this.designer.actions.getUUID();
  1159. this.designer.actions.getUUID(function(id){activityData.id = id;});
  1160. activityData.process = this.process.id;
  1161. activity = new MWF.APPPD.Activity[c](activityData, this);
  1162. activity.create();
  1163. activity.selected();
  1164. if (type=="begin"){
  1165. this.begin = activity;
  1166. this.process.begin = activityData;
  1167. }else{
  1168. this[type+"s"][activityData.id] = activity;
  1169. if (!this.process[type+"List"]){
  1170. this.process[type+"List"] = [];
  1171. }
  1172. this.process[type+"List"].push(activityData);
  1173. }
  1174. },
  1175. deleteActivity: function(e, activity){
  1176. var _self = this;
  1177. this.designer.shortcut = false;
  1178. this.designer.confirm("warn", e, MWF.APPPD.LP.notice.deleteActivityTitle, MWF.APPPD.LP.notice.deleteActivity, 300, 120, function(){
  1179. activity.destroy();
  1180. delete activity;
  1181. _self.designer.shortcut = true;
  1182. this.close();
  1183. }, function(){
  1184. _self.designer.shortcut = true;
  1185. this.close();
  1186. }, null);
  1187. },
  1188. explode: function(){
  1189. // this._getFormData();
  1190. MWF.require("MWF.widget.Base64", null, false);
  1191. var data = MWF.widget.Base64.encode(JSON.encode(this.process));
  1192. MWF.require("MWF.widget.Panel", function(){
  1193. var node = new Element("div");
  1194. //var size = this.designer.formNode.getSize();
  1195. var position = this.designer.paperNode.getPosition(this.designer.paperNode.getOffsetParent());
  1196. var textarea = new Element("textarea", {
  1197. "styles": {
  1198. "border": "1px solid #999",
  1199. "width": "770px",
  1200. "margin-left": "14px",
  1201. "margin-top": "14px",
  1202. "height": "580px"
  1203. },
  1204. "text": JSON.encode(this.process)
  1205. }).inject(node);
  1206. this.explodePanel = new MWF.widget.Panel(node, {
  1207. "style": "form",
  1208. "isResize": false,
  1209. "isMax": false,
  1210. "title": "",
  1211. "width": 800,
  1212. "height": 660,
  1213. "top": position.y,
  1214. "left": position.x+3,
  1215. "isExpand": false,
  1216. "target": this.designer.node
  1217. });
  1218. this.explodePanel.load();
  1219. }.bind(this));
  1220. }
  1221. });
  1222. MWF.xApplication.process.ProcessDesigner.Process.Panel = new Class({
  1223. initialize: function(process){
  1224. this.process = process;
  1225. this.width = 370;
  1226. this.top = 0;
  1227. var paperSize = this.process.designer.paperNode.getSize();
  1228. this.left = (paperSize.x.toFloat())-376;
  1229. this.height = (paperSize.y.toFloat())-6;
  1230. this.stopParseJson = false;
  1231. },
  1232. load: function(){
  1233. this.panelNode = new Element("div");
  1234. this.createModuleListTab();
  1235. this.createPropertyTab();
  1236. this.createPanelResizeNode();
  1237. this.moduleTabContent.inject(this.panelNode);
  1238. this.panelResizeNode.inject(this.panelNode);
  1239. this.propertyTabContent.inject(this.panelNode);
  1240. MWF.require("MWF.widget.Panel", function(){
  1241. this.modulePanel = new MWF.widget.Panel(this.panelNode, {
  1242. "title": MWF.APPPD.LP.property,
  1243. "isClose": false,
  1244. "target": this.process.designer.paperNode,
  1245. "height": this.height,
  1246. "width": this.width,
  1247. "left": this.left,
  1248. "top": this.top,
  1249. "transition": Fx.Transitions.linear.easeIn,
  1250. "transitionOut": Fx.Transitions.linear.easeOut,
  1251. "duration": 100,
  1252. "onResize": function(){
  1253. this.setPanelSize(this.panelModulePercent);
  1254. }.bind(this)
  1255. });
  1256. this.modulePanel.load();
  1257. this.setPanelSize(this.panelModulePercent);
  1258. }.bind(this));
  1259. },
  1260. setPanelSize: function(percent){
  1261. var contentSize = this.modulePanel.content.getSize();
  1262. var resizeSize = this.panelResizeNode.getSize();
  1263. var resizeMarginTop = this.panelResizeNode.getStyle("margin-top");
  1264. var resizeMarginBottom = this.panelResizeNode.getStyle("margin-bottom");
  1265. var useHeight = (contentSize.y.toFloat()) - (resizeSize.y.toFloat()) - (resizeMarginTop.toFloat()) - (resizeMarginBottom.toFloat());
  1266. var p = percent;
  1267. if (!p) p = 0.3;
  1268. var moduleHeight = useHeight*p;
  1269. var propertyHeight = useHeight - moduleHeight;
  1270. this.moduleListContent.setStyle("height", moduleHeight);
  1271. if (!this.propertyPanel) this.propertyListContent.setStyle("height", propertyHeight);
  1272. var moduleListTabSize = this.moduleListTab.tabNodeContainer.getSize();
  1273. this.moduleListTab.pages.each(function(page){
  1274. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1275. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1276. var tabContentNodeAreaHeight = moduleHeight - topMargin - bottomMargin - moduleListTabSize.y.toFloat()-2;
  1277. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1278. }.bind(this));
  1279. if (!this.propertyPanel) {
  1280. var propertyListTabSize = this.propertyListTab.tabNodeContainer.getSize();
  1281. this.propertyListTab.pages.each(function(page){
  1282. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1283. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1284. var tabContentNodeAreaHeight = propertyHeight - topMargin - bottomMargin - propertyListTabSize.y.toFloat()-2;
  1285. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1286. }.bind(this));
  1287. }
  1288. // var contentNodeContainerHeight = moduleHeight - moduleListTabSize.y.toFloat()-2;
  1289. // this.moduleListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1290. //
  1291. // contentNodeContainerHeight = propertyHeight - propertyListTabSize.y.toFloat()-2;
  1292. // this.propertyListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1293. if (this.jsonStringConfirmNode)this.setJsonStringConfirmNodePosition();
  1294. },
  1295. createPanelResizeNode: function(){
  1296. this.panelResizeNode = new Element("div", {
  1297. "styles": this.process.css.panelResizeNode
  1298. });
  1299. this.panelResizeNode.addEvent("mousedown", function(e){
  1300. this.beginPanelResize(e);
  1301. }.bind(this));
  1302. },
  1303. beginPanelResize: function(){
  1304. this.panelResizeMouseMoveBind = function(e){
  1305. this.panelResize(e);
  1306. }.bind(this);
  1307. this.panelResizeMouseUpBind = function(){
  1308. $(document.body).removeEvent("selectstart",this.panelResizeSelecttBind);
  1309. $(document.body).removeEvent("mousemove",this.panelResizeMouseMoveBind);
  1310. $(document.body).removeEvent("mouseup",this.panelResizeMouseUpBind);
  1311. }.bind(this);
  1312. this.panelResizeSelecttBind = function(){
  1313. return false;
  1314. }.bind(this);
  1315. $(document.body).addEvent("selectstart",this.panelResizeSelecttBind);
  1316. $(document.body).addEvent("mousemove",this.panelResizeMouseMoveBind);
  1317. $(document.body).addEvent("mouseup",this.panelResizeMouseUpBind);
  1318. },
  1319. panelResize: function(e){
  1320. var y = e.event.pageY;
  1321. var modulePosition = this.moduleListContent.getPosition();
  1322. var moduleHeight = (y.toFloat()) - (modulePosition.y.toFloat());
  1323. if (moduleHeight<40) moduleHeight = 40;
  1324. var contentSize = this.modulePanel.content.getSize();
  1325. var resizeSize = this.panelResizeNode.getSize();
  1326. var resizeMarginTop = this.panelResizeNode.getStyle("margin-top");
  1327. var resizeMarginBottom = this.panelResizeNode.getStyle("margin-bottom");
  1328. var useHeight = (contentSize.y.toFloat()) - (resizeSize.y.toFloat()) - (resizeMarginTop.toFloat()) - (resizeMarginBottom.toFloat());
  1329. var propertyHeight = useHeight - moduleHeight;
  1330. if (propertyHeight<40){
  1331. propertyHeight = 40;
  1332. moduleHeight = useHeight - propertyHeight;
  1333. }
  1334. this.moduleListContent.setStyle("height", moduleHeight);
  1335. this.propertyListContent.setStyle("height", propertyHeight);
  1336. var moduleListTabSize = this.moduleListTab.tabNodeContainer.getSize();
  1337. var propertyListTabSize = this.propertyListTab.tabNodeContainer.getSize();
  1338. this.moduleListTab.pages.each(function(page){
  1339. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1340. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1341. var tabContentNodeAreaHeight = moduleHeight - topMargin - bottomMargin - (moduleListTabSize.y.toFloat())-2;
  1342. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1343. }.bind(this));
  1344. this.propertyListTab.pages.each(function(page){
  1345. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1346. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1347. var tabContentNodeAreaHeight = propertyHeight - topMargin - bottomMargin - propertyListTabSize.y.toFloat()-2;
  1348. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1349. }.bind(this));
  1350. // var contentNodeContainerHeight = moduleHeight - moduleListTabSize.y.toFloat()-2;
  1351. // this.moduleListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1352. //
  1353. // contentNodeContainerHeight = propertyHeight - propertyListTabSize.y.toFloat()-2;
  1354. // this.propertyListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1355. if (this.jsonStringConfirmNode)this.setJsonStringConfirmNodePosition();
  1356. this.panelModulePercent = moduleHeight.toFloat()/useHeight.toFloat();
  1357. },
  1358. loadJson: function(json){
  1359. // MWF.require("MWF.widget.MaskNode", function(){
  1360. // this.jsonMarkNode = new MWF.widget.MaskNode(this.jsonObjectNode, {"zIndex": 30000});
  1361. // this.jsonMarkNode.load();
  1362. MWF.require("MWF.widget.JsonParse", function(){
  1363. this.jsonParse = new MWF.widget.JsonParse(json, this.jsonObjectNode, this.jsonStringNode);
  1364. this.jsonParse.load();
  1365. }.bind(this));
  1366. // this.jsonParse = new MWF.APPPD.Process.JsonParse(json, this.jsonObjectNode, this.jsonStringNode);
  1367. // window.setTimeout(function(){
  1368. // this.jsonParse.load();
  1369. // }.bind(this), 1);
  1370. // }.bind(this));
  1371. },
  1372. loadJsonString: function(json){
  1373. // o2.load("JSBeautifier_html", function(){
  1374. // htmlNode.set("text", html_beautify(copy.outerHTML, {"indent_size":1}));
  1375. // }.bind(this));
  1376. this.jsonStringNode.set("text", JSON.stringify(json,null,2));
  1377. o2.require("o2.widget.ace", function(){
  1378. MWF.widget.ace.load(function(){
  1379. COMMON.AjaxModule.loadDom("../o2_lib/ace/src-min-noconflict/ext-static_highlight.js", function(){
  1380. var highlight = ace.require("ace/ext/static_highlight");
  1381. highlight(this.jsonStringNode, {mode: "ace/mode/json", theme: "ace/theme/tomorrow", "fontSize": 16});
  1382. }.bind(this));
  1383. }.bind(this));
  1384. }.bind(this));
  1385. },
  1386. clearJson: function(){
  1387. this.json = null;
  1388. this.jsonString = "";
  1389. this.jsonStringNode.set("text", "");
  1390. this.jsonObjectNode.empty();
  1391. if (this.jsonParse) this.jsonParse = null;
  1392. // if (this.jsonMarkNode) this.jsonMarkNode.hide();
  1393. },
  1394. createJsonStringNode: function(){
  1395. var jsonStringNode = new Element("div", {
  1396. // "readonly": true,
  1397. "styles": {
  1398. "width": "100%",
  1399. "height": "100%",
  1400. "overflow": "auto",
  1401. "border": "0px"
  1402. }
  1403. });
  1404. // jsonStringNode.set("text", this.jsonString);
  1405. return jsonStringNode;
  1406. },
  1407. createJsonObjectNode: function(){
  1408. this.jsonObjectNode = new Element("div", {
  1409. "styles": {
  1410. //"overflow": "hideen",
  1411. "margin-top": "0px",
  1412. "height": "auto"
  1413. }
  1414. });
  1415. // this.loadObjectTree();
  1416. return this.jsonObjectNode;
  1417. },
  1418. createJsonStringConfirmNode: function(){
  1419. this.jsonStringConfirmNode = new Element("div", {
  1420. "styles": {
  1421. "width": "20px",
  1422. "height": "20px",
  1423. "background-color": "#EEE",
  1424. "background": "url("+MWF.defaultPath+"/process/ProcessChart/$Process/"+this.process.options.style+"/checkmark.png"+") no-repeat center center",
  1425. "position": "absolute",
  1426. "cursor": "pointer",
  1427. "display": "none"
  1428. },
  1429. "events": {
  1430. "mouseover": function(){
  1431. this.store("flag", true);
  1432. },
  1433. "mouseout": function(){
  1434. this.store("flag", false);
  1435. },
  1436. "click": function(){
  1437. this.checkJsonStringAndReload();
  1438. }.bind(this)
  1439. }
  1440. }).inject(this.jsonStringNode, "after");
  1441. },
  1442. checkJsonStringAndReload: function(){
  1443. if (!this.process.selectedActivitys.length){
  1444. try {
  1445. var data = JSON.decode(this.jsonStringNode.value);
  1446. if (data){
  1447. if (this.process.currentSelected){
  1448. Object.copy(data, this.process.currentSelected.data);
  1449. this.process.currentSelected.redraw();
  1450. }else{
  1451. data.id = this.process.process.id;
  1452. data.processCategory = this.process.process.processCategory;
  1453. this.process.reload(data);
  1454. }
  1455. }
  1456. }catch(e){
  1457. this.designer.notice(e.message, "error", this.jsonStringNode.getParent(), {x: "left", y:"top"});
  1458. }
  1459. }
  1460. },
  1461. setJsonStringConfirmNodePosition: function(){
  1462. var p = this.jsonStringNode.getPosition(this.panelNode);
  1463. var size = this.panelNode.getSize();
  1464. this.jsonStringConfirmNode.setStyles({
  1465. "display": "block",
  1466. "top" : p.y+4,
  1467. "left" : size.x-26
  1468. });
  1469. },
  1470. createPropertyTab: function(){
  1471. this.propertyTabContent = new Element("div");
  1472. this.propertyListContent = new Element("div", {
  1473. "styles": this.process.css.propertyListContent
  1474. }).inject(this.propertyTabContent);
  1475. this.propertyListNode = new Element("div", {
  1476. "styles": this.process.css.propertyListNode
  1477. });
  1478. this.process.propertyListNode = this.propertyListNode;
  1479. this.jsonObjectNode = this.createJsonObjectNode();
  1480. this.jsonStringNode = this.createJsonStringNode();
  1481. this.jsonStringNode.addEvents({
  1482. "focus": function(){
  1483. if (!this.process.selectedActivitys.length){
  1484. if (!this.jsonStringConfirmNode) this.createJsonStringConfirmNode();
  1485. this.setJsonStringConfirmNodePosition();
  1486. }
  1487. }.bind(this),
  1488. "blur": function(e){
  1489. if (this.jsonStringConfirmNode){
  1490. if (!this.jsonStringConfirmNode.retrieve("flag")) this.jsonStringConfirmNode.setStyle("display", "none");
  1491. }
  1492. }.bind(this)
  1493. });
  1494. MWF.require("MWF.widget.Tab", function(){
  1495. this.propertyListTab = new MWF.widget.Tab(this.propertyListContent, {"style": "moduleList"});
  1496. this.propertyListTab.load();
  1497. this.propertyTabPage = this.propertyListTab.addTab(this.propertyListNode, MWF.APPPD.LP.property, false);
  1498. this.objectTabPage = this.propertyListTab.addTab(this.jsonObjectNode, "JSON", false);
  1499. this.stringTabPage = this.propertyListTab.addTab(this.jsonStringNode, "Text", false);
  1500. this.process.setScrollBar(this.propertyTabPage.contentNodeArea, "small", null, null);
  1501. this.process.setScrollBar(this.objectTabPage.contentNodeArea, "small", null, null);
  1502. this.process.setScrollBar(this.stringTabPage.contentNodeArea, "small", null, null);
  1503. this.objectTabPage.setOptions({
  1504. "onShow": function(){
  1505. this.loadJson(this.data);
  1506. }.bind(this),
  1507. "onHide": function(){
  1508. this.clearJson();
  1509. }.bind(this)
  1510. });
  1511. this.stringTabPage.setOptions({
  1512. "onShow": function(){
  1513. this.loadJsonString(this.data);
  1514. }.bind(this),
  1515. "onHide": function(){
  1516. this.clearJson();
  1517. }.bind(this)
  1518. });
  1519. this.propertyTabPage.showTab();
  1520. this.propertyListTab.tabNodeContainer.addEvent("mousedown", function(event){
  1521. //event.stop();
  1522. this.propertyTabMove(event);
  1523. }.bind(this));
  1524. // this.propertyDrag = new Drag(this.propertyTabContent, {
  1525. // "handle": this.propertyListTab.tabNodeContainer,
  1526. // "snap": 10,
  1527. // "onStart": function(el, e){
  1528. // }.bind(this)
  1529. // });
  1530. }.bind(this), false);
  1531. // this.propertyListContent.setStyle("height", 300);
  1532. },
  1533. propertyTabMove: function(event){
  1534. // var tmpContent = this.propertyListContent.clone().setStyles(this.propertyListContent.getCoordinates()).setStyles({
  1535. // "opacity": 0.7,
  1536. // "border": "1px dashed #CCC",
  1537. // "z-index": this.modulePanel.container.getStyle("z-index").toInt()+1,
  1538. // "position": "absolute"
  1539. // }).inject(this.process.designer.paperNode);
  1540. var size = this.propertyListContent.getSize();
  1541. var tmpContent = new Element("div", {
  1542. "styles": {
  1543. "opacity": 0.7,
  1544. "border": "1px dashed #CCC",
  1545. "z-index": this.modulePanel.container.getStyle("z-index").toInt()+1,
  1546. "width": size.x,
  1547. "height": size.y,
  1548. "background-color": "#EEE",
  1549. "position": "absolute"
  1550. }
  1551. }).inject(this.process.designer.paperNode);
  1552. tmpContent.position({
  1553. relativeTo: this.propertyListContent,
  1554. position: 'upperLeft',
  1555. edge: 'upperLeft'
  1556. });
  1557. var drag = new Drag.Move(tmpContent, {
  1558. "droppables": [this.process.designer.paperNode, this.panelNode],
  1559. "onEnter": function(dragging, inObj){
  1560. if (this.propertyPanel){
  1561. if (this.panelNode==inObj){
  1562. dragging.tween('border', "4px dashed #666");
  1563. }else{
  1564. dragging.tween('border', "1px dashed #CCC");
  1565. }
  1566. }else{
  1567. if (this.panelNode==inObj){
  1568. dragging.tween('border', "1px dashed #CCC");
  1569. }else{
  1570. dragging.tween('border', "4px dashed #666");
  1571. }
  1572. }
  1573. }.bind(this),
  1574. "onLeave": function(dragging, paper){
  1575. dragging.tween('border', "1px dashed #CCC");
  1576. },
  1577. "onDrop": function(dragging, inObj){
  1578. if (this.panelNode!=inObj){
  1579. this.propertyOut(dragging);
  1580. }else{
  1581. this.propertyIn();
  1582. }
  1583. dragging.destroy();
  1584. }.bind(this),
  1585. "onCancel": function(dragging){
  1586. dragging.destroy();
  1587. }
  1588. });
  1589. drag.start(event);
  1590. },
  1591. propertyOut: function(dragging){
  1592. if (!this.propertyPanel){
  1593. var coordinates = dragging.getCoordinates();
  1594. var p = this.process.designer.paperNode.getPosition();
  1595. var propertyPanelNode = new Element("div");
  1596. this.propertyListContent.inject(propertyPanelNode);
  1597. MWF.require("MWF.widget.Panel", function(){
  1598. this.propertyPanel = new MWF.widget.Panel(propertyPanelNode, {
  1599. "title": MWF.APPPD.LP.property,
  1600. "isClose": false,
  1601. "target": this.process.designer.paperNode,
  1602. "height": coordinates.height,
  1603. "width": coordinates.width,
  1604. "left": coordinates.left.toFloat() - p.x.toFloat(),
  1605. "top": coordinates.top.toFloat() - p.y.toFloat(),
  1606. "onResize": function(){
  1607. this.setPropertyPanelSize();
  1608. }.bind(this)
  1609. });
  1610. this.propertyPanel.load();
  1611. this.propertyOutSetHeight();
  1612. this.setPropertyPanelSize(this.panelModulePercent);
  1613. }.bind(this));
  1614. };
  1615. },
  1616. setPropertyPanelSize: function(){
  1617. var contentSize = this.propertyPanel.content.getSize();
  1618. var propertyHeight = contentSize.y;
  1619. this.propertyListContent.setStyle("height", propertyHeight);
  1620. var propertyListTabSize = this.propertyListTab.tabNodeContainer.getSize();
  1621. this.propertyListTab.pages.each(function(page){
  1622. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1623. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1624. var tabContentNodeAreaHeight = propertyHeight - topMargin - bottomMargin - propertyListTabSize.y.toFloat()-2;
  1625. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1626. }.bind(this));
  1627. },
  1628. propertyOutSetHeight: function(){
  1629. this.panelResizeNode.setStyles(this.process.css.panelResizeNodeHide);
  1630. this.panelModulePercent = "1";
  1631. this.setPanelSize(this.panelModulePercent);
  1632. },
  1633. propertyIn: function(){
  1634. this.propertyListContent.inject(this.propertyTabContent);
  1635. if (this.propertyPanel) this.propertyPanel.closePanel();
  1636. this.propertyPanel = null;
  1637. this.propertyInSetHeight();
  1638. },
  1639. propertyInSetHeight: function(){
  1640. this.panelResizeNode.setStyles(this.process.css.panelResizeNode);
  1641. this.panelModulePercent = "0.3";
  1642. this.setPanelSize(this.panelModulePercent);
  1643. },
  1644. createModuleListTab: function(){
  1645. this.moduleTabContent = new Element("div");
  1646. this.moduleListContent = new Element("div", {
  1647. "styles": this.process.css.moduleListContent
  1648. }).inject(this.moduleTabContent);
  1649. this.activityListNode = new Element("div", {
  1650. "styles": this.process.css.activityListNode
  1651. });
  1652. this.process.activityListNode = this.activityListNode;
  1653. this.activityTable = new HtmlTable({
  1654. "properties": this.process.css.activityListTable
  1655. }).inject(this.activityListNode);
  1656. this.process.activityTable = this.activityTable;
  1657. this.routeListNode = new Element("div", {
  1658. "styles": this.process.css.routeListNode
  1659. });
  1660. this.process.routeListNode = this.routeListNode;
  1661. this.routeTable = new HtmlTable({
  1662. "properties": this.process.css.routeListTable
  1663. }).inject(this.routeListNode);
  1664. this.process.routeTable = this.routeTable;
  1665. MWF.require("MWF.widget.Tab", function(){
  1666. this.moduleListTab = new MWF.widget.Tab(this.moduleListContent, {"style": "moduleList"});
  1667. this.moduleListTab.load();
  1668. // this.process.setScrollBar(this.moduleListTab.contentNodeContainer, null, null, null);
  1669. var activityTabPage = this.moduleListTab.addTab(this.activityListNode, MWF.APPPD.LP.activity, false);
  1670. this.process.setScrollBar(activityTabPage.contentNodeArea, "small", null, null);
  1671. var routeTabPage = this.moduleListTab.addTab(this.routeListNode, MWF.APPPD.LP.route, false);
  1672. this.process.setScrollBar(routeTabPage.contentNodeArea, "small", null, null);
  1673. activityTabPage.showTab();
  1674. }.bind(this), false);
  1675. },
  1676. destroy: function(){
  1677. if (this.modulePanel) this.modulePanel.destroy();
  1678. if (this.propertyPanel) this.propertyPanel.destroy();
  1679. }
  1680. });
  1681. MWF.xApplication.process.ProcessDesigner.Process.Property = new Class({
  1682. Implements: [Options, Events],
  1683. Extends: MWF.APPPD.Property,
  1684. initialize: function(process, options){
  1685. this.setOptions(options);
  1686. this.process = process;
  1687. this.paper = this.process.paper;
  1688. this.data = process.process;
  1689. this.htmlPath = "../x_component_process_ProcessDesigner/$Process/process.html";
  1690. }
  1691. });
  1692. MWF.xApplication.process.ProcessDesigner.Process.JsonParse = new Class({
  1693. initialize: function(json, jsonObjectNode, jsonStringNode){
  1694. this.json = json;
  1695. this.jsonObjectNode = jsonObjectNode;
  1696. this.jsonStringNode = jsonStringNode;
  1697. this.stopParseJson = false;
  1698. },
  1699. load: function(){
  1700. this.jsonString = JSON.encode(this.json);
  1701. // this.jsonStringNode.set("text", JSON.format(this.json));
  1702. this.loadObjectTree();
  1703. },
  1704. loadObjectTree: function(){
  1705. if (this.objectTree){
  1706. this.objectTree.node.destroy();
  1707. this.objectTree = null;
  1708. }
  1709. MWF.require("MWF.widget.Tree", function(){
  1710. this.objectTree = new MWF.widget.Tree(this.jsonObjectNode, {"style": "jsonview"});
  1711. this.objectTree.load();
  1712. var str = this.parseJsonObject(0, this.objectTree, "", "JSON", this.json, true);
  1713. var jsonStr = str.substring(0, str.length-2);
  1714. if (!this.stopParseJson){
  1715. this.jsonStringNode.set("text", jsonStr);
  1716. }else{
  1717. this.stopParseJson = false;
  1718. }
  1719. }.bind(this));
  1720. },
  1721. parseJsonObject: function(level, treeNode, title, p, v, expand){
  1722. if (this.stopParseJson){
  1723. // alert(this.stopParseJson);
  1724. return false;
  1725. }
  1726. var o = {
  1727. "expand": expand,
  1728. "title": "",
  1729. "text": "",
  1730. "action": "",
  1731. "icon": ""
  1732. };
  1733. var tab = "";
  1734. for (var i=0; i<level; i++) tab+="\t";
  1735. //var title = title;
  1736. if (title) title="\""+title+"\": ";
  1737. var jsonStr = "";
  1738. var nextLevel = level+1;
  1739. switch (typeOf(v)){
  1740. case "object":
  1741. o.text = p;
  1742. o.icon = "object.png";
  1743. var node = treeNode.appendChild(o);
  1744. var jsonStrBegin = tab+title+"{";
  1745. var jsonStrEnd = tab+"}";
  1746. for (i in v){
  1747. jsonStr += this.parseJsonObject(nextLevel, node, i, i, v[i], false);
  1748. }
  1749. jsonStr = jsonStrBegin+"\n"+jsonStr.substring(0, jsonStr.length-2)+"\n"+jsonStrEnd+",\n";
  1750. break;
  1751. case "array":
  1752. o.text = p;
  1753. o.icon = "array.png";
  1754. var node = treeNode.appendChild(o);
  1755. var jsonStrBegin = tab+title+"[";
  1756. var jsonStrEnd = tab+"]";
  1757. v.each(function(item, idx){
  1758. jsonStr += this.parseJsonObject(nextLevel, node, "", "["+idx+"]", item, false);
  1759. }.bind(this));
  1760. jsonStr = jsonStrBegin+"\n"+jsonStr.substring(0, jsonStr.length-2)+"\n"+jsonStrEnd+",\n";
  1761. break;
  1762. case "string":
  1763. jsonStr += tab+title+"\""+v+"\",\n";
  1764. o.text = p + " : \""+v+"\"";
  1765. o.icon = "string.png";
  1766. //var node =
  1767. treeNode.appendChild(o);
  1768. break;
  1769. case "date":
  1770. jsonStr += tab+title+"\""+v+"\",\n";
  1771. o.text = p + " : \""+v+"\"";
  1772. o.icon = "string.png";
  1773. //var node =
  1774. treeNode.appendChild(o);
  1775. break;
  1776. default:
  1777. jsonStr += tab+title+v+",\n";
  1778. o.text = p + " : "+v;
  1779. o.icon = "string.png";
  1780. //var node =
  1781. treeNode.appendChild(o);
  1782. }
  1783. return jsonStr;
  1784. }
  1785. });