FTSearchView.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  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. if( !o2.api ){
  254. MWF.require("MWF.framework", function () {
  255. o2.api.page.openDocument(id);
  256. }.bind(this));
  257. }else{
  258. o2.api.page.openDocument(id);
  259. }
  260. },
  261. loadDocList: function(data, callback){
  262. this.docListNode.empty();
  263. this.docListNode.loadHtml(this.path+this.options.style+"/docList.html",
  264. {
  265. "bind": {"lp": this.app.lp, "data": data},
  266. "module": this,
  267. "reload": true
  268. },
  269. function(){
  270. if(callback)callback();
  271. }.bind(this)
  272. );
  273. },
  274. loadDocPagination: function(text){
  275. this.docPaginationNode.empty();
  276. if( o2.typeOf(this.docTotal) === "number" && this.docTotal > 0 ){
  277. this.docPaging = new o2.widget.Paging(this.docPaginationNode, {
  278. style: "blue_round",
  279. countPerPage: this.pageSize,
  280. visiblePages: 9,
  281. currentPage: 1,
  282. itemSize: this.docTotal,
  283. useMainColor: true,
  284. text: {
  285. firstPage: this.app.lp.firstPage,
  286. lastPage: this.app.lp.lastPage
  287. },
  288. // pageSize: pageSize,
  289. onJumpingPage: function (pageNum) {
  290. this._search(pageNum);
  291. }.bind(this),
  292. hasInfor: true,
  293. inforTextStyle: text,
  294. onPostLoad: function () {
  295. this.wraper.setStyle("border-top", "1px solid #4A90E2");
  296. this.wraper.addClass("mainColor_border");
  297. }
  298. });
  299. this.docPaging.load();
  300. }
  301. },
  302. loadCondition: function( json ){
  303. var lp = this.app.lp;
  304. json.each(function(d){
  305. d.label = lp[d.field.toString()] || d.field;
  306. d.valueCountPairList.each(function (v) {
  307. v.field = d.field;
  308. v.parentLabel = d.label;
  309. if( ["category","completed"].contains(d.field)){
  310. v.label = lp[v.value.toString()] || v.value;
  311. }else{
  312. v.label = v.value;
  313. }
  314. });
  315. });
  316. this.conditionArea.empty();
  317. json = json.filter(function(d){
  318. return d.valueCountPairList && d.valueCountPairList.length;
  319. });
  320. json.each(function(d, i){
  321. d.index = i;
  322. });
  323. this.conditionArea.loadHtml(this.path+this.options.style+"/condition.html",
  324. {
  325. "bind": {"lp": this.app.lp, "data": json, status: {
  326. collapseCondition: this.collapseCondition,
  327. showSwitch: json.length > 1
  328. }},
  329. "module": this,
  330. "reload": true
  331. },
  332. function(){
  333. }.bind(this)
  334. );
  335. // }.bind(this));
  336. },
  337. switchCondition: function(){
  338. this.collapseCondition = !this.collapseCondition;
  339. if( this.collapseCondition ){
  340. this.switchNode.getElement("i").addClass( 'o2icon-chevron-thin-down' ).removeClass('o2icon-chevron-thin-up');
  341. this.switchNode.getElement("span").set("text", this.app.lp.expandCondition);
  342. this.conditionNode.getElements(".itemWrap").each(function (item, index) {
  343. item.setStyle("display", index ? "none": "")
  344. })
  345. }else{
  346. this.switchNode.getElement("i").removeClass( 'o2icon-chevron-thin-down' ).addClass('o2icon-chevron-thin-up');
  347. this.switchNode.getElement("span").set("text", this.app.lp.collapseCondition);
  348. this.conditionNode.getElements(".itemWrap").each(function (item, index) {
  349. item.setStyle("display", "");
  350. })
  351. }
  352. MWF.UD.putData("ftsearchCollapseCondition", this.collapseCondition.toString(), null,);
  353. },
  354. loadSelectedCondition: function(){
  355. this.conditionSelectedArea.empty();
  356. this.selectedConditionList.each(function (item) {
  357. var condNode = new Element("div.item", {
  358. events: {
  359. mouseover: function (ev) {
  360. this.conditionSelectedOver(ev)
  361. }.bind(this),
  362. mouseout: function (ev) {
  363. this.conditionSelectedOut(ev)
  364. }.bind(this)
  365. }
  366. }).inject( this.conditionSelectedArea );
  367. condNode.addClass("mainColor_bg");
  368. condNode.addEvents({
  369. click: function (ev) {
  370. this.removeSelectedConditionItem(ev, item, condNode)
  371. }.bind(this),
  372. });
  373. new Element("span", {
  374. text: item.parentLabel+":"
  375. }).inject(condNode);
  376. var titleList = [];
  377. item.labelList.each(function (label, i) {
  378. if( i === 2 ){
  379. new Element("div.item-text", {
  380. text: "..."
  381. }).inject(condNode);
  382. }else if( i <= 1 ){
  383. new Element("div.item-text", {
  384. text: label
  385. }).inject(condNode);
  386. }
  387. titleList.push( label );
  388. });
  389. var iconNode = new Element("i.o2icon-close").inject(condNode);
  390. iconNode.addClass("icon");
  391. condNode.set("title", item.parentLabel+":" + titleList.join(","));
  392. }.bind(this))
  393. },
  394. // loadSelectedCondition: function(){
  395. // this.conditionSelectedArea.empty();
  396. // this.conditionSelectedArea.loadHtml(this.path+this.options.style+"/conditionSelected.html",
  397. // {
  398. // "bind": {"lp": this.app.lp, "data": this.selectedConditionList},
  399. // "module": this,
  400. // "reload": true
  401. // },
  402. // function(){
  403. //
  404. // }.bind(this)
  405. // );
  406. // },
  407. iconOver: function(e){
  408. e.target.addClass('mainColor_color');
  409. },
  410. iconOut: function(e){
  411. e.target.removeClass('mainColor_color');
  412. },
  413. inputOver: function(e){
  414. this.app.getEventTarget(e, "view_inputArea").addClass('mainColor_border');
  415. },
  416. inputOut: function(e){
  417. this.app.getEventTarget(e, "view_inputArea").removeClass('mainColor_border');
  418. },
  419. loadMultiSelectConditionItem: function(e, row){
  420. if( this.curMultiSelectNode ){
  421. this.curMultiSelectNode.empty();
  422. this.curMultiSelectNode.hide();
  423. this.curMultiSelectItemNode.show();
  424. }
  425. this.curMultiSelectConditionList = [];
  426. this.curMultiSelectItemNode = e.target.getParent(".item");
  427. this.curMultiSelectItemNode.hide();
  428. this.curMultiSelectNode = this.curMultiSelectItemNode.getParent().getElement(".item-multiselect").show();
  429. this.curMultiSelectNode.loadHtml(this.path+this.options.style+"/conditionItem_multiselect.html",
  430. {
  431. "bind": {"lp": this.app.lp, "data": row},
  432. "module": this,
  433. "reload": true
  434. },
  435. function(){}.bind(this)
  436. );
  437. },
  438. multiSelect: function(e, item){
  439. var target = this.app.getEventTarget(e, "subItem-content");
  440. var index = -1;
  441. this.curMultiSelectConditionList.each(function (cond, idx) {
  442. if( cond.field === item.field && cond.value === item.value )index = idx;
  443. });
  444. if( index > -1 ){ //已经选择了
  445. target.getElement("i.checkbox").removeClass("o2icon-check_box").addClass("o2icon-check_box_outline_blank").removeClass("mainColor_color");
  446. this.curMultiSelectConditionList.splice(index, 1);
  447. }else{ //还没有选择
  448. target.getElement("i.checkbox").removeClass("o2icon-check_box_outline_blank").addClass("o2icon-check_box").addClass("mainColor_color");
  449. this.curMultiSelectConditionList.push(item);
  450. }
  451. },
  452. okMultiSelect: function(e, item){
  453. if(!this.curMultiSelectConditionList.length){
  454. this.app.notice(this.app.lp.selectConditionNote, "info");
  455. return;
  456. }
  457. var object = {
  458. field: this.curMultiSelectConditionList[0].field,
  459. parentLabel: this.curMultiSelectConditionList[0].parentLabel,
  460. valueList: [],
  461. labelList: []
  462. };
  463. this.curMultiSelectConditionList.each(function(cond){
  464. object.valueList.push(cond.value);
  465. object.labelList.push(cond.label);
  466. })
  467. this.changeCondition(e, object)
  468. },
  469. cancelMultiSelect: function(e, item){
  470. if( this.curMultiSelectNode ){
  471. this.curMultiSelectItemNode.show();
  472. this.curMultiSelectNode.empty();
  473. this.curMultiSelectNode.hide();
  474. }
  475. },
  476. checkAllSwitchButton: function(e){
  477. if(this.conditionNode)this.conditionNode.getElements(".item").each(function(itemNode){
  478. var more = itemNode.getElement(".switch-button");
  479. var ul = itemNode.getElement(".subitem-wrap");
  480. if( 41 < ul.scrollHeight ){
  481. more.show();
  482. }else{
  483. more.hide();
  484. }
  485. });
  486. },
  487. checkSwitchButton: function(e){
  488. var p = e.target.getParent();
  489. var more = p.getElement(".switch-button");
  490. var ul = p.getElement(".subitem-wrap");
  491. if( 41 < ul.scrollHeight ){
  492. more.show();
  493. }else{
  494. more.hide();
  495. }
  496. },
  497. switchConditionItem: function(e){
  498. var more = this.app.getEventTarget(e, "switch-button");
  499. var ul = more.getParent().getElement(".subitem-wrap");
  500. if( ul.retrieve("expand") ){
  501. ul.removeClass("subitem-wrap_expand");
  502. more.getElement("i").addClass("o2icon-triangle_down").removeClass("o2icon-triangle_up");
  503. more.getElement("span").innerText = this.app.lp.more;
  504. ul.store("expand", false);
  505. }else{
  506. ul.addClass("subitem-wrap_expand");
  507. more.getElement("i").addClass("o2icon-triangle_up").removeClass("o2icon-triangle_down");
  508. more.getElement("span").innerText = this.app.lp.collapse;
  509. ul.store("expand", true);
  510. }
  511. },
  512. changeCondition: function(e, item, removedItemNode){
  513. var index = -1;
  514. this.selectedConditionList.each(function (cond, idx) {
  515. if( cond.field === item.field )index = idx;
  516. });
  517. if( index > -1 ) { //已经选择了
  518. this.selectedConditionList.splice(index, 1);
  519. }else{
  520. this.selectedConditionList.push(item);
  521. }
  522. this._search( null, null,function () {
  523. this.loadSelectedCondition()
  524. }.bind(this));
  525. },
  526. changeSingleCondition: function(e, item){
  527. var itemIndex = -1, valueIndex = -1;
  528. this.selectedConditionList.each(function (cond, idx) {
  529. if( cond.field === item.field ){
  530. itemIndex = idx;
  531. valueIndex = cond.valueList.indexOf(item.value);
  532. }
  533. });
  534. if( valueIndex > -1 ){ //已经选择了
  535. e.target.removeClass('mainColor_bg');
  536. e.target.store("selected", false);
  537. this.selectedConditionList[itemIndex].valueList.splice(valueIndex, 1);
  538. this.selectedConditionList[itemIndex].labelList.splice(valueIndex, 1);
  539. if( !this.selectedConditionList[itemIndex].valueList.length ){
  540. this.selectedConditionList.splice(itemIndex, 1);
  541. }
  542. }else{ //还没有选择
  543. e.target.removeClass('mainColor_bg_opacity');
  544. e.target.addClass('mainColor_bg');
  545. e.target.store("selected", true);
  546. if( itemIndex > -1 ){
  547. this.selectedConditionList[itemIndex].valueList.push(item.value);
  548. this.selectedConditionList[itemIndex].labelList.push(item.label);
  549. }else{
  550. this.selectedConditionList.push({
  551. field: item.field,
  552. parentLabel: item.parentLabel,
  553. valueList: [item.value],
  554. labelList: [item.label]
  555. });
  556. }
  557. }
  558. this._search(null, null, function () {
  559. // this.loadSelectedCondition();
  560. }.bind(this));
  561. },
  562. subConditionOver: function(e){
  563. if(!e.target.retrieve("selected"))e.target.addClass('mainColor_bg_opacity');
  564. },
  565. subConditionOut: function(e){
  566. if(!e.target.retrieve("selected"))e.target.removeClass('mainColor_bg_opacity');
  567. },
  568. subConditionOver_multi: function(e){
  569. var target = this.app.getEventTarget(e, "subItem-content");
  570. if(!target.retrieve("selected"))target.addClass('mainColor_bg_opacity');
  571. },
  572. subConditionOut_multi: function(e){
  573. var target = this.app.getEventTarget(e, "subItem-content");
  574. if(!target.retrieve("selected"))target.removeClass('mainColor_bg_opacity');
  575. },
  576. removeSelectedConditionItem: function(e, item, itemNode){
  577. this.changeCondition(e, item, itemNode);
  578. },
  579. conditionSelectedOver: function(e){
  580. this.app.getEventTarget(e, "item").getElement("i").addClass("icon_over");
  581. },
  582. conditionSelectedOut: function(e){
  583. this.app.getEventTarget(e, "item").getElement("i").removeClass("icon_over");
  584. },
  585. mainColorOver: function (className, e) {
  586. var target = this.app.getEventTarget(e, className);
  587. if(target)target.addClass('mainColor_color');
  588. },
  589. mainColorOut: function (className, e) {
  590. var target = this.app.getEventTarget(e, className);
  591. if(target)target.removeClass('mainColor_color');
  592. },
  593. loadFilter: function( json, callback ){
  594. var lp = this.app.lp;
  595. this.filterArea.empty();
  596. if( this.tooltipList && this.tooltipList.length ){
  597. this.tooltipList.each(function (tooltip) {
  598. tooltip.destroy();
  599. });
  600. this.tooltipList = [];
  601. this.currentTooltip = null;
  602. }
  603. var index = 0;
  604. var facetList = [];
  605. json.each(function(d) {
  606. if (d.valueCountPairList && d.valueCountPairList.length){
  607. d.index = index;
  608. index++;
  609. d.label = lp[d.field] || d.name || d.field;
  610. // d.valueCountPairList.each(function (v) {
  611. // v.field = d.field;
  612. // v.parentLabel = d.label;
  613. // if (["category","completed"].contains(d.field)) {
  614. // v.label = lp[v.value.toString()] || v.value;
  615. // } else {
  616. // v.label = v.value;
  617. // }
  618. // });
  619. facetList.push(d);
  620. }
  621. });
  622. this.filterArea.empty();
  623. if( this.selectedFilterList.length || facetList.length ){
  624. this.filterArea.removeClass("index-filterNoDoc");
  625. this.filterArea.loadHtml(this.path+this.options.style+"/filter.html",
  626. {
  627. "bind": {
  628. "lp": this.app.lp,
  629. "selectedFilterList": this.selectedFilterList,
  630. "filterList": facetList
  631. },
  632. "module": this,
  633. "reload": true
  634. },
  635. function(){
  636. if(callback)callback();
  637. }.bind(this)
  638. );
  639. }else{
  640. this.filterArea.addClass("index-filterNoDoc")
  641. if(callback)callback();
  642. }
  643. },
  644. checkedFilterItemEnter: function(e){
  645. e.target.addClass("mainColor_border").addClass("filterItem-content-selected-over");
  646. e.target.getElement("i").addClass("mainColor_color");
  647. },
  648. checkedFilterItemLeave: function(e){
  649. e.target.removeClass("mainColor_border").removeClass("filterItem-content-selected-over");
  650. e.target.getElement("i").removeClass("mainColor_color");
  651. },
  652. removeFilterItem: function(e, item){
  653. var index = -1;
  654. this.selectedFilterList.each(function (f, idx) {
  655. if( f.field === item.field )index = idx;
  656. });
  657. if( index > -1 ) { //已经选择了
  658. this.selectedFilterList.splice(index, 1);
  659. }
  660. this._search();
  661. },
  662. loadFilterTooltip: function(e, row){
  663. var target = this.app.getEventTarget(e, "filterItem-content");
  664. var arrowNode = target.getElement(".arrow");
  665. arrowNode.addEvents({
  666. "click": function (ev) {
  667. tooltip.status === "display" ? tooltip.hide() : tooltip.load();
  668. ev.stopPropagation();
  669. },
  670. "mouseover": function (ev) { ev.stopPropagation(); },
  671. "mouseout": function (ev) { ev.stopPropagation(); }
  672. });
  673. if( !this.tooltipList )this.tooltipList = [];
  674. var tooltip = new MWF.xApplication.ftsearch.FTSearchView.ConditionTooltip(this.app.appNode, target, this.app, row, {
  675. axis : "y",
  676. hasArrow: false,
  677. hiddenDelay : 300,
  678. displayDelay : 100,
  679. offset : {
  680. x : 0,
  681. y : -2
  682. },
  683. position : { //node 固定的位置
  684. x : "center", //x 轴上left center right, auto 系统自动计算
  685. y : "bottom" //y轴上top middle bottom, auto 系统自动计算
  686. },
  687. overflow : "scroll",
  688. isFitToContainer: true,
  689. nodeStyles: {
  690. "box-shadow": "#aaaaaa 0px 4px 18px 0px",
  691. "border": "1px solid #ccc"
  692. },
  693. onQueryLoad: function(){
  694. var width = Math.min(this.app.appNode.getSize().x - 80, 1200);
  695. if( tooltip.node ){
  696. tooltip.node.setStyle("width",width+"px");
  697. }else{
  698. tooltip.options.nodeStyles["width"] = width + "px"; //target.getSize().x + "px";
  699. tooltip.options.nodeStyles["max-width"] = "auto";
  700. }
  701. if( this.currentTooltip ){
  702. this.currentTooltip.hide();
  703. }
  704. }.bind(this),
  705. onPostLoad: function(){
  706. tooltip.node.addClass("mainColor_border");
  707. arrowNode.addClass("o2icon-chevron-thin-up").removeClass("o2icon-chevron-thin-down");
  708. target.addClass("filterItem-content-over").removeClass("filterItem-content").addClass("mainColor_border");
  709. target.setStyle("border-bottom", "0px");
  710. this.currentTooltip = tooltip;
  711. // if( tooltip.input )tooltip.input.focus();
  712. this.loadCurrentFilterItem(tooltip.contentNode, row);
  713. }.bind(this),
  714. onQueryCreate : function(){
  715. }.bind(this),
  716. onHide : function(){
  717. tooltip.node.removeClass("mainColor_border");
  718. arrowNode.addClass("o2icon-chevron-thin-down").removeClass("o2icon-chevron-thin-up");
  719. target.addClass("filterItem-content").removeClass("filterItem-content-over").removeClass("mainColor_border");
  720. target.setStyle("border-bottom", "1px solid #ccc");
  721. this.currentTooltip = null;
  722. }.bind(this),
  723. onSetCoondinates: function (obj) {
  724. obj.left = obj.left + 30
  725. }
  726. });
  727. this.tooltipList.push( tooltip );
  728. },
  729. loadCurrentFilterItem: function(node, row){
  730. node.empty();
  731. var itemWrap = new Element("div.filterItem-subitemWrap").inject(node);
  732. var array = this.data.facetList.filter(function (field) {
  733. return row.field === field.field
  734. });
  735. if( array.length > 0 ){
  736. var lp = this.app.lp;
  737. if( array[0].valueCountPairList.length > 1 ){
  738. var multiButton = new Element("div.filter-multi-button", {
  739. events: {
  740. "click": function () { this.loadMultiFilterItem(node, row) }.bind(this),
  741. "mouseenter": function () { multiButton.addClass("mainColor_color").addClass("mainColor_border") },
  742. "mouseleave": function () { multiButton.removeClass("mainColor_color").removeClass("mainColor_border") },
  743. }
  744. }).inject( itemWrap );
  745. new Element("i.o2icon-add").inject( multiButton );
  746. new Element("span", {text: lp.multiSelect}).inject( multiButton );
  747. }
  748. array[0].valueCountPairList.each(function (v) {
  749. // v.field = row.field;
  750. // v.parentLabel = row.label;
  751. if (["category","completed"].contains(row.field)) {
  752. v.label = lp[v.value.toString()] || v.value;
  753. } else {
  754. v.label = v.value;
  755. }
  756. var subitemNode = new Element("div.filterItem-subitem", {
  757. text: v.label + "("+v.count+")",
  758. events: {
  759. "click": function () {
  760. this.selectedFilterList.push({
  761. label: row.label,
  762. field: row.field,
  763. labelList: [v.label],
  764. valueList: [v.value]
  765. });
  766. this._search();
  767. }.bind(this),
  768. "mouseenter": function () { subitemNode.addClass("mainColor_color") },
  769. "mouseleave": function () { subitemNode.removeClass("mainColor_color") },
  770. }
  771. }).inject(itemWrap)
  772. }.bind(this));
  773. }
  774. },
  775. loadMultiFilterItem: function(node, row){
  776. node.empty();
  777. var itemWrap = new Element("div.filterItem-subitemWrap").inject(node);
  778. var array = this.data.facetList.filter(function (field) {
  779. return row.field === field.field
  780. });
  781. var lp = this.app.lp;
  782. array[0].valueCountPairList.each(function (v) {
  783. var sNode = new Element("div.filterItem-subitem", {
  784. events: {
  785. "click": function () {
  786. if( sNode.retrieve("checked") ){
  787. sNode.store("checked", false);
  788. icon.removeClass("o2icon-check_box").addClass("o2icon-check_box_outline_blank")
  789. }else{
  790. sNode.store("checked", true).addClass("mainColor_color");
  791. icon.addClass("o2icon-check_box").removeClass("o2icon-check_box_outline_blank")
  792. }
  793. },
  794. "mouseenter": function () { if( !sNode.retrieve("checked") )sNode.addClass("mainColor_color") },
  795. "mouseleave": function () { if( !sNode.retrieve("checked") )sNode.removeClass("mainColor_color") },
  796. }
  797. }).inject(itemWrap);
  798. sNode.store("v", v);
  799. var icon = new Element("i.checkbox").inject(sNode);
  800. icon.addClass("o2icon-check_box_outline_blank");
  801. var span = new Element("span", {
  802. text: v.label + "("+v.count+")",
  803. }).inject(sNode);
  804. });
  805. var buttonArea = new Element("div.filter-buttonArea").inject(node);
  806. var okButton = new Element("div.filter-okButton", {
  807. text: lp.ok,
  808. events: {
  809. "click": function () {
  810. var valueList = [], labelList = [];
  811. node.getElements("div.filterItem-subitem").each(function (sNode) {
  812. if( sNode.retrieve("checked") ){
  813. var v = sNode.retrieve("v");
  814. valueList.push( v.value );
  815. labelList.push( v.label );
  816. }
  817. })
  818. this.selectedFilterList.push({
  819. label: row.label,
  820. field: row.field,
  821. labelList: labelList,
  822. valueList: valueList
  823. });
  824. this._search();
  825. }.bind(this)
  826. }
  827. }).inject(buttonArea);
  828. okButton.addClass("mainColor_bg");
  829. var cancelButton = new Element("div.filter-cancelButton", {
  830. text: lp.cancel,
  831. events: {
  832. "click": function () { this.loadCurrentFilterItem(node, row) }.bind(this)
  833. }
  834. }).inject(buttonArea);
  835. }
  836. });
  837. MWF.xApplication.ftsearch.FTSearchView.ConditionTooltip = new Class({
  838. Extends: MTooltips,
  839. _customNode: function(node, contentNode){
  840. },
  841. _loadCustom : function( callback ){
  842. if(callback)callback();
  843. }
  844. });