Main.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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. debugger
  332. if (data.data) this.showFindResult(data.data, data.option);
  333. },
  334. getResultTree: function(callback){
  335. if (!this.tree){
  336. o2.require("o2.widget.Tree", function(){
  337. this.tree = new o2.widget.Tree(this.listContentNode, {
  338. "style": "findDesigner"
  339. // "onQueryExpand": function(item){
  340. // if (item.designer) this.loadDesignerPattern(item);
  341. // }.bind(this)
  342. });
  343. this.tree.load();
  344. if (callback) callback();
  345. }.bind(this), null, false);
  346. }else{
  347. if (callback) callback();
  348. }
  349. },
  350. createResultCategroyItem: function(text, title, tree){
  351. var obj = {
  352. "title": title,
  353. "text": "<span style='font-weight: bold'>"+text+"</span>",
  354. "icon": ""
  355. }
  356. return tree.appendChild(obj);
  357. },
  358. createResultAppItem: function(text, title, tree){
  359. var obj = {
  360. "title": title,
  361. "text": "<span style='font-weight: bold; color: #0b58a2'>"+text+"</span>",
  362. "icon": ""
  363. }
  364. return tree.appendChild(obj);
  365. },
  366. createResultTypeItem: function(text, title, tree){
  367. var obj = {
  368. "title": title,
  369. "text": "<span>"+text+"</span>",
  370. "icon": ""
  371. }
  372. return tree.appendChild(obj);
  373. },
  374. createResultDesignerItem: function(text, title, tree){
  375. var obj = {
  376. "expand": false,
  377. "title": title,
  378. "text": "<span>"+text+"</span>",
  379. "icon": ""
  380. }
  381. return tree.appendChild(obj);
  382. },
  383. createResultPatternItem: function(text, title, tree){
  384. var obj = {
  385. "title": title,
  386. "text": "<span style='color: #000000'>"+text+"</span>",
  387. "icon": ""
  388. }
  389. return tree.appendChild(obj);
  390. },
  391. updatePatternCount: function(node){
  392. node.patternCount++;
  393. var textDivNode = node.textNode.getElement("div");
  394. if (textDivNode){
  395. var text = this.lp.patternCount.replace("{n}", node.patternCount)
  396. var t = node.options.text+"&nbsp;&nbsp;<span style='color: #666666'>("+text+")</span>>";
  397. //var html = item.options.text;
  398. textDivNode.set("html", t);
  399. }
  400. },
  401. showFindResult: function(data,option){
  402. if (!this.patternCount) this.patternCount = 0;
  403. this.patternCount++;
  404. var t = this.lp.findPatternCount.replace("{n}", this.patternCount);
  405. this.listTitleInfoNode.set("text", t);
  406. this.listInfoNode.hide();
  407. this.listContentNode.show();
  408. var regexp = this.getFilterOptionRegex(option);
  409. var moduleNode = (this.tree.modules) ? this.tree.modules[data.module] : null;
  410. if (!moduleNode){
  411. moduleNode = this.createResultCategroyItem(this.lp[data.module], this.lp[data.module], this.tree);
  412. moduleNode.patternCount = 0;
  413. if (!this.tree.modules) this.tree.modules = {};
  414. this.tree.modules[data.module] = moduleNode;
  415. }
  416. this.updatePatternCount(moduleNode);
  417. var appNode = (moduleNode.apps) ? moduleNode.apps[data.appId] : null;
  418. if (!appNode){
  419. appNode = this.createResultAppItem(data.appName, data.appName, moduleNode);
  420. appNode.patternCount = 0;
  421. if (!moduleNode.apps) moduleNode.apps = {};
  422. moduleNode.apps[data.appId] = appNode;
  423. }
  424. this.updatePatternCount(appNode);
  425. var typeNode = (appNode.types) ? appNode.types[data.designerType] : null;
  426. if (!typeNode){
  427. typeNode = this.createResultTypeItem(this.lp[data.designerType], this.lp[data.designerType], appNode);
  428. typeNode.patternCount = 0;
  429. if (!appNode.types) appNode.types = {};
  430. appNode.types[data.designerType] = typeNode;
  431. }
  432. this.updatePatternCount(typeNode);
  433. var designerNode = (typeNode.designers) ? typeNode.designers[data.designerId] : null;
  434. if (!designerNode){
  435. designerNode = this.createResultDesignerItem(data.designerName, data.designerName, typeNode);
  436. designerNode.patternCount = 0;
  437. if (!typeNode.designers) typeNode.designers = {};
  438. typeNode.designers[data.designerId] = designerNode;
  439. }
  440. this.updatePatternCount(designerNode);
  441. switch (data.designerType){
  442. case "script":
  443. this.createScriptPatternNode(data, designerNode, regexp);
  444. break;
  445. case "form":
  446. break;
  447. case "process":
  448. break;
  449. }
  450. //}.bind(this));
  451. },
  452. getPatternValue: function(value, regexp){
  453. regexp.lastIndex = 0;
  454. var valueHtml = "";
  455. var idx = 0;
  456. while ((arr = regexp.exec(value)) !== null) {
  457. valueHtml += o2.common.encodeHtml(value.substring(idx, arr.index));
  458. valueHtml += "<span style='background-color: #ffef8f'>"+o2.common.encodeHtml(value.substring(arr.index, regexp.lastIndex))+"</span>";
  459. idx = regexp.lastIndex;
  460. }
  461. valueHtml += o2.common.encodeHtml(value.substring(idx, value.length));
  462. return valueHtml;
  463. },
  464. // getPatternScriptValue: function(pattern, regexp){
  465. // regexp.lastIndex = 0;
  466. // var valueHtml = "";
  467. //
  468. // valueHtml += pattern.value.substring(0, pattern.column);
  469. // valueHtml += "<span style='background-color: #ffef8f'><b>"+pattern.value.substring(pattern.column, pattern.column+pattern.key.length)+"</b></span>";
  470. // valueHtml += pattern.value.substring(pattern.column+pattern.key.length, pattern.value.length);
  471. //
  472. // return valueHtml;
  473. // },
  474. createScriptPatternNode: function(data, node, regexp){
  475. debugger;
  476. var patternNode;
  477. var text;
  478. if (data.pattern.property=="text"){
  479. text = "<span style='color: #666666'>"+data.pattern.line+"</span>&nbsp;&nbsp;"+this.getPatternValue(data.pattern.value, regexp);
  480. patternNode = this.createResultPatternItem(text, "", node);
  481. }else{
  482. text = this.lp.property+":&nbsp;<b>"+data.pattern.property+"</b> "+this.lp.value+":&nbsp;"+this.getPatternValue(data.pattern.value, regexp);
  483. patternNode = this.createResultPatternItem(text, "", node);
  484. }
  485. },
  486. getFilterOptionRegex: function(option){
  487. var keyword = option.keyword;
  488. if (option.matchRegExp){
  489. var flag = (option.caseSensitive) ? "g" : "gi";
  490. return new RegExp(keyword, flag);
  491. }else{
  492. var flag = (option.caseSensitive) ? "g" : "gi";
  493. keyword = (option.matchWholeWord) ? "\\b"+keyword+"\\b" : keyword;
  494. return new RegExp(keyword, flag);
  495. }
  496. },
  497. setReceiveMessage: function(){
  498. this.listTitleInfoNode.set("text", this.lp.receiveToFind);
  499. },
  500. setReadyMessage: function(data){
  501. this.findOptionModuleCount = data.count;
  502. this.findOptionModuleProcessed = 0;
  503. this.updateFindProgress();
  504. this.listTitleInfoNode.set("text", this.lp.readyToFind.replace("{n}", data.count));
  505. },
  506. updateFindProgress: function(){
  507. var percent = (this.findOptionModuleProcessed/this.findOptionModuleCount)*100;
  508. this.listTitleProgressNode.setStyle("width", ""+percent+"%");
  509. },
  510. getActionsUrl:function(){
  511. var processHost = o2.Actions.getHost("x_processplatform_assemble_designer");
  512. var cmsHost = o2.Actions.getHost("x_cms_assemble_control");
  513. var portalHost = o2.Actions.getHost("x_portal_assemble_designer");
  514. var queryHost = o2.Actions.getHost("x_query_assemble_designer");
  515. var serviceHost = o2.Actions.getHost("x_program_center");
  516. var findHost = o2.Actions.getHost("x_query_service_processing");
  517. var actions = {
  518. "listProcess": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/application/list"),
  519. "listProcessProcess": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/process/application/{applicationId}"),
  520. "listProcessForm": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/form/list/application/{applicationId}"),
  521. "listProcessScript": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/script/application/{applicationId}"),
  522. "getProcessProcess": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/process/{id}"),
  523. "getProcessForm": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/form/{id}"),
  524. "getProcessScript": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/script/{id}"),
  525. "listCms": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/appinfo/list/manage"),
  526. "listCmsForm": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/form/list/app/{appId}"),
  527. "listCmsScript": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/script/list/app/{flag}"),
  528. "getCmsForm": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/form/{id}"),
  529. "getCmsScript": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/script/{id}"),
  530. "listPortal": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/portal/list"),
  531. "listPortalPage": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/page/list/portal/{portalId}"),
  532. "listPortalScript": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/script/list/portal/{portalId}"),
  533. "listPortalWidget": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/widget/list/portal/{portalId}"),
  534. "getPortalPage": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/page/{id}"),
  535. "getPortalScript": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/script/{id}"),
  536. "getPortalWidget": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/widget/{id}"),
  537. "listQuery": o2.filterUrl(queryHost+"/x_query_assemble_designer/jaxrs/query/list/summary"),
  538. "listQueryView": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/view/list/query/{flag}"),
  539. "listQueryStat": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/stat/list/query/{flag}"),
  540. "listQueryStatement": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/statement/list/query/{flag}"),
  541. "getQueryView": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/view/{id}"),
  542. "getQueryStat": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/stat/{id}"),
  543. "getQueryStatement": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/statement/{id}"),
  544. "listInvoke": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/invoke"),
  545. "listAgent": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/agent"),
  546. "getInvoke": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/invoke/{flag}"),
  547. "getAgent": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/agent/{flag}"),
  548. "findAction": o2.filterUrl(findHost+"/x_query_service_processing/jaxrs/design/search")
  549. };
  550. return actions;
  551. },
  552. findDesigner: function(){
  553. this.listContentNode.hide();
  554. this.listContentNode.empty();
  555. this.listInfoNode.show().getFirst().set("text", "");
  556. this.listInfoNode.addClass("loadding");
  557. this.patternCount = 0;
  558. this.getFindWorker();
  559. var actions = this.getActionsUrl();
  560. this.tree = null;
  561. this.getResultTree(function(){
  562. var workerMessage = {
  563. actions:actions,
  564. filterOption: this.filterOption,
  565. debug: (window.layout && layout["debugger"]),
  566. token: (window.layout && layout.session && layout.session.user) ? layout.session.user.token : ""
  567. };
  568. this.findWorker.postMessage(workerMessage);
  569. }.bind(this));
  570. },
  571. //------------------------------------------------------------
  572. findDesigner_bak: function(){
  573. this.listContentNode.hide();
  574. this.listInfoNode.show().getFirst().set("text", "");
  575. this.listInfoNode.addClass("loadding")
  576. o2.Actions.load("x_query_service_processing").DesignAction.search(this.filterOption, function(json){
  577. if ((json.data.processPlatformList && json.data.processPlatformList.length) ||
  578. (json.data.cmsList && json.data.cmsList.length) ||
  579. (json.data.portalList && json.data.portalList.length) ||
  580. (json.data.queryList && json.data.queryList.length) ||
  581. (json.data.serviceList && json.data.serviceList.length)){
  582. this.listInfoNode.hide();
  583. this.listFindResult(json.data);
  584. }else{
  585. this.listInfoNode.show().removeClass("loadding").getFirst().set("text", this.lp.nothingFind);
  586. }
  587. }.bind(this));
  588. },
  589. createResultAppItem: function(text, title, tree){
  590. var obj = {
  591. "title": title,
  592. "text": "<span style='font-weight: bold; color: #4A90E2'>"+text+"</span>",
  593. "icon": ""
  594. }
  595. return tree.appendChild(obj);
  596. },
  597. // createResultDesignerItem: function(designer, tree){
  598. // var title = this.lp[designer.designerType]+ ": "+ designer.designerName + " ("+designer.designerId+")";
  599. // var text = this.lp[designer.designerType]+ ": <b>"+ designer.designerName+"</b>";
  600. // var obj = {
  601. // "expand": false,
  602. // "title": title,
  603. // "text": text,
  604. // "icon": ""
  605. // }
  606. // var item = tree.appendChild(obj);
  607. // item.designer = designer;
  608. // item.appendChild({ "expand": false, "text": "loading...", "icon": "" });
  609. // return item;
  610. // },
  611. listFindResult: function(data){
  612. this.listContentNode.empty();
  613. this.listContentNode.show();
  614. o2.require("o2.widget.Tree", function(){
  615. var tree = new o2.widget.Tree(this.listContentNode, {
  616. "onQueryExpand": function(item){
  617. if (item.designer) this.loadDesignerPattern(item);
  618. }.bind(this)
  619. });
  620. tree.load();
  621. if (data.processPlatformList && data.processPlatformList.length){
  622. var platformItem = this.createResultCategroyItem(this.lp.processPlatform, this.lp.processPlatform, tree);
  623. this.listProcessResult(platformItem, data.processPlatformList, "processPlatform");
  624. }
  625. if (data.cmsList && data.cmsList.length){
  626. var platformItem = this.createResultCategroyItem(this.lp.cms, this.lp.cms, tree);
  627. //this.listProcessResult(categroyItem, data.cmsList);
  628. }
  629. if (data.portalList && data.portalList.length){
  630. var platformItem = this.createResultCategroyItem(this.lp.portal, this.lp.portal, tree);
  631. }
  632. if (data.queryList && data.queryList.length){
  633. var platformItem = this.createResultCategroyItem(this.lp.query, this.lp.query, tree);
  634. }
  635. if (data.serviceList && data.serviceList.length){
  636. var platformItem = this.createResultCategroyItem(this.lp.service, this.lp.service, tree);
  637. }
  638. }.bind(this));
  639. },
  640. addPatternCount: function(item, count){
  641. if (!item.count) item.count = 0;
  642. item.count += count;
  643. var t = this.lp.patternCount.replace("{n}", item.count);
  644. var textDivNode = item.textNode.getElement("div");
  645. if (textDivNode){
  646. var html = item.options.text;
  647. textDivNode.set("html", html+" <span style=''>( "+t+" )</span>");
  648. }
  649. },
  650. listProcessResult: function(platformItem, list, platform){
  651. var applicationItems = {};
  652. list.each(function(designer){
  653. if (designer.patternList && designer.patternList.length){
  654. var appItem = applicationItems[designer.appId];
  655. if (!appItem){
  656. applicationItems[designer.appId] = appItem = this.createResultAppItem(designer.appName, designer.appName+" ("+designer.appId+")", platformItem);
  657. }
  658. designer.platform = platform;
  659. var designerItem = this.createResultDesignerItem(designer, appItem);
  660. var count=0;
  661. designer.patternList.each(function(p){
  662. if (p.lines && p.lines.length){
  663. count += p.lines.length;
  664. }else{
  665. count++;
  666. }
  667. });
  668. // var count = designer.patternList.length;
  669. this.addPatternCount(designerItem, count);
  670. this.addPatternCount(appItem, count);
  671. this.addPatternCount(platformItem, count);
  672. }
  673. }.bind(this));
  674. },
  675. getDesignerObject: function(designer){
  676. switch (designer.platform){
  677. case "processPlatform":
  678. var action = this.Actions.load("x_processplatform_assemble_designer");
  679. switch (designer.designerType){
  680. case "script":
  681. return action.ScriptAction.get(designer.designerId, function(json){return json.data;});
  682. case "form":
  683. return action.FomrAction.get(designer.designerId, function(json){return json.data;});
  684. case "process":
  685. return action.ProcessAction.get(designer.designerId, function(json){return json.data;});
  686. }
  687. case "cms":
  688. var action = this.Actions.load("x_cms_assemble_control");
  689. switch (designer.designerType){
  690. case "script":
  691. return action.ScriptAction.get(designer.designerId, function(json){return json.data;});
  692. case "form":
  693. return action.FormAction.get(designer.designerId, function(json){return json.data;});
  694. }
  695. case "portal":
  696. var action = this.Actions.load("x_portal_assemble_designer");
  697. switch (designer.designerType){
  698. case "script":
  699. return action.ScriptAction.get(designer.designerId, function(json){return json.data;});
  700. case "page":
  701. return action.PageAction.get(designer.designerId, function(json){return json.data;});
  702. case "widget":
  703. return action.WidgetAction.get(designer.designerId, function(json){return json.data;});
  704. }
  705. case "query":
  706. var action = this.Actions.load("x_query_assemble_designer");
  707. switch (designer.designerType){
  708. case "view":
  709. return action.ViewAction.get(designer.designerId, function(json){return json.data;});
  710. case "statement":
  711. return action.StatementAction.get(designer.designerId, function(json){return json.data;});
  712. case "stat":
  713. return action.StatAction.get(designer.designerId, function(json){return json.data;});
  714. }
  715. case "service":
  716. var action = this.Actions.load("x_program_center");
  717. switch (designer.appId){
  718. case "invoke":
  719. return action.InvokeAction.get(designer.designerId, function(json){return json.data;});
  720. case "agent":
  721. return action.AgentAction.get(designer.designerId, function(json){return json.data;});
  722. }
  723. }
  724. },
  725. loadDesignerPattern: function(item){
  726. if (item.firstChild && item.firstChild.options.text==="loading..."){
  727. item.firstChild.destroy();
  728. var root, actionName, fun;
  729. switch (designer.platform) {
  730. case "processPlatform":
  731. root = "x_processplatform_assemble_designer";
  732. switch (designer.designerType) {
  733. case "script": actionName = "ScriptAction"; fun = "listProcessScriptPattern";
  734. case "form": actionName = "FomrAction"; fun = "listProcessFormPattern";
  735. case "process": actionName = "ProcessAction"; fun = "listProcessProcessPattern";
  736. }
  737. case "cms":
  738. root = "x_cms_assemble_control";
  739. switch (designer.designerType) {
  740. case "script": actionName = "ScriptAction"; fun = "listCmsScriptPattern";
  741. case "form": actionName = "FormAction"; fun = "listCmsFormPattern";
  742. }
  743. case "portal":
  744. root = "x_portal_assemble_designer";
  745. switch (designer.designerType) {
  746. case "script": actionName = "ScriptAction"; fun = "listPortalScriptPattern";
  747. case "page": actionName = "PageAction"; fun = "listPortalPagePattern";
  748. case "widget": actionName = "WidgetAction"; fun = "listPortalWidgetPattern";
  749. }
  750. case "query":
  751. root = "x_query_assemble_designer";
  752. switch (designer.designerType) {
  753. case "view": actionName = "ViewAction"; fun = "listQueryViewPattern";
  754. case "statement": actionName = "StatementAction"; fun = "listQueryStatementPattern";
  755. case "stat": actionName = "StatAction"; fun = "listQueryStatPattern";
  756. }
  757. case "service":
  758. root = "x_program_center";
  759. switch (designer.appId) {
  760. case "invoke": actionName = "InvokeAction"; fun = "listServiceInvokePattern";
  761. case "agent": actionName = "AgentAction"; fun = "listServiceAgentPattern";
  762. }
  763. }
  764. this.Actions.load(root)[actionName].get(designer.designerId, function(json){
  765. this[fun](json.data, designer.patternList, item);
  766. }.bind(this))
  767. }
  768. },
  769. getFindRegExp: function(){
  770. var flag = "gm";
  771. var keyword = this.filterOption.keyword;
  772. if (!this.filterOption.caseSensitive) flag+="i";
  773. if (this.filterOption.matchRegExp){
  774. return new RegExp(keyword, flag)
  775. }else{
  776. if (this.filterOption.matchWholeWord) keyword = "\\b"+keyword+"\\b";
  777. return new RegExp(keyword, flag)
  778. }
  779. },
  780. //启动一个webworker处理
  781. listProcessScriptPattern: function (data, patternList, item){
  782. patternList.each(function(pattern){
  783. if (pattern.property == "text"){
  784. var textArr = data.split("\n");
  785. var regex = this.getFindRegExp();
  786. pattern.lines.each(function(line){
  787. var text = textArr[line];
  788. }.bind(this));
  789. }else{
  790. }
  791. }.bind(this));
  792. }
  793. });