nonDuplicationItems.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2008 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. //***************************************************
  11. //start NonDuplicationItems object
  12. //***************************************************
  13. function NonDuplicationItems(sItems)
  14. {
  15. //This list should not be displayed really.
  16. var uiStyle = new CUIStyle("CList_li", "CList_over", "CList_selected", "", null);
  17. this.cList = new CList('NonDupList',true, "CList_ul",uiStyle);
  18. this.DELIM=';';
  19. this.parseFromString(sItems);
  20. this.cList.setEqualityFunc(
  21. function listEqualityCheck(list,node) {
  22. var result = false;
  23. var items = list.getAllItems();
  24. for (var i=0; items && i < items.length;i++) {
  25. result = result || items[i].nodeValue.localeCompare(node.nodeValue) == 0;
  26. }
  27. return result;
  28. }
  29. );
  30. }
  31. /**
  32. * remove a non dupe item from this if there is one
  33. */
  34. NonDuplicationItems.prototype.getList = function()
  35. {
  36. return this.cList;
  37. }
  38. /**
  39. * remove a non dupe item from this if there is one
  40. */
  41. NonDuplicationItems.prototype.removeItem = function(sItem)
  42. {
  43. var nodes = this.cList.getAllNodes();
  44. for (var i=0; i < nodes.length; i++) {
  45. if(nodes[i].firstChild.nodeValue.localeCompare(sItem)== 0){
  46. var index = this.cList.indexById(nodes[i].id);
  47. this.cList.remove(index);
  48. }
  49. }
  50. }
  51. /**
  52. * remove a non dupe item from this if there is one
  53. */
  54. NonDuplicationItems.prototype.items = function()
  55. {
  56. var result = new Array();
  57. var items = this.cList.getAllItems();
  58. for (var i=0; i < items.length; i++) {
  59. result.push(items[i].nodeValue);
  60. }
  61. return result;
  62. }
  63. NonDuplicationItems.prototype.containsItem = function(sItem)
  64. {
  65. var textNode = document.createTextNode(sItem);
  66. return this.cList.containsItem(textNode);
  67. }
  68. //load all the query items into the textarea
  69. NonDuplicationItems.prototype.toString = function()
  70. {
  71. var theStr = "";
  72. var textNodes = this.cList.getAllItems();
  73. for (var i=0;i<textNodes.length;i++) {
  74. theStr = theStr + textNodes[i].nodeValue;
  75. }
  76. return theStr;
  77. }
  78. /*
  79. Parse the content of the textarea for valid query items
  80. */
  81. NonDuplicationItems.prototype.parseFromString = function(stringValue)
  82. {
  83. if (stringValue && stringValue != 'undefined' && stringValue.localeCompare("") != 0) {
  84. var items = stringValue.split(this.DELIM);
  85. for(var i=0;i < items.length;i++) {
  86. if (items[i].localeCompare("") != 0) {
  87. var textNode = document.createTextNode(items[i] + this.DELIM);
  88. this.cList.add(textNode);
  89. }
  90. }
  91. }
  92. }
  93. NonDuplicationItems.prototype.size = function()
  94. {
  95. return this.cList.size();
  96. }
  97. NonDuplicationItems.prototype.clear = function()
  98. {
  99. this.cList.removeAllNodes();
  100. }
  101. //***************************************************
  102. //end NonDuplicationItems object
  103. //***************************************************