123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- define(function () {
- "use strict";
- var oPage;
- function promptValueSaved() {
- };
- promptValueSaved.prototype.draw = function (oControlHost) {
- oPage = oControlHost.page;
- var elDate = oControlHost.container;
- elDate.innerHTML =
- '<style>' +
- '.myButtonDate { height:32px; width:180px; cursor:pointer; margin-left:5px; color:#4178BE; font-size:14px; padding:6px 12px 6px 12px; background-color:white; border:1px solid #4178BE; }' +
- '.myButtonDate:hover { background-color:#4178BE; color:white; border:1px solid #4178BE; }' +
- '</style>' +
- '<button class="myButtonDate btnSavePromptValues" type="button">Save Prompt Values</button>' +
- '<button class="myButtonDate btnFetchPromptSelections" type="button">Fetch Prompt Selections</button>';
- elDate.querySelector(".btnSavePromptValues").onclick = buttonActionSavePromptSelections;
- elDate.querySelector(".btnFetchPromptSelections").onclick = buttonActionFetchPromptSelections;
- };
- /*
- *
- * 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() {
- // 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;
- };
- // Set
- function buttonActionSavePromptSelections() {
- // Get the current prompt value
- // Create an array of prompt controls
- var aPromptControls = oPage.getAllPromptControls();
- // Loop through the prompt controls on this page
- for (var i = 0; i < aPromptControls.length; i++) {
- // For each prompt control, call a function to JSON encode the user selections (prompt values)
- var currentPrompt = aPromptControls[i];
- // Create the cookie name
- var cookieName = "cog" + currentPrompt.name;
- // Now save the JSON into a cookie
- storeCookie(cookieName, JSON.stringify(currentPrompt.getValues()));
- };
- alert("Your personal default prompt selections have been saved. You may now close this report.");
- // Return false, also in an effort to stop the onClick event from propagating to other controls
- return false;
- };
- /*
- *
- * This function creates a cookie
- * @cookieName is the name of the cookie to be created
- * @cookieValue is the value to be used to create the cookie
- * The date is always set to expire 1 January 2100 to ensure the cookie is effectively permanent
- *
- */
- function storeCookie(cookieName, cookieValue) {
- // Set the cookie expiry date to 1 January 2100 to ensure it does not expire
- var expDate = new Date();
- expDate.setFullYear(2100, 0, 1);
- document.cookie = cookieName + "=" + cookieValue + "; expires=" + expDate.toUTCString();
- };
- return promptValueSaved;
- }
- );
|