CFilterGroup.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /****************************************************************
  2. ** Licensed Materials - Property of IBM
  3. **
  4. ** BI and PM: qs
  5. **
  6. ** (C) Copyright IBM Corp. 2001, 2015
  7. **
  8. ** US Government Users Restricted Rights - Use, duplication or
  9. ** disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *****************************************************************/
  11. // Copyright (C) 2008 Cognos ULC, an IBM Company. All Rights Reserved.
  12. // Cognos and the Cognos logo are trademarks of Cognos ULC (formerly Cognos Incorporated) in the United States and/or other countries. IBM and the IBM logo are trademarks of International Business Machines Corporation in the United States, or other countries, or both. Other company, product, or service names may be trademarks or service marks of others.
  13. var gsFILTEROPERATOR_AND = "AND";
  14. var gsFILTEROPERATOR_OR = "OR";
  15. var gsFILTEROPERATOR_NAND = "NAND";
  16. var gsFILTEROPERATOR_NOR = "NOR";
  17. var greFILTEROPERATOR_AND = new RegExp("^" + gsFILTEROPERATOR_AND + "$", "i");
  18. var greFILTEROPERATOR_OR = new RegExp("^" + gsFILTEROPERATOR_OR + "$", "i");
  19. var greFILTEROPERATOR_NAND = new RegExp("^" + gsFILTEROPERATOR_NAND + "$", "i");
  20. var greFILTEROPERATOR_NOR = new RegExp("^" + gsFILTEROPERATOR_NOR + "$", "i");
  21. var greCombinedFilter = /^CombinedFilter$/i;
  22. var greFilterGroup = /^FilterGroup$/i;
  23. var greFilter = /^Filter$/i;
  24. function CFilterGroup(sId, nNode)
  25. {
  26. var oMQMgr = goApplicationManager.getMiniQueryManager();
  27. if (!nNode || !nNode.nodeName)
  28. {
  29. nNode = XMLBuilderCreateElementNS("", "FilterGroup", oMQMgr.getDoc());
  30. }
  31. this.m_nNode = nNode;
  32. var sCurrentId = this.m_nNode.getAttribute("id");
  33. if (this.m_nNode && (sCurrentId === "" || sCurrentId === null))
  34. {
  35. var oCC = getCombinedFilter();
  36. if (typeof oCC !== "undefined" && oCC && (! sId || sId === ""))
  37. {
  38. sId = oCC.generateID("FG");
  39. }
  40. this.m_nNode.setAttribute("id", sId);
  41. }
  42. };
  43. function CFilterGroup_clone()
  44. {
  45. return (new CFilterGroup("", this.m_nNode.cloneNode(true)));
  46. };
  47. function CFilterGroup_addPredicate(oNewPredicate)
  48. {
  49. if (oNewPredicate)
  50. {
  51. if (oNewPredicate.m_nNode)
  52. {
  53. this.m_nNode.appendChild(oNewPredicate.m_nNode);
  54. }
  55. else if (oNewPredicate.nodeName)
  56. {
  57. this.m_nNode.appendChild(oNewPredicate);
  58. }
  59. }
  60. this.m_nNode.setAttribute("dirty", "true");
  61. };
  62. function CFilterGroup_clearDirtyFlag()
  63. {
  64. this.m_nNode.removeAttribute("dirty");
  65. var aChildren = XMLHelper_FindChildrenByAttribute(this.m_nNode, "dirty", "true", true);
  66. for (var i = 0; i < aChildren.length; i++)
  67. {
  68. aChildren[i].removeAttribute("dirty");
  69. }
  70. };
  71. function CFilterGroup_getCommand()
  72. {
  73. var arCmd = [];
  74. if (this.m_nNode.childNodes.length > 0)
  75. {
  76. var aChildNodes = this.m_nNode.childNodes;
  77. arCmd.push(this.m_nNode.getAttribute("operator"));
  78. arCmd.push(aChildNodes.length);
  79. for (var i = 0; i < aChildNodes.length; i++)
  80. {
  81. var oTemp = null;
  82. if (aChildNodes[i].nodeName.match(greFilterGroup))
  83. {
  84. oTemp = new CFilterGroup("", aChildNodes[i]);
  85. }
  86. else if (aChildNodes[i].nodeName.match(greFilter))
  87. {
  88. oTemp = new CFilter("", aChildNodes[i]);
  89. }
  90. if (oTemp)
  91. {
  92. arCmd = arCmd.concat(oTemp.getCommand());
  93. }
  94. else
  95. {
  96. arCmd.push(gsFILTER_EMPTY);
  97. }
  98. }
  99. }
  100. else
  101. {
  102. arCmd.push(gsFILTER_EMPTY);
  103. }
  104. return arCmd;
  105. };
  106. function CFilterGroup_getDepth()
  107. {
  108. var iDepth = 0;
  109. var nParent = this.m_nNode.parentNode;
  110. while (nParent && nParent.nodeName.match(greFilterGroup))
  111. {
  112. iDepth++;
  113. nParent = nParent.parentNode;
  114. }
  115. return iDepth;
  116. };
  117. function CFilterGroup_getFilterById(sId)
  118. {
  119. var oRetVal = null;
  120. var nFilter = null;
  121. var idxPredicate = 0;
  122. if (sId == this.m_nNode.getAttribute("id"))
  123. {
  124. nFilter = this.m_nNode;
  125. }
  126. else
  127. {
  128. var aChildren = XMLHelper_FindChildrenByAttribute(this.m_nNode, "id", sId, true);
  129. if (aChildren && aChildren.length > 0)
  130. {
  131. nFilter = aChildren[0];
  132. }
  133. }
  134. if (nFilter !== null)
  135. {
  136. if (nFilter.nodeName.match(greFilterGroup))
  137. {
  138. oRetVal = new CFilterGroup("", nFilter);
  139. }
  140. else
  141. {
  142. oRetVal = new CFilter("", nFilter);
  143. }
  144. }
  145. return oRetVal;
  146. };
  147. function CFilterGroup_getId()
  148. {
  149. return (this.m_nNode.getAttribute("id"));
  150. };
  151. function CFilterGroup_getIndex()
  152. {
  153. if (this.m_nNode && this.m_nNode.parentNode && this.m_nNode.parentNode.nodeName.match(greFilterGroup))
  154. {
  155. var aChildNodes = this.m_nNode.parentNode.childNodes;
  156. for (var i = 0; i < aChildNodes.length; i++)
  157. {
  158. if (aChildNodes[i] == this.m_nNode)
  159. {
  160. return i;
  161. }
  162. }
  163. }
  164. return -1;
  165. };
  166. function CFilterGroup_getOperator()
  167. {
  168. return this.m_nNode.getAttribute("operator");
  169. };
  170. function CFilterGroup_getParent()
  171. {
  172. return (new CFilterGroup("", this.m_node.parentNode));
  173. };
  174. function CFilterGroup_getPredicates()
  175. {
  176. var aPreds = [];
  177. var aChildren = this.m_nNode.childNodes;
  178. for (var idxChild = 0; idxChild < aChildren.length; idxChild++)
  179. {
  180. var nChild = aChildren[idxChild];
  181. if (nChild && nChild.nodeName.match(greFilterGroup))
  182. {
  183. aPreds.push( new CFilterGroup("", nChild) );
  184. }
  185. else
  186. {
  187. aPreds.push( new CFilter("", nChild) );
  188. }
  189. }
  190. return aPreds;
  191. };
  192. function CFilterGroup_getSize()
  193. {
  194. return this.m_nNode.childNodes.length;
  195. };
  196. function CFilterGroup_isDirty()
  197. {
  198. return (this.m_nNode.getAttribute("dirty") == "true");
  199. };
  200. function CFilterGroup_hasDirtyChildren()
  201. {
  202. var oFs = this.getFilters();
  203. var oFGs = this.getFilterGroups();
  204. for (var i = 0; i < oFs.length; i++)
  205. {
  206. if (oFs[i].isDirty())
  207. {
  208. return true;
  209. }
  210. }
  211. for (var i = 0; i < oFGs.length; i++)
  212. {
  213. if (oFGs[i].isDirty())
  214. {
  215. return true;
  216. }
  217. return oFGs[i].hasDirtyChildren();
  218. }
  219. return false;
  220. }
  221. function CFilterGroup_isNot()
  222. {
  223. var sOp = this.getOperator();
  224. return (sOp == gsFILTEROPERATOR_NAND || sOp == gsFILTEROPERATOR_NOR);
  225. };
  226. function CFilterGroup_removePredicate(sId, bPreventRebalance)
  227. {
  228. var aChildren = XMLHelper_FindChildrenByAttribute(this.m_nNode, "id", sId, true);
  229. for (var i = 0; i < aChildren.length; i++)
  230. {
  231. aChildren[i].parentNode.removeChild(aChildren[i]);
  232. }
  233. var nParent = this.m_nNode.parentNode;
  234. if (this.m_nNode.childNodes.length <= 0 && nParent && nParent.nodeName.match(greFilterGroup))
  235. {
  236. this.removeSelf(bPreventRebalance);
  237. }
  238. else
  239. {
  240. this.setDirty();
  241. if (!bPreventRebalance)
  242. {
  243. this.rebalance();
  244. }
  245. }
  246. return oRetVal;
  247. };
  248. function CFilterGroup_rebalance()
  249. {
  250. var aChildren = this.m_nNode.childNodes;
  251. var nParent = this.m_nNode.parentNode;
  252. if (aChildren.length < 2)
  253. {
  254. var sParentNodeName = nParent.nodeName;
  255. if (sParentNodeName.match(greFilterGroup))
  256. {
  257. if(aChildren.length == 1)
  258. {
  259. nParent.insertBefore(aChildren[0], this.m_nNode);
  260. }
  261. this.removeSelf();
  262. var oParent = new CFilterGroup("", nParent);
  263. oParent.rebalance();
  264. }
  265. else
  266. {
  267. if(aChildren.length == 1 && aChildren[0].nodeName.match(greFilterGroup))
  268. {
  269. var nFG = aChildren[0];
  270. this.setOperator(nFG.getAttribute("operator"));
  271. for (var i = 0; i < nFG.childNodes.length; i++)
  272. {
  273. var nChild = nFG.childNodes[i];
  274. this.m_nNode.insertBefore(nChild.cloneNode(true), nFG);
  275. }
  276. this.m_nNode.removeChild(nFG);
  277. }
  278. }
  279. }
  280. };
  281. function CFilterGroup_removeSelf(bPreventRebalance)
  282. {
  283. var nParent = this.m_nNode.parentNode;
  284. nParent.removeChild(this.m_nNode);
  285. if (nParent.nodeName.match(greFilterGroup) && !bPreventRebalance)
  286. {
  287. var oParentFG = new CFilterGroup("", nParent);
  288. oParentFG.rebalance();
  289. }
  290. return this;
  291. };
  292. function CFilterGroup_render()
  293. {
  294. var s = '';
  295. var oFs = this.getFilters();
  296. var oFGs = this.getFilterGroups();
  297. s += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody><tr>';
  298. s += '<td style="vertical-align:top;">';
  299. if (this.isNot())
  300. {
  301. s += '<table border="0" cellspacing="0" cellpadding="0"><tbody><tr><td class="tabletext' + (this.isDirty() ? " bold" : "") + '" style="padding-right:5px;">';
  302. s += cf.filterMsgStrings["FILTER_COMBINE_GROUP_NOT"];
  303. s += '</td><td>';
  304. s += this.renderLeftGrouping();
  305. s += '</td></tr></tbody></table>';
  306. }
  307. else
  308. {
  309. s += this.renderLeftGrouping();
  310. }
  311. s += '</td>';
  312. s += '<td width="100%"><table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody>';
  313. if (oFs.length)
  314. {
  315. s += '<tr><td style="vertical-align:top;padding:5px;border:1px solid #cccccc;" class="tabletext" width="100%">';
  316. for (var i = 0; i < oFs.length; i++)
  317. {
  318. s += oFs[i].render();
  319. if (i < oFs.length-1)
  320. {
  321. s += this.renderOperator();
  322. }
  323. }
  324. s += '</td></tr>';
  325. }
  326. if (oFGs.length)
  327. {
  328. for (i = 0; i < oFGs.length; i++)
  329. {
  330. if ( i > 0 || oFs.length)
  331. {
  332. s += '<tr><td class="tabletext" style="text-align:right">';
  333. s += this.renderOperator();
  334. s += '</td></tr>';
  335. }
  336. s += '<tr><td class="tabletext">';
  337. s += oFGs[i].render();
  338. s += '</td></tr>';
  339. }
  340. }
  341. s += '</tbody></table></td>';
  342. s += '<td class="tabletext" style="vertical-align:bottom;" width="8">' + this.renderRightGrouping() + '</td>';
  343. s += '</tr></tbody></table>';
  344. return s;
  345. };
  346. function CFilterGroup_renderLeftGrouping()
  347. {
  348. var sRoot = "";
  349. if (goApplicationManager.getReportFrame())
  350. {
  351. sRoot = goApplicationManager.getReportFrame().oCVQS.getWebContentRoot();
  352. }
  353. return '<img src="' + sRoot + '/qs/images/filter/leftbracket.gif" width="5" height="19" style="margin-top:3px;margin-right:3px">';
  354. };
  355. function CFilterGroup_renderOperator()
  356. {
  357. var sSkinFolder = "";
  358. if (goApplicationManager.getReportFrame())
  359. {
  360. sSkinFolder = goApplicationManager.getReportFrame().oCVQS.getSkin();
  361. }
  362. var sOp = (greFILTEROPERATOR_OR.test(this.getOperator()) || greFILTEROPERATOR_NOR.test(this.getOperator()) ? getConfigFrame().gsFilterOperatorOR : getConfigFrame().gsFilterOperatorAND);
  363. if (!sOp)
  364. {
  365. sOp = this.getOperator();
  366. }
  367. var c = "clsFilterOperator" + (this.isDirty() ? " bold" : "");
  368. var s = '<span><nobr class="' + c + '" onmouseup="getConfigFrame().CF_showContextMenu(event, \''+this.getId()+'\');">&#160;' +
  369. sOp +
  370. '<img onmouseup="getConfigFrame().CF_showContextMenu(event, \''+this.getId()+'\');" style="vertical-align:middle;border:none;" class="image '+c+'" src="'+ sSkinFolder + '/viewer/images/dropdown.gif" border="0" width="13" height="12">' +
  371. '</nobr></span>';
  372. return s;
  373. };
  374. function CFilterGroup_renderRightGrouping()
  375. {
  376. var sRoot = "";
  377. if (goApplicationManager.getReportFrame())
  378. {
  379. sRoot = goApplicationManager.getReportFrame().oCVQS.getWebContentRoot();
  380. }
  381. return '<img src="' + sRoot + '/qs/images/filter/rightbracket.gif" width="5" height="19" style="margin-top:3px;margin-left:3px">';
  382. };
  383. function CFilterGroup_renderSelector()
  384. {
  385. var sRoot = "";
  386. if (goApplicationManager.getReportFrame())
  387. {
  388. sRoot = goApplicationManager.getReportFrame().oCVQS.getWebContentRoot();
  389. }
  390. var s = '<div class="clsFilterRowIcon">';
  391. s += '<img src="' + sRoot + '/qs/images/filter/row_selector.gif" width="16" height="16" onclick="getConfigFrame().CF_SelectRow(event)" title="' + htmlencode(filterMsgStrings["SELECT_LINE_TIP"]) + '">';
  392. s += '</div>';
  393. return s;
  394. };
  395. function CFilterGroup_setDirty(bDirty)
  396. {
  397. if (bDirty !== false)
  398. {
  399. this.m_nNode.setAttribute("dirty", "true");
  400. }
  401. else
  402. {
  403. this.m_nNode.removeAttribute("dirty");
  404. }
  405. };
  406. function CFilterGroup_setNot(bNot)
  407. {
  408. if (bNot === true || bNot == "true")
  409. {
  410. if (this.getOperator() == gsFILTEROPERATOR_AND)
  411. {
  412. this.setOperator(gsFILTEROPERATOR_NAND);
  413. }
  414. else if (this.getOperator() == gsFILTEROPERATOR_OR)
  415. {
  416. this.setOperator(gsFILTEROPERATOR_NOR);
  417. }
  418. }
  419. else
  420. {
  421. if (this.getOperator() == gsFILTEROPERATOR_NAND)
  422. {
  423. this.setOperator(gsFILTEROPERATOR_AND);
  424. }
  425. else if (this.getOperator() == gsFILTEROPERATOR_NOR)
  426. {
  427. this.setOperator(gsFILTEROPERATOR_OR);
  428. }
  429. }
  430. this.setDirty();
  431. };
  432. function CFilterGroup_setOperator(sOperator)
  433. {
  434. if (sOperator !== this.m_nNode.getAttribute("operator"))
  435. {
  436. if (greFILTEROPERATOR_OR.test(sOperator))
  437. {
  438. this.m_nNode.setAttribute("operator", gsFILTEROPERATOR_OR);
  439. }
  440. else if (greFILTEROPERATOR_NOR.test(sOperator))
  441. {
  442. this.m_nNode.setAttribute("operator", gsFILTEROPERATOR_NOR);
  443. }
  444. else if (greFILTEROPERATOR_NAND.test(sOperator))
  445. {
  446. this.m_nNode.setAttribute("operator", gsFILTEROPERATOR_NAND);
  447. }
  448. else
  449. {
  450. this.m_nNode.setAttribute("operator", gsFILTEROPERATOR_AND);
  451. }
  452. this.setDirty();
  453. }
  454. };
  455. function CFilterGroup_showContextMenu(e, fgID)
  456. {
  457. var oSrc = null;
  458. oSrc = (e.srcElement ? e.srcElement : e.target);
  459. var df = getDialogFrame();
  460. if ( !(df.gFContextMenu instanceof df.CFilterContextMenu) )
  461. {
  462. df.gFContextMenu = new df.CFilterContextMenu(fgID);
  463. }
  464. df.gFContextMenu.draw(e, (fgID?fgID:oSrc.oFilterGroup.getId()));
  465. };
  466. CFilterGroup.prototype.addPredicate = CFilterGroup_addPredicate;
  467. CFilterGroup.prototype.clearDirtyFlag = CFilterGroup_clearDirtyFlag;
  468. CFilterGroup.prototype.clone = CFilterGroup_clone;
  469. CFilterGroup.prototype.getCommand = CFilterGroup_getCommand;
  470. CFilterGroup.prototype.getDepth = CFilterGroup_getDepth;
  471. CFilterGroup.prototype.getId = CFilterGroup_getId;
  472. CFilterGroup.prototype.getIndex = CFilterGroup_getIndex;
  473. CFilterGroup.prototype.getFilterById = CFilterGroup_getFilterById;
  474. CFilterGroup.prototype.getOperator = CFilterGroup_getOperator;
  475. CFilterGroup.prototype.getParent = CFilterGroup_getParent;
  476. CFilterGroup.prototype.getPredicates = CFilterGroup_getPredicates;
  477. CFilterGroup.prototype.getSize = CFilterGroup_getSize;
  478. CFilterGroup.prototype.isDirty = CFilterGroup_isDirty;
  479. CFilterGroup.prototype.hasDirtyChildren = CFilterGroup_hasDirtyChildren;
  480. CFilterGroup.prototype.isNot = CFilterGroup_isNot;
  481. CFilterGroup.prototype.rebalance = CFilterGroup_rebalance;
  482. CFilterGroup.prototype.removePredicate = CFilterGroup_removePredicate;
  483. CFilterGroup.prototype.removeSelf = CFilterGroup_removeSelf;
  484. CFilterGroup.prototype.render = CFilterGroup_render;
  485. CFilterGroup.prototype.renderLeftGrouping = CFilterGroup_renderLeftGrouping;
  486. CFilterGroup.prototype.renderOperator = CFilterGroup_renderOperator;
  487. CFilterGroup.prototype.renderRightGrouping = CFilterGroup_renderRightGrouping;
  488. CFilterGroup.prototype.renderSelector = CFilterGroup_renderSelector;
  489. CFilterGroup.prototype.setDirty = CFilterGroup_setDirty;
  490. CFilterGroup.prototype.setNot = CFilterGroup_setNot;
  491. CFilterGroup.prototype.setOperator = CFilterGroup_setOperator;
  492. CFilterGroup.prototype.showContextMenu = CFilterGroup_showContextMenu;
  493. CFilterGroup.prototype.getFilters = function()
  494. {
  495. var aFilterNodes = this.m_nNode.getElementsByTagName("Filter");
  496. var aCFilters = [];
  497. for (var i = 0; i < aFilterNodes.length; i++)
  498. {
  499. var oParent = aFilterNodes[i].parentNode;
  500. if (oParent === this.m_nNode)
  501. {
  502. aCFilters.push( new CFilter("", aFilterNodes[i]) );
  503. }
  504. }
  505. return aCFilters;
  506. };
  507. CFilterGroup.prototype.getFilterGroups = function()
  508. {
  509. var aFilterNodes = this.m_nNode.getElementsByTagName("FilterGroup");
  510. var aCFilterGroups = [];
  511. for (var i = 0; i < aFilterNodes.length; i++)
  512. {
  513. var oParent = aFilterNodes[i].parentNode;
  514. if (oParent === this.m_nNode)
  515. {
  516. var sId = aFilterNodes[i].id;
  517. aCFilterGroups.push( new CFilterGroup(sId, aFilterNodes[i]) );
  518. }
  519. }
  520. return aCFilterGroups;
  521. };
  522. CFilterGroup.prototype.getColumnIds = function()
  523. {
  524. var aColumnIds = [];
  525. var aF = this.getFilters();
  526. for (var i = 0; i < aF.length; i++)
  527. {
  528. aColumnIds.push( aF[i].getColumnId() );
  529. }
  530. var aFG = this.getFilterGroups();
  531. for (var i = 0; i < aFG.length; i++)
  532. {
  533. aColumnIds = aColumnIds.concat( aFG[i].getColumnIds() );
  534. }
  535. return aColumnIds;
  536. };
  537. function CF_showContextMenu(e, fid)
  538. {
  539. var oCC = getCombinedFilter();
  540. if (oCC)
  541. {
  542. var f = oCC.getFilterById(fid);
  543. if (f)
  544. {
  545. f.showContextMenu(e, fid);
  546. }
  547. }
  548. };