Author: nbelaevski
Date: 2009-08-13 12:45:29 -0400 (Thu, 13 Aug 2009)
New Revision: 15171
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js
Log:
https://jira.jboss.org/jira/browse/RF-7648
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js
===================================================================
---
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js 2009-08-13
15:21:55 UTC (rev 15170)
+++
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js/4_0_0.js 2009-08-13
16:45:29 UTC (rev 15171)
@@ -37,45 +37,104 @@
//
//utils.js
- richfaces.console = (function(jQuery) {
+ richfaces.log = (function(jQuery) {
+ var LOG_LEVELS = {'debug': 1, 'info': 2, 'warn': 3,
'error': 4};
+ var LOG_LEVEL_COLORS = {'debug': 'darkblue', 'info':
'blue', 'warn': 'gold', 'error': 'red'};
+ var DEFAULT_LOG_LEVEL = LOG_LEVELS['info'];
+ var currentLogLevel = DEFAULT_LOG_LEVEL;
+
+ var consoleInitialized = false;
+
+ var setLevel = function(level) {
+ currentLogLevel = LOG_LEVELS[level] || DEFAULT_LOG_LEVEL;
+ if (consoleInitialized) {
+ getConsole().find("select.rich-log-element").val(currentLogLevel);
+ }
+ clear();
+ };
+
+ var setLevelFromSelect = function(iLevel) {
+ currentLogLevel = iLevel || DEFAULT_LOG_LEVEL;
+ };
+
+ var clear = function() {
+ if (window.console && useBrowserConsole) {
+ window.console.clear();
+ } else {
+ var console = getConsole();
+ console.children().not(".rich-log-element").remove();
+ }
+ };
+
var getConsole = function() {
- var console = jQuery('#richfaces\\.console');
+ var console = jQuery('#richfaces\\.log');
if (console.length == 0) {
- console = jQuery("<div
id='richfaces.console'><button>Clear</button></div>").appendTo("body");
+ console = jQuery("<div
id='richfaces.log'></div>").appendTo("body");
}
- console.find("button:first").click(function()
{jQuery(this).nextAll().remove();});
+
+ if (!consoleInitialized) {
+ consoleInitialized = true;
+
+ var clearBtn = console.find("button.rich-log-element");
+ if (clearBtn.length == 0) {
+ clearBtn = jQuery("<button
class='rich-log-element'>Clear</button>").appendTo(console);
+ }
+ clearBtn.click(clear);
+
+ var levelSelect = console.find("select.rich-log-element");
+ if (levelSelect.length == 0) {
+ levelSelect = jQuery("<select class='rich-log-element'
/>").appendTo(console);
+ }
+
+ if (levelSelect.children().length == 0) {
+ for (var level in LOG_LEVELS) {
+ jQuery("<option value='" + LOG_LEVELS[level]+
"'>" + level + "</option>").appendTo(levelSelect);
+ }
+ }
+
+ levelSelect.val(currentLogLevel);
+ levelSelect.change(function(event) { clear();
setLevelFromSelect(parseInt(jQuery(this).val(), 10)); return false;});
+ }
+
return console;
};
- var LOG_LEVEL_COLORS = {'debug': 'darkblue', 'info':
'blue', 'warn': 'yellow', 'error': 'red'};
-
+ var useBrowserConsole = false;
+
var formatMessage = function(level, message) {
return level + '[' + new Date().toLocaleTimeString() + ']: ' +
message;
};
- var appendLogEntry = function(level, text) {
- jQuery("<div style='color: " + LOG_LEVEL_COLORS[level] +
"'></div>").appendTo(getConsole()).text(text);
+ var appendConsoleEntry = function(level, text, console) {
+ jQuery("<div style='color: " + LOG_LEVEL_COLORS[level] +
"'></div>").appendTo(console).text(text);
};
- var useFirebugConsole = true;
+ var appendBrowserConsoleEntry = function(level, text) {
+ window.console[level]();
+ };
- var loggers = {};
- for (var logLevel in LOG_LEVEL_COLORS) {
- loggers[logLevel] = (function() {
- var _logLevel = logLevel;
-
- if (window.console && useFirebugConsole) {
- return function(message) {
- window.console[_logLevel](formatMessage(_logLevel, message));
- };
- } else {
- return function() {
- appendLogEntry(_logLevel, formatMessage(_logLevel, message))
- };
+ var appendMessage = function(level, message) {
+ if (window.console && useBrowserConsole) {
+ var text = formatMessage(level, message);
+ appendBrowserConsoleEntry(level, text);
+ } else {
+ var console = getConsole();
+ if (LOG_LEVELS[level] >= currentLogLevel) {
+ var text = formatMessage(level, message);
+ appendConsoleEntry(level, text, console);
}
- }());
+ }
+ };
+
+ var methods = {setLevel: setLevel, clear: clear};
+ for (var logLevel in LOG_LEVELS) {
+ var f = function(text) {
+ appendMessage(arguments.callee.logLevel, text);
+ };
+ f.logLevel = logLevel;
+ methods[logLevel] = f;
}
- return loggers;
+ return methods;
}(jQuery));
/**
@@ -121,7 +180,7 @@
value = eval(macro) ;
}
} catch (e) {
- richfaces.console.warn("Exception: " + e.message + "\n[" + macro
+ "]");
+ richfaces.log.warn("Exception: " + e.message + "\n[" + macro +
"]");
}
}