123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475 |
- // Licensed Materials - Property of IBM
- //
- // IBM Cognos Products: pps
- //
- // (C) Copyright IBM Corp. 2005, 2017
- //
- // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- var xtabCache;
- //A class responsible for maintaining and providing access to crosstab elements
- function xtabCache() {
- //**********************
- //Data members
- /* private */ xtabCells = new Array();
- /* private */ xtabLevelSelectors = new Array();
- xtabLevelSelectors["r"] = new Array();
- xtabLevelSelectors["c"] = new Array();
- /* private */ CLASS_HEADER_MOUSE_OVER = "header-mouse-over";
- /* private */ CLASS_CELL_SELECTED = "cell-selected";
- /* private */ CLASS_CELL_INTER_SELECTED = "cell-intersection-selected";
- /* private */ CLASS_HEADER_SELECTED = "header-selected";
- /* private */ CLASS_LEVEL_SELECTED = "level-selected";
- /* private */ CLASS_CHART_LEGEND_CELL_SELECTED = "chart-legend-cell-selected";
- /* private */ CLASS_CHART_LEGEND_LAST_CELL_SELECTED = "chart-legend-last-cell-selected"
- /* private */ CLASS_LEVEL_DRAG_OVER = "level-drag-over";
- /* private */ CLASS_LEVEL_AREA_SELECTED = "level-area-selected";
-
- /* public */ this.initialized = false;
- //**********************
- //Private Methods
- function cacheObj(obj) {
- if (obj.getAttribute && obj.getAttribute("type")) {
- var type = obj.getAttribute("type");
- if (type == "d" || type == "r" || type == "c") {
- var row = parseRowId(obj.id);
- var col = parseColId(obj.id);
- if (!exists(row,col)) {
-
- initClassName(obj);
- if ((type == "r" || type == "c") && obj.firstChild.setAttribute) {
- initClassName(obj.firstChild);
- }
- if (xtabCells[parseInt(row)] == null)
- xtabCells[parseInt(row)] = new Array();
- if (type != "d") {
- obj.setAttribute("selected","0");
- obj.setAttribute("dragover","0");
- }
- xtabCells[parseInt(row)][parseInt(col)] = obj;
- }
- } else if (type.indexOf("lr") >= 0 || type.indexOf("lc") >= 0) {
- initClassName(obj);
- xtabLevelSelectors[obj.id.charAt(1)][parseInt(obj.id.substr(2))] = obj;
- }
- }
- }
- function initClassName(obj) {
- if (obj.className)
- obj.setAttribute("unSelectedClassName",obj.className);
- else
- obj.setAttribute("unSelectedClassName","");
- }
- function processNode(node) {
- cacheObj(node);
- var child = node.firstChild;
- while (child != null) {
- processNode(child);
- child = child.nextSibling;
- }
- }
- //**********************
- //Initialize Method
- //Walk the element given and cache any level selection or cell children
- this.initialize = function(xtab) {
- if (xtab)
- processNode(xtab);
- this.initialized = true;
- }
- //**********************
- //Public methods and helper functions
- this.getXtabCell = function(row,col) {
- if (xtabCells[parseInt(row)] && xtabCells[parseInt(row)][parseInt(col)])
- return xtabCells[parseInt(row)][parseInt(col)];
- else {
- //Caching missed this one, so reconstruct the ID and get it the slow way
- return document.getElementById(row + "-" + col);
- }
- }
- this.getXtabLevelSelector = function(rc,level) {
- if (xtabLevelSelectors[rc][parseInt(level)])
- return xtabLevelSelectors[rc][parseInt(level)];
- else
- //Caching missed this one, so reconstruct the ID and get it the slow way
- return document.getElementById("l" + rc + level);
- }
- //The following methods select the row/cols in the xtab.
- //They rely on the underlying data structure to make things as efficient as possible
- //We also assume that the cells given exist, and are cached.
- function exists(row,col) {
- return (xtabCells[row] != null && xtabCells[row][col] != null);
- }
- this.exists = exists;
- function getRowHeader(row) {
- if (exists(row,numRowLevels - 1))
- return xtabCells[row][numRowLevels - 1];
- else {
- var col = numRowLevels - 2;
- while (!exists(row,col)) {
- col--;
- if (col < 0)
- return null;
- }
- return xtabCells[row][col];
- }
- }
- this.getRowHeader = getRowHeader;
- function getColHeader(col) {
- if (exists(numColLevels - 1,col))
- return xtabCells[numColLevels - 1][col];
- else {
- var row = numColLevels - 2;
- while (!exists(row,col)) {
- row--;
- if (row < 0)
- return null;
- }
- return xtabCells[row][col];
- }
- }
- this.getColHeader = getColHeader;
- function numberSelectedInRow(row) {
- return parseInt(getRowHeader(row).getAttribute("selected"));
- }
- function numberSelectedInColumn(col) {
- return parseInt(getColHeader(col).getAttribute("selected"));
- }
- function isACellInRowSelected(row) {
- return (getRowHeader(row).getAttribute("selected") != "0");
- }
- function isACellInColumnSelected(col) {
- return (getColHeader(col).getAttribute("selected") != "0");
- }
- this.isRowSelected = function(row) {
- return (isACellInRowSelected(row));
- }
- this.isColSelected = function(col) {
- return (isACellInColumnSelected(col));
- }
-
- this.selectRow = function(row,col,selecting) {
- row = parseInt(row);
- col = parseInt(col);
- //Obtain the start and ending row numbers;
- rowHeader = xtabCells[row][col];
- var startRow = row;
- var endRow = startRow + 1;
- if(!rowHeader.getAttribute("summary"))
- while(endRow < maxRowID && (!exists(endRow,col)))
- endRow++;
- //Loop throught each row header and select all cached cells
- for (var i = startRow; i < endRow; i++) {
- if (getRowHeader(i)) {
- for (var j = col; j < numRowLevels; j++)
- if (exists(i,j))
- selectRowColHeader(i,j,selecting);
- if ((selecting && numberSelectedInRow(i) == 1) || (!selecting && !isACellInRowSelected(i))) {
- //Display the sort icon
- var rowHeader = getRowHeader(i);
- if (selecting)
- showSortState(rowHeader,rowHeader.getAttribute("type"));
- else
- hideSortIcon(rowHeader,rowHeader.getAttribute("type"));
- //loop throught each cell in the row
- for (var j = numRowLevels; j < maxColID; j++)
- if (exists(i,j))
- selectRowCell(i,j,selecting);
- }
- }
- }
- }
- function selectRowColHeader(row,col,selecting) {
- if (selecting) {
- xtabCells[row][col].setAttribute("selected",parseInt(xtabCells[row][col].getAttribute("selected")) + 1);
- if (parseInt(xtabCells[row][col].getAttribute("selected")) == 1)
- switchRowColHeaderCell(xtabCells[row][col]," " + CLASS_HEADER_SELECTED);
- } else {
- xtabCells[row][col].setAttribute("selected",parseInt(xtabCells[row][col].getAttribute("selected")) - 1);
- if (parseInt(xtabCells[row][col].getAttribute("selected")) == 0)
- switchRowColHeaderCell(xtabCells[row][col],"");
- }
- }
- function switchRowColHeaderCell(obj,classExt) {
- //If this obj is a row, then we are dealing with a chart legend
- //and must set the class of each cell in the row.
- if (obj.tagName == "TR") {
- switchChartLegendCells(obj,classExt);
- } else {
- obj.className = obj.getAttribute("unSelectedClassName") + classExt;
- //For row.col headers apply the style to the inner table (first child) as well.
- //To ensure that the CSS inheritance is passed into the table element
- var kid = obj.firstChild;
- if (kid.getAttribute)
- kid.className = kid.getAttribute("unSelectedClassName") + classExt;
- }
- }
- function switchChartLegendCells(obj, classExt) {
- //Skip the first cell
- //Switch each other cell
- var kid = obj.firstChild.nextSibling;
- while (kid) {
- if (!kid.getAttribute("unSelectedClassName"))
- initClassName(kid);
- if (classExt == "")
- kid.className = kid.getAttribute("unSelectedClassName");
- else
- if (kid == obj.firstChild.nextSibling)
- kid.className = classExt + " " + CLASS_CHART_LEGEND_CELL_SELECTED;
- else
- kid.className = classExt + " " + CLASS_CHART_LEGEND_LAST_CELL_SELECTED;
- kid = kid.nextSibling;
- }
- }
- function selectRowCell(row,col,selecting) {
- if (selecting) {
- if (isACellInColumnSelected(col)) {
- xtabCells[row][col].className = xtabCells[row][col].getAttribute("unSelectedClassName") + " " + CLASS_CELL_INTER_SELECTED;
- } else {
- xtabCells[row][col].className = xtabCells[row][col].getAttribute("unSelectedClassName") + " " + CLASS_CELL_SELECTED;
- }
- } else {
- if (isACellInColumnSelected(col)) {
- xtabCells[row][col].className = xtabCells[row][col].getAttribute("unSelectedClassName") + " " + CLASS_CELL_SELECTED;
- } else {
- xtabCells[row][col].className = xtabCells[row][col].getAttribute("unSelectedClassName");
- }
- }
- }
- this.selectCol = function(row,col,selecting) {
- row = parseInt(row);
- col = parseInt(col);
- //Obtain the start and ending col numbers;
- colHeader = xtabCells[row][col];
- var startCol = col;
- var endCol = startCol + 1;
- if(!colHeader.getAttribute("summary"))
- while(endCol < maxColID && (!exists(row,endCol)))
- endCol++;
- //Loop throught each row and select all cached cells
- for (var i = startCol; i < endCol; i++) {
- if (getColHeader(i)) {
- for (var j = row; j < numColLevels; j++)
- if (exists(j,i))
- selectRowColHeader(j,i,selecting);
- if ((selecting && numberSelectedInColumn(i) == 1) || (!selecting && !isACellInColumnSelected(i))) {
- //Display the sort icon
- var colHeader = getColHeader(i);
- if (selecting)
- showSortState(colHeader,colHeader.getAttribute("type"));
- else
- hideSortIcon(colHeader,colHeader.getAttribute("type"));
-
- //loop throught each cell in the column
- for (var j = numColLevels; j < maxRowID; j++)
- if (exists(j,i)) {
- selectColumnCell(j,i,selecting);
- }
- }
- }
- }
- }
- function selectColumnCell(row,col,selecting) {
- if (selecting) {
- if (isACellInRowSelected(row)) {
- xtabCells[row][col].className = xtabCells[row][col].getAttribute("unSelectedClassName") + " " + CLASS_CELL_INTER_SELECTED;
- } else {
- xtabCells[row][col].className = xtabCells[row][col].getAttribute("unSelectedClassName") + " " + CLASS_CELL_SELECTED;
- }
- } else {
- if (isACellInRowSelected(row)) {
- xtabCells[row][col].className = xtabCells[row][col].getAttribute("unSelectedClassName") + " " + CLASS_CELL_SELECTED;
- } else {
- xtabCells[row][col].className = xtabCells[row][col].getAttribute("unSelectedClassName");
- }
- }
- }
- this.selectLevel = function(rc,level,selecting) {
- level = parseInt(level);
- selectLevelSelector (rc, level, selecting);
- if (rc == "r") {
- for (var i = numColLevels; i < maxRowID; i++) {
- if (exists(i,level))
- selectLevelCell(i,level,selecting);
- }
- } else {
- for (var i = numRowLevels; i < maxColID; i++) {
- if (exists(level,i))
- selectLevelCell(level,i,selecting);
- }
- }
- }
- function selectLevelSelector (rc, level, selecting) {
- if (selecting) {
- //Only if this is not a chart legend
- if (xtabLevelSelectors[rc][parseInt(level)].className != "legend")
- xtabLevelSelectors[rc][parseInt(level)].className = xtabLevelSelectors[rc][parseInt(level)].getAttribute("unSelectedClassName") + " " + CLASS_LEVEL_AREA_SELECTED;
- } else {
- xtabLevelSelectors[rc][parseInt(level)].className = xtabLevelSelectors[rc][parseInt(level)].getAttribute("unSelectedClassName");
- }
- }
- function selectLevelCell (row,col,selecting) {
- if (selecting) {
- xtabCells[row][col].setAttribute("selected",1);
- switchRowColHeaderCell(xtabCells[row][col]," " + CLASS_LEVEL_SELECTED);
- } else {
- xtabCells[row][col].setAttribute("selected",0);
- switchRowColHeaderCell(xtabCells[row][col],"");
- }
- }
- this.dragOverLevel = function (rc,level,selecting) {
- level = parseInt(level);
- selectLevelSelector (rc, level, false);
- if (rc == "r") {
- for (var i = numColLevels; i < maxRowID; i++) {
- if (exists(i,level))
- selectDragLevelCell(i,level,selecting);
- }
- } else {
- for (var i = numRowLevels; i < maxColID; i++) {
- if (exists(level,i))
- selectDragLevelCell(level,i,selecting);
- }
- }
- }
-
- this.mouseOverHeader = function(row,col,selecting) {
- row = parseInt(row);
- col = parseInt(col);
- if (parseInt(xtabCells[row][col].getAttribute("selected")) == 0 && parseInt(xtabCells[row][col].getAttribute("dragover")) == 0) {
- if (selecting) {
- switchRowColHeaderCell(xtabCells[row][col]," " + CLASS_HEADER_MOUSE_OVER);
- } else {
- switchRowColHeaderCell(xtabCells[row][col],"");
- }
- }
- }
- function selectDragLevelCell (row,col,selecting) {
- if (selecting) {
- xtabCells[row][col].setAttribute("dragover","1");
- switchRowColHeaderCell(xtabCells[row][col]," " + CLASS_LEVEL_DRAG_OVER);
- } else {
- xtabCells[row][col].setAttribute("dragover","0");
- switchRowColHeaderCell(xtabCells[row][col],"");
- }
- }
- this.getRowColHeaderParent = function(row,col) {
- var type = xtabCells[row][col].getAttribute("type");
- if (type.charAt(0) == "r" && row) {
- var i = row;
- while (!xtabCells[i] || !xtabCells[i][col - 1])
- i--;
- return xtabCells[i][col - 1];
- } else if (type.charAt(0) == "c" && col) {
- var i = col;
- while (!xtabCells[row - 1][i])
- i--;
- return xtabCells[row - 1][i];
- }
- return null;
- }
- this.getNextRowColHeaderSibling = function(row,col) {
- var type = xtabCells[row][col].getAttribute("type");
- if (type.charAt(0) == "r" && row) {
- var therow = parseInt(row) + 1;
- while(therow < maxRowID) {
- if (exists(therow,col))
- return xtabCells[therow][col];
- therow++;
- }
- } else if (type.charAt(0) == "c" && col) {
- var thecol = parseInt(col) + 1;
- while(thecol < maxColID) {
- if (exists(row,thecol))
- return xtabCells[row][thecol];
- thecol++;
- }
- }
- return null;
- }
- }
- function isBottomDimension(obj) {
- var level = parseInt(obj.getAttribute("level"));
- var rc = obj.getAttribute("type");
- var dimIdx = obj.getAttribute("dimIdx");
-
- var bottomLevel = true;
- while (bottomLevel && xtabCache.getXtabLevelSelector(rc,level)) {
- if (xtabCache.getXtabLevelSelector(rc,level).getAttribute("dimIdx") != dimIdx) {
- bottomLevel = false;
- } else
- level++;
- }
- return bottomLevel;
- }
- function isOnlyDimensioninAxis(obj) {
- var rc = obj.getAttribute("type");
- var dimIdx = obj.getAttribute("dimIdx");
-
- var level = 0;
- var onlyDimension = true;
- while (onlyDimension && xtabCache.getXtabLevelSelector(rc,level)) {
- if (xtabCache.getXtabLevelSelector(rc,level).getAttribute("dimIdx") != dimIdx) {
- onlyDimension = false;
- } else
- level++;
- }
- return onlyDimension;
- }
|