123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257 |
- // 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 Calculation pane of
- // PowerPlay Studio.
- // The functions handle any minor browser differences.
- var rightPane;
- var addrightPane;
- var subrightPane;
- var forrightPane;
- var forExplain;
- var accrightPane;
- var rollrightPane;
- var addSelect;
- var subSelect1;
- var subSelect2;
- var accSelect;
- var rollSelect;
- var operationSelect;
- var calcOpTypesSelect;
- var rc;
- var dim;
- var selecteddim;
- var selections;
- var catarr;
- var calcID;
- var editCode; //calculation being editing
- var errorMsg = "";
- var calcTypeIndex; //remember the calc type
- var calcOpTypesIndex; //remember the calc operation type
- var calcTypesArray = new Array();
- var calcOpTypesArray= new Array();
- var categories = new Array();
- categories["R"] = new Array();
- categories["C"] = new Array();
- var lowestDimInAxis = new Array();
- function addToArray(rc, dim, name, code, calc, rankBased, top_of_dim, POB_nonbaseable) {
- if (!categories[rc][dim]) {
- categories[rc][dim] = new Array();
- }
- //Use the fact that the lowest level categories are added last to the array
- lowestDimInAxis[rc] = dim;
- categories[rc][dim][categories[rc][dim].length] = new categoryRecord(name, code, calc, rankBased, top_of_dim, POB_nonbaseable);
- }
- function categoryRecord(name, code, calc, rankBased, top_of_dim, POB_nonbaseable) {
- this._name = name;
- this._calc = calc;
- this._code = code;
- this._rankBased = rankBased;
- this._top_of_dim = top_of_dim;
- this._POB_nonbaseable = POB_nonbaseable;
- if (!calc)
- {
- var comma = code.search(',');
- if (comma > -1)
- {
- var dimIdx = parseInt(code.substr(comma+1));
- this._isMeasure = topparent.getGlobal("gDimensionInfo")[dimIdx].isMeasureDimension;
- }
- }
- }
- function initVars() {
- rightPane = document.getElementById("details");
- //Store Each calculation type's sub-dom tree.
- addrightPane = document.getElementById("addDetails");
- subrightPane = document.getElementById("subDetails");
- forrightPane = document.getElementById("forDetails");
- accrightPane = document.getElementById("accDetails");
- rollrightPane = document.getElementById("rollDetails");
- pctbaserightPane = document.getElementById("PctBaseDetails");
- addSelect = document.getElementById("addCatSel");
- subSelect1 = document.getElementById("subCatSel1");
- subSelect2 = document.getElementById("subCatSel2");
- accSelect = document.getElementById("accCatSel");
- pctBaseSelect = document.getElementById("pctBaseSel");
- pctBaseBaseSelect = document.getElementById("pctBaseBase");
- rollSelect = document.getElementById("rollCatSel");
- forExplain = document.getElementById("forecastExplanation");
- operationSelect = document.getElementById("calcType");
- calcOpTypesSelect = document.getElementById("calcOpType");
-
- //Remove each calculations sub-dom tree.
- rightPane.removeChild(addrightPane);
- rightPane.removeChild(subrightPane);
- rightPane.removeChild(forrightPane);
- rightPane.removeChild(accrightPane);
- rightPane.removeChild(rollrightPane);
- rightPane.removeChild(pctbaserightPane);
-
- calcOpTypesIndex = -1;
- calcTypeIndex = -1;
- }
- function init() {
- topparent.openActionPane();
- ContextMenu.initialize(true,false);
- document.getElementById("calcOpType").selectedIndex = 0;
- document.getElementById("calcType").selectedIndex = 0;
- initVars();
- initErrorVars();
- createCategoryRecords();
- resetDialog();
- }
- function refresh() {
- resetDialog();
- }
- function resetDialog() {
- removeMessage();
- displayContent();
- if (document.getElementById("applyButton"))
- document.getElementById("applyButton").disabled = true;
-
- if (calcOpTypesSelect)
- calcOpTypesSelect.disabled = true;
-
- if (operationSelect)
- operationSelect.disabled = true;
- if (document.preCalculation) {
- document.preCalculation.delete_calc.checked=true;
- document.preCalculation.edit.checked=false;
- document.preCalculation.rename.checked=false;
- document.preCalculation.insert.checked=false;
- }
- popSelections();
- var rowcolswitch = false;
- 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
- if( !isLevelSelected("r") && !isLevelSelected("c") ) {
- handleError(strNoSelectionsMsg, true);
- return;
- }
- else {
- if( isLevelSelected("r") ) {
- rc = "R";
- }
- else {
- rc = "C";
- }
- }
- }
-
- if (rowSelections.length || isLevelSelected("r")) {
- if (rc != "R")
- rowcolswitch = true;
- rc = "R";
- if (isLevelSelected("r"))
- dim = getSelectedLevel().getAttribute("dimIdx");
- else if (!resetRowColArray(rowSelections))
- return;
- } else {
- if (rc != "C")
- rowcolswitch = true;
- rc = "C";
- if (isLevelSelected("c"))
- dim = getSelectedLevel().getAttribute("dimIdx");
- else if (!resetRowColArray(colSelections))
- return;
- }
- catarr = categories[rc][dim];
- if (!catarr || !catarr.length) {
- handleError(strNoSelectionsMsg, true);
- return;
- }
- //if the editingCalc is true, then user is editting a calculation (value of 2 is for renaming calculation only).
- var editCalc = topparent.getGlobal("editingCalc");
- //the only selection is a non-isolated calculation, 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(editCalc == -1) {
- var theSel = rowSelections.length > 0 ? rowSelections[0] : colSelections[0];
- if(theSel.getAttribute("calculation") == 'true' && theSel.getAttribute("rank") != 'true'){
- selecteddim = null;
- clearDialogs();
- displayPreContent();
- return;
- }
- }
- }
- }
-
- calcID = "0";
- editCode = "";
- if(editCalc == 1 || editCalc == 2 || editCalc == 3){
- editCode = rowSelections.length == 1 ? rowSelections[0].getAttribute("ppdsId") : colSelections[0].getAttribute("ppdsId");
- if(editCode.charAt(0) == 'T')
- calcID = editCode.substring(1, editCode.length);//will be used in the command sent to server when apply changes.
- }
-
- // While editing calculations, we need to preserve this variable so as to not allow replacement of any calculation by forecast.
- if(editCalc != 1)
- topparent.setGlobal("editingCalc", -1);
-
- if (rowSelections.length && resetforCalc(rowSelections, editCalc))
- return;
- else if (resetforCalc(colSelections, editCalc))
- return;
- document.getElementById("calcOpType").disabled = false;
- document.getElementById("calcType").disabled = false;
- document.getElementById("applyButton").disabled = false;
- if (((dim == selecteddim) && (!rowcolswitch)) && (calcID == "0")) {
- if (getCurrentCalc()._type == 0) {//refresh add or roll selections
- preSelectOptions(document.getElementById("addCatSel"));
- } else if (getCurrentCalc()._type == 3) {
- preSelectOptions(document.getElementById("rollCatSel"));
- }
- return;
- } else {
- selecteddim = dim;
- }
- clearDialogs();
- var sCmd = "gDimensionInfo[" + dim + "].isTimeDimension";
- popCalcOpTypes();
- popCalcTypes(topparent.getGlobal(sCmd),isOnlyRanks());
- setCalcType(true);
- }
- function resetforCalc(categ, editCalc) {
- if(calcID == "0")
- return false;
- if ((categ.length != 1) || (categ[0].getAttribute("ppdsId").charAt(0) != 'T')) //not a calculation edit
- return false;
- //set the calcId to new calculation;
- dim = categ[0].getAttribute("dimIdx");
- catarr = categories[rc][dim];
- if(editCalc == 1) {
- popDialogWithCalcInfo(categ[0].getAttribute("ppdsId")); //We have to populate for the calculation.
- displayContent();
- }
- else if (editCalc == 2) {
- displayRenameContent(); //change label only
- popRenameInfo(categ[0].getAttribute("ppdsId"));
- document.getElementById("labelRenameField").select()
- }
- else if( editCalc == 3 )
- {
- //close the dialog and delete the calc!!
- 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("calcOpType"))
- document.getElementById("calcOpType").disabled = false;
- if (document.getElementById("calcType"))
- document.getElementById("calcType").disabled = false;
- if (document.getElementById("applyButton"))
- document.getElementById("applyButton").disabled = false;
- 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 resetRowColArray(array) {
- dim = array[0].getAttribute("dimIdx");
- for (var i = 1;i < array.length;i++) {
- var tempdim = array[i].getAttribute("dimIdx");
- if (tempdim != dim) {
- handleError(strIncorrectSelectionsMsg, true);
- return false;
- }
- }
- return true;
- }
- function clearDialogs() {
- if (document.getElementById("labelField"))
- document.getElementById("labelField").value = "";
- }
- function getCurrentCalcOpType() {
- return operationsTypesArray[document.getElementById("calcOpType").options[document.getElementById("calcOpType").selectedIndex].value];
- }
- function setCalcOpType(preselect) {
- //we pop only calculations that belong to selected operation type
- //and we preselect the very first calculation type
- var sCmd = "gDimensionInfo[" + dim + "].isTimeDimension";
- popCalcTypes(topparent.getGlobal(sCmd),isOnlyRanks());
- operationSelect.selectedIndex = 0;
- setCalcType(true);
- }
- function getCurrentCalc() {
- return operationsArray[document.getElementById("calcType").options[document.getElementById("calcType").selectedIndex].value];
- }
- function setCalcType(preselect) {
- calcTypeIndex = operationSelect.selectedIndex;
- var calc = getCurrentCalc();
- if (rightPane.childNodes.length > 0)
- rightPane.removeChild(rightPane.childNodes[0]);
- switch (calc._type) {
- case 0:
- rightPane.appendChild(addrightPane);
- document.getElementById("labelDiv").style.visibility = "visible";
- break;
- case 2:
- rightPane.appendChild(subrightPane);
- document.getElementById("subtagSpot").innerHTML = "<br>" + CEncodingUtil.HtmlEncode(calc._tag);
- document.getElementById("labelDiv").style.visibility = "visible";
- break;
- case 1:
- rightPane.appendChild(accrightPane);
- document.getElementById("labelDiv").style.visibility = "visible";
- break;
- case 3:
- rightPane.appendChild(rollrightPane);
- document.getElementById("labelDiv").style.visibility = "visible";
- break;
- case 4:
- rightPane.appendChild(forrightPane);
- document.getElementById("labelDiv").style.visibility = "hidden";
- document.getElementById("forecastExplanation").style.visibility = "visible";
- break;
- case 5:
- rightPane.appendChild(pctbaserightPane);
- document.getElementById("labelDiv").style.visibility = "visible";
- break;
- }
- popCategories(calc, preselect, editCode.length); //If editing then remove dependents of current calc
- }
- function operRec(tag, type, opType, rankApplicable) {
- this._tag = tag;
- this._type = type;
- this._opType = opType;
- if (rankApplicable != '')
- this._rankApplicable = true;
- else
- this._rankApplicable = false;
- }
- function calcOpTypeRec(name, opType) {
- this._name = name;
- this._opType = opType;
- }
- function calcTypeRec(name, value, opType, isOnlyTime,isRankApplicable) {
- this._name = name;
- this._value = value;
- this._opType = opType;
- if (isOnlyTime != '')
- this._isOnlyTime = true;
- else
- this._isOnlyTime = false;
- if (isRankApplicable != '')
- this._isRankApplicable = true;
- else
- this._isRankApplicable = false;
- }
- function addToOpTypeOptionArray(name, opType) {
- calcOpTypesArray[calcOpTypesArray.length] = new calcOpTypeRec(name,opType);
- }
- function addToOptionArray(name, value, opType, isOnlyTime, isRankApplicable) {
- calcTypesArray[calcTypesArray.length] = new calcTypeRec(name,value,opType, isOnlyTime,isRankApplicable);
- }
- function isOnlyRanks() {
- var onlyRanks = true;
- if (catarr != null) {
- for (var i = 0; i < catarr.length && onlyRanks; i++)
- if (!catarr[i]._rankBased)
- onlyRanks = false;
- }
- return onlyRanks;
- }
- function popOptions(select, incCalcs, incRanks, restrictCurrentCalc) {
- var idx = select.options.length;
- while (idx > 0) {
- select.options[--idx] = null;
- }
- var selIdx = 0;
- var showCat;
- if (catarr != null) {
- for (var i = 0; i < catarr.length; i++){
- showCat = true;
- if (catarr[i]._top_of_dim == true)
- showCat = false;
- if (catarr[i]._code == editCode)
- showCat = false;
- if (catarr[i]._calc && (!incCalcs || isForcastCalc(catarr[i]._code)))
- showCat = false;
- if (catarr[i]._rankBased && !incRanks)
- showCat = false;
- if (restrictCurrentCalc && catarr[i]._calc && isBasedOnCalc(catarr[i]._code,"T" + calcID))
- showCat = false;
- if (showCat) {
- select.options[selIdx] = new Option(catarr[i]._name,i);
- select.options[selIdx++].label = catarr[i]._name;
- }
- }
- }
- return selIdx;
- }
- function popOtherAxisOptions(select) {
- var dimArray = categories[ ((rc == "R")? "C" : "R") ][lowestDimInAxis[ ((rc == "R")? "C" : "R")] ];
- var selIdx = 0;
- var idx = select.options.length;
- while (idx > 0) {
- select.options[--idx] = null;
- }
- if (dimArray) {
- for (var i = 0; i < dimArray.length; i++) {
- if (!dimArray[i]._POB_nonbaseable) {
- select.options[selIdx] = new Option(dimArray[i]._name,i);
- select.options[selIdx++].label = CEncodingUtil.HtmlEncode(dimArray[i]._name);
- }
- }
- }
- }
- function clearOtherAxisOptions(select) {
- var idx = select.options.length;
- while (idx > 0) {
- select.options[--idx] = null;
- }
- }
- function isForcastCalc(id) {
- var calcInfo = getcalcInfo(id);
- if (calcInfo && (calcInfo._oper == "f")) {
- return true;
- }
- return false;
- }
- function popCalcOpTypes() {
- var select = document.getElementById("calcOpType");
- var idx = select.options.length;
- while (idx > 0) {
- select.options[--idx] = null;
- }
-
- var nIdx = 0;
- for (var i = 0; i < calcOpTypesArray.length; i++)
- {
- select.options[nIdx] = new Option(calcOpTypesArray[i]._name,calcOpTypesArray[i]._opType);
- select.options[nIdx].label = CEncodingUtil.HtmlEncode(calcOpTypesArray[i]._name);
- nIdx++;
- }
-
- if(calcOpTypesIndex != -1)
- select.selectedIndex = calcOpTypesIndex;
- else
- select.selectedIndex = 0;
- }
- function popCalcTypes(isTimeDim, isOnlyRanks) {
- var select = document.getElementById("calcType");
-
- var idx = select.options.length;
- while (idx > 0) {
- select.options[--idx] = null;
- }
-
- var selectedOpTypesIndex = 1; //initialize to one just in case
- //we'll pop only calculations that belong to selected operation type
- var selectedOpType = getCurrentCalcOpType();
- if(typeof selectedOpType != "undefined")
- selectedOpTypesIndex = selectedOpType._opType;
-
- //when poping calculation, first check if we are currently editing existing calc
- //in that case we do not want to pop forecast
- var excludeForecast = false;
- if(catarr != null){
- var editCalc = topparent.getGlobal("editingCalc");
- if(editCalc == 1){
- var rowSelections = getSelected("r");
- var colSelections = getSelected("c");
- if(catarr.length > 0 && (rowSelections.length == 1 ^ colSelections.length == 1))
- {
- var id = rowSelections.length == 1 ? rowSelections[0].getAttribute("ppdsId") : colSelections[0].getAttribute("ppdsId");
- if(id.charAt(0) == 'T')
- {
- var calcInfo = getcalcInfo(id);
- excludeForecast = operationsArray[calcInfo._oper]._type != 4;
- }
- }
- }
- }
-
- var nIdx = 0;
- for (var i = 0; i < calcTypesArray.length; i++) {
- if ((!calcTypesArray[i]._isOnlyTime || isTimeDim) &&
- (calcTypesArray[i]._isRankApplicable || !isOnlyRanks) &&
- (calcTypesArray[i]._value != 'f' || !excludeForecast) &&
- (calcTypesArray[i]._opType == selectedOpTypesIndex)) { //No forecast option for edits
- select.options[nIdx] = new Option(calcTypesArray[i]._name,calcTypesArray[i]._value);
- select.options[nIdx].label = CEncodingUtil.HtmlEncode(calcTypesArray[i]._name);
- nIdx++;
- }
- }
-
- if(calcTypeIndex != -1 && calcTypeIndex < select.childNodes.length) {
- select.selectedIndex = calcTypeIndex;
- }
- }
- function popCategories(calc, preselect, restrictCurrentCalc) {
- var currentSelectionIndex = 0;
- switch (calc._type) {
- case 0:
- currentSelectionIndex = popOptions(addSelect,true,calc._rankApplicable,restrictCurrentCalc);
- if (preselect && currentSelectionIndex)
- preSelectOptions(addSelect);
- break;
- case 2:
- currentSelectionIndex = popOptions(subSelect1,true,calc._rankApplicable,restrictCurrentCalc);
- if( currentSelectionIndex )
- currentSelectionIndex = popOptions(subSelect2,true,calc._rankApplicable,restrictCurrentCalc);
- break;
- case 1:
- currentSelectionIndex = popOptions(accSelect,true,calc._rankApplicable,restrictCurrentCalc);
- if (preselect && currentSelectionIndex)
- preSelectOptions(accSelect);
- break;
- case 3:
- currentSelectionIndex = popOptions(rollSelect,false,calc._rankApplicable,restrictCurrentCalc);
- if (preselect && currentSelectionIndex)
- preSelectOptions(rollSelect);
- break;
- case 5:
- currentSelectionIndex = popOptions(pctBaseSelect, true, calc._rankApplicable, restrictCurrentCalc);
- if (preselect && currentSelectionIndex)
- preSelectOptions(pctBaseSelect);
- clearOtherAxisOptions(pctBaseBaseSelect);
- break;
- }
- if( !currentSelectionIndex && calc._type != 4) {
- handleError(strNoSelectionsMsg, true);
- return;
- }
- }
- function preSelectOptions(select) {
- for (var i = 0; i < select.length; i++) {
- var val = select[i].value;
- if (catarr[val])
- {
- var catCode = catarr[val]._code;
- if(catCode.charAt(0) == 'T')
- select[i].selected = selections[catCode];
- else
- select[i].selected = selections[parseInt(catarr[val]._code)];
- }
- }
- }
- function popSelections() {
- var selects = getSelected("r");
- if (selects.length == 0)
- selects = getSelected("c");
- selections = new Array();
- for (var i = 0; i < selects.length; i++)
- selections[selects[i].getAttribute("ppdsId")] = true;
- }
- function onRenameCalculation() {
- 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 onDeleteCalculation() {
- if (document.getElementById("delCalc").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 applyChanges() {
- if (!validateInput()) {
- if(errorMsg != ""){
- calcOpTypesIndex = calcOpTypesSelect.selectedIndex;
- calcTypeIndex = operationSelect.selectedIndex;
- handleError(errorMsg, false);
- }
- return;
- }
- var cmd = "C" + operationSelect.options[operationSelect.selectedIndex].value + ":";
- var label = document.getElementById("labelField").value;
- cmd += (label && getCurrentCalc()._type != 4) ? ('"' + CEncodingUtil.EncodeStrOperand(label) + '"') : "";
- cmd += "\t" + calcID;
- cmd += "\t" + "-1\t";
- cmd += (document.getElementById("customPosition").checked)? ("2\t" + ((rc == 'R')? "1" : "0")) : "0\t0";
-
- topparent.getXtabFrame().fh.ACTPANE.value = 0;
- switch(getCurrentCalc()._type)
- {
- case 0:
- cmd = getAddCmd(cmd);break;
- case 1:
- cmd = getAccCmd(cmd); break;
- case 2:
- cmd = getSubCmd(cmd);break;
- case 3:
- cmd = getRollCmd(cmd);break;
- case 4:
- cmd = getForCmd(cmd);break;
- case 5:
- cmd = getPctBaseCmd(cmd);break;
- }
- if (cmd.charAt(0) == '!') {
- return;
- } else {
- topparent.getXtabFrame().doit(cmd);
- }
- topparent.closeActionPane();
- }
- function getCatFromDimIdxPair(catNo) {
- var dimArray = categories[ ((rc == "R")? "C" : "R") ][ lowestDimInAxis[ ((rc == "R")? "C" : "R")] ];
- return dimArray[catNo];
- }
- function getAccCmd(cmd) {
- cmd += "\t" + catarr[document.getElementById("accCatSel").options[document.getElementById("accCatSel").selectedIndex].value]._code;
- return cmd;
- }
- function getPctBaseCmd(cmd) {
- cmd += "\t" + catarr[document.getElementById("pctBaseSel").options[document.getElementById("pctBaseSel").selectedIndex].value]._code;
- if (document.getElementById("pctBaseTypeBase").checked) {
- var cat = getCatFromDimIdxPair(document.getElementById("pctBaseBase").options[document.getElementById("pctBaseBase").selectedIndex].value);
- cmd += "\t" + cat._code;
- }
- return cmd;
- }
- function getSubCmd(cmd) {
- var error = false;
- if (document.getElementById("rcat1").checked)
- cmd += "\t" + catarr[document.getElementById("subCatSel1").options[document.getElementById("subCatSel1").selectedIndex].value]._code;
- else {
- if (document.getElementById("subNum1").value)
- cmd += "\t" + CNumUtil.normalizeDecimal(document.getElementById("subNum1").value);
- else
- error = true;
- }
- if (document.getElementById("rcat2").checked)
- cmd += "\t" + catarr[document.getElementById("subCatSel2").options[document.getElementById("subCatSel2").selectedIndex].value]._code;
- else {
- if (document.getElementById("subNum2").value)
- cmd += "\t" + CNumUtil.normalizeDecimal(document.getElementById("subNum2").value);
- else
- error = true;
- }
- if (error)
- cmd = "!:" + strProvideNumbersMsg;
- return cmd;
- }
- function getAddCmd(cmd) {
- var ctr = numSelected(document.getElementById("addCatSel"));
- cmd += getListCmd(document.getElementById("addCatSel"));
- if (document.getElementById("userNumberCB").checked)
- {
- ctr++;
- cmd += "\t" + CNumUtil.normalizeDecimal(document.getElementById("addNum1").value);
- }
- if (ctr < 2)
- cmd = "!:" + strSelectMoreCatMsg;
- return cmd;
- }
- function getRollCmd(cmd) {
- var ctr = numSelected(document.getElementById("rollCatSel"));
- if (ctr == 0)
- cmd = "!:" + strSelectCatMsg;
- else
- cmd += getListCmd(document.getElementById("rollCatSel"));
- return cmd;
- }
- function getForCmd(cmd) {
- var i = 0;
- while (catarr[i]._top_of_dim)
- i++;
- cmd += "\t" + catarr[i]._code + "\t";
- cmd += document.getElementById("ForMethod").value + "\t";
- cmd += document.getElementById("ForNum").value;
- return cmd;
- }
- function numSelected(list) {
- var ctr = 0;
- for (var i = 0; i < list.options.length; i++) {
- if (list.options[i].selected)
- ctr++;
- }
- return ctr;
- }
- function getListCmd(list) {
- var cmd = "";
- for (var i = 0; i < list.options.length; i++) {
- if (list.options[i].selected)
- cmd += "\t" + catarr[list.options[i].value]._code;
- }
- return cmd;
- }
- function dialogOperand(type, code) {
- this._type = type;
- this._code = code;
- }
- function dialogInfo(oper, label, operands) {
- this._oper = oper;
- this._label = label;
- this._operands = operands;
- this._defaultPosition = true;
- }
- function getcalcInfo(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++];
- var opt = op.substring(2).split(",");
-
- var pos = opt[0];
- var label = opt[1];
- var operands = new Array;
- for (;j < x.length; j++) {
- if (x[j].charAt(0) == 'D') {
- x[j] = x[j].substr(x[j].indexOf(',') + 1);
- }
- if (x[j].charAt(0) == 'T') {
- operands[operands.length] = new dialogOperand('T',x[j]);
- } else {
- var p = x[j].split(",");
- if (p.length == 1)
- operands[operands.length] = new dialogOperand('N', x[j]);
- else
- operands[operands.length] = new dialogOperand('C', p[0] + "," + dim + "," + p[1]);
- }
- }
- var result = new dialogInfo(op.charAt(0),label,operands);
- if (pos.length > 1 && (pos.charAt(pos.indexOf(';') + 1) == '1' || pos.charAt(pos.indexOf(';') + 1) == '2'))
- result._defaultPosition = false;
- return(result);
- }
- }
- }
- return null;
- }
- function isBasedOnCalc(calc,ancestorCalc) {
- //Get the Info for this calc.
- var calcInfo = getcalcInfo(calc);
- //Loop through each of its operands and for each calc, if it's the ancestor or is based
- //on the ancestor return true;
- for (var i = 0; i < calcInfo._operands.length; i++) {
- if (calcInfo._operands[i]._type == "T")
- if (calcInfo._operands[i]._code == ancestorCalc ||
- isBasedOnCalc(calcInfo._operands[i]._code,ancestorCalc))
- return true;
- }
- return false;
- }
- function popRenameInfo(id) {
- // adjust the size of the action pane for the rename calculation pane.
- topparent.setActionPaneHeight("180");
- var calcInfo = getcalcInfo(id);
- if(calcInfo._label != "") {
- document.getElementById("labelRenameField").value = calcInfo._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 popPctBaseOtherAxisDropDown() {
- if (pctBaseBaseSelect.options.length == 0) {
- popOtherAxisOptions(pctBaseBaseSelect);
- }
- }
- function popDialogWithCalcInfo(id) {
- var sCmd = "gDimensionInfo[" + dim + "].isTimeDimension";
- var calcInfo = getcalcInfo(id);
- popCalcOpTypes();
- //find and select proper operation type
- for (var i = 0; i < calcOpTypesSelect.options.length; i++) {
- if (calcOpTypesSelect.options[i].value == operationsArray[calcInfo._oper]._opType) {
- calcOpTypesSelect.selectedIndex = i;
- break;
- }
- }
-
- popCalcTypes(topparent.getGlobal(sCmd),isOnlyRanks());
- //find and select proper calculation type;
- for (var i = 0; i < operationSelect.options.length; i++) {
- if (operationSelect.options[i].value == calcInfo._oper) {
- operationSelect.selectedIndex = i;
- break;
- }
- }
- //fill in label field if not a forcast
- if (operationsArray[calcInfo._oper]._type != 4)
- document.getElementById("labelField").value = calcInfo._label;
- if (!calcInfo._defaultPosition)
- document.getElementById("customPosition").checked = true;
- //populate menus
- setCalcType(false);
- // fill in operands based on calculation type;
- switch (operationsArray[calcInfo._oper]._type) {
- case 0: //Add type
- var allFound = true;
- for (var i = 0; i < calcInfo._operands.length;i++) {
- var found = false;
- if (calcInfo._operands[i]._type == 'N') {
- document.getElementById("userNumberCB").checked = true;
- document.getElementById("addNum1").value = CNumUtil.localizeDecimal(calcInfo._operands[i]._code);
- found = true;
- } else {
- for (var j = 0; j < document.getElementById("addCatSel").options.length; j++) {
- if (compareCategory(catarr[document.getElementById("addCatSel").options[j].value]._code, calcInfo._operands[i]._code)) {
- found = true;
- document.getElementById("addCatSel").options[j].selected = true;
- j = addSelect.options.length;
- }
- }
- }
- if (!found)
- allFound = false;
- }
-
- if (!allFound) {
- displayCommonMessage(strCalcCatsNotExist, MESSAGE_TYPE_INFO, [message_ok_button_text, message_cancel_button_text], [function() {removeMessage();}, function() {topparent.closeActionPane();}]);
- }
- break;
- case 2: //Subtract type
- var oper1 = calcInfo._operands[0];
- var oper2 = calcInfo._operands[1];
- var found1 = false;
- var found2 = false;
- if (calcInfo._oper == "g") {
- // Special case: For percent growth, the operands are in reverse order.
- // Like what was done in the javascript for dynamic mode, switch them around.
- oper1 = calcInfo._operands[1];
- oper2 = calcInfo._operands[0];
- }
- if (oper1._type == 'N') {
- document.getElementById("subNum1").value = CNumUtil.localizeDecimal(oper1._code);
- document.getElementById("rcat1").checked = false;
- document.getElementById("rnum1").checked = true;
- found1 = true;
- } else {
- for (var j = 0; j < document.getElementById("subCatSel1").options.length; j++) {
- if (compareCategory(catarr[document.getElementById("subCatSel1").options[j].value]._code, oper1._code)) {
- found1 = true;
- document.getElementById("subCatSel1").options[j].selected = true;
- j = document.getElementById("subCatSel1").options.length; //break out
- }
- }
- }
- if (oper2._type == 'N') {
- document.getElementById("subNum2").value = CNumUtil.localizeDecimal(oper2._code);
- document.getElementById("rcat2").checked = false;
- document.getElementById("rnum2").checked = true;
- found2 = true;
- } else {
- for (var j = 0; j < document.getElementById("subCatSel2").options.length; j++) {
- if (compareCategory(catarr[document.getElementById("subCatSel2").options[j].value]._code, oper2._code)) {
- found2 = true;
- document.getElementById("subCatSel2").options[j].selected = true;
- j = document.getElementById("subCatSel2").options.length;
- }
- }
- }
- if (!found1 || !found2) {
- displayCommonMessage(strCalcCatsNotExist, MESSAGE_TYPE_INFO, [message_ok_button_text, message_cancel_button_text], [function() {removeMessage();}, function() {topparent.closeActionPane();}]);
- }
- break;
- case 1: //Accumulate type
- var found = false;
- for (var j = 0; j < document.getElementById("accCatSel").options.length; j++) {
- if (compareCategory(catarr[document.getElementById("accCatSel").options[j].value]._code, calcInfo._operands[0]._code)) {
- found = true;
- document.getElementById("accCatSel").options[j].selected = true;
- j = document.getElementById("accCatSel").options.length;
- }
- }
- if (!found) {
- displayCommonMessage(strCalcCatsNotExist, MESSAGE_TYPE_INFO, [message_ok_button_text, message_cancel_button_text], [function() {removeMessage();}, function() {topparent.closeActionPane();}]);
- }
- break;
- case 3: //rollup style
- var allFound = true;
- for (var i = 0; i < calcInfo._operands.length;i++) {
- var found = false;
- for (var j = 0; j < document.getElementById("rollCatSel").options.length; j++) {
- if (compareCategory(catarr[document.getElementById("rollCatSel").options[j].value]._code,calcInfo._operands[i]._code)) {
- found = true;
- document.getElementById("rollCatSel").options[j].selected = true;
- j = document.getElementById("rollCatSel").options.length;
- }
- }
- if (!found)
- allFound = false;
- }
- if (!allFound) {
- displayCommonMessage(strCalcCatsNotExist, MESSAGE_TYPE_INFO, [message_ok_button_text, message_cancel_button_text], [function() {removeMessage();}, function() {topparent.closeActionPane();}]);
- }
- break;
- case 4: //Forcast
- document.getElementById("labelDiv").style.visibility = "hidden";
- document.getElementById("ForMethod").value = calcInfo._operands[1]._code;
- document.getElementById("ForNum").value = CNumUtil.localizeDecimal(calcInfo._operands[2]._code);
- break;
- case 5: //Percent Base type
- popOtherAxisOptions(pctBaseBaseSelect);
- var foundOper = false;
- for (var j = 0; j < document.getElementById("pctBaseSel").options.length; j++) {
- if (compareCategory(catarr[document.getElementById("pctBaseSel").options[j].value]._code, calcInfo._operands[0]._code)) {
- foundOper = true;
- document.getElementById("pctBaseSel").options[j].selected = true;
- j = document.getElementById("pctBaseSel").options.length;
- }
- }
- if (calcInfo._operands.length > 1) {
- document.getElementById("pctBaseTypeBase").checked = true;
- var found = !foundOper;
- for (var j = 0; j < document.getElementById("pctBaseBase").options.length; j++) {
- var cat = getCatFromDimIdxPair(document.getElementById("pctBaseBase").options[j].value);
- if (compareCategory(cat._code, calcInfo._operands[1]._code)) {
- found = true;
- document.getElementById("pctBaseBase").options[j].selected = true;
- j = document.getElementById("pctBaseBase").options.length;
- }
- }
- if (!foundOper) {
- displayCommonMessage(strCalcCatsNotExist, MESSAGE_TYPE_INFO, [message_ok_button_text, message_cancel_button_text], [function() {removeMessage();}, function() {topparent.closeActionPane();}]);
- }
- if (!found) {
- displayCommonMessage(strPrcntBaseBaseNotExist, MESSAGE_TYPE_INFO, [message_ok_button_text, message_cancel_button_text], [function() {removeMessage();}, function() {topparent.closeActionPane();}]);
- }
- }
-
- break;
- }
- }
- function validateInput() {
- var validChars = "/[^0-9" + decimalpt + "\-]/";
- switch(getCurrentCalc()._type) {
- case 0: //validate Add
- if(document.getElementById("userNumberCB").checked && document.getElementById("addNum1").value == ""){
- errorMsg = strProvideNumbersMsg;
- return false;
- }
- if (!CNumUtil.validateNumField(document.getElementById("addNum1"),true, validChars )) {
- errorMsg = strInvalidNumbersMsg;
- return false;
- }
- document.getElementById("addNum1").value = CNumUtil.normalizeDecimal(document.getElementById("addNum1").value);
- var ctr = numSelected(document.getElementById("addCatSel"));
- var num = document.getElementById("userNumberCB").checked ? 1 : 0;
- if( ctr + num < 2){
- errorMsg = strSelectMoreCatMsg;
- return false;
- }
- break;
- case 2: //Validate Subtract
- if(document.getElementById("rnum1").checked && document.getElementById("subNum1").value == ""){
- errorMsg = strProvideNumbersMsg;
- return false;
- }
- if(document.getElementById("rnum2").checked && document.getElementById("subNum2").value == ""){
- errorMsg = strProvideNumbersMsg;
- return false;
- }
- if (!CNumUtil.validateNumField(document.getElementById("subNum1"),true, validChars) || !CNumUtil.validateNumField(document.getElementById("subNum2"),true, validChars)) {
- errorMsg = strInvalidNumbersMsg;
- return false;
- }
- if((document.getElementById("rnum1").checked && CNumUtil.validateNumField(document.getElementById("subNum1"),true, validChars)) &&
- (document.getElementById("rnum2").checked && CNumUtil.validateNumField(document.getElementById("subNum2"),true, validChars)) ){
- errorMsg = strInvalidCalcMsg;
- return false;
- }
- document.getElementById("subNum1").value = CNumUtil.normalizeDecimal(document.getElementById("subNum1").value);
- document.getElementById("subNum2").value = CNumUtil.normalizeDecimal(document.getElementById("subNum2").value);
-
- document.getElementById("rnum1").value = CNumUtil.normalizeDecimal(document.getElementById("rnum1").value);
- document.getElementById("rnum2").value = CNumUtil.normalizeDecimal(document.getElementById("rnum2").value);
- break;
- case 3: //rollup style
- if (!numSelected(document.getElementById("rollCatSel"))) {
- errorMsg = strSelectMoreCatMsg;
- return false;
- }
- break;
- case 4: //Validate Forcast
- if (!CNumUtil.validateNumField(document.getElementById("ForNum"),false, validChars) || document.getElementById("ForNum").value <= 0) {
- errorMsg = strInvalidNumbersMsg;
- return false;
- }
- break;
- }
- return true;
- }
- function ableFormField(event, owner,field) {
- if (!owner.checked)
- field.value = "";
- }
- function selectAll(event, box) {
- var box = document.getElementById(box);
- for (var i = 0; i < box.options.length; i++) {
- box.options[i].selected = true;
- }
- var mgr = new eventManager(event);
- mgr.cancelBubble();
- }
- function unselectAll(event, box) {
- var box = document.getElementById(box);
- for (var i = 0; i < box.options.length; i++) {
- box.options[i].selected = false;
- }
- var mgr = new eventManager(event);
- mgr.cancelBubble();
- }
- function submitPreCalcDialog() {
- topparent.setGlobal("editingCalc", 0);
- if(document.preCalculation.edit.checked)
- topparent.setGlobal("editingCalc", 1);
- else if(document.preCalculation.insert.checked)
- topparent.setGlobal("editingCalc", 0);
- else if(document.preCalculation.rename.checked)
- topparent.setGlobal("editingCalc", 2);
- else if(document.preCalculation.delete_calc.checked)
- topparent.setGlobal("editingCalc", 3);
- resetDialog();
- }
- function handleError(sError, closeActionPane){
- selecteddim = null;
- if (closeActionPane)
- displayCommonMessage(sError, MESSAGE_TYPE_INFO, [], []);
- else
- displayCommonMessage(sError, MESSAGE_TYPE_INFO, [message_ok_button_text], [function() {removeMessage();}]);
- }
- function explainForecast(selectedOption) {
- var selectedVal = selectedOption.selectedIndex;
- document.getElementById("forecastExplanation").style.visibility = "visible";
- switch (selectedVal) {
- case 0:
- document.getElementById("forecastExplanation").innerHTML = "<table><tr><td><img name=\"Trend\" alt=\"" + CEncodingUtil.HtmlEncode(strForcastTrend) + "\" border=\"0\" height=\"28\" src=\"../ppwb/Icon/trend.gif\"></img></td><td class=\"ForecastMethodExplanation\">" + CEncodingUtil.HtmlEncode(strForcastExplTrend)+"</td></tr></table>";
- break;
-
- case 1:
- document.getElementById("forecastExplanation").innerHTML = "<table><tr><td><img name=\"Growth\" alt=\"" + CEncodingUtil.HtmlEncode(strForcastGrowth) + "\" border=\"0\" height=\"28\" src=\"../ppwb/Icon/growth.gif\"></img></img></td><td class=\"ForecastMethodExplanation\">" + CEncodingUtil.HtmlEncode(strForcastExplGrowth)+"</td></tr></table>";
- break;
-
- case 2:
- document.getElementById("forecastExplanation").innerHTML = "<table><tr><td><img name=\"AR\" alt=\"" + CEncodingUtil.HtmlEncode(strForcastAutoreg) + "\" border=\"0\" height=\"28\" src=\"../ppwb/Icon/autoregression.gif\"></img></img></td><td class=\"ForecastMethodExplanation\">" + CEncodingUtil.HtmlEncode(strForcastExplAutoreg)+"</td></tr></table>";
- break;
-
- default:
- //alert("explain trend");
- break;
- }
- return;
- }
- function compareCategory(code1, code2) {
- if(code1.charAt(0) == 'T')
- return code1 == code2;
- else
- return parseInt(code1) == parseInt(code2);
- }
|