Process.js 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022
  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": 330,
  490. "buttonList": [{
  491. "type": "ok",
  492. "text": this.designer.lp.ok,
  493. "action": function(){
  494. var textarea = this.content.getElement("textarea");
  495. var discription = textarea.get("value");
  496. if (!discription) {
  497. _self.designer.notice(_self.designer.lp.inputDiscription, "error", descriptionNode);
  498. }else{
  499. var checkbox = this.content.getElement("input");
  500. var enable = (!!checkbox && checkbox.get("checked"));
  501. _self.doSaveNewEdition(enable, discription);
  502. this.close();
  503. }
  504. }
  505. },{
  506. "text": this.designer.lp.cancel,
  507. "action": function(){
  508. this.close();
  509. }
  510. }]
  511. });
  512. // var _self = this;
  513. // this.designer.confirm("infor", e, this.designer.lp.upgradeConfirm, {"html": this.designer.lp.upgradeInfor}, 520, 210, function(){
  514. // var checkbox = this.content.getElement("input");
  515. // var enable = (!!checkbox && checkbox.get("checked"));
  516. // _self.doSaveNewEdition(enable);
  517. // this.close();
  518. // }, function(){
  519. // this.close();
  520. // });
  521. }
  522. },
  523. doSaveNewEdition: function(enable, description){
  524. debugger;
  525. var process = Object.clone(this.process);
  526. process.editionDes = description;
  527. var oldIds = [];
  528. oldIds.push(process.id);
  529. if (process.begin) oldIds.push(process.begin.id);
  530. if (process.endList) process.endList.each(function(a){oldIds.push(a.id);});
  531. if (process.agentList) process.agentList.each(function(a){oldIds.push(a.id);});
  532. if (process.manualList) process.manualList.each(function(a){oldIds.push(a.id);});
  533. if (process.conditionList) process.conditionList.each(function(a){oldIds.push(a.id);});
  534. if (process.choiceList) process.choiceList.each(function(a){oldIds.push(a.id);});
  535. if (process.parallelList) process.parallelList.each(function(a){oldIds.push(a.id);});
  536. if (process.splitList) process.splitList.each(function(a){oldIds.push(a.id);});
  537. if (process.mergeList) process.mergeList.each(function(a){oldIds.push(a.id);});
  538. if (process.embedList) process.embedList.each(function(a){oldIds.push(a.id);});
  539. if (process.invokeList) process.invokeList.each(function(a){oldIds.push(a.id);});
  540. if (process.cancelList) process.cancelList.each(function(a){oldIds.push(a.id);});
  541. if (process.delayList) process.delayList.each(function(a){oldIds.push(a.id);});
  542. if (process.messageList) process.messageList.each(function(a){oldIds.push(a.id);});
  543. if (process.serviceList) process.serviceList.each(function(a){oldIds.push(a.id);});
  544. if (process.routeList) process.routeList.each(function(a){oldIds.push(a.id);});
  545. var actions = o2.Actions.load("x_processplatform_assemble_designer");
  546. this.designer.actions.getId(oldIds.length, function(ids) {
  547. var checkUUIDs = ids.data;
  548. var processStr = JSON.encode(process);
  549. oldIds.each(function(oid, i){
  550. var reg = new RegExp(oid, "ig");
  551. processStr = processStr.replace(reg, checkUUIDs[i].id);
  552. }.bind(this));
  553. process = JSON.decode(processStr);
  554. actions.ProcessAction.upgrade(this.process.id, process, function(json){
  555. var processId = json.data.id;
  556. if (enable){
  557. actions.ProcessAction.enableProcess(processId, function(processJson){
  558. actions.ProcessAction.get(processId, function(processJson){
  559. this.reload(processJson.data);
  560. }.bind(this))
  561. }.bind(this))
  562. }else{
  563. actions.ProcessAction.get(processId, function(processJson){
  564. this.reload(processJson.data);
  565. }.bind(this))
  566. }
  567. }.bind(this));
  568. }.bind(this));
  569. },
  570. listEdition: function(){
  571. if (this.process.edition){
  572. MWF.xDesktop.requireApp("process.ProcessDesigner", "widget.EditionList", function(){
  573. var list = new MWF.xApplication.process.ProcessDesigner.widget.EditionList(this.process.application, this.process.edition, this);
  574. list.load();
  575. }.bind(this));
  576. // o2.Actions.load("x_processplatform_assemble_designer").ProcessAction.listEdition(this.process.application, this.process.edition, function(json){
  577. // var editionList = json.data;
  578. // this.listEditionDlg(json.data);
  579. // }.bind(this));
  580. }else{
  581. this.designer.notice("infor", this.designer.lp.save_process);
  582. }
  583. },
  584. listEditionDlg: function(editionList){
  585. //var node = new Element("div", )
  586. },
  587. switchGrid: function(item){
  588. if (this.isGrid){
  589. this.hideGrid();
  590. }else{
  591. this.showGrid();
  592. }
  593. },
  594. showGrid: function(){
  595. this.designer.paperNode.setStyle("background-image", "url("+MWF.defaultPath+"/process/ProcessChart/$Process/"+this.options.style+"/griddingbg.gif)");
  596. // if (this.GridSet){
  597. // this.GridSet.show();
  598. // }else{
  599. // var paperSize = $(this.paper.canvas).getParent().getSize();
  600. // this.GridSet = this.paper.set();
  601. // for (var i=20; i<paperSize.x; i=i+20){
  602. // var lineV = this.paper.path("M"+i+",0L"+i+","+paperSize.y).attr({
  603. // "stroke": "#ccc",
  604. // "stroke-dasharray": ".",
  605. // "stroke-width": 1
  606. // });
  607. // lineV.toBack();
  608. // this.GridSet.push(lineV);
  609. // }
  610. // for (var j=20; j<paperSize.y; j=j+20){
  611. // var lineL = this.paper.path("M0,"+j+"L"+paperSize.x+","+j).attr({
  612. // "stroke": "#ccc",
  613. // "stroke-dasharray": ".",
  614. // "stroke-width": 1
  615. // });
  616. // lineL.toBack();
  617. // this.GridSet.push(lineL);
  618. // }
  619. // }
  620. this.isGrid = true;
  621. },
  622. hideGrid: function(){
  623. this.designer.paperNode.setStyle("background-image", "");
  624. // if (this.GridSet){
  625. // this.GridSet.hide();
  626. // }
  627. this.isGrid = false;
  628. },
  629. getPointElement: function(x, y){
  630. var els = this.paper.getElementsByPoint(x, y);
  631. var bindObject = null;
  632. var bindType = "none";
  633. if (els.length){
  634. for (var i=0; i<els.length; i++){
  635. var bind = els[i].data("bind");
  636. if (bind){
  637. if (instanceOf(bind, MWF.APPPD.Activity)){
  638. bindObject = bind;
  639. bindType = "activity";
  640. break;
  641. }
  642. if (instanceOf(bind, MWF.APPPD.Route)){
  643. bindObject = bind;
  644. bindType = "route";
  645. }
  646. };
  647. }
  648. }
  649. return {"bind": bindObject, "type": bindType};
  650. },
  651. // loadProcessDecisions: function(){
  652. // if (this.process.decisionList){
  653. // this.process.decisionList.each(function(d){
  654. // this.decisionDatas[d.id] = d;
  655. // }.bind(this));
  656. // }
  657. // },
  658. loadActivityRoutes: function(){
  659. this.activitys.each(function(activity){
  660. activity.loadRoutes();
  661. });
  662. },
  663. // loadActivityDecisions: function(){
  664. // if (this.begin) this.begin.loadDecisions();
  665. // for (a in this.ends){
  666. // this.ends[a].loadDecisions();
  667. // };
  668. // for (a in this.manuals){
  669. // this.manuals[a].loadDecisions();
  670. // };
  671. // for (a in this.autos){
  672. // this.autos[a].loadDecisions();
  673. // };
  674. // for (a in this.conditions){
  675. // this.conditions[a].loadDecisions();
  676. // };
  677. // for (a in this.embeds){
  678. // this.embeds[a].loadDecisions();
  679. // };
  680. // for (a in this.invokes){
  681. // this.invokes[a].loadDecisions();
  682. // };
  683. // },
  684. loadProcessRoutes: function(){
  685. this.process.routeList.each(function(item){
  686. this.routes[item.id] = new MWF.APPPD.Route(item, this);
  687. this.routeDatas[item.id] = item;
  688. // this.routes[item.id].load();
  689. }.bind(this));
  690. },
  691. createPropertyPanel: function(){
  692. if (!this.options.isView){
  693. this.panel = new MWF.APPPD.Process.Panel(this);
  694. this.panel.load();
  695. }
  696. },
  697. loadedActivitys: function(callback){
  698. 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){
  699. if (callback) callback();
  700. }
  701. },
  702. loadProcessActivitys: function(callback){
  703. this.loadBegin(function(){this.loadedBegin = true; this.loadedActivitys(callback);}.bind(this));
  704. this.loadEndList(function(){this.loadedEnds = true; this.loadedActivitys(callback);}.bind(this));
  705. this.loadCancelList(function(){this.loadedCancels = true; this.loadedActivitys(callback);}.bind(this));
  706. this.loadManualList(function(){this.loadedManuals = true; this.loadedActivitys(callback);}.bind(this));
  707. this.loadConditionList(function(){this.loadedConditions = true; this.loadedActivitys(callback);}.bind(this));
  708. this.loadChoiceList(function(){this.loadedChoices = true; this.loadedActivitys(callback);}.bind(this));
  709. this.loadSplitList(function(){this.loadedSplits = true; this.loadedActivitys(callback);}.bind(this));
  710. this.loadParallelList(function(){this.loadedParallels = true; this.loadedActivitys(callback);}.bind(this));
  711. this.loadMergeList(function(){this.loadedMerges = true; this.loadedActivitys(callback);}.bind(this));
  712. this.loadEmbedList(function(){this.loadedEmbeds = true; this.loadedActivitys(callback);}.bind(this));
  713. this.loadDelayList(function(){this.loadedDelays = true; this.loadedActivitys(callback);}.bind(this));
  714. this.loadInvokeList(function(){this.loadedInvokes = true; this.loadedActivitys(callback);}.bind(this));
  715. this.loadServiceList(function(){this.loadedServices = true; this.loadedActivitys(callback);}.bind(this));
  716. this.loadAgentList(function(){this.loadedAgents = true; this.loadedActivitys(callback);}.bind(this));
  717. this.loadMessageList(function(){this.loadedMessages = true; this.loadedActivitys(callback);}.bind(this));
  718. },
  719. loadBegin: function(callback){
  720. var data = this.process["begin"];
  721. if (data){
  722. this.begin = new MWF.APPPD.Activity.Begin(data, this);
  723. this.begin.load(callback);
  724. }else{
  725. if (callback) callback();;
  726. }
  727. this.activitys.push(this.begin);
  728. },
  729. loadEndList: function(callback){
  730. this.loadActivitys("End", "endList", this.ends, callback);
  731. },
  732. loadCancelList: function(callback){
  733. this.loadActivitys("Cancel", "cancelList", this.cancels, callback);
  734. },
  735. loadManualList: function(callback){
  736. this.loadActivitys("Manual", "manualList", this.manuals, callback);
  737. },
  738. loadConditionList: function(callback){
  739. this.loadActivitys("Condition", "conditionList", this.conditions, callback);
  740. },
  741. loadChoiceList: function(callback){
  742. this.loadActivitys("Choice", "choiceList", this.choices, callback);
  743. },
  744. loadSplitList: function(callback){
  745. this.loadActivitys("Split", "splitList", this.splits, callback);
  746. },
  747. loadParallelList: function(callback){
  748. this.loadActivitys("Parallel", "parallelList", this.parallels, callback);
  749. },
  750. loadMergeList: function(callback){
  751. this.loadActivitys("Merge", "mergeList", this.merges, callback);
  752. },
  753. loadEmbedList: function(callback){
  754. this.loadActivitys("Embed", "embedList", this.embeds, callback);
  755. },
  756. loadDelayList: function(callback){
  757. this.loadActivitys("Delay", "delayList", this.delays, callback);
  758. },
  759. loadInvokeList: function(callback){
  760. this.loadActivitys("Invoke", "invokeList", this.invokes, callback);
  761. },
  762. loadServiceList: function(callback){
  763. this.loadActivitys("Service", "serviceList", this.services, callback);
  764. },
  765. loadAgentList: function(callback){
  766. this.loadActivitys("Agent", "agentList", this.agents, callback);
  767. },
  768. loadMessageList: function(callback){
  769. this.loadActivitys("Message", "messageList", this.messages, callback);
  770. },
  771. loadActivitys: function(c, p, children, callback){
  772. var datas = this.process[p];
  773. if (datas){
  774. var count = datas.length;
  775. var loadedCount = 0;
  776. if (count){
  777. datas.each(function(data){
  778. this.loadActivity(c, data, children, function(){
  779. loadedCount++;
  780. if (loadedCount==count){
  781. if (callback) callback();
  782. }
  783. }.bind(this));
  784. }.bind(this));
  785. }else{
  786. if (callback) callback();
  787. }
  788. }else{
  789. if (callback) callback();
  790. }
  791. },
  792. loadActivity: function(c, data, children, callback){
  793. activity = new MWF.APPPD.Activity[c](data, this);
  794. activity.load(callback);
  795. if (c==="begin"){
  796. this.begin = activity;
  797. }else{
  798. children[data.id] = activity;
  799. }
  800. this.activitys.push(activity);
  801. },
  802. destroy: function(){
  803. this.paper.remove();
  804. },
  805. checkActivityEmptyRouteList: function(activitys){
  806. if (activitys && activitys.length){
  807. activitys.each(function(a){
  808. if (a.routeList) a.routeList = a.routeList.filter(function(n){return !!n;});
  809. });
  810. }
  811. },
  812. checkEmptyRouteList: function(){
  813. this.checkActivityEmptyRouteList(this.process.endList);
  814. this.checkActivityEmptyRouteList(this.process.cancelList);
  815. this.checkActivityEmptyRouteList(this.process.manualList);
  816. this.checkActivityEmptyRouteList(this.process.conditionList);
  817. this.checkActivityEmptyRouteList(this.process.choiceList);
  818. this.checkActivityEmptyRouteList(this.process.splitList);
  819. this.checkActivityEmptyRouteList(this.process.parallelList);
  820. this.checkActivityEmptyRouteList(this.process.mergeList);
  821. this.checkActivityEmptyRouteList(this.process.embedList);
  822. this.checkActivityEmptyRouteList(this.process.delayList);
  823. this.checkActivityEmptyRouteList(this.process.invokeList);
  824. this.checkActivityEmptyRouteList(this.process.serviceList);
  825. this.checkActivityEmptyRouteList(this.process.agentList);
  826. this.checkActivityEmptyRouteList(this.process.messageList);
  827. },
  828. save: function(callback){
  829. if (!this.isSave){
  830. this.isSave = true;
  831. //check empty routeList
  832. this.checkEmptyRouteList();
  833. var reload = !!this.process.isNewProcess;
  834. this.designer.actions.saveProcess(this.process, function(responseJSON){
  835. this.isSave = false;
  836. this.process.isNewProcess = false;
  837. this.designer.notice(MWF.APPPD.LP.notice["save_success"], "ok", null, {x: "left", y:"bottom"} );
  838. this.isNewProcess = false;
  839. this.designer.options.id = responseJSON.data.id;
  840. if (reload){
  841. this.designer.actions.getProcess(responseJSON.data.id, function(json){
  842. this.reload(json.data);
  843. if (callback) callback();
  844. }.bind(this));
  845. }else{
  846. if (callback) callback();
  847. }
  848. }.bind(this), function(xhr, text, error){
  849. this.isSave = false;
  850. var errorText = error+":"+text;
  851. if (xhr) errorText = xhr.responseText;
  852. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  853. }.bind(this));
  854. }else{
  855. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
  856. }
  857. //this.process
  858. },
  859. getActivityTemplate: function(callback){
  860. if (this.activityTemplates){
  861. if (callback) callback();
  862. }else{
  863. var activityTemplateUrl = this.path+"activity.json";
  864. var r = new Request.JSON({
  865. url: activityTemplateUrl,
  866. secure: false,
  867. async: false,
  868. method: "get",
  869. noCache: true,
  870. onSuccess: function(responseJSON, responseText){
  871. this.activityTemplates = responseJSON;
  872. if (callback) callback();
  873. }.bind(this),
  874. onError: function(text, error){
  875. alert(error);
  876. }
  877. });
  878. r.send();
  879. }
  880. },
  881. getRouteTemplates: function(callback){
  882. if (this.routeTemplates){
  883. if (callback) callback();
  884. }else{
  885. var routeTemplateUrl = this.path+"route.json";
  886. var r = new Request.JSON({
  887. url: routeTemplateUrl,
  888. secure: false,
  889. async: false,
  890. method: "get",
  891. noCache: true,
  892. onSuccess: function(responseJSON, responseText){
  893. this.routeTemplates = responseJSON;
  894. if (callback) callback();
  895. }.bind(this),
  896. onError: function(text, error){
  897. alert(error);
  898. }
  899. });
  900. r.send();
  901. }
  902. },
  903. createActivity: function(d, c, position){
  904. if (d=="begin"){
  905. if (this.begin){
  906. this.designer.notice(MWF.APPPD.LP.notice["one_begin"], "error", null, {x: "right", y:"top"});
  907. return false;
  908. }
  909. }
  910. var activity = null;
  911. this.getActivityTemplate(function(){
  912. var activityData = Object.clone(this.activityTemplates[d]);
  913. //MWF.require("MWF.widget.UUID", function(){
  914. //activityData.id = (new MWF.widget.UUID()).toString();
  915. this.designer.actions.getUUID(function(id){activityData.id = id;});
  916. activityData.process = this.process.id;
  917. activityData.createTime = new Date().format('db');
  918. activityData.updateTime = new Date().format('db');
  919. activityData.position = position.x+","+position.y;
  920. activity = new MWF.APPPD.Activity[c](activityData, this);
  921. activity.create(position);
  922. if (d=="begin"){
  923. this.begin = activity;
  924. this.process.begin = activityData;
  925. }else{
  926. this[d+"s"][activityData.id] = activity;
  927. if (!this.process[d+"List"]){
  928. this.process[d+"List"] = [];
  929. }
  930. this.process[d+"List"].push(activityData);
  931. }
  932. this.activitys.push(activity);
  933. // }.bind(this));
  934. }.bind(this));
  935. return activity;
  936. },
  937. createManualActivity: function(){
  938. this.createActivity("manual", "Manual");
  939. },
  940. createConditionActivity: function(){
  941. this.createActivity("condition", "Condition");
  942. },
  943. createAutoActivity: function(){
  944. this.createActivity("auto", "Auto");
  945. },
  946. createSplitActivity: function(){
  947. this.createActivity("split", "Split");
  948. },
  949. createMergeActivity: function(){
  950. this.createActivity("merge", "Merge");
  951. },
  952. createEmbedActivity: function(){
  953. this.createActivity("embed", "Embed");
  954. },
  955. createInvokesActivity: function(){
  956. this.createActivity("invoke", "Invoke");
  957. },
  958. createBeginActivity: function(){
  959. this.createActivity("begin", "Begin");
  960. },
  961. createEndActivity: function(){
  962. this.createActivity("end", "End");
  963. },
  964. createRoute: function(){
  965. if (!this.isCopyRoute && !this.isCreateRoute){
  966. this.getRouteTemplates(function(){
  967. var routerData = Object.clone(this.routeTemplates.route);
  968. //routerData.id = this.designer.actions.getUUID();
  969. this.designer.actions.getUUID(function(id){routerData.id = id;});
  970. routerData.process = this.process.id;
  971. routerData.createTime = new Date().format('db');
  972. routerData.updateTime = new Date().format('db');
  973. var route = new MWF.APPPD.Route(routerData, this);
  974. route.isBack = true;
  975. route.load();
  976. route.set.toBack();
  977. this.beginRouteCreate(route);
  978. }.bind(this));
  979. }
  980. },
  981. beginRouteCreate: function(route){
  982. this.isCreateRoute = true;
  983. this.currentCreateRoute = route;
  984. this.designer.setToolBardisabled("createRoute");
  985. //route.set.toFront();
  986. this.routeCreateFromMouseMoveBind = function(e){
  987. this.routeCreateFromMouseMove(e);
  988. }.bind(this);
  989. this.paper.canvas.addEvent("mousemove", this.routeCreateFromMouseMoveBind);
  990. },
  991. routeCreateFromMouseMove: function(e){
  992. //var x = e.event.layerX.toFloat();
  993. //var y = e.event.layerY.toFloat();
  994. var x = e.event.offsetX.toFloat();
  995. var y = e.event.offsetY.toFloat();
  996. var dx = x - this.currentCreateRoute.beginPoint.x-5;
  997. var dy = y - this.currentCreateRoute.beginPoint.y+5;
  998. this.currentCreateRoute.set.transform("t"+dx+","+dy);
  999. },
  1000. routeCreateFromActivity: function(activity){
  1001. this.paper.canvas.removeEvent("mousemove", this.routeCreateFromMouseMoveBind);
  1002. var route = this.currentCreateRoute;
  1003. route.setActivity(null, activity);
  1004. route.reload();
  1005. this.routeCreateToMouseMoveBind = function(e){
  1006. this.routeCreateToMouseMove(e);
  1007. }.bind(this);
  1008. this.paper.canvas.addEvent("mousemove", this.routeCreateToMouseMoveBind);
  1009. },
  1010. routeCreateToMouseMove: function(e){
  1011. //var x = e.event.layerX.toFloat();
  1012. //var y = e.event.layerY.toFloat();
  1013. var x = e.event.offsetX.toFloat();
  1014. var y = e.event.offsetY.toFloat();
  1015. var route = this.currentCreateRoute;
  1016. route.tmpEndPoint = {"x": x-3, "y": y-3};
  1017. route.reload();
  1018. },
  1019. routeCreateToActivity: function(activity){
  1020. this.paper.canvas.removeEvent("mousemove", this.routeCreateToMouseMoveBind);
  1021. var route = this.currentCreateRoute;
  1022. route.tmpEndPoint = null;
  1023. route.tmpBeginPoint = null;
  1024. route.setActivity(activity, null);
  1025. route.isBack = false;
  1026. route.reload();
  1027. activity.shap.attr(activity.style.shap);
  1028. this.endRouteCreate();
  1029. },
  1030. endRouteCreate: function(){
  1031. var route = this.currentCreateRoute;
  1032. route.selected();
  1033. this.isCreateRoute = false;
  1034. this.currentCreateRoute = null;
  1035. route.setListItemData();
  1036. this.designer.setToolBardisabled("decision");
  1037. this.setNewRouteProcessData(route);
  1038. },
  1039. setNewRouteProcessData: function(route){
  1040. this.routes[route.data.id] = route;
  1041. this.process.routeList.push(route.data);
  1042. route.fromActivity.setRouteData(route.data.id);
  1043. // if (!route.fromActivity.data.routeList) route.fromActivity.data.routeList = [];
  1044. // route.fromActivity.data.routeList.push(route.data.id);
  1045. route.data.activity = route.toActivity.data.id;
  1046. route.data.activityType = route.toActivity.type;
  1047. },
  1048. routeCreateCancel: function(){
  1049. var route = this.currentCreateRoute;
  1050. if (route.fromActivity){
  1051. route.fromActivity.routes.erase(route);
  1052. }
  1053. route.destroy();
  1054. delete route;
  1055. this.isCreateRoute = false;
  1056. this.currentCreateRoute = null;
  1057. if (this.routeCreateFromMouseMoveBind) this.paper.canvas.removeEvent("mousemove", this.routeCreateFromMouseMoveBind);
  1058. if (this.routeCreateToMouseMoveBind) this.paper.canvas.removeEvent("mousemove", this.routeCreateToMouseMoveBind);
  1059. },
  1060. checkCreateRoute: function(e){
  1061. if (this.isCreateRoute || this.isCopyRoute){
  1062. if (e.rightClick){
  1063. if (this.isCreateRoute){
  1064. this.routeCreateCancel();
  1065. }
  1066. if (this.isCopyRoute){
  1067. this.routeAddCancel();
  1068. }
  1069. }
  1070. if (this.menu) this.menu.pause(1);
  1071. }
  1072. },
  1073. clearSelected: function(){
  1074. this.begin.unSelectActivity();
  1075. for (a in this.ends) this.ends[a].unSelected();
  1076. for (a in this.conditions) this.conditions[a].unSelected();
  1077. for (a in this.autos) this.autos[a].unSelected();
  1078. for (a in this.manuals) this.manuals[a].unSelected();
  1079. for (a in this.embeds) this.embeds[a].unSelected();
  1080. for (a in this.invokes) this.invokes[a].unSelected();
  1081. },
  1082. copyRoute: function(route){
  1083. if (!this.isCopyRoute && !this.isCreateRoute){
  1084. var newRouteData = Object.clone(route.data);
  1085. //newRouteData.id = Raphael.createUUID();
  1086. //newRouteData.id = this.designer.actions.getUUID();
  1087. this.designer.actions.getUUID(function(id){newRouteData.id = id;});
  1088. var route = new MWF.APPPD.Route(newRouteData, this);
  1089. route.load();
  1090. route.isBack = true;
  1091. this.isCopyRoute = true;
  1092. this.currentCopyRoute = route;
  1093. this.beginRouteCopy(route);
  1094. }
  1095. },
  1096. beginRouteCopy: function(route){
  1097. this.routeCopyMouseMoveBind = function(e){
  1098. this.copyRouteMouseMove(e, route);
  1099. }.bind(this);
  1100. this.paper.canvas.addEvent("mousemove", this.routeCopyMouseMoveBind);
  1101. },
  1102. copyRouteMouseMove: function(e, route){
  1103. route.tmpBeginPoint = {"x": e.event.offsetX-5, "y": e.event.offsetY-5};
  1104. route.reload();
  1105. },
  1106. routeAddFromActivity: function(activity){
  1107. var route = this.currentCopyRoute;
  1108. this.paper.canvas.removeEvent("mousemove", this.routeCopyMouseMoveBind);
  1109. route.setActivity(null, activity);
  1110. route.isBack = false;
  1111. route.reload();
  1112. activity.shap.attr(activity.style.shap);
  1113. this.endRouteCopy();
  1114. },
  1115. endRouteCopy: function(){
  1116. var route = this.currentCopyRoute;
  1117. route.selected();
  1118. this.isCopyRoute = false;
  1119. this.currentCopyRoute = null;
  1120. route.setListItemData();
  1121. this.designer.setToolBardisabled("decision");
  1122. this.setCopyRouteProcessData(route);
  1123. },
  1124. routeAddCancel: function(){
  1125. var route = this.currentCopyRoute;
  1126. route.destroy();
  1127. delete route;
  1128. this.isCopyRoute = false;
  1129. this.currentCopyRoute = null;
  1130. if (this.routeAddMouseMoveBind) this.paper.canvas.removeEvent("mousemove", this.routeAddMouseMoveBind);
  1131. },
  1132. setCopyRouteProcessData: function(route){
  1133. this.process.routeList.push(route.data);
  1134. route.fromActivity.setRouteData(route.data.id);
  1135. // if (!route.fromActivity.data.routeList) route.fromActivity.data.routeList = [];
  1136. // route.fromActivity.data.routeList.push(route.data.id);
  1137. this.routeDatas[route.data.id] = route.data;
  1138. },
  1139. deleteRoute: function(e, route){
  1140. var _self = this;
  1141. this.designer.shortcut = false;
  1142. this.designer.confirm("warn", e, MWF.APPPD.LP.notice.deleteRouteTitle, MWF.APPPD.LP.notice.deleteRoute, 300, 120, function(){
  1143. route.destroy();
  1144. delete route;
  1145. _self.designer.shortcut = true;
  1146. this.close();
  1147. }, function(){
  1148. _self.designer.shortcut = true;
  1149. this.close();
  1150. }, null);
  1151. },
  1152. copyActivity: function(activity){
  1153. var activityData = Object.clone(activity.data);
  1154. var type = activity.type;
  1155. var c = type.capitalize();
  1156. //activityData.id = this.designer.actions.getUUID();
  1157. this.designer.actions.getUUID(function(id){activityData.id = id;});
  1158. activityData.process = this.process.id;
  1159. activity = new MWF.APPPD.Activity[c](activityData, this);
  1160. activity.create();
  1161. activity.selected();
  1162. if (type=="begin"){
  1163. this.begin = activity;
  1164. this.process.begin = activityData;
  1165. }else{
  1166. this[type+"s"][activityData.id] = activity;
  1167. if (!this.process[type+"List"]){
  1168. this.process[type+"List"] = [];
  1169. }
  1170. this.process[type+"List"].push(activityData);
  1171. }
  1172. },
  1173. deleteActivity: function(e, activity){
  1174. var _self = this;
  1175. this.designer.shortcut = false;
  1176. this.designer.confirm("warn", e, MWF.APPPD.LP.notice.deleteActivityTitle, MWF.APPPD.LP.notice.deleteActivity, 300, 120, function(){
  1177. activity.destroy();
  1178. delete activity;
  1179. _self.designer.shortcut = true;
  1180. this.close();
  1181. }, function(){
  1182. _self.designer.shortcut = true;
  1183. this.close();
  1184. }, null);
  1185. },
  1186. explode: function(){
  1187. // this._getFormData();
  1188. MWF.require("MWF.widget.Base64", null, false);
  1189. var data = MWF.widget.Base64.encode(JSON.encode(this.process));
  1190. MWF.require("MWF.widget.Panel", function(){
  1191. var node = new Element("div");
  1192. //var size = this.designer.formNode.getSize();
  1193. var position = this.designer.paperNode.getPosition(this.designer.paperNode.getOffsetParent());
  1194. var textarea = new Element("textarea", {
  1195. "styles": {
  1196. "border": "1px solid #999",
  1197. "width": "770px",
  1198. "margin-left": "14px",
  1199. "margin-top": "14px",
  1200. "height": "580px"
  1201. },
  1202. "text": JSON.encode(this.process)
  1203. }).inject(node);
  1204. this.explodePanel = new MWF.widget.Panel(node, {
  1205. "style": "form",
  1206. "isResize": false,
  1207. "isMax": false,
  1208. "title": "",
  1209. "width": 800,
  1210. "height": 660,
  1211. "top": position.y,
  1212. "left": position.x+3,
  1213. "isExpand": false,
  1214. "target": this.designer.node
  1215. });
  1216. this.explodePanel.load();
  1217. }.bind(this));
  1218. }
  1219. });
  1220. MWF.xApplication.process.ProcessDesigner.Process.Panel = new Class({
  1221. initialize: function(process){
  1222. this.process = process;
  1223. this.width = 370;
  1224. this.top = 0;
  1225. var paperSize = this.process.designer.paperNode.getSize();
  1226. this.left = (paperSize.x.toFloat())-376;
  1227. this.height = (paperSize.y.toFloat())-6;
  1228. this.stopParseJson = false;
  1229. },
  1230. load: function(){
  1231. this.panelNode = new Element("div");
  1232. this.createModuleListTab();
  1233. this.createPropertyTab();
  1234. this.createPanelResizeNode();
  1235. this.moduleTabContent.inject(this.panelNode);
  1236. this.panelResizeNode.inject(this.panelNode);
  1237. this.propertyTabContent.inject(this.panelNode);
  1238. MWF.require("MWF.widget.Panel", function(){
  1239. this.modulePanel = new MWF.widget.Panel(this.panelNode, {
  1240. "title": MWF.APPPD.LP.property,
  1241. "isClose": false,
  1242. "target": this.process.designer.paperNode,
  1243. "height": this.height,
  1244. "width": this.width,
  1245. "left": this.left,
  1246. "top": this.top,
  1247. "transition": Fx.Transitions.linear.easeIn,
  1248. "transitionOut": Fx.Transitions.linear.easeOut,
  1249. "duration": 100,
  1250. "onResize": function(){
  1251. this.setPanelSize(this.panelModulePercent);
  1252. }.bind(this)
  1253. });
  1254. this.modulePanel.load();
  1255. this.setPanelSize(this.panelModulePercent);
  1256. }.bind(this));
  1257. },
  1258. setPanelSize: function(percent){
  1259. var contentSize = this.modulePanel.content.getSize();
  1260. var resizeSize = this.panelResizeNode.getSize();
  1261. var resizeMarginTop = this.panelResizeNode.getStyle("margin-top");
  1262. var resizeMarginBottom = this.panelResizeNode.getStyle("margin-bottom");
  1263. var useHeight = (contentSize.y.toFloat()) - (resizeSize.y.toFloat()) - (resizeMarginTop.toFloat()) - (resizeMarginBottom.toFloat());
  1264. var p = percent;
  1265. if (!p) p = 0.3;
  1266. var moduleHeight = useHeight*p;
  1267. var propertyHeight = useHeight - moduleHeight;
  1268. this.moduleListContent.setStyle("height", moduleHeight);
  1269. if (!this.propertyPanel) this.propertyListContent.setStyle("height", propertyHeight);
  1270. var moduleListTabSize = this.moduleListTab.tabNodeContainer.getSize();
  1271. this.moduleListTab.pages.each(function(page){
  1272. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1273. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1274. var tabContentNodeAreaHeight = moduleHeight - topMargin - bottomMargin - moduleListTabSize.y.toFloat()-2;
  1275. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1276. }.bind(this));
  1277. if (!this.propertyPanel) {
  1278. var propertyListTabSize = this.propertyListTab.tabNodeContainer.getSize();
  1279. this.propertyListTab.pages.each(function(page){
  1280. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1281. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1282. var tabContentNodeAreaHeight = propertyHeight - topMargin - bottomMargin - propertyListTabSize.y.toFloat()-2;
  1283. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1284. }.bind(this));
  1285. }
  1286. // var contentNodeContainerHeight = moduleHeight - moduleListTabSize.y.toFloat()-2;
  1287. // this.moduleListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1288. //
  1289. // contentNodeContainerHeight = propertyHeight - propertyListTabSize.y.toFloat()-2;
  1290. // this.propertyListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1291. if (this.jsonStringConfirmNode)this.setJsonStringConfirmNodePosition();
  1292. },
  1293. createPanelResizeNode: function(){
  1294. this.panelResizeNode = new Element("div", {
  1295. "styles": this.process.css.panelResizeNode
  1296. });
  1297. this.panelResizeNode.addEvent("mousedown", function(e){
  1298. this.beginPanelResize(e);
  1299. }.bind(this));
  1300. },
  1301. beginPanelResize: function(){
  1302. this.panelResizeMouseMoveBind = function(e){
  1303. this.panelResize(e);
  1304. }.bind(this);
  1305. this.panelResizeMouseUpBind = function(){
  1306. $(document.body).removeEvent("selectstart",this.panelResizeSelecttBind);
  1307. $(document.body).removeEvent("mousemove",this.panelResizeMouseMoveBind);
  1308. $(document.body).removeEvent("mouseup",this.panelResizeMouseUpBind);
  1309. }.bind(this);
  1310. this.panelResizeSelecttBind = function(){
  1311. return false;
  1312. }.bind(this);
  1313. $(document.body).addEvent("selectstart",this.panelResizeSelecttBind);
  1314. $(document.body).addEvent("mousemove",this.panelResizeMouseMoveBind);
  1315. $(document.body).addEvent("mouseup",this.panelResizeMouseUpBind);
  1316. },
  1317. panelResize: function(e){
  1318. var y = e.event.pageY;
  1319. var modulePosition = this.moduleListContent.getPosition();
  1320. var moduleHeight = (y.toFloat()) - (modulePosition.y.toFloat());
  1321. if (moduleHeight<40) moduleHeight = 40;
  1322. var contentSize = this.modulePanel.content.getSize();
  1323. var resizeSize = this.panelResizeNode.getSize();
  1324. var resizeMarginTop = this.panelResizeNode.getStyle("margin-top");
  1325. var resizeMarginBottom = this.panelResizeNode.getStyle("margin-bottom");
  1326. var useHeight = (contentSize.y.toFloat()) - (resizeSize.y.toFloat()) - (resizeMarginTop.toFloat()) - (resizeMarginBottom.toFloat());
  1327. var propertyHeight = useHeight - moduleHeight;
  1328. if (propertyHeight<40){
  1329. propertyHeight = 40;
  1330. moduleHeight = useHeight - propertyHeight;
  1331. }
  1332. this.moduleListContent.setStyle("height", moduleHeight);
  1333. this.propertyListContent.setStyle("height", propertyHeight);
  1334. var moduleListTabSize = this.moduleListTab.tabNodeContainer.getSize();
  1335. var propertyListTabSize = this.propertyListTab.tabNodeContainer.getSize();
  1336. this.moduleListTab.pages.each(function(page){
  1337. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1338. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1339. var tabContentNodeAreaHeight = moduleHeight - topMargin - bottomMargin - (moduleListTabSize.y.toFloat())-2;
  1340. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1341. }.bind(this));
  1342. this.propertyListTab.pages.each(function(page){
  1343. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1344. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1345. var tabContentNodeAreaHeight = propertyHeight - topMargin - bottomMargin - propertyListTabSize.y.toFloat()-2;
  1346. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1347. }.bind(this));
  1348. // var contentNodeContainerHeight = moduleHeight - moduleListTabSize.y.toFloat()-2;
  1349. // this.moduleListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1350. //
  1351. // contentNodeContainerHeight = propertyHeight - propertyListTabSize.y.toFloat()-2;
  1352. // this.propertyListTab.contentNodeContainer.setStyle("height", contentNodeContainerHeight);
  1353. if (this.jsonStringConfirmNode)this.setJsonStringConfirmNodePosition();
  1354. this.panelModulePercent = moduleHeight.toFloat()/useHeight.toFloat();
  1355. },
  1356. loadJson: function(json){
  1357. // MWF.require("MWF.widget.MaskNode", function(){
  1358. // this.jsonMarkNode = new MWF.widget.MaskNode(this.jsonObjectNode, {"zIndex": 30000});
  1359. // this.jsonMarkNode.load();
  1360. MWF.require("MWF.widget.JsonParse", function(){
  1361. this.jsonParse = new MWF.widget.JsonParse(json, this.jsonObjectNode, this.jsonStringNode);
  1362. this.jsonParse.load();
  1363. }.bind(this));
  1364. // this.jsonParse = new MWF.APPPD.Process.JsonParse(json, this.jsonObjectNode, this.jsonStringNode);
  1365. // window.setTimeout(function(){
  1366. // this.jsonParse.load();
  1367. // }.bind(this), 1);
  1368. // }.bind(this));
  1369. },
  1370. loadJsonString: function(json){
  1371. // o2.load("JSBeautifier_html", function(){
  1372. // htmlNode.set("text", html_beautify(copy.outerHTML, {"indent_size":1}));
  1373. // }.bind(this));
  1374. this.jsonStringNode.set("text", JSON.stringify(json,null,2));
  1375. MWF.widget.ace.load(function(){
  1376. COMMON.AjaxModule.loadDom("/o2_lib/ace/src-min-noconflict/ext-static_highlight.js", function(){
  1377. var highlight = ace.require("ace/ext/static_highlight");
  1378. highlight(this.jsonStringNode, {mode: "ace/mode/json", theme: "ace/theme/tomorrow", "fontSize": 16});
  1379. }.bind(this));
  1380. }.bind(this));
  1381. },
  1382. clearJson: function(){
  1383. this.json = null;
  1384. this.jsonString = "";
  1385. this.jsonStringNode.set("text", "");
  1386. this.jsonObjectNode.empty();
  1387. if (this.jsonParse) this.jsonParse = null;
  1388. // if (this.jsonMarkNode) this.jsonMarkNode.hide();
  1389. },
  1390. createJsonStringNode: function(){
  1391. var jsonStringNode = new Element("div", {
  1392. // "readonly": true,
  1393. "styles": {
  1394. "width": "100%",
  1395. "height": "100%",
  1396. "overflow": "auto",
  1397. "border": "0px"
  1398. }
  1399. });
  1400. // jsonStringNode.set("text", this.jsonString);
  1401. return jsonStringNode;
  1402. },
  1403. createJsonObjectNode: function(){
  1404. this.jsonObjectNode = new Element("div", {
  1405. "styles": {
  1406. //"overflow": "hideen",
  1407. "margin-top": "0px",
  1408. "height": "auto"
  1409. }
  1410. });
  1411. // this.loadObjectTree();
  1412. return this.jsonObjectNode;
  1413. },
  1414. createJsonStringConfirmNode: function(){
  1415. this.jsonStringConfirmNode = new Element("div", {
  1416. "styles": {
  1417. "width": "20px",
  1418. "height": "20px",
  1419. "background-color": "#EEE",
  1420. "background": "url("+MWF.defaultPath+"/process/ProcessChart/$Process/"+this.process.options.style+"/checkmark.png"+") no-repeat center center",
  1421. "position": "absolute",
  1422. "cursor": "pointer",
  1423. "display": "none"
  1424. },
  1425. "events": {
  1426. "mouseover": function(){
  1427. this.store("flag", true);
  1428. },
  1429. "mouseout": function(){
  1430. this.store("flag", false);
  1431. },
  1432. "click": function(){
  1433. this.checkJsonStringAndReload();
  1434. }.bind(this)
  1435. }
  1436. }).inject(this.jsonStringNode, "after");
  1437. },
  1438. checkJsonStringAndReload: function(){
  1439. if (!this.process.selectedActivitys.length){
  1440. try {
  1441. var data = JSON.decode(this.jsonStringNode.value);
  1442. if (data){
  1443. if (this.process.currentSelected){
  1444. Object.copy(data, this.process.currentSelected.data);
  1445. this.process.currentSelected.redraw();
  1446. }else{
  1447. data.id = this.process.process.id;
  1448. data.processCategory = this.process.process.processCategory;
  1449. this.process.reload(data);
  1450. }
  1451. }
  1452. }catch(e){
  1453. this.designer.notice(e.message, "error", this.jsonStringNode.getParent(), {x: "left", y:"top"});
  1454. }
  1455. }
  1456. },
  1457. setJsonStringConfirmNodePosition: function(){
  1458. var p = this.jsonStringNode.getPosition(this.panelNode);
  1459. var size = this.panelNode.getSize();
  1460. this.jsonStringConfirmNode.setStyles({
  1461. "display": "block",
  1462. "top" : p.y+4,
  1463. "left" : size.x-26
  1464. });
  1465. },
  1466. createPropertyTab: function(){
  1467. this.propertyTabContent = new Element("div");
  1468. this.propertyListContent = new Element("div", {
  1469. "styles": this.process.css.propertyListContent
  1470. }).inject(this.propertyTabContent);
  1471. this.propertyListNode = new Element("div", {
  1472. "styles": this.process.css.propertyListNode
  1473. });
  1474. this.process.propertyListNode = this.propertyListNode;
  1475. this.jsonObjectNode = this.createJsonObjectNode();
  1476. this.jsonStringNode = this.createJsonStringNode();
  1477. this.jsonStringNode.addEvents({
  1478. "focus": function(){
  1479. if (!this.process.selectedActivitys.length){
  1480. if (!this.jsonStringConfirmNode) this.createJsonStringConfirmNode();
  1481. this.setJsonStringConfirmNodePosition();
  1482. }
  1483. }.bind(this),
  1484. "blur": function(e){
  1485. if (this.jsonStringConfirmNode){
  1486. if (!this.jsonStringConfirmNode.retrieve("flag")) this.jsonStringConfirmNode.setStyle("display", "none");
  1487. }
  1488. }.bind(this)
  1489. });
  1490. MWF.require("MWF.widget.Tab", function(){
  1491. this.propertyListTab = new MWF.widget.Tab(this.propertyListContent, {"style": "moduleList"});
  1492. this.propertyListTab.load();
  1493. this.propertyTabPage = this.propertyListTab.addTab(this.propertyListNode, MWF.APPPD.LP.property, false);
  1494. this.objectTabPage = this.propertyListTab.addTab(this.jsonObjectNode, "JSON", false);
  1495. this.stringTabPage = this.propertyListTab.addTab(this.jsonStringNode, "Text", false);
  1496. this.process.setScrollBar(this.propertyTabPage.contentNodeArea, "small", null, null);
  1497. this.process.setScrollBar(this.objectTabPage.contentNodeArea, "small", null, null);
  1498. this.process.setScrollBar(this.stringTabPage.contentNodeArea, "small", null, null);
  1499. this.objectTabPage.setOptions({
  1500. "onShow": function(){
  1501. this.loadJson(this.data);
  1502. }.bind(this),
  1503. "onHide": function(){
  1504. this.clearJson();
  1505. }.bind(this)
  1506. });
  1507. this.stringTabPage.setOptions({
  1508. "onShow": function(){
  1509. this.loadJsonString(this.data);
  1510. }.bind(this),
  1511. "onHide": function(){
  1512. this.clearJson();
  1513. }.bind(this)
  1514. });
  1515. this.propertyTabPage.showTab();
  1516. this.propertyListTab.tabNodeContainer.addEvent("mousedown", function(event){
  1517. //event.stop();
  1518. this.propertyTabMove(event);
  1519. }.bind(this));
  1520. // this.propertyDrag = new Drag(this.propertyTabContent, {
  1521. // "handle": this.propertyListTab.tabNodeContainer,
  1522. // "snap": 10,
  1523. // "onStart": function(el, e){
  1524. // }.bind(this)
  1525. // });
  1526. }.bind(this), false);
  1527. // this.propertyListContent.setStyle("height", 300);
  1528. },
  1529. propertyTabMove: function(event){
  1530. // var tmpContent = this.propertyListContent.clone().setStyles(this.propertyListContent.getCoordinates()).setStyles({
  1531. // "opacity": 0.7,
  1532. // "border": "1px dashed #CCC",
  1533. // "z-index": this.modulePanel.container.getStyle("z-index").toInt()+1,
  1534. // "position": "absolute"
  1535. // }).inject(this.process.designer.paperNode);
  1536. var size = this.propertyListContent.getSize();
  1537. var tmpContent = new Element("div", {
  1538. "styles": {
  1539. "opacity": 0.7,
  1540. "border": "1px dashed #CCC",
  1541. "z-index": this.modulePanel.container.getStyle("z-index").toInt()+1,
  1542. "width": size.x,
  1543. "height": size.y,
  1544. "background-color": "#EEE",
  1545. "position": "absolute"
  1546. }
  1547. }).inject(this.process.designer.paperNode);
  1548. tmpContent.position({
  1549. relativeTo: this.propertyListContent,
  1550. position: 'upperLeft',
  1551. edge: 'upperLeft'
  1552. });
  1553. var drag = new Drag.Move(tmpContent, {
  1554. "droppables": [this.process.designer.paperNode, this.panelNode],
  1555. "onEnter": function(dragging, inObj){
  1556. if (this.propertyPanel){
  1557. if (this.panelNode==inObj){
  1558. dragging.tween('border', "4px dashed #666");
  1559. }else{
  1560. dragging.tween('border', "1px dashed #CCC");
  1561. }
  1562. }else{
  1563. if (this.panelNode==inObj){
  1564. dragging.tween('border', "1px dashed #CCC");
  1565. }else{
  1566. dragging.tween('border', "4px dashed #666");
  1567. }
  1568. }
  1569. }.bind(this),
  1570. "onLeave": function(dragging, paper){
  1571. dragging.tween('border', "1px dashed #CCC");
  1572. },
  1573. "onDrop": function(dragging, inObj){
  1574. if (this.panelNode!=inObj){
  1575. this.propertyOut(dragging);
  1576. }else{
  1577. this.propertyIn();
  1578. }
  1579. dragging.destroy();
  1580. }.bind(this),
  1581. "onCancel": function(dragging){
  1582. dragging.destroy();
  1583. }
  1584. });
  1585. drag.start(event);
  1586. },
  1587. propertyOut: function(dragging){
  1588. if (!this.propertyPanel){
  1589. var coordinates = dragging.getCoordinates();
  1590. var p = this.process.designer.paperNode.getPosition();
  1591. var propertyPanelNode = new Element("div");
  1592. this.propertyListContent.inject(propertyPanelNode);
  1593. MWF.require("MWF.widget.Panel", function(){
  1594. this.propertyPanel = new MWF.widget.Panel(propertyPanelNode, {
  1595. "title": MWF.APPPD.LP.property,
  1596. "isClose": false,
  1597. "target": this.process.designer.paperNode,
  1598. "height": coordinates.height,
  1599. "width": coordinates.width,
  1600. "left": coordinates.left.toFloat() - p.x.toFloat(),
  1601. "top": coordinates.top.toFloat() - p.y.toFloat(),
  1602. "onResize": function(){
  1603. this.setPropertyPanelSize();
  1604. }.bind(this)
  1605. });
  1606. this.propertyPanel.load();
  1607. this.propertyOutSetHeight();
  1608. this.setPropertyPanelSize(this.panelModulePercent);
  1609. }.bind(this));
  1610. };
  1611. },
  1612. setPropertyPanelSize: function(){
  1613. var contentSize = this.propertyPanel.content.getSize();
  1614. var propertyHeight = contentSize.y;
  1615. this.propertyListContent.setStyle("height", propertyHeight);
  1616. var propertyListTabSize = this.propertyListTab.tabNodeContainer.getSize();
  1617. this.propertyListTab.pages.each(function(page){
  1618. var topMargin = page.contentNodeArea.getStyle("margin-top").toFloat();
  1619. var bottomMargin = page.contentNodeArea.getStyle("margin-bottom").toFloat();
  1620. var tabContentNodeAreaHeight = propertyHeight - topMargin - bottomMargin - propertyListTabSize.y.toFloat()-2;
  1621. page.contentNodeArea.setStyle("height", tabContentNodeAreaHeight);
  1622. }.bind(this));
  1623. },
  1624. propertyOutSetHeight: function(){
  1625. this.panelResizeNode.setStyles(this.process.css.panelResizeNodeHide);
  1626. this.panelModulePercent = "1";
  1627. this.setPanelSize(this.panelModulePercent);
  1628. },
  1629. propertyIn: function(){
  1630. this.propertyListContent.inject(this.propertyTabContent);
  1631. if (this.propertyPanel) this.propertyPanel.closePanel();
  1632. this.propertyPanel = null;
  1633. this.propertyInSetHeight();
  1634. },
  1635. propertyInSetHeight: function(){
  1636. this.panelResizeNode.setStyles(this.process.css.panelResizeNode);
  1637. this.panelModulePercent = "0.3";
  1638. this.setPanelSize(this.panelModulePercent);
  1639. },
  1640. createModuleListTab: function(){
  1641. this.moduleTabContent = new Element("div");
  1642. this.moduleListContent = new Element("div", {
  1643. "styles": this.process.css.moduleListContent
  1644. }).inject(this.moduleTabContent);
  1645. this.activityListNode = new Element("div", {
  1646. "styles": this.process.css.activityListNode
  1647. });
  1648. this.process.activityListNode = this.activityListNode;
  1649. this.activityTable = new HtmlTable({
  1650. "properties": this.process.css.activityListTable
  1651. }).inject(this.activityListNode);
  1652. this.process.activityTable = this.activityTable;
  1653. this.routeListNode = new Element("div", {
  1654. "styles": this.process.css.routeListNode
  1655. });
  1656. this.process.routeListNode = this.routeListNode;
  1657. this.routeTable = new HtmlTable({
  1658. "properties": this.process.css.routeListTable
  1659. }).inject(this.routeListNode);
  1660. this.process.routeTable = this.routeTable;
  1661. MWF.require("MWF.widget.Tab", function(){
  1662. this.moduleListTab = new MWF.widget.Tab(this.moduleListContent, {"style": "moduleList"});
  1663. this.moduleListTab.load();
  1664. // this.process.setScrollBar(this.moduleListTab.contentNodeContainer, null, null, null);
  1665. var activityTabPage = this.moduleListTab.addTab(this.activityListNode, MWF.APPPD.LP.activity, false);
  1666. this.process.setScrollBar(activityTabPage.contentNodeArea, "small", null, null);
  1667. var routeTabPage = this.moduleListTab.addTab(this.routeListNode, MWF.APPPD.LP.route, false);
  1668. this.process.setScrollBar(routeTabPage.contentNodeArea, "small", null, null);
  1669. activityTabPage.showTab();
  1670. }.bind(this), false);
  1671. },
  1672. destroy: function(){
  1673. if (this.modulePanel) this.modulePanel.destroy();
  1674. if (this.propertyPanel) this.propertyPanel.destroy();
  1675. }
  1676. });
  1677. MWF.xApplication.process.ProcessDesigner.Process.Property = new Class({
  1678. Implements: [Options, Events],
  1679. Extends: MWF.APPPD.Property,
  1680. initialize: function(process, options){
  1681. this.setOptions(options);
  1682. this.process = process;
  1683. this.paper = this.process.paper;
  1684. this.data = process.process;
  1685. this.htmlPath = "/x_component_process_ProcessDesigner/$Process/process.html";
  1686. }
  1687. });
  1688. MWF.xApplication.process.ProcessDesigner.Process.JsonParse = new Class({
  1689. initialize: function(json, jsonObjectNode, jsonStringNode){
  1690. this.json = json;
  1691. this.jsonObjectNode = jsonObjectNode;
  1692. this.jsonStringNode = jsonStringNode;
  1693. this.stopParseJson = false;
  1694. },
  1695. load: function(){
  1696. this.jsonString = JSON.encode(this.json);
  1697. // this.jsonStringNode.set("text", JSON.format(this.json));
  1698. this.loadObjectTree();
  1699. },
  1700. loadObjectTree: function(){
  1701. if (this.objectTree){
  1702. this.objectTree.node.destroy();
  1703. this.objectTree = null;
  1704. }
  1705. MWF.require("MWF.widget.Tree", function(){
  1706. this.objectTree = new MWF.widget.Tree(this.jsonObjectNode, {"style": "jsonview"});
  1707. this.objectTree.load();
  1708. var str = this.parseJsonObject(0, this.objectTree, "", "JSON", this.json, true);
  1709. var jsonStr = str.substring(0, str.length-2);
  1710. if (!this.stopParseJson){
  1711. this.jsonStringNode.set("text", jsonStr);
  1712. }else{
  1713. this.stopParseJson = false;
  1714. }
  1715. }.bind(this));
  1716. },
  1717. parseJsonObject: function(level, treeNode, title, p, v, expand){
  1718. if (this.stopParseJson){
  1719. // alert(this.stopParseJson);
  1720. return false;
  1721. }
  1722. var o = {
  1723. "expand": expand,
  1724. "title": "",
  1725. "text": "",
  1726. "action": "",
  1727. "icon": ""
  1728. };
  1729. var tab = "";
  1730. for (var i=0; i<level; i++) tab+="\t";
  1731. //var title = title;
  1732. if (title) title="\""+title+"\": ";
  1733. var jsonStr = "";
  1734. var nextLevel = level+1;
  1735. switch (typeOf(v)){
  1736. case "object":
  1737. o.text = p;
  1738. o.icon = "object.png";
  1739. var node = treeNode.appendChild(o);
  1740. var jsonStrBegin = tab+title+"{";
  1741. var jsonStrEnd = tab+"}";
  1742. for (i in v){
  1743. jsonStr += this.parseJsonObject(nextLevel, node, i, i, v[i], false);
  1744. }
  1745. jsonStr = jsonStrBegin+"\n"+jsonStr.substring(0, jsonStr.length-2)+"\n"+jsonStrEnd+",\n";
  1746. break;
  1747. case "array":
  1748. o.text = p;
  1749. o.icon = "array.png";
  1750. var node = treeNode.appendChild(o);
  1751. var jsonStrBegin = tab+title+"[";
  1752. var jsonStrEnd = tab+"]";
  1753. v.each(function(item, idx){
  1754. jsonStr += this.parseJsonObject(nextLevel, node, "", "["+idx+"]", item, false);
  1755. }.bind(this));
  1756. jsonStr = jsonStrBegin+"\n"+jsonStr.substring(0, jsonStr.length-2)+"\n"+jsonStrEnd+",\n";
  1757. break;
  1758. case "string":
  1759. jsonStr += tab+title+"\""+v+"\",\n";
  1760. o.text = p + " : \""+v+"\"";
  1761. o.icon = "string.png";
  1762. //var node =
  1763. treeNode.appendChild(o);
  1764. break;
  1765. case "date":
  1766. jsonStr += tab+title+"\""+v+"\",\n";
  1767. o.text = p + " : \""+v+"\"";
  1768. o.icon = "string.png";
  1769. //var node =
  1770. treeNode.appendChild(o);
  1771. break;
  1772. default:
  1773. jsonStr += tab+title+v+",\n";
  1774. o.text = p + " : "+v;
  1775. o.icon = "string.png";
  1776. //var node =
  1777. treeNode.appendChild(o);
  1778. }
  1779. return jsonStr;
  1780. }
  1781. });