<script src="../JS/OpenSave/opensave.js" type="text/javascript"></script>
<script>
/*
* Fake Namespace and prompt getters.
*/
var paulScripts = {}
var oCR = cognos.Report.getReport("_THIS_");
/*
* function paulScripts.getControl - Paul Mendelson
* Simply returns the prompt control.
*/
paulScripts.getControl = function(promptName)
{
return oCR.prompt.getControlByName(promptName);
};
/*
* function paulScripts.getSource - Paul Mendelson
* Finds the source of the action.
*/
paulScripts.getSource = function()
{
var targ;
if (!e) var e = window.event;
if(!e) return false;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
return targ;
}
/*
* function paulScripts.JSONEncode - Rick Blackwell - ?
* Modified by Paul Mendelson - 2012-11-20
* Why reinvent the wheel? Rick wrote this to populate a cookie (as opposed to a file) with the prompt values.
* Modified to escape the strings.
*
*/
paulScripts.JSONEncode = function(promptControl) {
// Create an empty variable to contain the JSON encoded prompt values
var JSONData = " ";
// Create an array to hold the selected values for the prompt control passed to this function (promptControl)
aPromptValues = promptControl.getValues();
// If there are no selected values, then the array length is zero
if (aPromptValues.length == 0) {
JSONData = "[]";
} else {
JSONData = "[";
// Loop through the prompt values
for (var j=0; j< aPromptValues.length; j++) {
var promptValue = aPromptValues[j];
if (promptValue.use) {
// Non Range value
if (j == 0) {
JSONData = JSONData + " {'use' : '" + escape(promptValue.use) + "'" +", 'display' : '" + escape(promptValue.display) + "' }";
} else {
JSONData = JSONData + ", {'use' : '" + escape(promptValue.use) + "'" +", 'display' : '" + escape(promptValue.display) + "' }";
}
} else {
// Range value
var rangeStart = promptValue.start;
var rangeEnd = promptValue.end;
if (rangeStart && rangeEnd) {
if (j == 0) {
JSONData = JSONData + " {'start' : {'use' : '" + escape(rangeStart.use) + "'";
} else {
JSONData = JSONData + ", {'start' : {'use' : '" + escape(rangeStart.use) + "'";
}
if (rangeStart.display) {
JSONData = JSONData + ", 'display' : '" + escape(rangeStart.display) + "'}"
} else {
JSONData = JSONData + "}"
}
JSONData = JSONData + ", 'end' : {'use' : '" + escape(rangeEnd.use) + "'";
if (rangeEnd.display) {
JSONData = JSONData + ", 'display' : '" + escape(rangeEnd.display) + "'} }"
} else {
JSONData = JSONData + "} }"
}
} else if (rangeStart && !rangeEnd) {
if (j == 0) {
JSONData = JSONData + " {'start' : {'use' : '" + escape(rangeStart.use) + "'";
} else {
JSONData = JSONData + ", {'start' : {'use' : '" + escape(rangeStart.use) + "'";
}
if (rangeStart.display) {
JSONData = JSONData + ", 'display' : '" + escape(rangeStart.display) + "'} }"
} else {
JSONData = JSONData + "} }"
}
} else if (!rangeStart && rangeEnd) {
if (j == 0) {
JSONData = JSONData + " {'end' : {'use' : '" + escape(rangeEnd.use) + "'";
} else {
JSONData = JSONData + ", {'end' : {'use' : '" + escape(rangeEnd.use) + "'";
}
if (rangeEnd.display) {
JSONData = JSONData + ", 'display' : '" + escape(rangeEnd.display) + "'} }"
} else {
JSONData = JSONData + "} }"
}
} else {
alert ("Range not set.");
} // end if
} // end if
} // end for
JSONData = JSONData + " ]";
} //end if
return JSONData;
}; // end JSONEncode function
/*
* Function createPrompts. Paul Mendelson 2012-11-12
* This will pass a string containing all of the prompts and currently selected values to the OpenSave save button.
*/
paulScripts.createPrompts = function()
{
//find all of the controls and stick them in aPromptControls.
var aPromptControls = oCR.prompt.getControls( );
var names = [];
var choices = names
//loop through the controls - finding the name and values and sticking them into the names array
for(i=0;i<aPromptControls.length;i++)
{
var ctrl = aPromptControls[i];
var values = ctrl.getValues();
names[i] = ctrl.getName();
//if the prompt doesn't have any selected values, then skip it and move on.
if(values.length == 0) continue;
//append the JSON encoded values to the prompt name.
names[i] = ctrl.getName() + '||' + paulScripts.JSONEncode(ctrl);
}
names.unshift('Cognos Prompts');
return names.join('\r\n');
}
/*
* function paulScripts.getFile - Paul Mendelson 2012-11-20
* This function will load the file and populate the prompts accordingly. If the prompt file has unmatched prompt
* names, it will dump those into an array and alert the users at the end.
*/
paulScripts.getFile = function(base)
{
var base = opensave.Base64_decode(base.data64);
if(!base||base.length===0) {alert('File is empty');return false};
var params=base.split('\r\n');
var notFound = new Array();
//is this a prompts file? If not, STOP EVERYTHING.
if(params[0] != 'Cognos Prompts') {alert('File is not formatted correctly.');return false;};
for (i=1;i<params.length;i++)
{
if(params[i].length===0) continue;
//any params with values will have '||' separating the param name from the value
//on second thought, if the parameter exists on the page, but has no value selected, it should simply clear the parameter.
//if(params[i].indexOf('||')<0) continue;
var sepPos = params[i].indexOf('||');
//if the sep isn't found, then the promptname is the entire string
var promptName = sepPos<0?params[i]:params[i].substring(0,sepPos);
var promptObject = paulScripts.getControl(promptName);
//sanity check - does the prompt exit? If not, push it into the notFound array
if(!promptObject) {notFound.push(promptName);continue}
//clear the prompt before applying the new values
promptObject.clearValues();
//now set the value, if there is a value to set
if(sepPos>0) promptObject.setValues(eval(unescape(params[i].substring(sepPos+2))));
promptObject.checkData();
}
//Are there any unmatched prompt names? Oh no! Quick, tell the user!
if(notFound.length>0) alert('Could not find the following prompts: ' + notFound.join(', '));
}
</script> [sales_and_marketing].[Products].[Products].[Product][sales_and_marketing].[Products].[Products].[Products]export prompts with flash