hideshow.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. // This forms the javascript functions used for the Find pane of
  9. // PowerPlay Studio.
  10. // The functions handle any minor browser differences.
  11. var visBox;
  12. var invisBox;
  13. var rc;
  14. var xtabgroup;
  15. var catarr;
  16. var sumarr;
  17. var selectedGroup;
  18. var categories = new Array();
  19. categories["R"] = new Array();
  20. categories["C"] = new Array();
  21. var hiddenSummaries = new Array();
  22. hiddenSummaries["R"] = new Array();
  23. hiddenSummaries["C"] = new Array();
  24. var selections;
  25. function addToArray(rc, group, name, code, vis, level) {
  26. if (!categories[rc][group])
  27. categories[rc][group] = new Array();
  28. categories[rc][group][categories[rc][group].length] = new categoryRecord(name, code, vis, level, categories[rc][group].length);
  29. }
  30. function addHiddenSummary (rc, group) {
  31. hiddenSummaries[rc][group] = new summaryRec(true,true);
  32. }
  33. function isHiddenSummary () {
  34. //If it doesent yet exist in the array, it isn't hidden
  35. if (typeof hiddenSummaries[rc][parseInt(xtabgroup)-1] == "undefined") {
  36. hiddenSummaries[rc][parseInt(xtabgroup)-1] = new summaryRec(false,false);
  37. }
  38. return hiddenSummaries[rc][parseInt(xtabgroup)-1]._present;
  39. }
  40. function setHiddenSummary (hidden) {
  41. if (typeof hiddenSummaries[rc][parseInt(xtabgroup)-1] == "undefined") {
  42. hiddenSummaries[rc][parseInt(xtabgroup)-1] = new summaryRec(false,false);
  43. }
  44. hiddenSummaries[rc][parseInt(xtabgroup)-1]._present = hidden;
  45. }
  46. function summaryRec(original,present) {
  47. this._original = original;
  48. this._present = present;
  49. }
  50. function toggleCheckSummary () {
  51. setHiddenSummary(!document.getElementById("showSummariesCheck").checked);
  52. }
  53. function selectAll(event, box) {
  54. var box = document.getElementById(box);
  55. for (var i = 0; i < box.options.length; i++) {
  56. box.options[i].selected = true;
  57. }
  58. var mgr = new eventManager(event);
  59. mgr.cancelBubble();
  60. }
  61. function unselectAll(event, box) {
  62. var box = document.getElementById(box);
  63. for (var i = 0; i < box.options.length; i++) {
  64. box.options[i].selected = false;
  65. }
  66. var mgr = new eventManager(event);
  67. mgr.cancelBubble();
  68. }
  69. function refresh() {
  70. resetDialog()
  71. }
  72. function clearDialogs() {
  73. visBox.innerHTML = "";
  74. invisBox.innerHTML = "";
  75. rc = null;
  76. selectedGroup = null;
  77. if (document.getElementById("showSummariesCheck"))
  78. document.getElementById("showSummariesCheck").checked = false;
  79. }
  80. function resetDialog() {
  81. removeMessage();
  82. var rowcolswitch = false;
  83. var rowSelections = getSelected("r");
  84. var colSelections = getSelected("c");
  85. var summarySelected = false;
  86. if (rowSelections.length && colSelections.length) { //Both rows and columns selected
  87. displayCommonMessage(strNoSelectionsMsg, MESSAGE_TYPE_INFO, [], []);
  88. return;
  89. } else if (!rowSelections.length && !colSelections.length) {//No rows or columns selected
  90. if( !isLevelSelected("r") && !isLevelSelected("c") ) {
  91. clearDialogs();
  92. displayCommonMessage(strNoSelectionsMsg, MESSAGE_TYPE_INFO, [], []);
  93. return;
  94. }
  95. else {
  96. if( isLevelSelected("r") ) {
  97. xtabgroup = getSelectedLevelNum();
  98. xtabgroup ++;
  99. rc = "R";
  100. }
  101. else {
  102. xtabgroup = getSelectedLevelNum();
  103. xtabgroup ++;
  104. rc = "C";
  105. }
  106. }
  107. }
  108. else {
  109. if (rowSelections.length) {
  110. if (rc != "R")
  111. rowcolswitch = true;
  112. rc = "R";
  113. xtabgroup = (rowSelections[0].getAttribute("summary"))? (parseInt(rowSelections[0].getAttribute("group")) + 1) : rowSelections[0].getAttribute("group");
  114. if(rowSelections[0].getAttribute("summary"))
  115. summarySelected = true;
  116. for (var i = 1;i < rowSelections.length;i++) {
  117. var tempgroup = (rowSelections[i].getAttribute("summary"))? (parseInt(rowSelections[i].getAttribute("group")) + 1) : rowSelections[i].getAttribute("group");
  118. if (tempgroup != xtabgroup) {
  119. clearDialogs();
  120. displayCommonMessage(strIncorrectRowsSelMsg, MESSAGE_TYPE_INFO, [], []);
  121. return;
  122. }
  123. }
  124. } else {
  125. if (rc != "C")
  126. rowcolswitch = true;
  127. rc = "C";
  128. xtabgroup = (colSelections[0].getAttribute("summary"))? (parseInt(colSelections[0].getAttribute("group")) + 1) : colSelections[0].getAttribute("group");
  129. if(colSelections[0].getAttribute("summary"))
  130. summarySelected = true;
  131. for (var i = 1;i < colSelections.length;i++) {
  132. var tempgroup = (colSelections[i].getAttribute("summary"))? (parseInt(colSelections[i].getAttribute("group")) + 1) : colSelections[i].getAttribute("group");
  133. if (tempgroup != xtabgroup) {
  134. displayCommonMessage(strIncorrectRowsSelMsg, MESSAGE_TYPE_INFO, [], []);
  135. clearDialogs();
  136. return;
  137. }
  138. }
  139. }
  140. }
  141. popSelections();
  142. if ((xtabgroup == selectedGroup) && (!rowcolswitch)) {
  143. preSelectOptions(visBox);
  144. return;
  145. } else {
  146. selectedGroup = xtabgroup;
  147. }
  148. catarr = categories[rc][parseInt(xtabgroup)];
  149. //Bug 468335 : Check if the summary is selected; only then bump up the group number to retrieve child categories if catarr is empty
  150. if(summarySelected)
  151. {
  152. //in a chart with no legend, only the column summary is shown
  153. //when selected, it has a group of 1 less the categories we wanna show...
  154. //so, bump it up by one and give it a whirl...
  155. if (!catarr)
  156. catarr = categories[rc][parseInt(xtabgroup) + 1];
  157. }
  158. populateDialogs();
  159. }
  160. function init() {
  161. topparent.openActionPane();
  162. ContextMenu.initialize(true,false);
  163. visBox = document.getElementById("shownCategories");
  164. invisBox = document.getElementById("hiddenCategories");
  165. resetDialog();
  166. }
  167. function categoryRecord(name, code, vis, level, index) {
  168. this._name = name;
  169. this._code = code;
  170. this._vis = vis;
  171. this._level = level;
  172. this._index = index;
  173. }
  174. function popSelections() {
  175. var selects = getSelected("r");
  176. if (selects.length == 0)
  177. selects = getSelected("c");
  178. selections = new Array();
  179. for (var i = 0; i < selects.length; i++) {
  180. selections[selects[i].getAttribute("ppdsId")] = true;
  181. }
  182. }
  183. function populateDialogs() {
  184. visBox.innerHTML = "";
  185. invisBox.innerHTML = "";
  186. if (catarr){
  187. for (var i = 0;i < catarr.length; i++) {
  188. if (catarr[i]._vis)
  189. {
  190. visBox.options[visBox.options.length] = new Option(catarr[i]._name,catarr[i]._index);
  191. visBox.options[visBox.options.length - 1].label = catarr[i]._name;
  192. }
  193. else
  194. {
  195. invisBox.options[invisBox.options.length] = new Option(catarr[i]._name,catarr[i]._index);
  196. invisBox.options[invisBox.options.length - 1].label = catarr[i]._name;
  197. }
  198. }
  199. }
  200. if (isHiddenSummary())
  201. document.getElementById("showSummariesCheck").checked = false;
  202. else
  203. document.getElementById("showSummariesCheck").checked = true;
  204. preSelectOptions(visBox);
  205. }
  206. function preSelectOptions(box) {
  207. for (var i = 0; i < box.length; i++) {
  208. var catCode = catarr[box[i].value]._code;
  209. if(catCode.charAt(0) == 'T')
  210. box[i].selected = selections[catCode];
  211. else
  212. box[i].selected = selections[parseInt(catarr[box[i].value]._code)];
  213. }
  214. }
  215. function switchVis(element) {
  216. element._vis = !element._vis;
  217. }
  218. function moveSelectedOptions(event, direction) {
  219. var fromBox = visBox;
  220. var toBox = invisBox;
  221. var options = new Array();
  222. var array = catarr;
  223. if (direction == "left") {
  224. fromBox = invisBox;
  225. toBox = visBox;
  226. }
  227. for (var i = fromBox.options.length - 1; i >= 0; i--) {
  228. //Find all selected options in reverse order;
  229. if (fromBox.options[i].selected) {
  230. options[options.length] = fromBox.options[i];
  231. switchVis(array[fromBox.options[i].value]); //switch its visibility;
  232. fromBox.options[i] = null;
  233. }
  234. }
  235. insertOptions(options,toBox);
  236. var mgr = new eventManager(event);
  237. mgr.cancelBubble();
  238. }
  239. function insertOptions(options, dialog) {
  240. //Works backwards for efficiency. Assumes options not already in select
  241. var opCtr = 0;
  242. var dptr = dialog.options.length - 1;
  243. for (var i = options.length - 1; i >= 0; i--) {
  244. dialog.options[dialog.options.length] = options[i]; //First add them to the end.
  245. }
  246. if (dptr != -1) {
  247. for (var i = dptr + options.length;opCtr < options.length; i--) {
  248. if ((dptr < 0) || (dialog.options[dptr].value < options[opCtr].value)) {
  249. //Insert the next option at i
  250. dialog.options[i] = options[opCtr];
  251. opCtr++;
  252. } else {
  253. //Move this option down to make room (by the number of options left to insert)
  254. dialog.options[i] = new Option(dialog.options[dptr].label,dialog.options[dptr].value);
  255. dialog.options[i].label = dialog.options[dptr].label;
  256. dptr--;
  257. }
  258. }
  259. }
  260. }
  261. function applyChanges() {
  262. var command = "MH:1\t";
  263. var groupNum = (xtabgroup == 0)? 0: xtabgroup - 1;
  264. command += rc + groupNum;
  265. var numCats = 0;
  266. if (catarr){
  267. for (var i = 0;i < catarr.length;i++) {
  268. if (!catarr[i]._vis) {
  269. command += "\t" + catarr[i]._code;
  270. numCats++;
  271. }
  272. }
  273. }
  274. else {
  275. topparent.closeActionPane();
  276. return;
  277. }
  278. if (!numCats)
  279. command = "MS:2\t" + rc + groupNum;
  280. if(hiddenSummaries[rc][parseInt(xtabgroup)-1]._present != hiddenSummaries[rc][parseInt(xtabgroup)-1]._original) {
  281. if (groupNum == 0)
  282. command += "\t\tET:" + rc + "0";
  283. else
  284. command += "\t\tES:" + rc + groupNum;
  285. }
  286. //close the pane...
  287. topparent.closeActionPane();
  288. command += "\t\tMQ";
  289. topparent.getXtabFrame().doit(command);
  290. }