FTSearchView.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. MWF.require("o2.widget.Paging", null, false);
  2. // MWF.require("o2.widget.Mask", null, false);
  3. o2.requireApp("Template", "MTooltips", null, false);
  4. MWF.xApplication.ftsearch.FTSearchView = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "query": ""
  10. },
  11. initialize: function(node, app, options){
  12. this.setOptions(options);
  13. this.path = "../x_component_ftsearch/$FTSearchView/";
  14. this.app = app;
  15. this.container = $(node);
  16. this.facetOrderList = ["category","applicationName", "processName","appName","categoryName"];
  17. this.load();
  18. },
  19. load: function(){
  20. this.pageSize = 10;
  21. this.currentKey = "";
  22. this.docPageNum = 1;
  23. this.docTotal = 0;
  24. this.docList = [];
  25. this.selectedConditionList = [];
  26. this.selectedFilterList = [];
  27. var url = this.path+this.options.style+"/view.html";
  28. this.container.loadHtml(url, {
  29. "bind": {"lp": this.app.lp, "data": {"query":this.options.query}},
  30. "module": this
  31. }, function(){
  32. // this.loadSelectedCondition();
  33. this.search(null, this.options.query);
  34. }.bind(this));
  35. // this.resizeFun = this.checkAllSwitchButton.bind(this);
  36. // this.app.addEvent("resize", this.resizeFun);
  37. this.setSizeFun = this.setSize.bind(this);
  38. this.app.addEvent("resize", this.setSizeFun);
  39. },
  40. recordStatus: function(){
  41. return {
  42. // view: "ftsearch",
  43. query: this.getQuery()
  44. }
  45. },
  46. reload: function(){
  47. this.container.empty();
  48. if(this.resizeFun){
  49. this.app.removeEvent("resize", this.resizeFun);
  50. }
  51. this.load();
  52. },
  53. destroy : function(){
  54. // this.app.removeEvent("resize", this.resetNodeSizeFun );
  55. this.container.empty();
  56. if(this.resizeFun){
  57. this.app.removeEvent("resize", this.resizeFun);
  58. }
  59. },
  60. getQuery: function(){
  61. return this.searchInput.get("value") || "";
  62. },
  63. gotoMainPage: function(){
  64. this.app.gotoMainPage();
  65. },
  66. selectTab: function(){
  67. this.app.selectTab();
  68. },
  69. searchKeydown: function(e){
  70. if( e.keyCode === 13 ){
  71. this.search();
  72. }
  73. },
  74. setSize: function(){
  75. var contentY = this.app.content.getSize().y - 10;
  76. var topY = this.topNode ? ( this.topNode.getSize().y + this.getOffsetY(this.topNode) ): 0;
  77. var bottomY = this.docPaginationNode ? ( this.docPaginationNode.getSize().y + this.getOffsetY(this.topNode) ) : 0;
  78. // this.docContent.setStyle("height", "calc( 100% - "+ (topY + bottomY + this.getOffsetY(this.docContent) ) +"px )");
  79. this.docContent.setStyle("height", contentY - topY - bottomY );
  80. },
  81. getOffsetY : function(node){
  82. return (node.getStyle("margin-top").toInt() || 0 ) +
  83. (node.getStyle("margin-bottom").toInt() || 0 ) +
  84. (node.getStyle("padding-top").toInt() || 0 ) +
  85. (node.getStyle("padding-bottom").toInt() || 0 )+
  86. (node.getStyle("border-top-width").toInt() || 0 ) +
  87. (node.getStyle("border-bottom-width").toInt() || 0 );
  88. },
  89. search: function(pageNum, query){
  90. this.selectedConditionList = [];
  91. this.selectedFilterList = [];
  92. if( typeOf(this.collapseCondition) === "boolean" ){
  93. this._search(pageNum, query, function () {
  94. // this.loadSelectedCondition();
  95. }.bind(this));
  96. }else{
  97. MWF.UD.getDataJson("ftsearchCollapseCondition", function (json) {
  98. this.collapseCondition = json === "true" || !json ;
  99. this._search(pageNum, query, function () {
  100. // this.loadSelectedCondition();
  101. }.bind(this));
  102. }.bind(this), true);
  103. }
  104. },
  105. _search: function( pageNum, query, callback ){
  106. // this.mask = new o2.widget.Mask({ "style": "desktop", "zIndex": 50000 });
  107. // this.mask.loadNode(this.app.content);
  108. pageNum = o2.typeOf(pageNum) === "number" ? pageNum : null;
  109. this.docPageNum = pageNum || 1;
  110. this.currentKey = query || this.searchInput.get("value") || "";
  111. var docLoaded = false;
  112. var filterLoaded = false;
  113. var afterLoadFun = function () {
  114. debugger;
  115. if(docLoaded && filterLoaded){
  116. this.setSize();
  117. if(!pageNum){
  118. if( this.docTotal ){
  119. var endDate = new Date();
  120. var t = endDate.getTime()-startDate.getTime();
  121. t = ((t/1000)*100).toInt()/100;
  122. var text = this.app.lp.docTotalInfor.replace("{count}", this.docTotal||0).replace("{time}", t);
  123. // this.docTotalNode.set("html", text);
  124. this.loadDocPagination( text );
  125. }else{
  126. this.docPaginationNode.empty();
  127. }
  128. }
  129. if( typeOf(callback) === "function" )callback();
  130. }
  131. // if (this.mask) { this.mask.hide(); this.mask = null; }
  132. }.bind(this);
  133. if( this.currentKey ){
  134. var startDate = new Date();
  135. // var filterList = this.selectedConditionList.map(function(cond){
  136. // return {
  137. // field: cond.field,
  138. // valueList: cond.valueList
  139. // };
  140. // });
  141. var filterList = this.selectedFilterList.map(function(cond){
  142. return {
  143. field: cond.field,
  144. valueList: cond.valueList
  145. };
  146. });
  147. o2.Actions.load("x_query_assemble_surface").SearchAction.post({
  148. query: this.currentKey || "",
  149. page: this.docPageNum,
  150. size: this.pageSize,
  151. filterList: filterList
  152. }).then(function(json){
  153. var sequence = (this.docPageNum - 1) * this.pageSize;
  154. this.data = json.data;
  155. this.docList = json.data.documentList.map(function (d) {
  156. sequence++;
  157. d.sequence = sequence;
  158. return d;
  159. });
  160. this.docTotal = json.data.count;
  161. if( o2.typeOf(this.docTotal) !== "number" )this.docTotal = 0;
  162. this.loadDocList(this.docList, function () {
  163. docLoaded = true;
  164. afterLoadFun();
  165. });
  166. var facetList = this.orderFacet(json.data.facetList);
  167. this.loadFilter(facetList, function () {
  168. filterLoaded = true;
  169. afterLoadFun();
  170. });
  171. // this.loadCondition( facetList);
  172. // if(!pageNum){
  173. // var endDate = new Date();
  174. // var t = endDate.getTime()-startDate.getTime();
  175. // t = ((t/1000)*100).toInt()/100;
  176. // var text = this.app.lp.docTotalInfor.replace("{count}", this.docTotal||0).replace("{time}", t);
  177. // this.docTotalNode.set("html", text);
  178. //
  179. // this.loadDocPagination();
  180. // }
  181. // if( typeOf(callback) === "function" )callback();
  182. }.bind(this), function () {
  183. this.data = {};
  184. this.docList = [];
  185. this.docTotal = 0;
  186. this.loadFilter([], function () {
  187. filterLoaded = true;
  188. afterLoadFun();
  189. });
  190. this.loadDocList(null, function () {
  191. docLoaded = true;
  192. afterLoadFun();
  193. });
  194. }.bind(this));
  195. }else{
  196. this.data = {};
  197. this.docList = [];
  198. this.docTotal = 0;
  199. this.loadFilter([], function () {
  200. filterLoaded = true;
  201. afterLoadFun();
  202. });
  203. this.loadDocList(null, function () {
  204. docLoaded = true;
  205. afterLoadFun();
  206. });
  207. }
  208. },
  209. orderFacet: function(facetList){
  210. facetList.sort(function (a, b) {
  211. var indexA = this.facetOrderList.indexOf(a.field);
  212. var indexB = this.facetOrderList.indexOf(b.field);
  213. if( indexA === -1 )indexA = 999999;
  214. if( indexB === -1 )indexB = 999999;
  215. return indexA - indexB;
  216. }.bind(this));
  217. return facetList
  218. },
  219. setBody: function(ev, d){
  220. // var body;
  221. // var regex = /(<([^>]+)>)/ig;
  222. // if(d.highlighting ){
  223. // body = o2.typeOf( d.highlighting ) === "array" ? d.highlighting[0] : d.highlighting;
  224. // }
  225. // if( !body && d._summary_){
  226. // body = o2.typeOf( d._summary_ ) === "array" ? d._summary_.join("") : d._summary_;
  227. // }
  228. ev.target.set("html", d.highlighting || d.summary || "")
  229. },
  230. setSummary: function(ev, d){
  231. var body;
  232. if( !body && d._summary_){
  233. body = o2.typeOf( d._summary_ ) === "array" ? d._summary_.join("") : d._summary_;
  234. }
  235. if( body ){
  236. ev.target.set("text", body)
  237. }else{
  238. ev.target.getParent().hide();
  239. }
  240. },
  241. // openWork: function(id, event, row){
  242. // o2.api.page.openWork(id);
  243. // },
  244. openWork: function(id, event, row){
  245. var appId = "process.Work"+id;
  246. var op = {
  247. "jobId": id,
  248. "appId": appId
  249. };
  250. return layout.desktop.openApplication(this.event, "process.Work", op);
  251. },
  252. openDoc: function(id, event, row){
  253. debugger;
  254. o2.api.page.openDocument(id);
  255. },
  256. loadDocList: function(data, callback){
  257. this.docListNode.empty();
  258. this.docListNode.loadHtml(this.path+this.options.style+"/docList.html",
  259. {
  260. "bind": {"lp": this.app.lp, "data": data},
  261. "module": this,
  262. "reload": true
  263. },
  264. function(){
  265. if(callback)callback();
  266. }.bind(this)
  267. );
  268. },
  269. loadDocPagination: function(text){
  270. this.docPaginationNode.empty();
  271. if( o2.typeOf(this.docTotal) === "number" && this.docTotal > 0 ){
  272. this.docPaging = new o2.widget.Paging(this.docPaginationNode, {
  273. style: "blue_round",
  274. countPerPage: this.pageSize,
  275. visiblePages: 9,
  276. currentPage: 1,
  277. itemSize: this.docTotal,
  278. useMainColor: true,
  279. text: {
  280. firstPage: this.app.lp.firstPage,
  281. lastPage: this.app.lp.lastPage
  282. },
  283. // pageSize: pageSize,
  284. onJumpingPage: function (pageNum) {
  285. this._search(pageNum);
  286. }.bind(this),
  287. hasInfor: true,
  288. inforTextStyle: text,
  289. onPostLoad: function () {
  290. this.wraper.setStyle("border-top", "1px solid #4A90E2");
  291. this.wraper.addClass("mainColor_border");
  292. }
  293. });
  294. this.docPaging.load();
  295. }
  296. },
  297. loadCondition: function( json ){
  298. var lp = this.app.lp;
  299. json.each(function(d){
  300. d.label = lp[d.field.toString()] || d.field;
  301. d.valueCountPairList.each(function (v) {
  302. v.field = d.field;
  303. v.parentLabel = d.label;
  304. if( ["category","completed"].contains(d.field)){
  305. v.label = lp[v.value.toString()] || v.value;
  306. }else{
  307. v.label = v.value;
  308. }
  309. });
  310. });
  311. this.conditionArea.empty();
  312. json = json.filter(function(d){
  313. return d.valueCountPairList && d.valueCountPairList.length;
  314. });
  315. json.each(function(d, i){
  316. d.index = i;
  317. });
  318. this.conditionArea.loadHtml(this.path+this.options.style+"/condition.html",
  319. {
  320. "bind": {"lp": this.app.lp, "data": json, status: {
  321. collapseCondition: this.collapseCondition,
  322. showSwitch: json.length > 1
  323. }},
  324. "module": this,
  325. "reload": true
  326. },
  327. function(){
  328. }.bind(this)
  329. );
  330. // }.bind(this));
  331. },
  332. switchCondition: function(){
  333. this.collapseCondition = !this.collapseCondition;
  334. if( this.collapseCondition ){
  335. this.switchNode.getElement("i").addClass( 'o2icon-chevron-thin-down' ).removeClass('o2icon-chevron-thin-up');
  336. this.switchNode.getElement("span").set("text", this.app.lp.expandCondition);
  337. this.conditionNode.getElements(".itemWrap").each(function (item, index) {
  338. item.setStyle("display", index ? "none": "")
  339. })
  340. }else{
  341. this.switchNode.getElement("i").removeClass( 'o2icon-chevron-thin-down' ).addClass('o2icon-chevron-thin-up');
  342. this.switchNode.getElement("span").set("text", this.app.lp.collapseCondition);
  343. this.conditionNode.getElements(".itemWrap").each(function (item, index) {
  344. item.setStyle("display", "");
  345. })
  346. }
  347. MWF.UD.putData("ftsearchCollapseCondition", this.collapseCondition.toString(), null,);
  348. },
  349. loadSelectedCondition: function(){
  350. this.conditionSelectedArea.empty();
  351. this.selectedConditionList.each(function (item) {
  352. var condNode = new Element("div.item", {
  353. events: {
  354. mouseover: function (ev) {
  355. this.conditionSelectedOver(ev)
  356. }.bind(this),
  357. mouseout: function (ev) {
  358. this.conditionSelectedOut(ev)
  359. }.bind(this)
  360. }
  361. }).inject( this.conditionSelectedArea );
  362. condNode.addClass("mainColor_bg");
  363. condNode.addEvents({
  364. click: function (ev) {
  365. this.removeSelectedConditionItem(ev, item, condNode)
  366. }.bind(this),
  367. });
  368. new Element("span", {
  369. text: item.parentLabel+":"
  370. }).inject(condNode);
  371. var titleList = [];
  372. item.labelList.each(function (label, i) {
  373. if( i === 2 ){
  374. new Element("div.item-text", {
  375. text: "..."
  376. }).inject(condNode);
  377. }else if( i <= 1 ){
  378. new Element("div.item-text", {
  379. text: label
  380. }).inject(condNode);
  381. }
  382. titleList.push( label );
  383. });
  384. var iconNode = new Element("i.o2icon-close").inject(condNode);
  385. iconNode.addClass("icon");
  386. condNode.set("title", item.parentLabel+":" + titleList.join(","));
  387. }.bind(this))
  388. },
  389. // loadSelectedCondition: function(){
  390. // this.conditionSelectedArea.empty();
  391. // this.conditionSelectedArea.loadHtml(this.path+this.options.style+"/conditionSelected.html",
  392. // {
  393. // "bind": {"lp": this.app.lp, "data": this.selectedConditionList},
  394. // "module": this,
  395. // "reload": true
  396. // },
  397. // function(){
  398. //
  399. // }.bind(this)
  400. // );
  401. // },
  402. iconOver: function(e){
  403. e.target.addClass('mainColor_color');
  404. },
  405. iconOut: function(e){
  406. e.target.removeClass('mainColor_color');
  407. },
  408. inputOver: function(e){
  409. this.app.getEventTarget(e, "view_inputArea").addClass('mainColor_border');
  410. },
  411. inputOut: function(e){
  412. this.app.getEventTarget(e, "view_inputArea").removeClass('mainColor_border');
  413. },
  414. loadMultiSelectConditionItem: function(e, row){
  415. if( this.curMultiSelectNode ){
  416. this.curMultiSelectNode.empty();
  417. this.curMultiSelectNode.hide();
  418. this.curMultiSelectItemNode.show();
  419. }
  420. this.curMultiSelectConditionList = [];
  421. this.curMultiSelectItemNode = e.target.getParent(".item");
  422. this.curMultiSelectItemNode.hide();
  423. this.curMultiSelectNode = this.curMultiSelectItemNode.getParent().getElement(".item-multiselect").show();
  424. this.curMultiSelectNode.loadHtml(this.path+this.options.style+"/conditionItem_multiselect.html",
  425. {
  426. "bind": {"lp": this.app.lp, "data": row},
  427. "module": this,
  428. "reload": true
  429. },
  430. function(){}.bind(this)
  431. );
  432. },
  433. multiSelect: function(e, item){
  434. var target = this.app.getEventTarget(e, "subItem-content");
  435. var index = -1;
  436. this.curMultiSelectConditionList.each(function (cond, idx) {
  437. if( cond.field === item.field && cond.value === item.value )index = idx;
  438. });
  439. if( index > -1 ){ //已经选择了
  440. target.getElement("i.checkbox").removeClass("o2icon-check_box").addClass("o2icon-check_box_outline_blank").removeClass("mainColor_color");
  441. this.curMultiSelectConditionList.splice(index, 1);
  442. }else{ //还没有选择
  443. target.getElement("i.checkbox").removeClass("o2icon-check_box_outline_blank").addClass("o2icon-check_box").addClass("mainColor_color");
  444. this.curMultiSelectConditionList.push(item);
  445. }
  446. },
  447. okMultiSelect: function(e, item){
  448. if(!this.curMultiSelectConditionList.length){
  449. this.app.notice(this.app.lp.selectConditionNote, "info");
  450. return;
  451. }
  452. var object = {
  453. field: this.curMultiSelectConditionList[0].field,
  454. parentLabel: this.curMultiSelectConditionList[0].parentLabel,
  455. valueList: [],
  456. labelList: []
  457. };
  458. this.curMultiSelectConditionList.each(function(cond){
  459. object.valueList.push(cond.value);
  460. object.labelList.push(cond.label);
  461. })
  462. this.changeCondition(e, object)
  463. },
  464. cancelMultiSelect: function(e, item){
  465. if( this.curMultiSelectNode ){
  466. this.curMultiSelectItemNode.show();
  467. this.curMultiSelectNode.empty();
  468. this.curMultiSelectNode.hide();
  469. }
  470. },
  471. checkAllSwitchButton: function(e){
  472. if(this.conditionNode)this.conditionNode.getElements(".item").each(function(itemNode){
  473. var more = itemNode.getElement(".switch-button");
  474. var ul = itemNode.getElement(".subitem-wrap");
  475. if( 41 < ul.scrollHeight ){
  476. more.show();
  477. }else{
  478. more.hide();
  479. }
  480. });
  481. },
  482. checkSwitchButton: function(e){
  483. var p = e.target.getParent();
  484. var more = p.getElement(".switch-button");
  485. var ul = p.getElement(".subitem-wrap");
  486. if( 41 < ul.scrollHeight ){
  487. more.show();
  488. }else{
  489. more.hide();
  490. }
  491. },
  492. switchConditionItem: function(e){
  493. var more = this.app.getEventTarget(e, "switch-button");
  494. var ul = more.getParent().getElement(".subitem-wrap");
  495. if( ul.retrieve("expand") ){
  496. ul.removeClass("subitem-wrap_expand");
  497. more.getElement("i").addClass("o2icon-triangle_down").removeClass("o2icon-triangle_up");
  498. more.getElement("span").innerText = this.app.lp.more;
  499. ul.store("expand", false);
  500. }else{
  501. ul.addClass("subitem-wrap_expand");
  502. more.getElement("i").addClass("o2icon-triangle_up").removeClass("o2icon-triangle_down");
  503. more.getElement("span").innerText = this.app.lp.collapse;
  504. ul.store("expand", true);
  505. }
  506. },
  507. changeCondition: function(e, item, removedItemNode){
  508. var index = -1;
  509. this.selectedConditionList.each(function (cond, idx) {
  510. if( cond.field === item.field )index = idx;
  511. });
  512. if( index > -1 ) { //已经选择了
  513. this.selectedConditionList.splice(index, 1);
  514. }else{
  515. this.selectedConditionList.push(item);
  516. }
  517. this._search( null, null,function () {
  518. this.loadSelectedCondition()
  519. }.bind(this));
  520. },
  521. changeSingleCondition: function(e, item){
  522. var itemIndex = -1, valueIndex = -1;
  523. this.selectedConditionList.each(function (cond, idx) {
  524. if( cond.field === item.field ){
  525. itemIndex = idx;
  526. valueIndex = cond.valueList.indexOf(item.value);
  527. }
  528. });
  529. if( valueIndex > -1 ){ //已经选择了
  530. e.target.removeClass('mainColor_bg');
  531. e.target.store("selected", false);
  532. this.selectedConditionList[itemIndex].valueList.splice(valueIndex, 1);
  533. this.selectedConditionList[itemIndex].labelList.splice(valueIndex, 1);
  534. if( !this.selectedConditionList[itemIndex].valueList.length ){
  535. this.selectedConditionList.splice(itemIndex, 1);
  536. }
  537. }else{ //还没有选择
  538. e.target.removeClass('mainColor_bg_opacity');
  539. e.target.addClass('mainColor_bg');
  540. e.target.store("selected", true);
  541. if( itemIndex > -1 ){
  542. this.selectedConditionList[itemIndex].valueList.push(item.value);
  543. this.selectedConditionList[itemIndex].labelList.push(item.label);
  544. }else{
  545. this.selectedConditionList.push({
  546. field: item.field,
  547. parentLabel: item.parentLabel,
  548. valueList: [item.value],
  549. labelList: [item.label]
  550. });
  551. }
  552. }
  553. this._search(null, null, function () {
  554. // this.loadSelectedCondition();
  555. }.bind(this));
  556. },
  557. subConditionOver: function(e){
  558. if(!e.target.retrieve("selected"))e.target.addClass('mainColor_bg_opacity');
  559. },
  560. subConditionOut: function(e){
  561. if(!e.target.retrieve("selected"))e.target.removeClass('mainColor_bg_opacity');
  562. },
  563. subConditionOver_multi: function(e){
  564. var target = this.app.getEventTarget(e, "subItem-content");
  565. if(!target.retrieve("selected"))target.addClass('mainColor_bg_opacity');
  566. },
  567. subConditionOut_multi: function(e){
  568. var target = this.app.getEventTarget(e, "subItem-content");
  569. if(!target.retrieve("selected"))target.removeClass('mainColor_bg_opacity');
  570. },
  571. removeSelectedConditionItem: function(e, item, itemNode){
  572. this.changeCondition(e, item, itemNode);
  573. },
  574. conditionSelectedOver: function(e){
  575. this.app.getEventTarget(e, "item").getElement("i").addClass("icon_over");
  576. },
  577. conditionSelectedOut: function(e){
  578. this.app.getEventTarget(e, "item").getElement("i").removeClass("icon_over");
  579. },
  580. mainColorOver: function (className, e) {
  581. var target = this.app.getEventTarget(e, className);
  582. if(target)target.addClass('mainColor_color');
  583. },
  584. mainColorOut: function (className, e) {
  585. var target = this.app.getEventTarget(e, className);
  586. if(target)target.removeClass('mainColor_color');
  587. },
  588. loadFilter: function( json, callback ){
  589. var lp = this.app.lp;
  590. this.filterArea.empty();
  591. if( this.tooltipList && this.tooltipList.length ){
  592. this.tooltipList.each(function (tooltip) {
  593. tooltip.destroy();
  594. });
  595. this.tooltipList = [];
  596. this.currentTooltip = null;
  597. }
  598. var index = 0;
  599. var facetList = [];
  600. json.each(function(d) {
  601. if (d.valueCountPairList && d.valueCountPairList.length){
  602. d.index = index;
  603. index++;
  604. d.label = lp[d.field] || d.name || d.field;
  605. // d.valueCountPairList.each(function (v) {
  606. // v.field = d.field;
  607. // v.parentLabel = d.label;
  608. // if (["category","completed"].contains(d.field)) {
  609. // v.label = lp[v.value.toString()] || v.value;
  610. // } else {
  611. // v.label = v.value;
  612. // }
  613. // });
  614. facetList.push(d);
  615. }
  616. });
  617. this.filterArea.empty();
  618. if( this.selectedFilterList.length || facetList.length ){
  619. this.filterArea.removeClass("index-filterNoDoc");
  620. this.filterArea.loadHtml(this.path+this.options.style+"/filter.html",
  621. {
  622. "bind": {
  623. "lp": this.app.lp,
  624. "selectedFilterList": this.selectedFilterList,
  625. "filterList": facetList
  626. },
  627. "module": this,
  628. "reload": true
  629. },
  630. function(){
  631. if(callback)callback();
  632. }.bind(this)
  633. );
  634. }else{
  635. this.filterArea.addClass("index-filterNoDoc")
  636. if(callback)callback();
  637. }
  638. },
  639. checkedFilterItemEnter: function(e){
  640. e.target.addClass("mainColor_border").addClass("filterItem-content-selected-over");
  641. e.target.getElement("i").addClass("mainColor_color");
  642. },
  643. checkedFilterItemLeave: function(e){
  644. e.target.removeClass("mainColor_border").removeClass("filterItem-content-selected-over");
  645. e.target.getElement("i").removeClass("mainColor_color");
  646. },
  647. removeFilterItem: function(e, item){
  648. var index = -1;
  649. this.selectedFilterList.each(function (f, idx) {
  650. if( f.field === item.field )index = idx;
  651. });
  652. if( index > -1 ) { //已经选择了
  653. this.selectedFilterList.splice(index, 1);
  654. }
  655. this._search();
  656. },
  657. loadFilterTooltip: function(e, row){
  658. var target = this.app.getEventTarget(e, "filterItem-content");
  659. var arrowNode = target.getElement(".arrow");
  660. arrowNode.addEvents({
  661. "click": function (ev) {
  662. tooltip.status === "display" ? tooltip.hide() : tooltip.load();
  663. ev.stopPropagation();
  664. },
  665. "mouseover": function (ev) { ev.stopPropagation(); },
  666. "mouseout": function (ev) { ev.stopPropagation(); }
  667. });
  668. if( !this.tooltipList )this.tooltipList = [];
  669. var tooltip = new MWF.xApplication.ftsearch.FTSearchView.ConditionTooltip(this.app.appNode, target, this.app, row, {
  670. axis : "y",
  671. hasArrow: false,
  672. hiddenDelay : 300,
  673. displayDelay : 100,
  674. offset : {
  675. x : 0,
  676. y : -2
  677. },
  678. position : { //node 固定的位置
  679. x : "center", //x 轴上left center right, auto 系统自动计算
  680. y : "bottom" //y轴上top middle bottom, auto 系统自动计算
  681. },
  682. overflow : "scroll",
  683. isFitToContainer: true,
  684. nodeStyles: {
  685. "box-shadow": "#aaaaaa 0px 4px 18px 0px",
  686. "border": "1px solid #ccc"
  687. },
  688. onQueryLoad: function(){
  689. var width = Math.min(this.app.appNode.getSize().x - 80, 1200);
  690. if( tooltip.node ){
  691. tooltip.node.setStyle("width",width+"px");
  692. }else{
  693. tooltip.options.nodeStyles["width"] = width + "px"; //target.getSize().x + "px";
  694. tooltip.options.nodeStyles["max-width"] = "auto";
  695. }
  696. if( this.currentTooltip ){
  697. this.currentTooltip.hide();
  698. }
  699. }.bind(this),
  700. onPostLoad: function(){
  701. tooltip.node.addClass("mainColor_border");
  702. arrowNode.addClass("o2icon-chevron-thin-up").removeClass("o2icon-chevron-thin-down");
  703. target.addClass("filterItem-content-over").removeClass("filterItem-content").addClass("mainColor_border");
  704. target.setStyle("border-bottom", "0px");
  705. this.currentTooltip = tooltip;
  706. // if( tooltip.input )tooltip.input.focus();
  707. this.loadCurrentFilterItem(tooltip.contentNode, row);
  708. }.bind(this),
  709. onQueryCreate : function(){
  710. }.bind(this),
  711. onHide : function(){
  712. tooltip.node.removeClass("mainColor_border");
  713. arrowNode.addClass("o2icon-chevron-thin-down").removeClass("o2icon-chevron-thin-up");
  714. target.addClass("filterItem-content").removeClass("filterItem-content-over").removeClass("mainColor_border");
  715. target.setStyle("border-bottom", "1px solid #ccc");
  716. this.currentTooltip = null;
  717. }.bind(this),
  718. onSetCoondinates: function (obj) {
  719. obj.left = obj.left + 30
  720. }
  721. });
  722. this.tooltipList.push( tooltip );
  723. },
  724. loadCurrentFilterItem: function(node, row){
  725. node.empty();
  726. var itemWrap = new Element("div.filterItem-subitemWrap").inject(node);
  727. var array = this.data.facetList.filter(function (field) {
  728. return row.field === field.field
  729. });
  730. if( array.length > 0 ){
  731. var lp = this.app.lp;
  732. if( array[0].valueCountPairList.length > 1 ){
  733. var multiButton = new Element("div.filter-multi-button", {
  734. events: {
  735. "click": function () { this.loadMultiFilterItem(node, row) }.bind(this),
  736. "mouseenter": function () { multiButton.addClass("mainColor_color").addClass("mainColor_border") },
  737. "mouseleave": function () { multiButton.removeClass("mainColor_color").removeClass("mainColor_border") },
  738. }
  739. }).inject( itemWrap );
  740. new Element("i.o2icon-add").inject( multiButton );
  741. new Element("span", {text: lp.multiSelect}).inject( multiButton );
  742. }
  743. array[0].valueCountPairList.each(function (v) {
  744. // v.field = row.field;
  745. // v.parentLabel = row.label;
  746. if (["category","completed"].contains(row.field)) {
  747. v.label = lp[v.value.toString()] || v.value;
  748. } else {
  749. v.label = v.value;
  750. }
  751. var subitemNode = new Element("div.filterItem-subitem", {
  752. text: v.label + "("+v.count+")",
  753. events: {
  754. "click": function () {
  755. this.selectedFilterList.push({
  756. label: row.label,
  757. field: row.field,
  758. labelList: [v.label],
  759. valueList: [v.value]
  760. });
  761. this._search();
  762. }.bind(this),
  763. "mouseenter": function () { subitemNode.addClass("mainColor_color") },
  764. "mouseleave": function () { subitemNode.removeClass("mainColor_color") },
  765. }
  766. }).inject(itemWrap)
  767. }.bind(this));
  768. }
  769. },
  770. loadMultiFilterItem: function(node, row){
  771. node.empty();
  772. var itemWrap = new Element("div.filterItem-subitemWrap").inject(node);
  773. var array = this.data.facetList.filter(function (field) {
  774. return row.field === field.field
  775. });
  776. var lp = this.app.lp;
  777. array[0].valueCountPairList.each(function (v) {
  778. var sNode = new Element("div.filterItem-subitem", {
  779. events: {
  780. "click": function () {
  781. if( sNode.retrieve("checked") ){
  782. sNode.store("checked", false);
  783. icon.removeClass("o2icon-check_box").addClass("o2icon-check_box_outline_blank")
  784. }else{
  785. sNode.store("checked", true).addClass("mainColor_color");
  786. icon.addClass("o2icon-check_box").removeClass("o2icon-check_box_outline_blank")
  787. }
  788. },
  789. "mouseenter": function () { if( !sNode.retrieve("checked") )sNode.addClass("mainColor_color") },
  790. "mouseleave": function () { if( !sNode.retrieve("checked") )sNode.removeClass("mainColor_color") },
  791. }
  792. }).inject(itemWrap);
  793. sNode.store("v", v);
  794. var icon = new Element("i.checkbox").inject(sNode);
  795. icon.addClass("o2icon-check_box_outline_blank");
  796. var span = new Element("span", {
  797. text: v.label + "("+v.count+")",
  798. }).inject(sNode);
  799. });
  800. var buttonArea = new Element("div.filter-buttonArea").inject(node);
  801. var okButton = new Element("div.filter-okButton", {
  802. text: lp.ok,
  803. events: {
  804. "click": function () {
  805. var valueList = [], labelList = [];
  806. node.getElements("div.filterItem-subitem").each(function (sNode) {
  807. if( sNode.retrieve("checked") ){
  808. var v = sNode.retrieve("v");
  809. valueList.push( v.value );
  810. labelList.push( v.label );
  811. }
  812. })
  813. this.selectedFilterList.push({
  814. label: row.label,
  815. field: row.field,
  816. labelList: labelList,
  817. valueList: valueList
  818. });
  819. this._search();
  820. }.bind(this)
  821. }
  822. }).inject(buttonArea);
  823. okButton.addClass("mainColor_bg");
  824. var cancelButton = new Element("div.filter-cancelButton", {
  825. text: lp.cancel,
  826. events: {
  827. "click": function () { this.loadCurrentFilterItem(node, row) }.bind(this)
  828. }
  829. }).inject(buttonArea);
  830. }
  831. });
  832. MWF.xApplication.ftsearch.FTSearchView.ConditionTooltip = new Class({
  833. Extends: MTooltips,
  834. _customNode: function(node, contentNode){
  835. },
  836. _loadCustom : function( callback ){
  837. if(callback)callback();
  838. }
  839. });