// 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 Find pane of
// PowerPlay Studio.
// The functions handle any minor browser differences.
var gFindResults;
var selectedControlIdx = -1;
var displayLimit = 5;
var currentPosition = 0;
var rowsDisplayed = 0;
var blockInvalidate = false;
var navprev = "";
var navnext = "";
function invalidateResults() {
if (document.searchForm.searchTarget.value == "R" && !blockInvalidate)
{
submitSearch();
poll();
}
}
function init() {
topparent.openActionPane();
ContextMenu.initialize(true,false);
topparent.getXtabFrame().fh.FIND.value = "1";
topparent.ResultUnload();
changeTarget(document.searchForm.searchTarget.value);
}
function displayActions() {
var actions = document.getElementById("navigationDisplayBottom");
var buttons = "";
actions.style.visibility = "visible";
if (gFindResults) {
if (document.searchForm.searchTarget.value == "R") { //find in report
buttons += '
';
} else { // find in cube
buttons += '';
}
}
actions.innerHTML = buttons;
}
function displayNavigationLinks(target) {
navprev = ' | ';
if (currentPosition > displayLimit) {
var sPrev = CMsgUtil.SubstituteMessage(strCmdPrev, 5);
sPrev = CEncodingUtil.HtmlEncode(sPrev);
navprev = '' + sPrev + ' | ';
}
navnext = ' | ';
if (currentPosition < gFindResults.length) {
var sNext = CMsgUtil.SubstituteMessage(strCmdNext, 5);
sNext = CEncodingUtil.HtmlEncode(sNext);
navnext = '' + sNext + ' | ';
}
}
function select(event, control) {
var name = control.id;
var idx = name.replace(/\D/g, "");
unselect();
if (selectedControlIdx == idx) {
selectedControlIdx = -1;
return;
}
control.className = "findRowSelected";
selectedControlIdx = idx;
var category = gFindResults[selectedControlIdx];
var link = document.getElementById('filterLink');
if(category._tempInfo != "")
{
link.className = 'FindResultsLinkDisabled';
link.onclick = '';
}
else
{
link.className = 'FindResultsLink';
link.onclick = filterOnFindResult;
}
var eventM = new eventManager(event);
eventM.cancelBubble();
return false;
}
function unselect() {
if (selectedControlIdx == -1)
return;
var control = document.getElementById("FindResult" + selectedControlIdx);
control.className = "findRow";
}
function submitSearch() {
//hide results so actions don't get fired while we're processing a new result set
var navBottom = document.getElementById("navigationDisplayBottom");
if (navBottom && navBottom.style.visibility) navBottom.style.visibility = "hidden";
var resultDisplay = document.getElementById("resultsDisplay");
if (resultDisplay && resultDisplay.style.visibility) resultDisplay.style.visibility = "hidden";
disableButton(document.getElementById("findButton"));
topparent.ResultUnload();
currentPosition = 0;
rowsDisplayed = 0;
var cmd = document.searchForm.searchTarget.value;
var pattern = document.searchForm.searchPattern.value;
var restrict = document.searchForm.searchRestriction.value;
var hf = topparent.getXtabFrame().document.getElementById("fhidden");
var target = hf.target;
hf.CNCT.value = 12;
var appendUrl = 'F' + cmd + ':"' + CEncodingUtil.EncodeStrOperand(pattern) + '"' + '\t' + restrict;
if (cmd == "C") {
appendUrl += '\t' + document.getElementById("searchDimension").value;
} else {
appendUrl += '\t' + document.getElementById("searchAxis").value;
}
hf.CO.value = appendUrl;
hf.target = findResultFrame.name;
hf.RA.value = "999";
hf.submit();
hf.target = target;
}
function poll() {
if (topparent.isResultStillLoading())
{
setTimeout("poll()", 50);
return;
}
gFindResults = findResultFrame.FindResults;
displayFindResults();
}
function filterOnFindResult(){
if (topparent.isXtabStillLoading())
{
setTimeout("filterOnFindResult()", 50);
return;
}
if(gFindResults.length == 1 && selectedControlIdx == -1)
selectedControlIdx = 0;
if (isError(selectedControlIdx == -1, errNoSelection))
return;
var command = '';
var category = gFindResults[selectedControlIdx];
if (document.searchForm.searchTarget.value == "R")
{
if(category._tempInfo == "")
command = 'DG' + ':' + category._axis + category._group + '\t' + category._id + "," + category._dim + ';' + category._code;
}
else
{
command = 'DC' + ':' + category._id + "," + category._dim + ';' + category._code;
}
if (command != '')
{
topparent.getXtabFrame().document.fhidden.target = "_self";
topparent.getXtabFrame().doit(command);
}
}
function GoToCategory(){
if(gFindResults.length == 1 && selectedControlIdx == -1)
selectedControlIdx = 0;
if (isError(selectedControlIdx == -1, errNoSelection))
return;
var category = gFindResults[selectedControlIdx];
var rowPage = 0;
var colPage = 0;
var isOnCurrentPage = true;
var hasPagination = topparent.getXtabFrame().document.fhidden.J && topparent.getXtabFrame().document.fhidden.K;
if (hasPagination) {
rowPage = topparent.getXtabFrame().document.fhidden.J.value;
colPage = topparent.getXtabFrame().document.fhidden.K.value;
}
if(category._axis == 'R')
isOnCurrentPage = rowPage == category._pageNo;
else
isOnCurrentPage = colPage == category._pageNo;
if (isError(isOnCurrentPage, currSelection))
return;
if(category._axis == 'R')
command = 'PG' + ':' + category._pageNo + '\t' + colPage;
else if(category._axis == 'C')
command = 'PG' + ':' + rowPage + '\t' + category._pageNo;
blockInvalidate = true;
topparent.getXtabFrame().doit(command);
blockInvalidate = false;
}
function replaceRows(){
if(gFindResults.length == 1 && selectedControlIdx == -1)
selectedControlIdx = 0;
if (isError(selectedControlIdx == -1, errNoSelection))
return;
var Results = findResultFrame.FindResults;
var category = Results[selectedControlIdx];
var command = 'ER' + ':' + 'R-1' + '\t' + 'D' + category._dim + '\t' + category._id + "," + category._dim + ';' + category._code;
topparent.getXtabFrame().doit(command);
}
function replaceColumns(){
if(gFindResults.length == 1 && selectedControlIdx == -1)
selectedControlIdx = 0;
if (isError(selectedControlIdx == -1, errNoSelection))
return;
var Results = findResultFrame.FindResults;
var category = Results[selectedControlIdx];
var command = 'ER' + ':' + 'C-1' + '\t' + 'D' + category._dim + '\t' + category._id + "," + category._dim + ';' + category._code;
topparent.getXtabFrame().doit(command);
}
function isError (condition, msg) {
if (condition)
writeErrorMessage(msg);
return condition;
}
function changeTarget (value) {
if (value == "R") { //find in report
document.getElementById("limitLabel").innerHTML = CEncodingUtil.HtmlEncode(strReportAxis);
document.getElementById("limitElement").innerHTML = document.getElementById("reportAxisHTML").innerHTML;
} else {
document.getElementById("limitLabel").innerHTML = CEncodingUtil.HtmlEncode(strDimensionList);
document.getElementById("limitElement").innerHTML = document.getElementById("DimensionListHTML").innerHTML;
}
}
function clearResults() {
var results = document.getElementById("searchResults");
var navUp = document.getElementById("navigationDisplayTop");
var navDown = document.getElementById("navigationDisplayBottom");
var sResult = "";
var sNoResultMsg = strNoResults;
navUp.innerHTML = "";
navDown.innerHTML = "";
sResult += '';
sResult += CEncodingUtil.HtmlEncode(sNoResultMsg) + ' | ';
sResult += '
';
results.innerHTML = sResult;
}
function FindRecord (ppds_id, dim_index, code, label, path, axis, group, tempInfo, pageNo) {
this._id = ppds_id;
this._dim = dim_index;
this._code = code;
this._label = label;
this._path = path;
this._axis = axis;
this._group = group;
this._tempInfo = tempInfo;
this._pageNo = pageNo;
}
function renderHTML(record,index) {
var label = record._label;
var path = record._path;
if (path == "") {
path = " ";
}
var pageNo = record._pageNo;
pageNo++; //pageNo is zero based, so increase it just for display purposes
var sResult = "";
sResult += '';
sResult += CEncodingUtil.HtmlEncode(label) + ' | ';
sResult += CEncodingUtil.HtmlEncode(path) + ' | ';
sResult += '
';
return sResult;
}
// the results of the find query are written to a separate frame in the following manner...
// var FindResults = new Array();
// FindResults[0] = new FindRecord(PPDS_ID, 'Label', 'Report/Cube Path');
// FindResults[1] = ...
// only matching results are returned to the pane
// if no results match the query, the array size will be set to 0.
function displayFindResults() {
enableButton(document.getElementById("findButton"));
displayResults();
document.getElementById("resultsDisplay").style.visibility = "visible";
}
function displayResults() {
selectedControlIdx = -1;
var table = document.getElementById("searchResults");
if (gFindResults) {
displayTitles(false);
var sTable = '';
sTable += ' |
';
sTable += '';
sTable += '';
var startPos = currentPosition;
var maxPos = Math.min(startPos + displayLimit, gFindResults.length);
rowsDisplayed = 0;
for ( ; currentPosition < maxPos; currentPosition++) {
sTable += renderHTML(gFindResults[currentPosition],currentPosition);
rowsDisplayed++;
}
sTable += "
";
sTable += "
";
table.innerHTML = sTable;
displayNavigationLinks();
displayTitles(false);
displayActions();
selectedControlIdx = startPos;
var control = document.getElementById("FindResult" + selectedControlIdx);
control.className = "findRowSelected";
} else {
clearResults();
}
}
function displayTitles(doDefault) {
var titles = document.getElementById("navigationDisplayTop");
var contents = "";
var displayStart;
if (gFindResults || doDefault)
{
contents += '' + navprev + '' + CEncodingUtil.HtmlEncode(catTitle);
if (!doDefault)
{
if (gFindResults.length > 0)
{
if (gFindResults.length > displayLimit) {
displayStart = displayLimit * parseInt((currentPosition-1)/displayLimit) + 1;
} else {
displayStart = 1;
}
contents += ' (' + displayStart + '-' + Math.min(displayStart-1 + displayLimit, gFindResults.length) + ' ' + CEncodingUtil.HtmlEncode(strResultOf) + ' ' + gFindResults.length + ')';
}
}
contents += ' | ' + navnext + '
';
}
titles.innerHTML = contents;
}
function writeErrorMessage(msg) {
displayCommonMessage(msg, MESSAGE_TYPE_INFO, [message_ok_button_text], [function() {removeMessage();}]);
}