123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- define(function () {
- "use strict";
- function PageModule() {
- };
- /*
- *
- * This function coordinates the basic operations of this program as so:
- * 1. Loop through the prompts on the page
- * 2. For each prompt look to see if there is a cookie with the naming convention cog<prompt name> containing prompt values
- * 3. Apply the saved values to each prompt
- *
- * Note:
- * The prompt names must not contain spaces or special characters
- * The prompt names must match the prompt names in subsequent reports
- * Cookie values are JSON encoded and ready for use
- */
- function buttonActionFetchPromptSelections(oPage) {
- // Get the current prompt value
- // Create the report object
- // Create an array of prompt controls
- var aPromptControls = oPage.getAllPromptControls();
- // Determine
- var loadedValues = false;
- // Loop through the prompt controls on this page
- for (var i = 0; i < aPromptControls.length; i++) {
- // For each prompt control ...
- var currentPrompt = aPromptControls[i];
- // Create the cookie name
- var cookieName = "cog" + currentPrompt.name;
- // Fetch the cookie values (if they exist) as a JavaScript object
- var JSONEncodedPromptSelections = fetchCookie(cookieName);
- if (JSONEncodedPromptSelections) {
- if (JSONEncodedPromptSelections.length > 0) {
- // Apply cookie values to prompt
- currentPrompt.setValues(JSONEncodedPromptSelections);
- loadedValues = true;
- };
- };
- }; // end for
- if (loadedValues) {
- alert("Your personal default prompt selections have been loaded. You may now edit them as required and press the Save Prompt Selections button.");
- }
- // Return false, also in an effort to stop the onClick event from propagating to other controls
- return false;
- };
- /*
- *
- * This function parses the browser cookie string looking for the cookie
- * and passing it to the calling function
- * @cookieName is the name of the cookie we wish to find
- *
- */
- function fetchCookie(passedCookieName) {
- // Create an array of strings from the document cookie object using the split method to separate the cookies
- var aCookies = document.cookie.split(";");
- //create a variable to hold the cookie value
- var cookie = "";
- // Loop through the cookie array to find cognosPrompts
- for (var i = 0; i < aCookies.length; i++) {
- var currentCookie = aCookies[i];
- // The = sign separates the cookie name from the cookie value
- var signLocation = currentCookie.indexOf("=");
- var currentCookieName = currentCookie.substr(0, signLocation);
- var regexPattern = passedCookieName.valueOf();
- if (currentCookieName.match(regexPattern)) {
- cookie = currentCookie.substr(signLocation + 1, currentCookie.length);
- }
- }
- // Convert the JavaScript object to useable form
- cookie = eval(cookie);
- return cookie;
- };
- PageModule.prototype.load = function (oPage) {
-
- buttonActionFetchPromptSelections(oPage);
-
- };
- return PageModule;
- });
|