// Licensed Materials - Property of IBM // // IBM Cognos Products: cogadmin // // (C) Copyright IBM Corp. 2005, 2010 // // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. // // // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated). //---------------------------------------------------------- com.cognos.admin.ObjectFactory("com.cognos.admin.util.ClientState"); /* * This is a J2HTML client state management class * * */ com.cognos.admin.util.ClientState = function (fragId) { this.fragId = fragId; this.states = {}; this.skipPersistStates = []; this.states[com.cognos.admin.util.ClientState.J2HTML_UI_STATE] = {}; }; com.cognos.admin.util.ClientState.VERSION = "0.1.0"; com.cognos.admin.util.ClientState.J2HTML_UI_STATE = "j2html-ui-state" com.cognos.admin.util.ClientState.SELECTED_ROW = "selectedRow"; com.cognos.admin.util.ClientState.GROUP_ACTION_ROWS = "grpActionRows"; com.cognos.admin.util.ClientState.BREADCRUMBS = "breadcrumbs"; com.cognos.admin.util.ClientState.SORT = "sort"; com.cognos.admin.util.ClientState.SCROLL_TOP = "scrollTop"; com.cognos.admin.util.ClientState.SCROLL_LEFT = "scrollLeft"; com.cognos.admin.util.ClientState.COGADMIN_WINDOW_STATE = "cogadminWindowState"; com.cognos.admin.util.ClientState.prototype = { restoreStates : function () { if (com.cognos.admin.publicParam.states[this.fragId]){ this.states = com.cognos.admin.publicParam.states[this.fragId]; } }, saveStates : function () { var isEmpty = true; for (var o in this.states) { if (typeof this.states[o] !== 'function') { if (this.states[o]){ isEmpty = false; break; } } } if (!isEmpty) { if (!com.cognos.admin.publicParam.states[this.fragId]) com.cognos.admin.publicParam.states[this.fragId] = []; com.cognos.admin.publicParam.states[this.fragId] = this.states; } }, /* * format the "," as a seperator's string to array */ formatedString : function (value){ return value.toString().split(","); }, // add a state param as a array addState : function (key,value,isUIState) { if (key) { var ret = this.formatedString(value); var state = isUIState?this.states[com.cognos.admin.util.ClientState.J2HTML_UI_STATE]:this.states; if (!state[key] || state[key].length == 0){ state[key] = ret; } else if (state[key] instanceof Array) { state[key] = _F_Array.unique(state[key].concat(ret)); } this.saveStates(); } }, // add a state param as a single type setState : function (key,value,isUIState) { if (key) { var state = isUIState?this.states[com.cognos.admin.util.ClientState.J2HTML_UI_STATE]:this.states; state[key] = value; this.saveStates(); } }, getState : function (key,isUIState) { var state = isUIState?this.states[com.cognos.admin.util.ClientState.J2HTML_UI_STATE]:this.states; if (state[key] === undefined) return; return state[key]; }, /** * Remove the input value from the array, or set the value to "" for the string * @param {string} key * @param {Object} value * @param {Boolean} isUIState whether is a j2html_ui_state */ removeState : function (key,value,isUIState) { var state = isUIState?this.states[com.cognos.admin.util.ClientState.J2HTML_UI_STATE]:this.states; if (state[key]){ if (state[key] instanceof Array){ _F_Array.remove(state[key],value); } else { this.clearState(key); } this.saveStates(); } }, /** * Get rid of the key from the state set. * @param {String} key * @param {Boolean} isUIState */ clearState : function (key,isUIState) { var state = isUIState?this.states[com.cognos.admin.util.ClientState.J2HTML_UI_STATE]:this.states; if (state[key]){ if (state[key] instanceof Array){ state[key] = []; } else if (typeof state[key] == "object"){ state[key] = null; } else { state[key] = ""; } this.saveStates(); } }, /** * remove the client state form the round trip list * @param {Object} skipPersistStates could be either a string (option: seperated by ",") or an array */ setSkipPersistStates : function (skipPersistStates){ if (skipPersistStates){ if (typeof skipPersistStates == "string"){ this.skipPersistStates = skipPersistStates.split(","); } else { this.skipPersistStates = skipPersistStates; } } }, getSkipPersistStates : function (){ return this.skipPersistStates; }, clearSkipPersistStates : function () { var skipPersistStates = this.getSkipPersistStates(); for (var i = 0; i < skipPersistStates.length; i++){ this.clearState(skipPersistStates[i],true); } }, getStateURL : function () { var str = ""; this.clearSkipPersistStates(); for (var o in this.states){ //this is to filter out the expended funcitons for Array object. if (!(this.states[o] instanceof Function)){ var param; if (typeof this.states[o] == "object"){ param = com.cognos.admin.util.Tools.JSON.stringify(this.states[o]); } else { param = this.states[o]; } str = com.cognos.admin.util.Tools.generateQueryString(str,o,param,true); } } return str; } };