Main.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  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. if (this.editor) this.editor.resize();
  117. }.bind(this),
  118. "onComplete": function(){
  119. o2.UD.putData("findDesignerLayout", {"layout": this.options.layout});
  120. }.bind(this)
  121. });
  122. }
  123. },
  124. setResizeNode_leftRight: function(){
  125. if (this.previewSeparatorNode){
  126. this.resizeDrag = new Drag(this.previewSeparatorNode, {
  127. "onStart": function(el, e){
  128. el.store("position", o2.eventPosition(e));
  129. el.store("initialSize", this.listNode.getSize());
  130. }.bind(this),
  131. "onDrag": function(el, e){
  132. var p = o2.eventPosition(e);
  133. var position = el.retrieve("position");
  134. var initialSize = el.retrieve("initialSize");
  135. var dx = position.x.toFloat()-p.x.toFloat();
  136. var width = initialSize.x-dx;
  137. var size = this.resultNode.getSize();
  138. this.options.layout.percent = width/size.x;
  139. if (this.options.layout.percent<0.1) this.options.layout.percent = 0.1;
  140. if (this.options.layout.percent>0.85) this.options.layout.percent = 0.85;
  141. this.sizeNode_leftRight();
  142. if (this.editor) this.editor.resize();
  143. }.bind(this),
  144. "onComplete": function(){
  145. o2.UD.putData("findDesignerLayout", {"layout": this.options.layout});
  146. }.bind(this)
  147. });
  148. }
  149. },
  150. checkFilter: function(e){
  151. if (e.target.hasClass("filterNode_item")) e.target.getElement("input").click();
  152. e.stopPropagation();
  153. },
  154. checkRange: function(e){
  155. if (e.target.hasClass("rangeType_Item")) e.target.getElement("input").click();
  156. e.stopPropagation();
  157. },
  158. overKeywordOption: function(e){
  159. if (e.target.hasClass("o2_findDesigner_keywordNode_optionItem")){
  160. if (!e.target.hasClass("optionItem_over")) e.target.addClass("optionItem_over");
  161. }
  162. },
  163. outKeywordOption: function(e){
  164. if (e.target.hasClass("o2_findDesigner_keywordNode_optionItem")) e.target.removeClass("optionItem_over");
  165. },
  166. setCaseSensitive: function(e){
  167. this.filterOption.caseSensitive = !this.filterOption.caseSensitive;
  168. this.caseSensitiveNode.removeClass("caseSensitiveNode_"+!this.filterOption.caseSensitive);
  169. this.caseSensitiveNode.addClass("caseSensitiveNode_"+this.filterOption.caseSensitive);
  170. },
  171. setMatchWholeWord: function(e){
  172. this.filterOption.matchWholeWord = !this.filterOption.matchWholeWord;
  173. this.matchWholeWordNode.removeClass("matchWholeWordNode_"+!this.filterOption.matchWholeWord);
  174. this.matchWholeWordNode.addClass("matchWholeWordNode_"+this.filterOption.matchWholeWord);
  175. },
  176. setMatchRegExp: function(e){
  177. this.filterOption.matchRegExp = !this.filterOption.matchRegExp;
  178. this.matchRegExpNode.removeClass("matchRegExpNode_"+!this.filterOption.matchRegExp);
  179. this.matchRegExpNode.addClass("matchRegExpNode_"+this.filterOption.matchRegExp);
  180. },
  181. layoutAddClass: function(flag){
  182. flag = flag || "";
  183. this.listNode.addClass("listNode"+flag);
  184. this.previewNode.addClass("previewNode"+flag);
  185. this.previewSeparatorNode.addClass("previewNode_separator"+flag);
  186. this.previewTitleNode.addClass("previewNode_title"+flag);
  187. this.previewTitleActionNode.addClass("previewNode_title_action"+flag);
  188. this.previewContentNode.addClass("previewNode_content"+flag);
  189. },
  190. layoutRemoveClass: function(flag){
  191. flag = flag || "";
  192. this.listNode.removeClass("listNode"+flag);
  193. this.previewNode.removeClass("previewNode"+flag);
  194. this.previewSeparatorNode.removeClass("previewNode_separator"+flag);
  195. this.previewTitleNode.removeClass("previewNode_title"+flag);
  196. this.previewTitleActionNode.removeClass("previewNode_title_action"+flag);
  197. this.previewContentNode.removeClass("previewNode_content"+flag);
  198. },
  199. toLeftRight: function(){
  200. this.layoutAddClass("_lr");
  201. this.layoutRemoveClass();
  202. this.options.layout.type="leftRight";
  203. },
  204. toTopBottom: function(){
  205. this.layoutAddClass();
  206. this.layoutRemoveClass("_lr");
  207. this.options.layout.type="topBottom";
  208. },
  209. changeLayout: function(){
  210. if (this.options.layout.type=="leftRight"){
  211. this.options.layout.type="topBottom";
  212. }else{
  213. this.options.layout.type="leftRight";
  214. }
  215. this.setSizeNode();
  216. o2.UD.putData("findDesignerLayout", {"layout": this.options.layout});
  217. },
  218. getSelectedRange: function(){
  219. this.selectedRange = [];
  220. var rangeInputs = this.rangeContentNode.getElements("input");
  221. rangeInputs.each(function(input){
  222. if (input.checked) this.selectedRange.push(input.get("value"));
  223. }.bind(this));
  224. },
  225. setSelectedRange: function(){
  226. if (this.selectedRange && this.selectedRange.length){
  227. var rangeInputs = this.rangeContentNode.getElements("input");
  228. rangeInputs.each(function(input){
  229. if (this.selectedRange.indexOf(input.get("value"))!=-1) input.set("checked", true);
  230. }.bind(this));
  231. }
  232. },
  233. removeRangeItem: function(item){
  234. item.destroy();
  235. var itemNodes = this.rangeSelectedContentNode.getChildren();
  236. if (!itemNodes.length) this.setSelectedRange();
  237. },
  238. selectFindRange: function(loadFun){
  239. o2.requireApp("Selector", "package", function(){
  240. new o2.O2Selector(this.content, {
  241. "values": this.selectedModules,
  242. "type": "PlatApp",
  243. "selectAllEnable": true,
  244. "onLoad": function(){
  245. if (loadFun && o2.typeOf(loadFun)=="function") loadFun();
  246. },
  247. "onComplete": function(list){
  248. this.rangeSelectedContentNode.empty();
  249. //this.selectedModules = [];
  250. if (list.length){
  251. this.getSelectedRange();
  252. this.rangeContentNode.getElements("input").set("checked", false);
  253. o2.require("o2.widget.O2Identity", function(){
  254. list.each(function(app){
  255. //this.selectedModules.push(app.data);
  256. app.data.name = this.lp.service + "-" + app.data.name;
  257. var item = new o2.widget.O2Other(app.data, this.rangeSelectedContentNode, {"canRemove": true, "style": "find", "onRemove": function(item){this.removeRangeItem(item);}.bind(this)});
  258. item.node.store("data", item.data);
  259. }.bind(this));
  260. }.bind(this));
  261. }else{
  262. this.setSelectedRange();
  263. }
  264. }.bind(this)
  265. });
  266. }.bind(this));
  267. },
  268. getFindOption: function(){
  269. var filterTypes = [];
  270. filterItems = this.filterNode.getElements("input");
  271. filterItems.each(function(item){
  272. if (item.checked) filterTypes.push(item.get("value"));
  273. }.bind(this));
  274. var keyword = this.keywordInputNode.get("value");
  275. var moduleList = [];
  276. var itemNodes = this.rangeSelectedContentNode.getChildren();
  277. if (!itemNodes.length){
  278. this.getSelectedRange();
  279. this.selectedRange.each(function(type){
  280. moduleList.push({"moduleType": type, "flagList": []});
  281. });
  282. }else{
  283. var rangeApp = {};
  284. itemNodes.each(function(node){
  285. var data = node.retrieve("data");
  286. if (!rangeApp[data.moduleType]) rangeApp[data.moduleType] = [];
  287. rangeApp[data.moduleType].push({"id": data.id});
  288. }.bind(this));
  289. Object.keys(rangeApp).each(function(k){
  290. moduleList.push({"moduleType": k, "flagList": rangeApp[k]});
  291. });
  292. }
  293. this.filterOption.keyword = keyword;
  294. this.filterOption.designerTypes = filterTypes;
  295. this.filterOption.moduleList = moduleList;
  296. return this.filterOption;
  297. },
  298. checkFindDesigner: function(e){
  299. if (e.keyCode===13){
  300. this.getFindOption();
  301. if (!this.filterOption.keyword){
  302. this.listInfoNode.show().removeClass("loadding").getFirst().set("text", this.lp.nothingFind_keyword);
  303. return false;
  304. }
  305. if (!this.filterOption.designerTypes.length){
  306. this.listInfoNode.show().removeClass("loadding").getFirst().set("text", this.lp.nothingFind_noFilter);
  307. return false;
  308. }
  309. if (!this.filterOption.moduleList.length){
  310. this.listInfoNode.show().removeClass("loadding").getFirst().set("text", this.lp.nothingFind_noRange);
  311. return false;
  312. }
  313. this.findDesigner();
  314. }
  315. },
  316. getFindWorker: function(){
  317. if (!this.findWorker) this.findWorker = new Worker("../x_component_FindDesigner/FindWorker.js");
  318. this.findWorker.onmessage = function(e) {
  319. if (e.data && e.data.type=="receive") this.setReceiveMessage();
  320. if (e.data && e.data.type=="ready") this.setReadyMessage(e.data);
  321. if (e.data && e.data.type=="done") this.doFindOptionResult(e.data);
  322. if (e.data && e.data.type=="find") this.doFindResult(e.data);
  323. }.bind(this);
  324. },
  325. doFindOptionResult: function(){
  326. // this.listInfoNode.hide();
  327. // this.listContentNode.show();
  328. // moduleNode = this.createResultCategroyItem("xxxx", "", this.tree);
  329. this.findOptionModuleProcessed++;
  330. this.updateFindProgress();
  331. },
  332. doFindResult: function(data){
  333. debugger
  334. if (data.data) this.showFindResult(data.data, data.option);
  335. },
  336. getResultTree: function(callback){
  337. if (!this.tree){
  338. o2.require("o2.widget.Tree", function(){
  339. this.tree = new o2.widget.Tree(this.listContentNode, {
  340. "style": "findDesigner"
  341. // "onQueryExpand": function(item){
  342. // if (item.designer) this.loadDesignerPattern(item);
  343. // }.bind(this)
  344. });
  345. this.tree.load();
  346. if (callback) callback();
  347. }.bind(this), null, false);
  348. }else{
  349. if (callback) callback();
  350. }
  351. },
  352. createResultCategroyItem: function(text, title, tree){
  353. var obj = {
  354. "title": title,
  355. "text": "<span style='font-weight: bold'>"+text+"</span>",
  356. "icon": ""
  357. }
  358. return tree.appendChild(obj);
  359. },
  360. createResultAppItem: function(text, title, tree){
  361. var obj = {
  362. "title": title,
  363. "text": "<span style='font-weight: bold; color: #0b58a2'>"+text+"</span>",
  364. "icon": ""
  365. }
  366. return tree.appendChild(obj);
  367. },
  368. createResultTypeItem: function(text, title, tree){
  369. var obj = {
  370. "title": title,
  371. "text": "<span style='color: #333333'>"+text+"</span>",
  372. "icon": ""
  373. }
  374. return tree.appendChild(obj);
  375. },
  376. createResultDesignerItem: function(text, title, tree){
  377. var obj = {
  378. "expand": false,
  379. "title": title,
  380. "text": "<span style='color: #333333'>"+text+"</span>",
  381. "icon": ""
  382. }
  383. return tree.appendChild(obj);
  384. },
  385. createResultPatternItem: function(text, title, tree, icon, action){
  386. var obj = {
  387. "title": title,
  388. "text": "<span style='color: #000000'>"+text+"</span>",
  389. "icon": icon||"",
  390. "action": action || null
  391. }
  392. return tree.appendChild(obj);
  393. },
  394. updatePatternCount: function(node){
  395. node.patternCount++;
  396. var textDivNode = node.textNode.getElement("div");
  397. if (textDivNode){
  398. var text = this.lp.patternCount.replace("{n}", node.patternCount)
  399. var t = node.options.text+"&nbsp;&nbsp;<span style='color: #666666'>("+text+")</span>>";
  400. //var html = item.options.text;
  401. textDivNode.set("html", t);
  402. }
  403. },
  404. showFindResult: function(data,option){
  405. if (!this.patternCount) this.patternCount = 0;
  406. this.patternCount++;
  407. var t = this.lp.findPatternCount.replace("{n}", this.patternCount);
  408. this.listTitleInfoNode.set("text", t);
  409. this.listInfoNode.hide();
  410. this.listContentNode.show();
  411. var regexp = this.getFilterOptionRegex(option);
  412. var moduleNode = (this.tree.modules) ? this.tree.modules[data.module] : null;
  413. if (!moduleNode){
  414. moduleNode = this.createResultCategroyItem(this.lp[data.module], this.lp[data.module], this.tree);
  415. moduleNode.patternCount = 0;
  416. if (!this.tree.modules) this.tree.modules = {};
  417. this.tree.modules[data.module] = moduleNode;
  418. }
  419. this.updatePatternCount(moduleNode);
  420. var appNode = (moduleNode.apps) ? moduleNode.apps[data.appId] : null;
  421. if (!appNode){
  422. appNode = this.createResultAppItem(data.appName, data.appName, moduleNode);
  423. appNode.patternCount = 0;
  424. if (!moduleNode.apps) moduleNode.apps = {};
  425. moduleNode.apps[data.appId] = appNode;
  426. }
  427. this.updatePatternCount(appNode);
  428. var typeNode = (appNode.types) ? appNode.types[data.designerType] : null;
  429. if (!typeNode){
  430. typeNode = this.createResultTypeItem(this.lp[data.designerType], this.lp[data.designerType], appNode);
  431. typeNode.patternCount = 0;
  432. if (!appNode.types) appNode.types = {};
  433. appNode.types[data.designerType] = typeNode;
  434. }
  435. this.updatePatternCount(typeNode);
  436. var designerNode = (typeNode.designers) ? typeNode.designers[data.designerId] : null;
  437. if (!designerNode){
  438. designerNode = this.createResultDesignerItem(data.designerName, data.designerName, typeNode);
  439. designerNode.patternCount = 0;
  440. if (!typeNode.designers) typeNode.designers = {};
  441. typeNode.designers[data.designerId] = designerNode;
  442. }
  443. this.updatePatternCount(designerNode);
  444. switch (data.designerType){
  445. case "script":
  446. this.createScriptPatternNode(data, designerNode, regexp);
  447. break;
  448. case "form":
  449. this.createFormPatternNode(data, designerNode, regexp);
  450. break;
  451. case "process":
  452. break;
  453. }
  454. },
  455. createFormPatternNode: function(data, node, regexp){
  456. var text = this.lp.elementPattern.replace("{element}", "&lt;"+data.pattern.type+"&gt;"+data.pattern.name).
  457. replace("{property}", "{"+data.pattern.key+"}"+data.pattern.propertyName);
  458. text = "<span style='color: #666666'>"+text+"</span>&nbsp;&nbsp;"
  459. if (data.pattern.line){
  460. if (data.pattern.evkey){
  461. text += "<b>["+data.pattern.evkey+"]</b>&nbsp;"+((data.pattern.line) ? data.pattern.line+"&nbsp;&nbsp;" : "" )+this.getPatternValue(data.pattern.value, regexp);
  462. }else{
  463. text += ((data.pattern.line) ? data.pattern.line+"&nbsp;&nbsp;" : "" )+this.getPatternValue(data.pattern.value, regexp);
  464. }
  465. }else{
  466. text += this.getPatternValue(data.pattern.value, regexp);
  467. }
  468. if (data.pattern.mode){
  469. text = "<b>["+data.pattern.mode+"]</b>&nbsp;"+text;
  470. }
  471. patternNode = this.createResultPatternItem(text, "", node, "icon_"+data.pattern.propertyType+".png");
  472. },
  473. getPatternValue: function(value, regexp, pattern){
  474. regexp.lastIndex = 0;
  475. var valueHtml = "";
  476. var idx = 0;
  477. while ((arr = regexp.exec(value)) !== null) {
  478. if (pattern){
  479. if (!pattern.cols) pattern.cols = [];
  480. pattern.cols.push({"start": arr.index+1, "end": regexp.lastIndex+1});
  481. }
  482. valueHtml += o2.common.encodeHtml(value.substring(idx, arr.index));
  483. valueHtml += "<span style='background-color: #ffef8f'>"+o2.common.encodeHtml(value.substring(arr.index, regexp.lastIndex))+"</span>";
  484. idx = regexp.lastIndex;
  485. }
  486. valueHtml += o2.common.encodeHtml(value.substring(idx, value.length));
  487. return valueHtml;
  488. },
  489. createScriptPatternNode: function(data, node, regexp){
  490. var patternNode;
  491. var text;
  492. var openScript = function(node){
  493. this.openPatternScript(node.pattern);
  494. }.bind(this);
  495. if (data.pattern.property=="text"){
  496. text = "<span style='color: #666666'>"+data.pattern.line+"</span>&nbsp;&nbsp;"+this.getPatternValue(data.pattern.value, regexp, data.pattern);
  497. patternNode = this.createResultPatternItem(text, "", node, "icon_script.png", openScript);
  498. }else{
  499. text = this.lp.property+":&nbsp;<b>"+data.pattern.property+"</b> "+this.lp.value+":&nbsp;"+this.getPatternValue(data.pattern.value, regexp);
  500. patternNode = this.createResultPatternItem(text, "", node, "icon_text.png", openScript);
  501. }
  502. patternNode.pattern = data;
  503. },
  504. openPatternScript: function(pattern){
  505. // appId: "267d4445-b75c-4627-af26-251e623a5fe8"
  506. // appName: "合同"
  507. // designerAliase: ""
  508. // designerId: "ff1d382f-54af-4bb1-80f9-1e3bc3e4f03c"
  509. // designerName: "file"
  510. // designerType: "script"
  511. // module: "processPlatform"
  512. //
  513. // appId: "invoke"
  514. // appName: "接口"
  515. // designerAliase: ""
  516. // designerId: "80c08112-afa1-48b1-b693-87ba8504f47c"
  517. // designerName: "getService"
  518. // designerType: "script"
  519. // module: "service"
  520. debugger;
  521. if (this.editor && this.editor.pattern.designerId === pattern.designerId && this.editor.pattern.module === pattern.module){
  522. this.reLocationEditor(pattern);
  523. }else{
  524. if (this.editor) this.editor.destroyEditor();
  525. this.editor = null;
  526. this.previewInforNode.hide().dispose();
  527. switch (pattern.module){
  528. case "processPlatform":
  529. o2.Actions.load("x_processplatform_assemble_designer").ScriptAction.get(pattern.designerId).then(function(json){
  530. if (json.data) this.openProcessPlatformPatternScript(json.data, pattern);
  531. }.bind(this), function(){});
  532. break;
  533. case "cms":
  534. break;
  535. case "portal":
  536. break;
  537. case "service":
  538. break;
  539. }
  540. }
  541. },
  542. openProcessPlatformPatternScript: function(data, pattern){
  543. o2.require("o2.widget.JavascriptEditor", function(){
  544. this.editor = new o2.widget.JavascriptEditor(this.previewContentNode, {
  545. "option": {"value": data.text}
  546. });
  547. this.editor.pattern = pattern;
  548. this.editor.load(function(){
  549. this.reLocationEditor(pattern);
  550. }.bind(this));
  551. }.bind(this));
  552. },
  553. reLocationEditor: function(pattern){
  554. this.editor.gotoLine(pattern.pattern.line, 1);
  555. if (pattern.pattern.cols && pattern.pattern.cols.length){
  556. var rs = [];
  557. pattern.pattern.cols.forEach(function(col){
  558. rs.push(this.editor.getRange(pattern.pattern.line,col.start, pattern.pattern.line, col.end));
  559. }.bind(this));
  560. this.editor.selectRange(rs);
  561. }else{
  562. this.editor.selectRange(this.editor.getRange(pattern.pattern.line,0));
  563. }
  564. },
  565. getFilterOptionRegex: function(option){
  566. var keyword = option.keyword;
  567. if (option.matchRegExp){
  568. var flag = (option.caseSensitive) ? "gm" : "gmi";
  569. return new RegExp(keyword, flag);
  570. }else{
  571. var flag = (option.caseSensitive) ? "gm" : "gmi";
  572. keyword = (option.matchWholeWord) ? "\\b"+keyword+"\\b" : keyword;
  573. return new RegExp(keyword, flag);
  574. }
  575. },
  576. setReceiveMessage: function(){
  577. this.listTitleInfoNode.set("text", this.lp.receiveToFind);
  578. },
  579. setReadyMessage: function(data){
  580. this.findOptionModuleCount = data.count;
  581. this.findOptionModuleProcessed = 0;
  582. this.updateFindProgress();
  583. this.listTitleInfoNode.set("text", this.lp.readyToFind.replace("{n}", data.count));
  584. },
  585. updateFindProgress: function(){
  586. var percent = (this.findOptionModuleProcessed/this.findOptionModuleCount)*100;
  587. this.listTitleProgressNode.setStyle("width", ""+percent+"%");
  588. },
  589. getActionsUrl:function(){
  590. var processHost = o2.Actions.getHost("x_processplatform_assemble_designer");
  591. var cmsHost = o2.Actions.getHost("x_cms_assemble_control");
  592. var portalHost = o2.Actions.getHost("x_portal_assemble_designer");
  593. var queryHost = o2.Actions.getHost("x_query_assemble_designer");
  594. var serviceHost = o2.Actions.getHost("x_program_center");
  595. var findHost = o2.Actions.getHost("x_query_service_processing");
  596. var actions = {
  597. "listProcess": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/application/list"),
  598. "listProcessProcess": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/process/application/{applicationId}"),
  599. "listProcessForm": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/form/list/application/{applicationId}"),
  600. "listProcessScript": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/script/application/{applicationId}"),
  601. "getProcessProcess": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/process/{id}"),
  602. "getProcessForm": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/form/{id}"),
  603. "getProcessScript": o2.filterUrl(processHost+"/x_processplatform_assemble_designer/jaxrs/script/{id}"),
  604. "listCms": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/appinfo/list/manage"),
  605. "listCmsForm": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/form/list/app/{appId}"),
  606. "listCmsScript": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/script/list/app/{flag}"),
  607. "getCmsForm": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/form/{id}"),
  608. "getCmsScript": o2.filterUrl(cmsHost+"/x_cms_assemble_control/jaxrs/script/{id}"),
  609. "listPortal": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/portal/list"),
  610. "listPortalPage": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/page/list/portal/{portalId}"),
  611. "listPortalScript": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/script/list/portal/{portalId}"),
  612. "listPortalWidget": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/widget/list/portal/{portalId}"),
  613. "getPortalPage": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/page/{id}"),
  614. "getPortalScript": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/script/{id}"),
  615. "getPortalWidget": o2.filterUrl(portalHost+"/x_portal_assemble_designer/jaxrs/widget/{id}"),
  616. "listQuery": o2.filterUrl(queryHost+"/x_query_assemble_designer/jaxrs/query/list/summary"),
  617. "listQueryView": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/view/list/query/{flag}"),
  618. "listQueryStat": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/stat/list/query/{flag}"),
  619. "listQueryStatement": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/statement/list/query/{flag}"),
  620. "getQueryView": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/view/{id}"),
  621. "getQueryStat": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/stat/{id}"),
  622. "getQueryStatement": o2.filterUrl(portalHost+"/x_query_assemble_designer/jaxrs/statement/{id}"),
  623. "listInvoke": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/invoke"),
  624. "listAgent": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/agent"),
  625. "getInvoke": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/invoke/{flag}"),
  626. "getAgent": o2.filterUrl(serviceHost+"/x_program_center/jaxrs/agent/{flag}"),
  627. "findAction": o2.filterUrl(findHost+"/x_query_service_processing/jaxrs/design/search")
  628. };
  629. return actions;
  630. },
  631. findDesigner: function(){
  632. this.listContentNode.hide();
  633. this.listContentNode.empty();
  634. this.listInfoNode.show().getFirst().set("text", "");
  635. this.listInfoNode.addClass("loadding");
  636. this.patternCount = 0;
  637. if (this.editor) this.editor.destroyEditor();
  638. this.editor = null;
  639. this.previewInforNode.show().inject(this.previewContentNode);
  640. this.getFindWorker();
  641. var actions = this.getActionsUrl();
  642. this.tree = null;
  643. this.getResultTree(function(){
  644. var workerMessage = {
  645. actions:actions,
  646. filterOption: this.filterOption,
  647. debug: (window.layout && layout["debugger"]),
  648. token: (window.layout && layout.session && layout.session.user) ? layout.session.user.token : ""
  649. };
  650. this.findWorker.postMessage(workerMessage);
  651. }.bind(this));
  652. },
  653. //------------------------------------------------------------
  654. findDesigner_bak: function(){
  655. this.listContentNode.hide();
  656. this.listInfoNode.show().getFirst().set("text", "");
  657. this.listInfoNode.addClass("loadding")
  658. o2.Actions.load("x_query_service_processing").DesignAction.search(this.filterOption, function(json){
  659. if ((json.data.processPlatformList && json.data.processPlatformList.length) ||
  660. (json.data.cmsList && json.data.cmsList.length) ||
  661. (json.data.portalList && json.data.portalList.length) ||
  662. (json.data.queryList && json.data.queryList.length) ||
  663. (json.data.serviceList && json.data.serviceList.length)){
  664. this.listInfoNode.hide();
  665. this.listFindResult(json.data);
  666. }else{
  667. this.listInfoNode.show().removeClass("loadding").getFirst().set("text", this.lp.nothingFind);
  668. }
  669. }.bind(this));
  670. },
  671. createResultAppItem: function(text, title, tree){
  672. var obj = {
  673. "title": title,
  674. "text": "<span style='font-weight: bold; color: #4A90E2'>"+text+"</span>",
  675. "icon": ""
  676. }
  677. return tree.appendChild(obj);
  678. },
  679. // createResultDesignerItem: function(designer, tree){
  680. // var title = this.lp[designer.designerType]+ ": "+ designer.designerName + " ("+designer.designerId+")";
  681. // var text = this.lp[designer.designerType]+ ": <b>"+ designer.designerName+"</b>";
  682. // var obj = {
  683. // "expand": false,
  684. // "title": title,
  685. // "text": text,
  686. // "icon": ""
  687. // }
  688. // var item = tree.appendChild(obj);
  689. // item.designer = designer;
  690. // item.appendChild({ "expand": false, "text": "loading...", "icon": "" });
  691. // return item;
  692. // },
  693. listFindResult: function(data){
  694. this.listContentNode.empty();
  695. this.listContentNode.show();
  696. o2.require("o2.widget.Tree", function(){
  697. var tree = new o2.widget.Tree(this.listContentNode, {
  698. "onQueryExpand": function(item){
  699. if (item.designer) this.loadDesignerPattern(item);
  700. }.bind(this)
  701. });
  702. tree.load();
  703. if (data.processPlatformList && data.processPlatformList.length){
  704. var platformItem = this.createResultCategroyItem(this.lp.processPlatform, this.lp.processPlatform, tree);
  705. this.listProcessResult(platformItem, data.processPlatformList, "processPlatform");
  706. }
  707. if (data.cmsList && data.cmsList.length){
  708. var platformItem = this.createResultCategroyItem(this.lp.cms, this.lp.cms, tree);
  709. //this.listProcessResult(categroyItem, data.cmsList);
  710. }
  711. if (data.portalList && data.portalList.length){
  712. var platformItem = this.createResultCategroyItem(this.lp.portal, this.lp.portal, tree);
  713. }
  714. if (data.queryList && data.queryList.length){
  715. var platformItem = this.createResultCategroyItem(this.lp.query, this.lp.query, tree);
  716. }
  717. if (data.serviceList && data.serviceList.length){
  718. var platformItem = this.createResultCategroyItem(this.lp.service, this.lp.service, tree);
  719. }
  720. }.bind(this));
  721. },
  722. addPatternCount: function(item, count){
  723. if (!item.count) item.count = 0;
  724. item.count += count;
  725. var t = this.lp.patternCount.replace("{n}", item.count);
  726. var textDivNode = item.textNode.getElement("div");
  727. if (textDivNode){
  728. var html = item.options.text;
  729. textDivNode.set("html", html+" <span style=''>( "+t+" )</span>");
  730. }
  731. },
  732. listProcessResult: function(platformItem, list, platform){
  733. var applicationItems = {};
  734. list.each(function(designer){
  735. if (designer.patternList && designer.patternList.length){
  736. var appItem = applicationItems[designer.appId];
  737. if (!appItem){
  738. applicationItems[designer.appId] = appItem = this.createResultAppItem(designer.appName, designer.appName+" ("+designer.appId+")", platformItem);
  739. }
  740. designer.platform = platform;
  741. var designerItem = this.createResultDesignerItem(designer, appItem);
  742. var count=0;
  743. designer.patternList.each(function(p){
  744. if (p.lines && p.lines.length){
  745. count += p.lines.length;
  746. }else{
  747. count++;
  748. }
  749. });
  750. // var count = designer.patternList.length;
  751. this.addPatternCount(designerItem, count);
  752. this.addPatternCount(appItem, count);
  753. this.addPatternCount(platformItem, count);
  754. }
  755. }.bind(this));
  756. },
  757. getDesignerObject: function(designer){
  758. switch (designer.platform){
  759. case "processPlatform":
  760. var action = this.Actions.load("x_processplatform_assemble_designer");
  761. switch (designer.designerType){
  762. case "script":
  763. return action.ScriptAction.get(designer.designerId, function(json){return json.data;});
  764. case "form":
  765. return action.FomrAction.get(designer.designerId, function(json){return json.data;});
  766. case "process":
  767. return action.ProcessAction.get(designer.designerId, function(json){return json.data;});
  768. }
  769. case "cms":
  770. var action = this.Actions.load("x_cms_assemble_control");
  771. switch (designer.designerType){
  772. case "script":
  773. return action.ScriptAction.get(designer.designerId, function(json){return json.data;});
  774. case "form":
  775. return action.FormAction.get(designer.designerId, function(json){return json.data;});
  776. }
  777. case "portal":
  778. var action = this.Actions.load("x_portal_assemble_designer");
  779. switch (designer.designerType){
  780. case "script":
  781. return action.ScriptAction.get(designer.designerId, function(json){return json.data;});
  782. case "page":
  783. return action.PageAction.get(designer.designerId, function(json){return json.data;});
  784. case "widget":
  785. return action.WidgetAction.get(designer.designerId, function(json){return json.data;});
  786. }
  787. case "query":
  788. var action = this.Actions.load("x_query_assemble_designer");
  789. switch (designer.designerType){
  790. case "view":
  791. return action.ViewAction.get(designer.designerId, function(json){return json.data;});
  792. case "statement":
  793. return action.StatementAction.get(designer.designerId, function(json){return json.data;});
  794. case "stat":
  795. return action.StatAction.get(designer.designerId, function(json){return json.data;});
  796. }
  797. case "service":
  798. var action = this.Actions.load("x_program_center");
  799. switch (designer.appId){
  800. case "invoke":
  801. return action.InvokeAction.get(designer.designerId, function(json){return json.data;});
  802. case "agent":
  803. return action.AgentAction.get(designer.designerId, function(json){return json.data;});
  804. }
  805. }
  806. },
  807. loadDesignerPattern: function(item){
  808. if (item.firstChild && item.firstChild.options.text==="loading..."){
  809. item.firstChild.destroy();
  810. var root, actionName, fun;
  811. switch (designer.platform) {
  812. case "processPlatform":
  813. root = "x_processplatform_assemble_designer";
  814. switch (designer.designerType) {
  815. case "script": actionName = "ScriptAction"; fun = "listProcessScriptPattern";
  816. case "form": actionName = "FomrAction"; fun = "listProcessFormPattern";
  817. case "process": actionName = "ProcessAction"; fun = "listProcessProcessPattern";
  818. }
  819. case "cms":
  820. root = "x_cms_assemble_control";
  821. switch (designer.designerType) {
  822. case "script": actionName = "ScriptAction"; fun = "listCmsScriptPattern";
  823. case "form": actionName = "FormAction"; fun = "listCmsFormPattern";
  824. }
  825. case "portal":
  826. root = "x_portal_assemble_designer";
  827. switch (designer.designerType) {
  828. case "script": actionName = "ScriptAction"; fun = "listPortalScriptPattern";
  829. case "page": actionName = "PageAction"; fun = "listPortalPagePattern";
  830. case "widget": actionName = "WidgetAction"; fun = "listPortalWidgetPattern";
  831. }
  832. case "query":
  833. root = "x_query_assemble_designer";
  834. switch (designer.designerType) {
  835. case "view": actionName = "ViewAction"; fun = "listQueryViewPattern";
  836. case "statement": actionName = "StatementAction"; fun = "listQueryStatementPattern";
  837. case "stat": actionName = "StatAction"; fun = "listQueryStatPattern";
  838. }
  839. case "service":
  840. root = "x_program_center";
  841. switch (designer.appId) {
  842. case "invoke": actionName = "InvokeAction"; fun = "listServiceInvokePattern";
  843. case "agent": actionName = "AgentAction"; fun = "listServiceAgentPattern";
  844. }
  845. }
  846. this.Actions.load(root)[actionName].get(designer.designerId, function(json){
  847. this[fun](json.data, designer.patternList, item);
  848. }.bind(this))
  849. }
  850. },
  851. getFindRegExp: function(){
  852. var flag = "gm";
  853. var keyword = this.filterOption.keyword;
  854. if (!this.filterOption.caseSensitive) flag+="i";
  855. if (this.filterOption.matchRegExp){
  856. return new RegExp(keyword, flag)
  857. }else{
  858. if (this.filterOption.matchWholeWord) keyword = "\\b"+keyword+"\\b";
  859. return new RegExp(keyword, flag)
  860. }
  861. },
  862. //启动一个webworker处理
  863. listProcessScriptPattern: function (data, patternList, item){
  864. patternList.each(function(pattern){
  865. if (pattern.property == "text"){
  866. var textArr = data.split("\n");
  867. var regex = this.getFindRegExp();
  868. pattern.lines.each(function(line){
  869. var text = textArr[line];
  870. }.bind(this));
  871. }else{
  872. }
  873. }.bind(this));
  874. }
  875. });