// Licensed Materials - Property of IBM // // IBM Cognos Products: cpscrn // // (C) Copyright IBM Corp. 2005, 2011 // // 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). // _F_Debug object can // 1) output to a log // 2) display a fragment tree. // 3) dump an object's contents to a new html window - make sure popups are not blocked // For more details see: // Debugging Fragments section on http://sottcps4/wiki/index.php?title=Fragment_Implementation_Debugging /* ** general log object definition */ function _FD_log(useFireBugLite) { this.useFireBugLite = useFireBugLite; // array of queued log entries this.entries = new Array(); } _FD_log.prototype = { // add an entry to the log queue logEntry: function(obj, func, parms) { this.obj = obj; // "this" object for func this.func = func; // function to execute this.parms = parms; // array of arguments }, // call this function to add new entries to the log queue // it is expected that the parameters to the func will be passed in the call to this function appendLogEntry: function(obj, func) // ... { var parms = Array.prototype.slice.call(arguments, 2); var entry = new this.logEntry(obj, func, parms); this.entries.push(entry); }, // process the queue of log entries by calling the specified functions in each log entry processQueuedEntries: function() { var current = null; if (window.console !== undefined) { for (var i=0; i < this.entries.length; i++) { current = this.entries[i]; if (typeof current.func == "string") { try { func = eval(current.func); } catch(e) {} } else { func = current.func; } if (typeof func == "function") { func.apply(current.obj, current.parms); } } } }, // begin a new group group: function (text, addTimeStamp) { if (addTimeStamp) { var date = new Date(); text += " : Time: " + date.toLocaleTimeString() } if (this.useFireBugLite) { if (_F_Config.browser == "unknown") { // firebug lite console has not finished loading // queue the log entry this.appendLogEntry(window, "console.group", text); return; } } if (window.console !== undefined) { console.group(text); } }, // end group groupEnd: function () { if (this.useFireBugLite) { if (_F_Config.browser == "unknown") { // firebug lite console has not finished loading // queue the log entry this.appendLogEntry(window, "console.groupEnd"); return; } } if (window.console !== undefined) { console.groupEnd(); } }, // log text logText: function (text) { if (this.useFireBugLite) { if (_F_Config.browser == "unknown") { // firebug lite console has not finished loading // queue the log entry this.appendLogEntry(window, "console.log", text ); return; } } if (window.console !== undefined) { console.log(text); } }, // log with option to group and option to send multiple object arguments logDetails: function (groupText) // ... { if (_F_Debug.useFireBugLite) { if (_F_Config.browser == "unknown") { // firebug lite console has not finished loading // queue the log entry var newArgs = Array.prototype.slice.call(arguments, 0); newArgs.unshift(this.logDetails); // add "function to call" to front of arguments newArgs.unshift(this); // add "object instance to execute function in" to front of arguments this.appendLogEntry.apply(_F_Debug.log, newArgs); return; } } if (window.console !== undefined) { var objs = Array.prototype.slice.call(arguments, 1); if (groupText != null) { console.group(groupText); } var curObj = null; for ( i = 0 ; i < objs.length; i++) { curObj = objs[i]; if (typeof curObj == "object") { if (curObj.debugInfo !== undefined) { curObj.debugInfo(curObj); } else { console.log(curObj); } } else { console.log(curObj); } } if (groupText != null) { console.groupEnd(); } } } } /* ** fragTree object definition */ function _FD_fragTree(useFireBugLite, IELiteLevel ) { this.useFireBugLite = useFireBugLite; this.IELiteLevel = IELiteLevel; } _FD_fragTree.prototype = { // walk the fragment tree and process each node for display. display: function (nodeId, maxLevel) { var curLevel = 0; if (maxLevel == null) { maxLevel = 9999; } if (nodeId != null && nodeId != "root") { this.processFragment(fragments[nodeId], maxLevel, curLevel); } else { for (var id in fragments) { if (fragments[id].parent == null) { this.processFragment(fragments[id], maxLevel, curLevel); } } } }, processFragment: function(frag, maxLevel, curLevel) { if (frag != null && window.console !== undefined) { console.group(frag.id + "\ttitle: " + _F_Strings.normalize(frag.title)); this.outputFragmentNode(frag); this.processBranch(frag, maxLevel, curLevel); console.groupEnd(); } }, // recursive function to display the fragments in a tree branch processBranch: function(frag, maxLevel, curLevel) { curLevel++; if (frag != null && curLevel < maxLevel) { var children = frag.getChildren(); var i, l = children.length; for (i = 0; i < l; i++) { this.processFragment(children[i], maxLevel, curLevel); } } }, // output the fragment node to the console outputFragmentNode: function(frag) { if (window.console !== undefined) { if (this.useFireBugLite) { if (this.IELiteLevel & _F_Debug.OBJECT_LVL) { console.group("frag"); console.dir(frag); console.groupEnd(); } console.group("div"); if (this.IELiteLevel & _F_Debug.DIV_LVL) { var divObj = $(frag.div); if (divObj !== null) { console.dirxml($(frag.div)); } } else { console.log(frag.div); } console.groupEnd(); } else { // Firebug on Firefox console.log(frag); console.log($(frag.div)); } } } } /* ** Dump object definition */ function _FD_Dump () { _debug_all = []; } _FD_Dump.prototype = { DebugView: function(o) { this._debug_all = []; var w = window.open("about:blank"); if ( w == null) { return ("Cannot open window!"); } w.location.href = "about:blank"; w.document.open(); w.document.writeln(""+ "Dump"+ ""+ "" + ""); w.document.writeln(this._debug_renderObject(o,1)); w.document.writeln(""); w.document.close(); return ("Done"); }, _debug_indent: function(l) { var ret = ""; for (var i=0; inull"; } else if (typeof(o)=="string") { return "\"" + this._debugHtmlEncode(o) + "\""; } else if (typeof(o)=="boolean") { return ""+((o) ? "true" : "false")+""; } else if (typeof(o)=="number") { return ""+o+""; } else if (typeof(o)=="function") { return "function() { /* code omitted */ }"; } else if (typeof(o)=="object") { var ret = this._debug_filterObject(o); if (ret != null) { return ret; } var i = this._debug_wasDisplayed(o); if (i != -1) { return "{ object }"; } var ret; if (typeof(o.length)=="number" ) { ret = "
[ "; i = 0; if (o.length >= 0) { for (i=0; i0) { ret += ",
\n"; } else { ret += "
\n"; } ret += this._debug_indent(l) + this._debug_renderObject(o[i],l+1); } } if (i > 0) { ret += "
\n"; } ret += this._debug_indent(l-1) + "]
"; return ret; } else { ret = "
{ "; var count = 0; try { for (i in o) { if (count++>0) { ret += ",
\n"; } else { ret += "
\n"; } ret += this._debug_indent(l) + i + ": " + this._debug_renderObject(o[i],l+1); } } catch(e) { } if (count > 0) { ret += "
\n"; } ret += this._debug_indent(l-1) + "}
"; return ret; } } else { return "!"+typeof(o); } }, _debug_wasDisplayed: function(o) { var c=this._debug_all.length; for (var i=0; i/g, ">"); } } /** * Initial settings for _F_Debug come from pf.properties file * Main object for debug functionality */ var _F_Debug = { enabled: false, useFireBugLite: (navigator.userAgent.indexOf("Firefox")== -1), // bit masks for IE logging level // developers can change this setting by calling setIELiteLevel NORMAL_LVL : 0x1, // 1 - minimal logging OBJECT_LVL : 0x2, // 2 - output object xml DIV_LVL : 0x4, // 4 - output div html // 15 - for all levels of IE Lite logging IELiteLevel: 1, // developers can change the global settings per object type directly on the firebug console cmd line. // _F_Debug.settings["fragment"]= 0; or 1 or 2 ( OFF, ON, DEPEND ) // _F_Debug.settings["_F_Event"]= 2; SETTING_OFF: 0, SETTING_ON: 1, SETTING_DEPEND: 2, // example: if parent or source debug is on settings: new Object(), log: new _FD_log((navigator.userAgent.indexOf("Firefox")== -1)), fragTree: new _FD_fragTree((navigator.userAgent.indexOf("Firefox")== -1), 1), dump: new _FD_Dump(), initialize: function() { if(this.useFireBugLite) { if (window.console === undefined) { window.alert("FireBugLite is not installed"); } else { _F_Debug.log.processQueuedEntries(); } } else if (window.console === undefined) { window.alert("FireBug is not installed or it is disabled"); } }, /** * CONSOLE CMD: developer can change IE logging level from the firebug command line * see values above. **/ setIELiteLevel: function (level) { _F_Debug.IELiteLevel = level; _F_Debug.fragTree.IELiteLevel = level; return ("Done"); }, /** * CONSOLE CMD: Used to set the debug override for fragment objects and possibly their children. * * Example to debug events that apply only to a particular fragment and the fragment's children: * _F_Debug.settings["fragment"] = 0; turn off global fragment debugging * _F_Debug.settings["_F_Event"]= 2; sets global event setting to DEPEND which will check the source fragment * setFragmentDebug(fragId, 1, true); turn on debugging for only certain fragments. */ setFragmentSetting: function(objectId, setting, bChildren) { var frag = fragments[objectId]; if (frag != null) { frag.debugOverride = setting; if (bChildren) { var children = frag.getChildren(); var i, l = children.length; for (i = 0; i < l; i++) { children[i].debugOverride = setting; } } return "Done"; } else { return "Fragment( " + objectId + ") was not found"; } }, /** * CONSOLE CMD: Used to display the fragments in a tree. Useful to get id to send to setFragmentSetting. * Examples: * showFragmentTree(); returns entire tree * showFragmentTree("root",4); returns the first 4 levels of the tree starting from the root * showFragmentTree("adminconsole_xmlbooklet"); returns the tree starting from the given fragment id. * showFragmentTree("adminconsole_xmlbooklet", 4); returns the first 4 levels starting from the given fragment id. **/ showFragmentTree: function(nodeId, maxLevel) { if (_F_Debug.enabled) { _F_Debug.fragTree.display( nodeId, maxLevel); return("Done"); } return ("Debug not enabled"); }, /** * CONSOLE CMD: Dumps the contents of an object to a new window */ dumpObject: function(object) { return(_F_Debug.dump.DebugView(object)); } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Extend the fragment object definition // set the debugOverride to override the global setting for this object fragment.prototype.debugOverride = -1; // 0 - off, 1 - on, 2 - depends fragment.prototype.debugEnabled = function() { if ( _F_Debug.enabled) { var debug = this.debugOverride != -1? this.debugOverride : _F_Debug.settings["fragment"]; if ( debug == _F_Debug.SETTING_DEPEND) { var frag = this.parent; if (frag) { return frag.debugEnabled(); } } return (debug == _F_Debug.SETTING_ON); } else { return false; } }; // output the fragment information to the console fragment.prototype.debugInfo = function(frag) { if (window.console !== undefined) { if (_F_Debug.useFireBugLite) { if (_F_Debug.IELiteLevel & _F_Debug.OBJECT_LVL) { console.group("frag"); console.dir(frag); console.groupEnd(); } console.group("div"); if (_F_Debug.IELiteLevel & _F_Debug.DIV_LVL) { var divObj = $(frag.div); if (divObj !== null) { console.dirxml($(frag.div)); } } else { console.log(frag.div); } console.groupEnd(); } else { // Firebug on Firefox console.log(frag); console.log($(frag.div)); } } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Extend the _F_Event object definition // set the debugOverride to override the global setting for this object _F_Event.Event.prototype.debugOverride = -1; // 0 - off, 1 - on, 2 - depends _F_Event.Event.prototype.debugEnabled = function() { if ( _F_Debug.enabled) { var debug = this.debugOverride != -1? this.debugOverride : _F_Debug.settings["_F_Event"]; if ( debug == _F_Debug.SETTING_DEPEND) { var frag = this.source; if (frag) { return frag.debugEnabled(); } } return (debug == _F_Debug.SETTING_ON); } else { return false; } }; //output event information to the console _F_Event.Event.prototype.debugInfo = function( evt) { if (window.console !== undefined) { if (this.useFireBugLite) { if (this.IELiteLevel & _F_Debug.OBJECT_LVL) { console.group("evt"); console.dir(evt); console.groupEnd(); } else { console.log(evt.name); } } else // Firebug on Firefox { console.log(evt); } } }