Main.js 35 KB

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