//////////////////////////////////////////////////////////////////////////// // (c) Copyright 2000 - 2001, i2 Technologies, Inc. (formerly Intellection)// // ALL RIGHTS RESERVED. // // // // This UNPUBLISHED PROPRIETARY software is subject to the full copyright // // notice in the COPYRIGHT file in this directory. // ///////////////////////////////////////////////////////////////////////////// /* support for editable table, spreadsheet and pivot */ // colors here vs style sheet var PivotCellColor = "#eceef8"; var PivotCellTotalColor = "#f7f8fd"; var PivotLabelColor = "#d1d6f0"; var PivotFontFamily = "verdana"; // only get 1 choice here /* item names that are too long will cause problems in the pivot */ var maxItemNameLength = 22; var xmlDom = null; var XAXISDELIMITER = ":"; // was \\n // pivot 1-sum, 2-count, 3-min, 4-max, 5-avg, 6-stddev, 7-variance var showAsValues = new Array(); showAsValues["sum"] = 1; showAsValues["count"] = 2; showAsValues["min"] = 3; showAsValues["max"] = 4; showAsValues["avg"] = 5; showAsValues["stddev"] = 6; showAsValues["variance"] = 7; function i2uiDetectEditableTable(objname) { return i2uiDetectSpreadsheet(objname); } function i2uiDetectSpreadsheet(objname) { var ssobj = document.getElementById(objname+"Spreadsheet"); if (ssobj == null) return 1; if (ssobj.HTMLData == null || ssobj.HTMLData == "") return 2; return 0; } function i2uiInitEditableTable(objname, ownername, mode, col, height, width) { if (!i2uiCheckVersion(objname+"Spreadsheet")) return false; var tbl2obj = null; var tblobj = document.getElementById(objname+"_header"); if (tblobj == null) tblobj = document.getElementById(objname); else tbl2obj = document.getElementById(objname+"_data"); var ssobj = document.getElementById(objname+"Spreadsheet"); if (col == null) col = 0; ssobj.setAttribute("editablecolumn",col); document.getElementById(objname+"EditAction").style.display="none"; document.getElementById(objname+"CancelAction").style.display=""; document.getElementById(objname+"SaveAction").style.display=""; i2uiBuildSpreadsheet(objname, tblobj, tbl2obj, ssobj, col, false, 2); // if unlock editable area here and large number of cells to become unlocked // then component will render a black, unusable region on the page !! // delay until i2uiStartTableEdit // var range = i2uiBuildRange(2,col+1,tblobj.rows.length+1,tblobj.rows(0).cells.length); // ssobj.activeSheet.Range(range).Locked = false; // ssobj.activeSheet.Range(range).Interior.Color = "white"; ssobj.activeSheet.Protection.Enabled = true; i2uiCreateNamedRanges(objname, tblobj, ssobj); if (mode == null) i2uiSaveTableEdit(objname); else i2uiCancelTableEdit(objname); i2uiResizeSpreadsheet(objname, ownername, true, height); } function i2uiProtectSpreadsheet(objname, flag) { var ssobj = document.getElementById(objname+"Spreadsheet"); if (ssobj != null) ssobj.activeSheet.Protection.Enabled = flag; } function i2uiInitSpreadsheet(objname, ownername, col, height, width, autofit, numExtraRows) { if (!i2uiCheckVersion(objname+"Spreadsheet")) return false; var ssobj = document.getElementById(objname+"Spreadsheet"); var tblobj = document.getElementById(objname+"Spreadsheet_xml"); if (tblobj == null) tblobj = document.getElementById(objname); if (tblobj.tagName.toLowerCase() == "xml") { ssobj.xmlData = tblobj.xml; var rows = tblobj.selectNodes("//Worksheet/Table/Row").length; var ssheight = (ssobj.activeSheet.Cells.RowHeight * (rows + 2)) + 95; if (height == null) height = ssheight; else height = Math.min(height, ssheight); i2uiResizeSpreadsheet(objname, ownername, true, height); return; } if (col == null) col = 0; ssobj.setAttribute("editablecolumn",col); i2uiBuildSpreadsheet(objname, tblobj, null, ssobj, col, true, numExtraRows); // if unlock editable area here and large number of cells to become unlocked // then component will render a black, unusable region on the page !! // delay until i2uiStartTableEdit // var range = i2uiBuildRange(2,col+1,tblobj.rows.length+1,tblobj.rows(0).cells.length); // ssobj.activeSheet.Range(range).Locked = false; // ssobj.activeSheet.Range(range).Interior.Color = "white"; ssobj.activeSheet.Protection.Enabled = true; i2uiCreateNamedRanges(objname, tblobj, ssobj); var ssheight = (ssobj.activeSheet.Cells.RowHeight * (tblobj.rows.length + 2)) + 95; if (height == null) height = ssheight; else height = Math.min(height, ssheight); i2uiResizeSpreadsheet(objname, ownername, true, height); // if spreadsheet wider than allowed width, invoke autofit if (autofit == null) autofit = false; var sum = tblobj.rows(0).cells.length * ssobj.Columns.ColumnWidth; if (sum > ssobj.width) autofit = true; i2uiFirstEdit(objname, tblobj, ssobj, tblobj.rows.length, autofit, numExtraRows); } function i2uiResizeSpreadsheet(objname, ownername, bypass, h, w) { var tblobj = document.getElementById(objname+"Spreadsheet_xml"); if (tblobj == null) tblobj = document.getElementById(objname); var ssobj = document.getElementById(objname+"Spreadsheet"); var ownerobj = document.getElementById(ownername); var tabletop = i2uiComputeTop(objname); var ownertop = i2uiComputeTop(ownername); if (h == null) ssobj.height = Math.max(20, ownerobj.clientHeight-50-(tabletop-ownertop)); else ssobj.height = h; if (w == null) ssobj.width = Math.max(ownerobj.clientWidth-3,340); else ssobj.width = w; if (bypass == null || bypass==false) ssobj.HTMLData = i2uiAlignSpreadsheet(objname, tblobj, ssobj); } function i2uiAlignSpreadsheet(objname, tblobj, ssobj, defn) { if (defn == null) defn = ssobj.HTMLData; var at1 = defn.indexOf(" "; var newdefn = defn.substring(0,at1-1) + newcols + defn.substring(at2); return(newdefn); } function i2uiBuildSpreadsheetColumnWidths(objname, tblobj, ssobj, owner) { try { var objCol; var objColAttr; var numcols = tblobj.rows(0).cells.length; var rowobj = tblobj.rows(0); for(var j=0; j"; for (var i=1; i"+tblobj.rows[i].cells[ids[j]].innerText+""; } catch(e){} } result += ""; } result += ""; return(result); } function i2uiExtractSpreadsheet(objname, cols, names, action) { var range; var cellvalue; var tblobj = document.getElementById(objname); var ssobj = document.getElementById(objname+"Spreadsheet"); var len3 = 0; var ids = new Array(); var len2 = 0; if (cols != null) { ids = cols.split(","); len2 = ids.length; } else { len2 = tblobj.rows(0).cells.length; for (var i=0; i"; if (action == null || action == "table" || action == "all") { for (var i=1; i"; for (var j=0; j"+cellvalue+""; } result += ""; } } if (action == "all" || action == "new") { // process all rows here var last = ssobj.activesheet.UsedRange.EntireRow.Count; window.status = last; for (var i=len; i"; var rowempty = true; for (var j=0; j"+cellvalue+""; } if (!rowempty) result += rowresult+""; } } if (action == "highlighted") { var first = ssobj.activesheet.application.selection.row; var len = first + ssobj.activesheet.application.selection.rows.count; for (var i=first; i"; for (var j=0; j"+cellvalue+""; } result += ""; } } result += ""; return(result); } function i2uiBuildSpreadsheet(objname, tblobj, tbl2obj, ssobj, col, autofit, numExtraRows) { var formula; var at; var unlockedColumns = new Array(); var lockedColumns = new Array(); var defn = ssobj.HTMLData; // add our styles at = defn.indexOf(""); if (at != -1) { var extraStyles = ""; extraStyles += ".header{background-color:#d1d6f0;border-top:solid #999999 1px;border-left:solid #999999 1px;border-right:solid #999999 1px;border-bottom:solid #999999 1px;}"; extraStyles += ".cellodd{background-color:#f7f8fd;border-top:solid #999999 1px;border-left:solid #999999 1px;border-right:solid #999999 1px;border-bottom:solid #999999 1px;}"; extraStyles += ".celleven{background-color:#eceef8;border-top:solid #999999 1px;border-left:solid #999999 1px;border-right:solid #999999 1px;border-bottom:solid #999999 1px;}"; extraStyles += ".readwrite {background-color:white;}"; defn = defn.substring(0,at)+extraStyles+defn.substring(at); } objDom = new ActiveXObject("Microsoft.XMLDOM"); objDom.preserveWhiteSpace = true; var objRoot = objDom.createElement("table"); objDom.appendChild(objRoot); i2uiBuildSpreadsheetColumnWidths(objname, tblobj, ssobj, objRoot); var numrows = tblobj.rows.length; var numcols = tblobj.rows(0).cells.length; var value; var readonly = new Array("celleven","cellodd"); var rowdefn; var objRow; var objRowAttr; var objCell; var objCellAttr; var rowobj; var cellobj; for (var i=0; i= col) unlockedColumns[unlockedColumns.length] = j; objCell.text = cellobj.innerText; } } else if (tagName == "INPUT") { objCellAttr = objDom.createAttribute("class"); objCellAttr.text = "readwrite"; objCell.setAttributeNode(objCellAttr); objCell.text = cellobj.childNodes[0].getAttribute("value"); if (i == 1) unlockedColumns[unlockedColumns.length] = j; } else if (tagName == "SELECT") { var selectobj = cellobj.childNodes[0]; objCell.text = selectobj.options[selectobj.selectedIndex].text; } else { if (i == 1 && j >= col) unlockedColumns[unlockedColumns.length] = j; objCell.text = cellobj.innerText; } } catch(e) { try { if ((formula = cellobj.getAttribute("x:fmla")) != null) { objCellAttr = objDom.createAttribute("x:fmla"); objCellAttr.text = formula; objCell.setAttributeNode(objCellAttr); if (i == 1) lockedColumns[lockedColumns.length] = j; } else { if (i == 1 && j >= col) unlockedColumns[unlockedColumns.length] = j; objCell.text = cellobj.innerText; } } catch(e){} } } } if (tbl2obj != null) { numrows = tbl2obj.rows.length; for (var i=0; i= col) unlockedColumns[unlockedColumns.length] = j; objCell.text = cellobj.innerText; } } else if (tagName == "INPUT") { objCellAttr = objDom.createAttribute("class"); objCellAttr.text = "readwrite"; objCell.setAttributeNode(objCellAttr); objCell.text = cellobj.childNodes[0].getAttribute("value"); if (i == 0) unlockedColumns[unlockedColumns.length] = j; } else if (tagName == "SELECT") { var selectobj = cellobj.childNodes[0]; objCell.text = selectobj.options[selectobj.selectedIndex].text; } else { if (i == 0 && j >= col) unlockedColumns[unlockedColumns.length] = j; objCell.text = cellobj.innerText; } } catch(e) { if ((formula = cellobj.getAttribute("x:fmla")) != null) { objCellAttr = objDom.createAttribute("x:fmla"); objCellAttr.text = formula; objCell.setAttributeNode(objCellAttr); if (i == 0) lockedColumns[lockedColumns.length] = j; } else { if (i == 0 && j >= col) unlockedColumns[unlockedColumns.length] = j; objCell.text = cellobj.innerText; } } } } } at = defn.indexOf(" 0) { tagName = rowobj.cells(j).childNodes[0].tagName; if (tagName == "INPUT") cellvalue = rowobj.cells(j).childNodes[0].getAttribute("value"); else if (tagName == "SELECT") { var selectobj = rowobj.cells(j).childNodes[0]; cellvalue = selectobj.options[selectobj.selectedIndex].text; } else if (j < col || rowobj.cells(j).getAttribute("x:fmla") != null) continue; else cellvalue = rowobj.cells(j).innerText; } else { tagName == ""; if (j < col || rowobj.cells(j).getAttribute("x:fmla") != null) continue; else cellvalue = rowobj.cells(j).innerText; } try { var numExtraRows = 0; range = i2uiBuildRange(i+numExtraRows-firstrow,j+1); if (j < col && (tagName == "INPUT" || tagName == "SELECT")) ssobj.ActiveSheet.Range(range).Locked = false; ssobj.ActiveSheet.Range(range).Value = cellvalue; } catch(e){} } } // reenable calculation //ssobj.activeSheet.EnableAutoCalculate = true; try {ssobj.activeSheet.Application.ScreenUpdating = true;}catch(e){} } function i2uiCreateNamedRanges(objname, tblobj, ssobj) { try{ if (tblobj == null) tblobj = document.getElementById(objname); if (ssobj == null) ssobj = document.getElementById(objname+"Spreadsheet"); var numrows = tblobj.rows.length; var numcols = tblobj.rows(0).cells.length; for (var j=0; j 0) view.ColumnAxis.FieldSets(len-1).Fields(0).Expanded = false; len = view.RowAxis.FieldSets.Count; for (i=0; i 0) view.RowAxis.FieldSets(len-1).Fields(0).Expanded = false; } function i2uiLayoutPivot(pivot, view) { var rc = false; view.AutoLayout(); activePivot = pivot; // retain style info pivot.chartColorInfo = new Array(); pivot.chartStyleInfo = new Array(); pivot.chartTypeInfo = new Array(); pivot.seriesColor = new Array(); pivot.seriesColorCount = 0; pivot.seriesStyle = new Array(); pivot.seriesStyleCount = 0; pivot.editableColumns = new Array(); pivot.proportionalEditColumns = new Array(); pivot.lockedColumns = new Array(); var customSort = new Array(); try { pivot.coloring = 1*xmlDom.selectSingleNode("/pivot/chart").getAttribute("coloring"); } catch(e) { pivot.coloring = 2; } i2uiPivotAsofName = null; i2uiPivotAsofCaption = null; i2uiPivotAsofValue = null; i2uiPivotAsofColor = null; try { i2uiPivotAsofName = xmlDom.selectSingleNode("/pivot/chart").getAttribute("asofname"); i2uiPivotAsofValue = xmlDom.selectSingleNode("/pivot/chart").getAttribute("asofvalue"); i2uiPivotAsofColor = xmlDom.selectSingleNode("/pivot/chart").getAttribute("asofcolor"); } catch(e){} try { i2uiPivotAsofCaption = xmlDom.selectSingleNode("/pivot/chart").getAttribute("asofcaption"); var len = i2uiPivotAsofCaption.length; } catch(e){i2uiPivotAsofCaption="Asof";} try { pivot.chartThreshold = xmlDom.selectSingleNode("/pivot/chart/threshhold").xml; } catch(e){pivot.chartThreshold="";} var stylenodes = xmlDom.selectNodes("/pivot/chart/*"); if (stylenodes.length == 0) stylenodes = xmlDom.selectNodes("/PIVOT/CHART/*"); pivot.chartColorInfo[0] = stylenodes.length; for (var i=0; i maxItemNameLength) view.FieldSets(itemName).Fields(0).Caption = itemnodes[i].text; // handle unsorted data if (itemnodes[i].getAttribute("sorted") == "no") view.FieldSets(itemName.substring(0,maxItemNameLength)).Fields(0).SortDirection = pivot.Constants.plSortDirectionCustom; // set initial filtering var filter; var filterArray; var filterSeparator = itemnodes[i].getAttribute("separator"); if (filterSeparator == null) filterSeparator = ","; filter = itemnodes[i].getAttribute("include"); if (filter == null) { try { filter = pivot.retainincludes[itemName].join(filterSeparator); } catch(e) {filter=null;} } if (filter != null) { filterArray = filter.split(filterSeparator); view.FieldSets(itemName).Fields(0).IncludedMembers = filterArray; } filter = itemnodes[i].getAttribute("exclude"); if (filter == null) { try { filter = pivot.retainexcludes[itemName].join(filterSeparator); } catch(e) {filter=null;} } if (filter != null) { filterArray = filter.split(filterSeparator); view.FieldSets(itemName).Fields(0).ExcludedMembers = filterArray; } // set initial formating if ((numberformat = itemnodes[i].getAttribute("numberformat")) != null) { view.FieldSets(itemName).Fields(0).NumberFormat = numberformat; } } var cleanup = new Array(); // create totals for data axis for (var i=0; i