Main.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. MWF.xApplication.FindDesigner.options.multitask = false;
  2. MWF.xApplication.FindDesigner.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "FindDesigner",
  8. "mvcStyle": "style.css",
  9. "icon": "icon.png",
  10. "width": "1200",
  11. "height": "800",
  12. "isResize": true,
  13. "isMax": true,
  14. "layout": {
  15. "type": "leftRight",
  16. "percent": 0.3
  17. },
  18. "title": MWF.xApplication.FindDesigner.LP.title
  19. },
  20. onQueryLoad: function(){
  21. this.lp = MWF.xApplication.FindDesigner.LP;
  22. this.filterOption = {
  23. "keyword": "",
  24. "designerTypes": [],
  25. "caseSensitive": false,
  26. "matchWholeWord": false,
  27. "matchRegExp": false,
  28. "moduleList": []
  29. }
  30. this.selectedModules = [];
  31. this.selectedRange = [];
  32. o2.UD.getDataJson("findDesignerLayout", function(json){
  33. this.setOptions(json);
  34. }.bind(this), false);
  35. },
  36. loadApplication: function(callback){
  37. var url = this.path+this.options.style+"/view.html";
  38. this.content.loadHtml(url, {"bind": {"lp": this.lp}, "module": this}, function(){
  39. this.setSizeNode();
  40. if (callback) callback();
  41. }.bind(this));
  42. },
  43. initLayout: function(){
  44. this.listNode.set("style", "");
  45. this.previewNode.set("style", "");
  46. if (this.resizeDrag) this.resizeDrag.detach();
  47. if (this.sizeNodeFun) this.removeEvent("resize", this.sizeNodeFun);
  48. if (this.options.layout.type=="leftRight"){
  49. this.toLeftRight();
  50. }else{
  51. this.toTopBottom();
  52. }
  53. },
  54. setSizeNode: function(){
  55. this.initLayout();
  56. this["sizeNode_"+this.options.layout.type]();
  57. this["setResizeNode_"+this.options.layout.type]();
  58. this.sizeNodeFun = null;
  59. this.sizeNodeFun = this["sizeNode_"+this.options.layout.type].bind(this);
  60. this.addEvent("resize", this.sizeNodeFun);
  61. },
  62. sizeResultNode: function(){
  63. var size = this.content.getSize();
  64. var filterSzie = this.filterNode.getSize();
  65. var keywordSize = this.keywordNode.getSize();
  66. var rangeSize = this.rangeNode.getSize();
  67. var h = size.y-filterSzie.y-keywordSize.y-rangeSize.y;
  68. this.resultNode.setStyle("height", ""+h+"px");
  69. return h;
  70. },
  71. sizeNode_topBottom: function(){
  72. var h = this.sizeResultNode();
  73. var listHeight = h*this.options.layout.percent;
  74. this.listNode.setStyle("height", ""+listHeight+"px");
  75. var previewHeight = h*(1-this.options.layout.percent);
  76. this.previewNode.setStyle("height", ""+previewHeight+"px");
  77. var listTitleSize = this.listTitleNode.getSize();
  78. var listContentHeight = listHeight - listTitleSize.y;
  79. this.listAreaNode.setStyle("height", ""+listContentHeight+"px");
  80. var previewSeparatorSize = this.previewSeparatorNode.getSize();
  81. var previewTitleSize = this.previewTitleNode.getSize();
  82. var previewContentHeight = previewHeight - previewSeparatorSize.y - previewTitleSize.y;
  83. this.previewContentNode.setStyle("height", ""+previewContentHeight+"px");
  84. },
  85. sizeNode_leftRight: function(){
  86. var h = this.sizeResultNode();
  87. var w = this.resultNode.getSize().x;
  88. var listWidth = w*this.options.layout.percent;
  89. this.listNode.setStyle("width", ""+listWidth+"px");
  90. this.previewNode.setStyle("margin-left", ""+listWidth+"px");
  91. var listTitleSize = this.listTitleNode.getSize();
  92. var listContentHeight = h - listTitleSize.y;
  93. this.listAreaNode.setStyle("height", ""+listContentHeight+"px");
  94. var previewTitleSize = this.previewTitleNode.getSize();
  95. var previewContentHeight = h - previewTitleSize.y;
  96. this.previewContentNode.setStyle("height", ""+previewContentHeight+"px");
  97. },
  98. setResizeNode_topBottom: function(){
  99. if (this.previewSeparatorNode){
  100. this.resizeDrag = new Drag(this.previewSeparatorNode, {
  101. "onStart": function(el, e){
  102. el.store("position", o2.eventPosition(e));
  103. el.store("initialSize", this.listNode.getSize());
  104. }.bind(this),
  105. "onDrag": function(el, e){
  106. var p = o2.eventPosition(e);
  107. var position = el.retrieve("position");
  108. var initialSize = el.retrieve("initialSize");
  109. var dy = position.y.toFloat()-p.y.toFloat();
  110. var height = initialSize.y-dy;
  111. var size = this.resultNode.getSize();
  112. this.options.layout.percent = height/size.y;
  113. if (this.options.layout.percent<0.1) this.options.layout.percent = 0.1;
  114. if (this.options.layout.percent>0.85) this.options.layout.percent = 0.85;
  115. this.sizeNode_topBottom();
  116. }.bind(this),
  117. "onComplete": function(){
  118. o2.UD.putData("findDesignerLayout", {"layout": this.options.layout});
  119. }.bind(this)
  120. });
  121. }
  122. },
  123. setResizeNode_leftRight: function(){
  124. if (this.previewSeparatorNode){
  125. this.resizeDrag = new Drag(this.previewSeparatorNode, {
  126. "onStart": function(el, e){
  127. el.store("position", o2.eventPosition(e));
  128. el.store("initialSize", this.listNode.getSize());
  129. }.bind(this),
  130. "onDrag": function(el, e){
  131. var p = o2.eventPosition(e);
  132. var position = el.retrieve("position");
  133. var initialSize = el.retrieve("initialSize");
  134. var dx = position.x.toFloat()-p.x.toFloat();
  135. var width = initialSize.x-dx;
  136. var size = this.resultNode.getSize();
  137. this.options.layout.percent = width/size.x;
  138. if (this.options.layout.percent<0.1) this.options.layout.percent = 0.1;
  139. if (this.options.layout.percent>0.85) this.options.layout.percent = 0.85;
  140. this.sizeNode_leftRight();
  141. }.bind(this),
  142. "onComplete": function(){
  143. o2.UD.putData("findDesignerLayout", {"layout": this.options.layout});
  144. }.bind(this)
  145. });
  146. }
  147. },
  148. checkFilter: function(e){
  149. if (e.target.hasClass("filterNode_item")) e.target.getElement("input").click();
  150. e.stopPropagation();
  151. },
  152. checkRange: function(e){
  153. if (e.target.hasClass("rangeType_Item")) e.target.getElement("input").click();
  154. e.stopPropagation();
  155. },
  156. overKeywordOption: function(e){
  157. if (e.target.hasClass("o2_findDesigner_keywordNode_optionItem")){
  158. if (!e.target.hasClass("optionItem_over")) e.target.addClass("optionItem_over");
  159. }
  160. },
  161. outKeywordOption: function(e){
  162. if (e.target.hasClass("o2_findDesigner_keywordNode_optionItem")) e.target.removeClass("optionItem_over");
  163. },
  164. setCaseSensitive: function(e){
  165. this.filterOption.caseSensitive = !this.filterOption.caseSensitive;
  166. this.caseSensitiveNode.removeClass("caseSensitiveNode_"+!this.filterOption.caseSensitive);
  167. this.caseSensitiveNode.addClass("caseSensitiveNode_"+this.filterOption.caseSensitive);
  168. },
  169. setMatchWholeWord: function(e){
  170. this.filterOption.matchWholeWord = !this.filterOption.matchWholeWord;
  171. this.matchWholeWordNode.removeClass("matchWholeWordNode_"+!this.filterOption.matchWholeWord);
  172. this.matchWholeWordNode.addClass("matchWholeWordNode_"+this.filterOption.matchWholeWord);
  173. },
  174. setMatchRegExp: function(e){
  175. this.filterOption.matchRegExp = !this.filterOption.matchRegExp;
  176. this.matchRegExpNode.removeClass("matchRegExpNode_"+!this.filterOption.matchRegExp);
  177. this.matchRegExpNode.addClass("matchRegExpNode_"+this.filterOption.matchRegExp);
  178. },
  179. layoutAddClass: function(flag){
  180. flag = flag || "";
  181. this.listNode.addClass("listNode"+flag);
  182. this.previewNode.addClass("previewNode"+flag);
  183. this.previewSeparatorNode.addClass("previewNode_separator"+flag);
  184. this.previewTitleNode.addClass("previewNode_title"+flag);
  185. this.previewTitleActionNode.addClass("previewNode_title_action"+flag);
  186. this.previewContentNode.addClass("previewNode_content"+flag);
  187. },
  188. layoutRemoveClass: function(flag){
  189. flag = flag || "";
  190. this.listNode.removeClass("listNode"+flag);
  191. this.previewNode.removeClass("previewNode"+flag);
  192. this.previewSeparatorNode.removeClass("previewNode_separator"+flag);
  193. this.previewTitleNode.removeClass("previewNode_title"+flag);
  194. this.previewTitleActionNode.removeClass("previewNode_title_action"+flag);
  195. this.previewContentNode.removeClass("previewNode_content"+flag);
  196. },
  197. toLeftRight: function(){
  198. this.layoutAddClass("_lr");
  199. this.layoutRemoveClass();
  200. this.options.layout.type="leftRight";
  201. },
  202. toTopBottom: function(){
  203. this.layoutAddClass();
  204. this.layoutRemoveClass("_lr");
  205. this.options.layout.type="topBottom";
  206. },
  207. changeLayout: function(){
  208. if (this.options.layout.type=="leftRight"){
  209. this.options.layout.type="topBottom";
  210. }else{
  211. this.options.layout.type="leftRight";
  212. }
  213. this.setSizeNode();
  214. o2.UD.putData("findDesignerLayout", {"layout": this.options.layout});
  215. },
  216. getSelectedRange: function(){
  217. this.selectedRange = [];
  218. var rangeInputs = this.rangeContentNode.getElements("input");
  219. rangeInputs.each(function(input){
  220. if (input.checked) this.selectedRange.push(input.get("value"));
  221. }.bind(this));
  222. },
  223. setSelectedRange: function(){
  224. if (this.selectedRange && this.selectedRange.length){
  225. var rangeInputs = this.rangeContentNode.getElements("input");
  226. rangeInputs.each(function(input){
  227. if (this.selectedRange.indexOf(input.get("value"))!=-1) input.set("checked", true);
  228. }.bind(this));
  229. }
  230. },
  231. removeRangeItem: function(item){
  232. item.destroy();
  233. var itemNodes = this.rangeSelectedContentNode.getChildren();
  234. if (!itemNodes.length) this.setSelectedRange();
  235. },
  236. selectFindRange: function(loadFun){
  237. o2.requireApp("Selector", "package", function(){
  238. new o2.O2Selector(this.content, {
  239. "values": this.selectedModules,
  240. "type": "PlatApp",
  241. "selectAllEnable": true,
  242. "onLoad": function(){
  243. if (loadFun && o2.typeOf(loadFun)=="function") loadFun();
  244. },
  245. "onComplete": function(list){
  246. this.rangeSelectedContentNode.empty();
  247. //this.selectedModules = [];
  248. if (list.length){
  249. this.getSelectedRange();
  250. this.rangeContentNode.getElements("input").set("checked", false);
  251. o2.require("o2.widget.O2Identity", function(){
  252. list.each(function(app){
  253. //this.selectedModules.push(app.data);
  254. app.data.name = this.lp.service + "-" + app.data.name;
  255. var item = new o2.widget.O2Other(app.data, this.rangeSelectedContentNode, {"canRemove": true, "style": "find", "onRemove": function(item){this.removeRangeItem(item);}.bind(this)});
  256. item.node.store("data", item.data);
  257. }.bind(this));
  258. }.bind(this));
  259. }else{
  260. this.setSelectedRange();
  261. }
  262. }.bind(this)
  263. });
  264. }.bind(this));
  265. },
  266. getFindOption: function(){
  267. var filterTypes = [];
  268. filterItems = this.filterNode.getElements("input");
  269. filterItems.each(function(item){
  270. if (item.checked) filterTypes.push(item.get("value"));
  271. }.bind(this));
  272. var keyword = this.keywordInputNode.get("value");
  273. var moduleList = [];
  274. var itemNodes = this.rangeSelectedContentNode.getChildren();
  275. if (!itemNodes.length){
  276. this.getSelectedRange();
  277. this.selectedRange.each(function(type){
  278. moduleList.push({"moduleType": type, "flagList": []});
  279. });
  280. }else{
  281. var rangeApp = {};
  282. itemNodes.each(function(node){
  283. var data = node.retrieve("data");
  284. if (!rangeApp[data.moduleType]) rangeApp[data.moduleType] = [];
  285. rangeApp[data.moduleType].push({"id": data.id});
  286. }.bind(this));
  287. Object.keys(rangeApp).each(function(k){
  288. moduleList.push({"moduleType": k, "flagList": rangeApp[k]});
  289. });
  290. }
  291. this.filterOption.keyword = keyword;
  292. this.filterOption.designerTypes = filterTypes;
  293. this.filterOption.moduleList = moduleList;
  294. return this.filterOption;
  295. },
  296. checkFindDesigner: function(e){
  297. if (e.keyCode===13){
  298. this.getFindOption();
  299. if (!this.filterOption.keyword){
  300. this.listInfoNode.show().removeClass("loadding").getFirst().set("text", this.lp.nothingFind_keyword);
  301. return false;
  302. }
  303. if (!this.filterOption.designerTypes.length){
  304. this.listInfoNode.show().removeClass("loadding").getFirst().set("text", this.lp.nothingFind_noFilter);
  305. return false;
  306. }
  307. if (!this.filterOption.moduleList.length){
  308. this.listInfoNode.show().removeClass("loadding").getFirst().set("text", this.lp.nothingFind_noRange);
  309. return false;
  310. }
  311. this.findDesigner();
  312. }
  313. },
  314. getFindWorker: function(){
  315. if (!this.findWorker) this.findWorker = new Worker("../x_component_FindDesigner/FindWorker.js");
  316. this.findWorker.onmessage = function(e) {
  317. if (e.data && e.data.type=="receive") this.setReceiveMessage();
  318. if (e.data && e.data.type=="ready") this.setReadyMessage(e.data);
  319. if (e.data && e.data.type=="done") this.doFindOptionResult(e.data);
  320. if (e.data && e.data.type=="find") this.doFindResult(e.data);
  321. }.bind(this);
  322. },
  323. doFindOptionResult: function(){
  324. // this.listInfoNode.hide();
  325. // this.listContentNode.show();
  326. // moduleNode = this.createResultCategroyItem("xxxx", "", this.tree);
  327. this.findOptionModuleProcessed++;
  328. this.updateFindProgress();
  329. },
  330. doFindResult: function(data){
  331. if (data.data) this.showFindResult(data.data);
  332. },
  333. getResultTree: function(callback){
  334. if (!this.tree){
  335. o2.require("o2.widget.Tree", function(){
  336. this.tree = new o2.widget.Tree(this.listContentNode, {
  337. "style": "findDesigner"
  338. // "onQueryExpand": function(item){
  339. // if (item.designer) this.loadDesignerPattern(item);
  340. // }.bind(this)
  341. });
  342. this.tree.load();
  343. if (callback) callback();
  344. }.bind(this), null, false);
  345. }else{
  346. if (callback) callback();
  347. }
  348. },
  349. createResultCategroyItem: function(text, title, tree){
  350. var obj = {
  351. "title": title,
  352. "text": "<span style='font-weight: bold'>"+text+"</span>",
  353. "icon": ""
  354. }
  355. return tree.appendChild(obj);
  356. },
  357. createResultAppItem: function(text, title, tree){
  358. var obj = {
  359. "title": title,
  360. "text": "<span style='font-weight: bold; color: #0b58a2'>"+text+"</span>",
  361. "icon": ""
  362. }
  363. return tree.appendChild(obj);
  364. },
  365. createResultTypeItem: function(text, title, tree){
  366. var obj = {
  367. "title": title,
  368. "text": "<span>"+text+"</span>",
  369. "icon": ""
  370. }
  371. return tree.appendChild(obj);
  372. },
  373. createResultPatternItem: function(text, title, tree){
  374. var obj = {
  375. "title": title,
  376. "text": "<span style='color: #666666'>"+text+"</span>",
  377. "icon": ""
  378. }
  379. return tree.appendChild(obj);
  380. },
  381. showFindResult: function(data){
  382. if (!this.patternCount) this.patternCount = 0;
  383. this.patternCount++;
  384. var t = this.lp.findPatternCount.replace("{n}", this.patternCount);
  385. this.listTitleInfoNode.set("text", t);
  386. this.listInfoNode.hide();
  387. this.listContentNode.show();
  388. // this.listContentNode.appendHTML("<div>2</div>");
  389. //return "";
  390. //this.getResultTree(function(){
  391. var moduleNode = (this.tree.modules) ? this.tree.modules[data.module] : null;
  392. if (!moduleNode){
  393. moduleNode = this.createResultCategroyItem(this.lp[data.module], this.lp[data.module], this.tree);
  394. if (!this.tree.modules) this.tree.modules = {};
  395. this.tree.modules[data.module] = moduleNode;
  396. }
  397. var appNode = (moduleNode.apps) ? moduleNode.apps[data.appId] : null;
  398. if (!appNode){
  399. appNode = this.createResultAppItem(data.appName, data.appName, moduleNode);
  400. if (!moduleNode.apps) moduleNode.apps = {};
  401. moduleNode.apps[data.appId] = appNode;
  402. }
  403. var typeNode = (appNode.types) ? appNode.types[data.designerType] : null;
  404. if (!typeNode){
  405. typeNode = this.createResultTypeItem(this.lp[data.designerType], this.lp[data.designerType], appNode);
  406. if (!appNode.types) appNode.types = {};
  407. appNode.types[data.designerType] = typeNode;
  408. }
  409. var designerNode = (typeNode.designers) ? typeNode.designers[data.designerId] : null;
  410. if (!designerNode){
  411. designerNode = this.createResultTypeItem(data.designerName, data.designerName, typeNode);
  412. if (!typeNode.designers) typeNode.designers = {};
  413. typeNode.designers[data.designerId] = designerNode;
  414. }
  415. switch (data.designerType){
  416. case "script":
  417. this.createScriptPatternNode(data, designerNode);
  418. break;
  419. case "form":
  420. break;
  421. case "process":
  422. break;
  423. }
  424. //}.bind(this));
  425. },
  426. createScriptPatternNode: function(data, node){
  427. var patternNode;
  428. var text;
  429. if (data.pattern.property=="text"){
  430. text = data.pattern.line+" "+data.pattern.value;
  431. patternNode = this.createResultPatternItem(text, "", node);
  432. }else{
  433. text = "<b>"+data.pattern.property+"</b> "+data.pattern.value;
  434. patternNode = this.createResultPatternItem(text, "", node);
  435. }
  436. },
  437. setReceiveMessage: function(){
  438. this.listTitleInfoNode.set("text", this.lp.receiveToFind);
  439. },
  440. setReadyMessage: function(data){
  441. this.findOptionModuleCount = data.count;
  442. this.findOptionModuleProcessed = 0;
  443. this.updateFindProgress();
  444. this.listTitleInfoNode.set("text", this.lp.readyToFind.replace("{n}", data.count));
  445. },
  446. updateFindProgress: function(){
  447. var percent = (this.findOptionModuleProcessed/this.findOptionModuleCount)*100;
  448. this.listTitleProgressNode.setStyle("width", ""+percent+"%");
  449. },
  450. getActionsUrl:function(){
  451. var processHost = o2.Actions.getHost("x_processplatform_assemble_designer");
  452. var cmsHost = o2.Actions.getHost("x_cms_assemble_control");
  453. var portalHost = o2.Actions.getHost("x_portal_assemble_designer");
  454. var queryHost = o2.Actions.getHost("x_query_assemble_designer");
  455. var serviceHost = o2.Actions.getHost("x_program_center");
  456. var findHost = o2.Actions.getHost("x_query_service_processing");
  457. var actions = {
  458. "listProcess": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/application/list"),
  459. "listProcessProcess": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/process/application/{applicationId}"),
  460. "listProcessForm": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/form/list/application/{applicationId}"),
  461. "listProcessScript": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/script/application/{applicationId}"),
  462. "getProcessProcess": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/process/{id}"),
  463. "getProcessForm": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/form/{id}"),
  464. "getProcessScript": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/script/{id}"),
  465. "listCms": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/appinfo/list/manage"),
  466. "listCmsForm": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/form/list/app/{appId}"),
  467. "listCmsScript": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/script/list/app/{flag}"),
  468. "getCmsForm": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/form/{id}"),
  469. "getCmsScript": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/script/{id}"),
  470. "listPortal": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/portal/list"),
  471. "listPortalPage": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/page/list/portal/{portalId}"),
  472. "listPortalScript": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/script/list/portal/{portalId}"),
  473. "listPortalWidget": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/widget/list/portal/{portalId}"),
  474. "getPortalPage": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/page/{id}"),
  475. "getPortalScript": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/script/{id}"),
  476. "getPortalWidget": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/widget/{id}"),
  477. "listQuery": o2.filterUrl(queryHost+"/x_query_assemble_designer/jaxrs/query/list/summary"),
  478. "listQueryView": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/view/list/query/{flag}"),
  479. "listQueryStat": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/stat/list/query/{flag}"),
  480. "listQueryStatement": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/statement/list/query/{flag}"),
  481. "getQueryView": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/view/{id}"),
  482. "getQueryStat": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/stat/{id}"),
  483. "getQueryStatement": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/statement/{id}"),
  484. "listInvoke": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/invoke"),
  485. "listAgent": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/agent"),
  486. "getInvoke": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/invoke/{flag}"),
  487. "getAgent": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/agent/{flag}"),
  488. "findAction": o2.filterUrl(findHost+"/x_query_service_processing/jaxrs/design/search")
  489. };
  490. return actions;
  491. },
  492. findDesigner: function(){
  493. this.listContentNode.hide();
  494. this.listContentNode.empty();
  495. this.listInfoNode.show().getFirst().set("text", "");
  496. this.listInfoNode.addClass("loadding");
  497. this.patternCount = 0;
  498. this.getFindWorker();
  499. var actions = this.getActionsUrl();
  500. this.tree = null;
  501. this.getResultTree(function(){
  502. var workerMessage = {
  503. actions:actions,
  504. filterOption: this.filterOption,
  505. debug: (window.layout && layout["debugger"]),
  506. token: (window.layout && layout.session && layout.session.user) ? layout.session.user.token : ""
  507. };
  508. this.findWorker.postMessage(workerMessage);
  509. }.bind(this));
  510. },
  511. //------------------------------------------------------------
  512. findDesigner_bak: function(){
  513. this.listContentNode.hide();
  514. this.listInfoNode.show().getFirst().set("text", "");
  515. this.listInfoNode.addClass("loadding")
  516. o2.Actions.load("x_query_service_processing").DesignAction.search(this.filterOption, function(json){
  517. if ((json.data.processPlatformList && json.data.processPlatformList.length) ||
  518. (json.data.cmsList && json.data.cmsList.length) ||
  519. (json.data.portalList && json.data.portalList.length) ||
  520. (json.data.queryList && json.data.queryList.length) ||
  521. (json.data.serviceList && json.data.serviceList.length)){
  522. this.listInfoNode.hide();
  523. this.listFindResult(json.data);
  524. }else{
  525. this.listInfoNode.show().removeClass("loadding").getFirst().set("text", this.lp.nothingFind);
  526. }
  527. }.bind(this));
  528. },
  529. createResultAppItem: function(text, title, tree){
  530. var obj = {
  531. "title": title,
  532. "text": "<span style='font-weight: bold; color: #4A90E2'>"+text+"</span>",
  533. "icon": ""
  534. }
  535. return tree.appendChild(obj);
  536. },
  537. createResultDesignerItem: function(designer, tree){
  538. var title = this.lp[designer.designerType]+ ": "+ designer.designerName + " ("+designer.designerId+")";
  539. var text = this.lp[designer.designerType]+ ": <b>"+ designer.designerName+"</b>";
  540. var obj = {
  541. "expand": false,
  542. "title": title,
  543. "text": text,
  544. "icon": ""
  545. }
  546. var item = tree.appendChild(obj);
  547. item.designer = designer;
  548. item.appendChild({ "expand": false, "text": "loading...", "icon": "" });
  549. return item;
  550. },
  551. listFindResult: function(data){
  552. this.listContentNode.empty();
  553. this.listContentNode.show();
  554. o2.require("o2.widget.Tree", function(){
  555. var tree = new o2.widget.Tree(this.listContentNode, {
  556. "onQueryExpand": function(item){
  557. if (item.designer) this.loadDesignerPattern(item);
  558. }.bind(this)
  559. });
  560. tree.load();
  561. if (data.processPlatformList && data.processPlatformList.length){
  562. var platformItem = this.createResultCategroyItem(this.lp.processPlatform, this.lp.processPlatform, tree);
  563. this.listProcessResult(platformItem, data.processPlatformList, "processPlatform");
  564. }
  565. if (data.cmsList && data.cmsList.length){
  566. var platformItem = this.createResultCategroyItem(this.lp.cms, this.lp.cms, tree);
  567. //this.listProcessResult(categroyItem, data.cmsList);
  568. }
  569. if (data.portalList && data.portalList.length){
  570. var platformItem = this.createResultCategroyItem(this.lp.portal, this.lp.portal, tree);
  571. }
  572. if (data.queryList && data.queryList.length){
  573. var platformItem = this.createResultCategroyItem(this.lp.query, this.lp.query, tree);
  574. }
  575. if (data.serviceList && data.serviceList.length){
  576. var platformItem = this.createResultCategroyItem(this.lp.service, this.lp.service, tree);
  577. }
  578. }.bind(this));
  579. },
  580. addPatternCount: function(item, count){
  581. if (!item.count) item.count = 0;
  582. item.count += count;
  583. var t = this.lp.patternCount.replace("{n}", item.count);
  584. var textDivNode = item.textNode.getElement("div");
  585. if (textDivNode){
  586. var html = item.options.text;
  587. textDivNode.set("html", html+" <span style=''>( "+t+" )</span>");
  588. }
  589. },
  590. listProcessResult: function(platformItem, list, platform){
  591. var applicationItems = {};
  592. list.each(function(designer){
  593. if (designer.patternList && designer.patternList.length){
  594. var appItem = applicationItems[designer.appId];
  595. if (!appItem){
  596. applicationItems[designer.appId] = appItem = this.createResultAppItem(designer.appName, designer.appName+" ("+designer.appId+")", platformItem);
  597. }
  598. designer.platform = platform;
  599. var designerItem = this.createResultDesignerItem(designer, appItem);
  600. var count=0;
  601. designer.patternList.each(function(p){
  602. if (p.lines && p.lines.length){
  603. count += p.lines.length;
  604. }else{
  605. count++;
  606. }
  607. });
  608. // var count = designer.patternList.length;
  609. this.addPatternCount(designerItem, count);
  610. this.addPatternCount(appItem, count);
  611. this.addPatternCount(platformItem, count);
  612. }
  613. }.bind(this));
  614. },
  615. getDesignerObject: function(designer){
  616. switch (designer.platform){
  617. case "processPlatform":
  618. var action = this.Actions.load("x_processplatform_assemble_designer");
  619. switch (designer.designerType){
  620. case "script":
  621. return action.ScriptAction.get(designer.designerId, function(json){return json.data;});
  622. case "form":
  623. return action.FomrAction.get(designer.designerId, function(json){return json.data;});
  624. case "process":
  625. return action.ProcessAction.get(designer.designerId, function(json){return json.data;});
  626. }
  627. case "cms":
  628. var action = this.Actions.load("x_cms_assemble_control");
  629. switch (designer.designerType){
  630. case "script":
  631. return action.ScriptAction.get(designer.designerId, function(json){return json.data;});
  632. case "form":
  633. return action.FormAction.get(designer.designerId, function(json){return json.data;});
  634. }
  635. case "portal":
  636. var action = this.Actions.load("x_portal_assemble_designer");
  637. switch (designer.designerType){
  638. case "script":
  639. return action.ScriptAction.get(designer.designerId, function(json){return json.data;});
  640. case "page":
  641. return action.PageAction.get(designer.designerId, function(json){return json.data;});
  642. case "widget":
  643. return action.WidgetAction.get(designer.designerId, function(json){return json.data;});
  644. }
  645. case "query":
  646. var action = this.Actions.load("x_query_assemble_designer");
  647. switch (designer.designerType){
  648. case "view":
  649. return action.ViewAction.get(designer.designerId, function(json){return json.data;});
  650. case "statement":
  651. return action.StatementAction.get(designer.designerId, function(json){return json.data;});
  652. case "stat":
  653. return action.StatAction.get(designer.designerId, function(json){return json.data;});
  654. }
  655. case "service":
  656. var action = this.Actions.load("x_program_center");
  657. switch (designer.appId){
  658. case "invoke":
  659. return action.InvokeAction.get(designer.designerId, function(json){return json.data;});
  660. case "agent":
  661. return action.AgentAction.get(designer.designerId, function(json){return json.data;});
  662. }
  663. }
  664. },
  665. loadDesignerPattern: function(item){
  666. if (item.firstChild && item.firstChild.options.text==="loading..."){
  667. item.firstChild.destroy();
  668. var root, actionName, fun;
  669. switch (designer.platform) {
  670. case "processPlatform":
  671. root = "x_processplatform_assemble_designer";
  672. switch (designer.designerType) {
  673. case "script": actionName = "ScriptAction"; fun = "listProcessScriptPattern";
  674. case "form": actionName = "FomrAction"; fun = "listProcessFormPattern";
  675. case "process": actionName = "ProcessAction"; fun = "listProcessProcessPattern";
  676. }
  677. case "cms":
  678. root = "x_cms_assemble_control";
  679. switch (designer.designerType) {
  680. case "script": actionName = "ScriptAction"; fun = "listCmsScriptPattern";
  681. case "form": actionName = "FormAction"; fun = "listCmsFormPattern";
  682. }
  683. case "portal":
  684. root = "x_portal_assemble_designer";
  685. switch (designer.designerType) {
  686. case "script": actionName = "ScriptAction"; fun = "listPortalScriptPattern";
  687. case "page": actionName = "PageAction"; fun = "listPortalPagePattern";
  688. case "widget": actionName = "WidgetAction"; fun = "listPortalWidgetPattern";
  689. }
  690. case "query":
  691. root = "x_query_assemble_designer";
  692. switch (designer.designerType) {
  693. case "view": actionName = "ViewAction"; fun = "listQueryViewPattern";
  694. case "statement": actionName = "StatementAction"; fun = "listQueryStatementPattern";
  695. case "stat": actionName = "StatAction"; fun = "listQueryStatPattern";
  696. }
  697. case "service":
  698. root = "x_program_center";
  699. switch (designer.appId) {
  700. case "invoke": actionName = "InvokeAction"; fun = "listServiceInvokePattern";
  701. case "agent": actionName = "AgentAction"; fun = "listServiceAgentPattern";
  702. }
  703. }
  704. this.Actions.load(root)[actionName].get(designer.designerId, function(json){
  705. this[fun](json.data, designer.patternList, item);
  706. }.bind(this))
  707. }
  708. },
  709. getFindRegExp: function(){
  710. var flag = "gm";
  711. var keyword = this.filterOption.keyword;
  712. if (!this.filterOption.caseSensitive) flag+="i";
  713. if (this.filterOption.matchRegExp){
  714. return new RegExp(keyword, flag)
  715. }else{
  716. if (this.filterOption.matchWholeWord) keyword = "\\b"+keyword+"\\b";
  717. return new RegExp(keyword, flag)
  718. }
  719. },
  720. //启动一个webworker处理
  721. listProcessScriptPattern: function (data, patternList, item){
  722. patternList.each(function(pattern){
  723. if (pattern.property == "text"){
  724. var textArr = data.split("\n");
  725. var regex = this.getFindRegExp();
  726. pattern.lines.each(function(line){
  727. var text = textArr[line];
  728. }.bind(this));
  729. }else{
  730. }
  731. }.bind(this));
  732. }
  733. });