Main.js 32 KB

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