123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493 |
- // 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.
- // This forms the javascript functions used for the Rank pane of
- // PowerPlay Studio.
- // The functions handle any minor browser differences.
- var rc;
- var dim;
- var editCode;
- var catarr;
- var rankID;
- var categories = new Array();
- categories["R"] = new Array();
- categories["C"] = new Array();
- var RANK_DEFAULT_NUM_ORDINALS = 10;
- function init() {
- topparent.openActionPane();
- ContextMenu.initialize(true,false);
-
- initErrorVars();
- resetDialog();
- }
- function refresh() {
- resetDialog();
- }
- function addToArray(rc, name, code, calc, rankable) {
- categories[rc][categories[rc].length] = new categoryRecord(name, code, calc, rankable);
- }
- function categoryRecord(name, code, calc, rankable) {
- this._name = name;
- this._code = code;
- this._calc = calc;
- this._rankable = rankable;
- }
- function dialogOperand(type, code) {
- this._type = type;
- this._code = code;
- }
- function rankInfo(label, operand, show_op, show_num, start_op, sort_op) {
- this._operand = operand;
- this._label = label;
- this._show_op = show_op;
- this._show_num = show_num;
- this._start_op = start_op;
- this._sort_op = sort_op;
- }
- function submitPreRankDialog() {
- topparent.setGlobal("editingRank", 0);
- if(document.preEditRank.rank_edit.checked)
- topparent.setGlobal("editingRank", 1);
- else if(document.preEditRank.rank_rename.checked)
- topparent.setGlobal("editingRank", 2);
- else if(document.preEditRank.rank_delete.checked)
- topparent.setGlobal("editingRank", 3);
- resetDialog();
- }
- function resetDialog() {
- removeMessage();
- displayContent();
- var rowSelections = getSelected("r");
- var colSelections = getSelected("c");
-
- if (rowSelections.length && colSelections.length) { //Both rows and columns selected
- handleError(strNoSelectionsMsg, true);
- return;
- } else if (!rowSelections.length && !colSelections.length) {//No rows or columns selected
- handleError(strNoSelectionsMsg, true);
- return;
- } else {
- if (rowSelections.length) {
- if (rc != "R")
- rowcolswitch = true;
- rc = "R";
- xtabgroup = topparent.getXtabFrame().numRowLevels;
- for (var i = 0;i < rowSelections.length;i++) {
- if (!topparent.getXtabFrame().isBottomDimension(rowSelections[i])) {
- clearDialogs();
- handleError(strNoSelectionsMsg, true);
- return;
- }
- }
- } else {
- if (rc != "C")
- rowcolswitch = true;
- rc = "C";
- xtabgroup = topparent.getXtabFrame().numColLevels;
- for (var i = 0;i < colSelections.length;i++) {
- if (!topparent.getXtabFrame().isBottomDimension(colSelections[i])) {
- handleError(strNoSelectionsMsg, true);
- clearDialogs();
- return;
- }
- }
- }
- }
- if (rowSelections.length) {
- if (rc != "R")
- rowcolswitch = true;
- rc = "R";
- setRankByLabel(strRankByRowLabel);
- } else {
- if (rc != "C")
- rowcolswitch = true;
- rc = "C";
- setRankByLabel(strRankByColumnLabel);
- }
- catarr = categories[rc];
- if (!catarr || !catarr.length) {
- handleError(strNoSelectionsMsg, true);
- return;
- }
- //if the editingRank is true, then user is editting a rank (value of 2 is for renaming rank only).
- var editRank = topparent.getGlobal("editingRank");
- //the only selection is a non-isolated rank, so render the preContent to ask user to
- //choose it is going to be an insert or edit.
- if(catarr != null){
- if(catarr.length > 1 && (rowSelections.length == 1 ^ colSelections.length == 1)){
- if(editRank == -1) {
- var theSel = rowSelections.length > 0 ? rowSelections[0] : colSelections[0];
- if(theSel.getAttribute("rank") == 'true'){
- selecteddim = null;
- clearDialogs();
- displayPreContent();
- return;
- }
- }
- }
- }
- rankID = "0";
- editCode = "";
- if(editRank == 1 || editRank == 2 || editRank == 3){
- editCode = rowSelections.length == 1 ? rowSelections[0].getAttribute("ppdsId") : colSelections[0].getAttribute("ppdsId");
- if(editCode.charAt(0) == 'T')
- rankID = editCode.substring(1, editCode.length);//will be used in the command sent to server when apply changes.
- }
- topparent.setGlobal("editingRank", -1);
- presetRankFields();
- if (rowSelections.length && resetforRank(rowSelections, editRank))
- return;
- else if (resetforRank(colSelections, editRank))
- return;
- if (!popOptions(document.getElementById("rankByItemId"))) {
- handleError(strNoSelectionsMsg, true);
- return;
- }
- preSelectOptions(document.getElementById("rankByItemId"));
- if (!document.getElementById("rankShowOrdinalsId").disabled)
- document.getElementById("rankOrdinalsNum").value = RANK_DEFAULT_NUM_ORDINALS;
- }
- function presetRankFields() {
- var rowSelections = getSelected("r");
- var colSelections = getSelected("c");
- var selections = (rowSelections.length)? rowSelections : colSelections;
- if (!topparent.getXtabFrame().isOnlyDimensioninAxis(selections[0])) {
- document.getElementById("rankShowOrdinalsId").selectedIndex = 2;
- document.getElementById("rankShowOrdinalsId").disabled = true;
- document.getElementById("rankOrdinalsNum").value = "";
- document.getElementById("rankOrdinalsNum").disabled = true;
- document.getElementById("rankOrdinalsNum").style.visibility = "hidden";
- document.getElementById("rankSortOrderId").selectedIndex = 2;
- document.getElementById("rankSortOrderId").disabled = true;
- }
- }
- function resetforRank(categ, editRank) {
- if(rankID == "0")
- return false;
- if ((categ.length != 1) || (categ[0].getAttribute("ppdsId").charAt(0) != 'T')) //not a rank edit
- return false;
- //set the calcId to new calculation;
- dim = categ[0].getAttribute("dimIdx");
- catarr = categories[rc];
- if(editRank == 1) {
- popDialogWithRankInfo(categ[0].getAttribute("ppdsId")); //We have to populate for the calculation.
- displayContent();
- }
- else if (editRank == 2) {
- displayRenameContent(); //change label only
- popRenameInfo(categ[0].getAttribute("ppdsId"));
- document.getElementById("labelRenameField").select()
- }
- else if(editRank == 3 )
- {
- if (categ[0].getAttribute("dependent_cats") != null) {
- displayDeleteContent();
- popDeleteInfo(categ[0].getAttribute("dependent_cats"));
- } else {
- topparent.closeActionPane();
- var del = 'MK:' + categ[0].getAttribute("ppdsId");
- topparent.getXtabFrame().doit(del);
- }
- return true;
- }
- if (document.getElementById("applyButton"))
- enableButton(document.getElementById("applyButton"));
- return true;
- }
- function popDeleteInfo(dependents) {
- var div = document.getElementById("referencedCalcs");
- var deps = dependents.split("\\t");
- for (var i = 0; i < deps.length; i++) {
- div.appendChild(document.createTextNode(deps[i]));
- div.appendChild(document.createElement("BR"));
- }
- }
- function popDialogWithRankInfo(id) {
- var rankInfo = getRankInfo(id);
- var catSelect = document.getElementById("rankByItemId");
- popOptions(catSelect);
- //find and select proper categories;
- var operandCode = "";
- if( rankInfo._operand._code.substring(0,1) == "T" )
- operandCode = rankInfo._operand._code;
- else
- operandCode = rankInfo._operand._code.substring(0,rankInfo._operand._code.indexOf(","));
- var ctr = 0;
- for (var i = 0; i < catarr.length; i++)
- {
- //LB: if it is calculation code "T..." it has to be matched as is: "T24",
- //and if it is a regular category, than we need to extract and match it's code
- //relying on "," as a separator
- if( ((catarr[i]._code.substring(0,1) == "T") && (catarr[i]._code == operandCode ))
- || (catarr[i]._code.substring(0,catarr[i]._code.indexOf(",")) == operandCode )
- )
- {
- catSelect.selectedIndex = ctr;
- break;
- }
- if (catarr[i]._rankable)
- ctr++;
- }
- //fill in label field
- document.getElementById("RankLabelField").value = rankInfo._label;
- document.getElementById("rankShowOrdinalsId").selectedIndex = rankInfo._show_op;
- if (rankInfo._show_op == 2)
- document.getElementById("rankOrdinalsNum").style.visibility = "hidden";
- else {
- document.getElementById("rankOrdinalsNum").style.visibility = "";
- if (rankInfo._show_num >= 0)
- document.getElementById("rankOrdinalsNum").value = rankInfo._show_num;
- }
- document.getElementById("rankStartFromId").selectedIndex = rankInfo._start_op;
- document.getElementById("rankSortOrderId").selectedIndex = rankInfo._sort_op;
- }
- function popRenameInfo(id) {
- // adjust the size of the action pane for the rename calculation pane.
- topparent.setActionPaneHeight("180");
- var rankInfo = getRankInfo(id);
- if(rankInfo._label != "") {
- document.getElementById("labelRenameField").value = rankInfo._label;
- }
- else {
- for (var i = 0; i < catarr.length; i++) {
- var temp = catarr[i]._code.split(",");
- if(temp[0] == id)
- document.getElementById("labelRenameField").value = catarr[i]._name;
- }
- }
-
- }
- function getRankInfo(id) {
- var idx = parseInt(id.substring(1));
- if (topparent.getXtabFrame().fh && topparent.getXtabFrame().fh.PT) {
- var calcs = topparent.getXtabFrame().fh.PT.value.split("\t\t");
- var dim;
- for (var i = 0; i < calcs.length; i++) {
- var x = calcs[i].split("\t");
- var j = 0;
- if (x[j].charAt(0) == 'D') dim = x[j++].substring(1);
- if (i == idx - 1) {
- var rIdx = 0;
- var op = x[j++];
- if (op.charAt(0) == 'R') {
- var opt = op.substring(2).split(",");
- var label = opt[1];
- //var decimal = opt[0]; //for the moment;
- var operand
- if (x[j].charAt(0) == 'T') {
- operand = new dialogOperand('T',x[j]);
- } else {
- var p = x[j].split(",");
- operand = new dialogOperand('C', p[0] + "," + dim + "," + p[1]);
- }
- j++;
- var show_op = parseInt(x[j++]);
- var show_num = parseInt(x[j++]);
- var start_op = parseInt(x[j++]);
- var sort_op = parseInt(x[j]);
- var result = new rankInfo(label,operand,show_op,show_num,start_op,sort_op);
- return(result);
- }
- }
- }
- }
- return null;
- }
- function popOptions(select) {
- while (select.childNodes.length) {
- select.removeChild(select.firstChild);
- }
- var selIdx = 0;
- if (catarr != null) {
- for (var i = 0; i < catarr.length; i++){
- if (catarr[i]._rankable) {
- select.options[selIdx] = new Option(catarr[i]._name,i);
- select.options[selIdx++].label = catarr[i]._name;
- }
- }
- }
- return selIdx;
- }
- function handleError(sError, closeActionPane){
- if (closeActionPane)
- displayCommonMessage(sError, MESSAGE_TYPE_INFO, [], []);
- else
- displayCommonMessage(sError, MESSAGE_TYPE_INFO, [message_ok_button_text], [function() {removeMessage();}]);
- }
- function clearDialogs() {
- if (document.getElementById("labelField"))
- document.getElementById("labelField").value = "";
- }
- function preSelectOptions(select) {
-
- var selects = getSelected("r");
- if (selects.length != 1) {
- selects = getSelected("c");
- if (selects.length != 1)
- return;
- }
- for (var i = 0; i < select.length; i++) {
- var catCode = catarr[select[i].value]._code;
- if (catCode.charAt(0) == 'T')
- select[i].selected = (catCode == selects[0].getAttribute("ppdsId"));
- else
- select[i].selected = (catCode == selects[0].getAttribute("ppdsId") + "," + selects[0].getAttribute("dimIdx") + "," + selects[0].getAttribute("code"));
- }
- }
- function setRankByLabel(str) {
- var cell = document.getElementById("RankByLabelText");
- while (cell.childNodes.length)
- cell.removeChild(cell.firstChild);
- cell.appendChild(document.createTextNode(str));
- }
- function applyChanges() {
- if (!validateInput())
- return;
- var cmd = "CR:";
- var label = document.getElementById("RankLabelField").value;
- cmd += (label) ? ('"' + CEncodingUtil.EncodeStrOperand(label) + '"') : "";
- cmd += "\t" + rankID;
- cmd += "\t-1\t0\t0\t";
-
- var catSelect = document.getElementById("rankByItemId");
- cmd += catarr[catSelect.options[catSelect.selectedIndex].value]._code + "\t";
- var numVals = -1;
- if (document.getElementById("rankShowOrdinalsId").selectedIndex != 2)
- numVals = document.getElementById("rankOrdinalsNum").value;
- cmd += document.getElementById("rankShowOrdinalsId").selectedIndex + "\t" + numVals + "\t";
- cmd += document.getElementById("rankStartFromId").selectedIndex + "\t";
- cmd += document.getElementById("rankSortOrderId").selectedIndex;
- topparent.getXtabFrame().fh.ACTPANE.value = 0;
- topparent.getXtabFrame().doit(cmd);
- topparent.closeActionPane();
- }
- function doRankOrdinalsChange() {
- var select = document.getElementById("rankShowOrdinalsId");
- if (select.selectedIndex == 2) {
- document.getElementById("rankOrdinalsNum").style.visibility = "hidden";
- } else {
- document.getElementById("rankOrdinalsNum").style.visibility = "";
- }
- }
- function onRenameRank() {
- if (document.getElementById("labelRenameField").value == "") {
- topparent.closeActionPane();
- return;
- }
- var label = document.getElementById("labelRenameField").value;
- var cmd = 'MN:' + editCode;
- cmd += "\t";
- cmd += '"' + CEncodingUtil.EncodeStrOperand(label) + '"';
- topparent.closeActionPane();
- topparent.getXtabFrame().doit(cmd);
-
- }
- function onDeleteRank() {
- if (document.getElementById("delRank").checked) {
- topparent.closeActionPane();
- var cmd = 'MK:' + editCode;
- topparent.getXtabFrame().doit(cmd);
- } else {
- topparent.closeActionPane();
- var cmd = 'MH:0\t' + editCode;
- topparent.getXtabFrame().doit(cmd);
- }
- }
- function validateInput() {
-
- var validChars = "/[^0-9]/";
- if ((document.getElementById("rankShowOrdinalsId").selectedIndex != 2) && (document.getElementById("rankOrdinalsNum").value <= 0) || !CNumUtil.validateNumField(document.getElementById("rankOrdinalsNum"),true, validChars )) {
- handleError(strInvalidOrdinalNumber, false);
- return false;
- }
- return true;
- }
|