123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- com.cognos.admin.ObjectFactory("com.cognos.admin.util.ClientState");
- 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;
- }
- },
-
-
- formatedString : function (value){
- return value.toString().split(",");
- },
-
-
- 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();
- }
- },
-
-
- 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];
- },
-
- 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();
- }
- },
-
- 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();
- }
- },
-
- 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){
-
- 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;
- }
- };
|