ComboBox.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: pps
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2017
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. var COMBO_BOX_FLYOUT_SCROLL_PADDING = 30;
  9. var comboBoxes = new Array();
  10. function initComboBox(container) {
  11. comboBoxes[container.id] = new comboBox(container);
  12. return comboBoxes[container.id];
  13. }
  14. function displayCBOptions(event) {
  15. var eventM = new eventManager(event);
  16. eventM.cancelBubble();
  17. var caller = eventM.getSrc().parentNode.parentNode.parentNode.parentNode;
  18. comboBoxes[caller.id].displayDropDown();
  19. }
  20. function cbTextItem(text, action, isDefault) {
  21. this.text = text;
  22. this.action = action;
  23. this.itemType = "textItem";
  24. this.isDefault = isDefault;
  25. }
  26. function cbTextImageItem(text, image, action, isDefault) {
  27. this.text = text;
  28. this.image = image;
  29. this.action = action;
  30. this.itemType = "textImageItem";
  31. this.isDefault = isDefault;
  32. }
  33. function cbImageTextItem(text, image, action, isDefault) {
  34. this.text = text;
  35. this.image = image;
  36. this.action = action;
  37. this.itemType = "imageTextItem";
  38. this.isDefault = isDefault;
  39. }
  40. function cbRepeatingImageItem(image, action, isDefault) {
  41. this.image = image;
  42. this.action = action;
  43. this.itemType = "repeatingImageItem";
  44. this.isDefault = isDefault;
  45. }
  46. function comboBox(container) {
  47. this.container = container;
  48. var selectedItem = -1;
  49. this.getSelectedItem = function() {
  50. return selectedItem;
  51. }
  52. var items = new Array();
  53. var flyout;
  54. this.addItem = function(item) {
  55. items[items.length] = item;
  56. if (item.isDefault || items.length == 1)
  57. setSelectedItem(items.length - 1);
  58. }
  59. this.getItem = function(item) {
  60. return items[item];
  61. }
  62. this.numItems = function() {
  63. return items.length;
  64. }
  65. this.clearItems = function() {
  66. items = new Array();
  67. selectedItem = -1;
  68. }
  69. function setSelectedItem(idx) {
  70. var text = container.firstChild.firstChild.firstChild;
  71. while(text.firstChild)
  72. text.removeChild(text.lastChild);
  73. createFlyoutItemContent(text, items[idx]);
  74. selectedItem = idx;
  75. }
  76. this.setSelectedItem = setSelectedItem;
  77. this.numItems = function() {
  78. return items.length;
  79. }
  80. this.displayDropDown = function() {
  81. if (selectedItem == -1)
  82. setSelectedItem(0);
  83. if (flyout != null) {
  84. document.body.removeChild(flyout);
  85. flyout = null;
  86. }
  87. flyout = document.createElement("DIV");
  88. if (items.length <= 5)
  89. flyout.className = "comboBoxDropDown";
  90. else
  91. flyout.className = "comboBoxDropDownLimited";
  92. flyout.style.top = getPageOffsetTop(container) + container.offsetHeight;
  93. flyout.style.left = getPageOffsetLeft(container);
  94. flyout.style.width = container.offsetWidth;
  95. for (var i = 0; i < items.length; i++)
  96. populateFlyoutItem(i);
  97. document.body.appendChild(flyout);
  98. window.setTimeout("comboBoxes[\"" + container.id + "\"].sizeDropDown();",1);
  99. }
  100. this.sizeDropDown = function() {
  101. if (flyout.scrollWidth > flyout.offsetWidth) {
  102. flyout.style.width = flyout.scrollWidth + COMBO_BOX_FLYOUT_SCROLL_PADDING;
  103. }
  104. }
  105. function populateFlyoutItem(idx) {
  106. var fItem = document.createElement("DIV");
  107. fItem.className = "comboBoxItem";
  108. fItem.onmouseover = function() {
  109. this.className = "comboBoxItemOver";
  110. }
  111. fItem.onmouseout = function() {
  112. this.className = "comboBoxItem";
  113. }
  114. fItem.onclick = function() {
  115. setSelectedItem(idx);
  116. hideDropDown();
  117. if (items[idx].action)
  118. eval(items[idx].action);
  119. }
  120. createFlyoutItemContent(fItem, items[idx]);
  121. flyout.appendChild(fItem);
  122. }
  123. function createFlyoutItemContent(cont, item) {
  124. if (item.itemType == "textItem") {
  125. cont.appendChild(document.createTextNode(item.text));
  126. } else if (item.itemType == "textImageItem") {
  127. cont.appendChild(document.createTextNode(item.text + " ("));
  128. insertIMGNode(cont, item.image, "comboBoxItemImg", [new attrib("width","16"),new attrib("height","16")]);
  129. cont.appendChild(document.createTextNode(")"));
  130. } else if (item.itemType == "imageTextItem") {
  131. insertIMGNode(cont, item.image, "comboBoxItemImg", [new attrib("width","16"),new attrib("height","16")]);
  132. cont.appendChild(document.createTextNode(" " + item.text));
  133. } else if (item.itemType == "repeatingImageItem") {
  134. insertIMGNode(cont, item.image, "comboBoxItemImg", [new attrib("height","16")]);
  135. }
  136. }
  137. function hideDropDown() {
  138. if (flyout != null) {
  139. for (var i = flyout.childNodes.length - 1; i >= 0; i--) {
  140. if (flyout.childNodes[i].onmouseover)
  141. flyout.childNodes[i].onmouseover = null;
  142. if (flyout.childNodes[i].onmouseout)
  143. flyout.childNodes[i].onmouseout = null;
  144. if (flyout.childNodes[i].onclick)
  145. flyout.childNodes[i].onclick = null;
  146. }
  147. document.body.removeChild(flyout);
  148. flyout = null;
  149. }
  150. }
  151. this.hideDropDown = function () {hideDropDown();}
  152. }
  153. function getPageOffsetLeft(obj) {
  154. var left = obj.offsetLeft;
  155. var oParent = obj.offsetParent;
  156. while (oParent) {
  157. left += oParent.offsetLeft;
  158. oParent = oParent.offsetParent;
  159. }
  160. //Now we have to remove any scrolling
  161. var scrollLeft = 0;
  162. oParent = obj;
  163. while (oParent && !oParent.body) {
  164. scrollLeft += oParent.scrollLeft;
  165. oParent = oParent.parentNode;
  166. }
  167. return left - scrollLeft;
  168. }
  169. function getPageOffsetTop(obj) {
  170. var top = obj.offsetTop;
  171. var oParent = obj.offsetParent;
  172. while (oParent) {
  173. top += oParent.offsetTop;
  174. oParent = oParent.offsetParent;
  175. }
  176. //Now we have to remove any scrolling
  177. var scrollTop = 0;
  178. oParent = obj;
  179. while (oParent && !oParent.body) {
  180. scrollTop += oParent.scrollTop;
  181. oParent = oParent.parentNode;
  182. }
  183. return top - scrollTop;
  184. }
  185. function hideChartDropdowns(event) {
  186. if (comboBoxRows)
  187. comboBoxRows.hideDropDown();
  188. if (comboBoxColumns)
  189. comboBoxColumns.hideDropDown();
  190. }
  191. function changeChartView()
  192. {
  193. var form = topparent.getXtabFrame().document.fhidden;
  194. var target = form.target;
  195. form.target = "Chart";
  196. var command = "";
  197. if (comboBoxRows && comboBoxRows.getSelectedItem() >= 0)
  198. command = 'RS:"' + CEncodingUtil.EncodeStrOperand(summaryRowCats[comboBoxRows.getSelectedItem()]) + '"';
  199. if (comboBoxColumns && comboBoxColumns.getSelectedItem() >= 0)
  200. {
  201. if (command.length > 0)
  202. command += '\t\t';
  203. command += 'RT:"' + CEncodingUtil.EncodeStrOperand(summaryColCats[comboBoxColumns.getSelectedItem()]) + '"';
  204. }
  205. form.CO.value = command;
  206. form.RA.value = 999;
  207. form.CNCT.value = 20;
  208. parseAndSubmit(form);
  209. form.target = target;
  210. form.CO.value = "";
  211. }