summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/MochiKit/LoggingPane.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/MochiKit/LoggingPane.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/MochiKit/LoggingPane.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/frontend/gamma/js/MochiKit/LoggingPane.js b/frontend/gamma/js/MochiKit/LoggingPane.js
index c960c21..b7ea120 100644
--- a/frontend/gamma/js/MochiKit/LoggingPane.js
+++ b/frontend/gamma/js/MochiKit/LoggingPane.js
@@ -1,75 +1,78 @@
1/*** 1/***
2 2
3MochiKit.LoggingPane 1.5 3MochiKit.LoggingPane 1.5
4 4
5See <http://mochikit.com/> for documentation, downloads, license, etc. 5See <http://mochikit.com/> for documentation, downloads, license, etc.
6 6
7(c) 2005 Bob Ippolito. All rights Reserved. 7(c) 2005 Bob Ippolito. All rights Reserved.
8 8
9***/ 9***/
10 10
11MochiKit.Base._module('LoggingPane', '1.5', ['Base', 'Logging']); 11MochiKit.Base.module(MochiKit, 'LoggingPane', '1.5', ['Base', 'Logging']);
12 12
13/** @id MochiKit.LoggingPane.createLoggingPane */ 13/** @id MochiKit.LoggingPane.createLoggingPane */
14MochiKit.LoggingPane.createLoggingPane = function (inline/* = false */) { 14MochiKit.LoggingPane.createLoggingPane = function (inline/* = false */) {
15 var m = MochiKit.LoggingPane; 15 var m = MochiKit.LoggingPane;
16 inline = !(!inline); 16 inline = !(!inline);
17 if (m._loggingPane && m._loggingPane.inline != inline) { 17 if (m._loggingPane && m._loggingPane.inline != inline) {
18 m._loggingPane.closePane(); 18 m._loggingPane.closePane();
19 m._loggingPane = null; 19 m._loggingPane = null;
20 } 20 }
21 if (!m._loggingPane || m._loggingPane.closed) { 21 if (!m._loggingPane || m._loggingPane.closed) {
22 m._loggingPane = new m.LoggingPane(inline, MochiKit.Logging.logger); 22 m._loggingPane = new m.LoggingPane(inline, MochiKit.Logging.logger);
23 } 23 }
24 return m._loggingPane; 24 return m._loggingPane;
25}; 25};
26 26
27/** @id MochiKit.LoggingPane.LoggingPane */ 27/**
28 * @id MochiKit.LoggingPane.LoggingPane
29 * @constructor
30 */
28MochiKit.LoggingPane.LoggingPane = function (inline/* = false */, logger/* = MochiKit.Logging.logger */) { 31MochiKit.LoggingPane.LoggingPane = function (inline/* = false */, logger/* = MochiKit.Logging.logger */) {
29 32
30 /* Use a div if inline, pop up a window if not */ 33 /* Use a div if inline, pop up a window if not */
31 /* Create the elements */ 34 /* Create the elements */
32 if (typeof(logger) == "undefined" || logger === null) { 35 if (typeof(logger) == "undefined" || logger === null) {
33 logger = MochiKit.Logging.logger; 36 logger = MochiKit.Logging.logger;
34 } 37 }
35 this.logger = logger; 38 this.logger = logger;
36 var update = MochiKit.Base.update; 39 var update = MochiKit.Base.update;
37 var updatetree = MochiKit.Base.updatetree; 40 var updatetree = MochiKit.Base.updatetree;
38 var bind = MochiKit.Base.bind; 41 var bind = MochiKit.Base.bind;
39 var clone = MochiKit.Base.clone; 42 var clone = MochiKit.Base.clone;
40 var win = window; 43 var win = window;
41 var uid = "_MochiKit_LoggingPane"; 44 var uid = "_MochiKit_LoggingPane";
42 if (typeof(MochiKit.DOM) != "undefined") { 45 if (typeof(MochiKit.DOM) != "undefined") {
43 win = MochiKit.DOM.currentWindow(); 46 win = MochiKit.DOM.currentWindow();
44 } 47 }
45 if (!inline) { 48 if (!inline) {
46 // name the popup with the base URL for uniqueness 49 // name the popup with the base URL for uniqueness
47 var url = win.location.href.split("?")[0].replace(/[#:\/.><&%-]/g, "_"); 50 var url = win.location.href.split("?")[0].replace(/[#:\/.><&%-]/g, "_");
48 var name = uid + "_" + url; 51 var name = uid + "_" + url;
49 var nwin = win.open("", name, "dependent,resizable,height=200"); 52 var nwin = win.open("", name, "dependent,resizable,height=200");
50 if (!nwin) { 53 if (!nwin) {
51 alert("Not able to open debugging window due to pop-up blocking."); 54 alert("Not able to open debugging window due to pop-up blocking.");
52 return undefined; 55 return undefined;
53 } 56 }
54 nwin.document.write( 57 nwin.document.write(
55 '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ' 58 '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" '
56 + '"http://www.w3.org/TR/html4/loose.dtd">' 59 + '"http://www.w3.org/TR/html4/loose.dtd">'
57 + '<html><head><title>[MochiKit.LoggingPane]</title></head>' 60 + '<html><head><title>[MochiKit.LoggingPane]</title></head>'
58 + '<body></body></html>' 61 + '<body></body></html>'
59 ); 62 );
60 nwin.document.close(); 63 nwin.document.close();
61 nwin.document.title += ' ' + win.document.title; 64 nwin.document.title += ' ' + win.document.title;
62 win = nwin; 65 win = nwin;
63 } 66 }
64 var doc = win.document; 67 var doc = win.document;
65 this.doc = doc; 68 this.doc = doc;
66 69
67 // Connect to the debug pane if it already exists (i.e. in a window orphaned by the page being refreshed) 70 // Connect to the debug pane if it already exists (i.e. in a window orphaned by the page being refreshed)
68 var debugPane = doc.getElementById(uid); 71 var debugPane = doc.getElementById(uid);
69 var existing_pane = !!debugPane; 72 var existing_pane = !!debugPane;
70 if (debugPane && typeof(debugPane.loggingPane) != "undefined") { 73 if (debugPane && typeof(debugPane.loggingPane) != "undefined") {
71 debugPane.loggingPane.logger = this.logger; 74 debugPane.loggingPane.logger = this.logger;
72 debugPane.loggingPane.buildAndApplyFilter(); 75 debugPane.loggingPane.buildAndApplyFilter();
73 return debugPane.loggingPane; 76 return debugPane.loggingPane;
74 } 77 }
75 78
@@ -101,175 +104,175 @@ MochiKit.LoggingPane.LoggingPane = function (inline/* = false */, logger/* = Moc
101 104
102 /** @id MochiKit.LoggingPane.messageLevel */ 105 /** @id MochiKit.LoggingPane.messageLevel */
103 var messageLevel = function (msg) { 106 var messageLevel = function (msg) {
104 var level = msg.level; 107 var level = msg.level;
105 if (typeof(level) == "number") { 108 if (typeof(level) == "number") {
106 level = MochiKit.Logging.LogLevel[level]; 109 level = MochiKit.Logging.LogLevel[level];
107 } 110 }
108 return level; 111 return level;
109 }; 112 };
110 113
111 /** @id MochiKit.LoggingPane.messageText */ 114 /** @id MochiKit.LoggingPane.messageText */
112 var messageText = function (msg) { 115 var messageText = function (msg) {
113 return msg.info.join(" "); 116 return msg.info.join(" ");
114 }; 117 };
115 118
116 /** @id MochiKit.LoggingPane.addMessageText */ 119 /** @id MochiKit.LoggingPane.addMessageText */
117 var addMessageText = bind(function (msg) { 120 var addMessageText = bind(function (msg) {
118 var level = messageLevel(msg); 121 var level = messageLevel(msg);
119 var text = messageText(msg); 122 var text = messageText(msg);
120 var c = this.colorTable[level]; 123 var c = this.colorTable[level];
121 var p = doc.createElement("span"); 124 var p = doc.createElement("span");
122 p.className = "MochiKit-LogMessage MochiKit-LogLevel-" + level; 125 p.className = "MochiKit-LogMessage MochiKit-LogLevel-" + level;
123 p.style.cssText = "margin: 0px; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; white-space: pre-line; word-wrap: break-word; wrap-option: emergency; color: " + c; 126 p.style.cssText = "margin: 0px; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; white-space: pre-line; word-wrap: break-word; wrap-option: emergency; color: " + c;
124 p.appendChild(doc.createTextNode(level + ": " + text)); 127 p.appendChild(doc.createTextNode(level + ": " + text));
125 logPane.appendChild(p); 128 logPane.appendChild(p);
126 logPane.appendChild(doc.createElement("br")); 129 logPane.appendChild(doc.createElement("br"));
127 if (logPaneArea.offsetHeight > logPaneArea.scrollHeight) { 130 if (logPaneArea.offsetHeight > logPaneArea.scrollHeight) {
128 logPaneArea.scrollTop = 0; 131 logPaneArea.scrollTop = 0;
129 } else { 132 } else {
130 logPaneArea.scrollTop = logPaneArea.scrollHeight; 133 logPaneArea.scrollTop = logPaneArea.scrollHeight;
131 } 134 }
132 }, this); 135 }, this);
133 136
134 /** @id MochiKit.LoggingPane.addMessage */ 137 /** @id MochiKit.LoggingPane.addMessage */
135 var addMessage = function (msg) { 138 var addMessage = function (msg) {
136 messages[messages.length] = msg; 139 messages[messages.length] = msg;
137 addMessageText(msg); 140 addMessageText(msg);
138 }; 141 };
139 142
140 /** @id MochiKit.LoggingPane.buildMessageFilter */ 143 /** @id MochiKit.LoggingPane.buildMessageFilter */
141 var buildMessageFilter = function () { 144 var buildMessageFilter = function () {
142 var levelre, infore; 145 var levelre, infore;
143 try { 146 try {
144 /* Catch any exceptions that might arise due to invalid regexes */ 147 /* Catch any exceptions that might arise due to invalid regexes */
145 levelre = new RegExp(levelFilterField.value); 148 levelre = new RegExp(levelFilterField.value);
146 infore = new RegExp(infoFilterField.value); 149 infore = new RegExp(infoFilterField.value);
147 } catch(e) { 150 } catch(e) {
148 /* If there was an error with the regexes, do no filtering */ 151 /* If there was an error with the regexes, do no filtering */
149 logDebug("Error in filter regex: " + e.message); 152 MochiKit.Logging.logDebug("Error in filter regex: " + e.message);
150 return null; 153 return null;
151 } 154 }
152 155
153 return function (msg) { 156 return function (msg) {
154 return ( 157 return (
155 levelre.test(messageLevel(msg)) && 158 levelre.test(messageLevel(msg)) &&
156 infore.test(messageText(msg)) 159 infore.test(messageText(msg))
157 ); 160 );
158 }; 161 };
159 }; 162 };
160 163
161 /** @id MochiKit.LoggingPane.clearMessagePane */ 164 /** @id MochiKit.LoggingPane.clearMessagePane */
162 var clearMessagePane = function () { 165 var clearMessagePane = function () {
163 while (logPane.firstChild) { 166 while (logPane.firstChild) {
164 logPane.removeChild(logPane.firstChild); 167 logPane.removeChild(logPane.firstChild);
165 } 168 }
166 }; 169 };
167 170
168 /** @id MochiKit.LoggingPane.clearMessages */ 171 /** @id MochiKit.LoggingPane.clearMessages */
169 var clearMessages = function () { 172 var clearMessages = function () {
170 messages = []; 173 messages = [];
171 clearMessagePane(); 174 clearMessagePane();
172 }; 175 };
173 176
174 /** @id MochiKit.LoggingPane.closePane */ 177 /** @id MochiKit.LoggingPane.closePane */
175 var closePane = bind(function () { 178 var closePane = bind(function () {
176 if (this.closed) { 179 if (this.closed) {
177 return; 180 return;
178 } 181 }
179 this.closed = true; 182 this.closed = true;
180 if (MochiKit.LoggingPane._loggingPane == this) { 183 if (MochiKit.LoggingPane._loggingPane == this) {
181 MochiKit.LoggingPane._loggingPane = null; 184 MochiKit.LoggingPane._loggingPane = null;
182 } 185 }
183 this.logger.removeListener(listenerId); 186 this.logger.removeListener(listenerId);
184 try { 187 try {
185 try { 188 try {
186 debugPane.loggingPane = null; 189 debugPane.loggingPane = null;
187 } catch(e) { logFatal("Bookmarklet was closed incorrectly."); } 190 } catch(e) { MochiKit.Logging.logFatal("Bookmarklet was closed incorrectly."); }
188 if (inline) { 191 if (inline) {
189 debugPane.parentNode.removeChild(debugPane); 192 debugPane.parentNode.removeChild(debugPane);
190 } else { 193 } else {
191 this.win.close(); 194 this.win.close();
192 } 195 }
193 } catch(e) {} 196 } catch(e) {}
194 }, this); 197 }, this);
195 198
196 /** @id MochiKit.LoggingPane.filterMessages */ 199 /** @id MochiKit.LoggingPane.filterMessages */
197 var filterMessages = function () { 200 var filterMessages = function () {
198 clearMessagePane(); 201 clearMessagePane();
199 202
200 for (var i = 0; i < messages.length; i++) { 203 for (var i = 0; i < messages.length; i++) {
201 var msg = messages[i]; 204 var msg = messages[i];
202 if (messageFilter === null || messageFilter(msg)) { 205 if (messageFilter === null || messageFilter(msg)) {
203 addMessageText(msg); 206 addMessageText(msg);
204 } 207 }
205 } 208 }
206 }; 209 };
207 210
208 this.buildAndApplyFilter = function () { 211 this.buildAndApplyFilter = function () {
209 messageFilter = buildMessageFilter(); 212 messageFilter = buildMessageFilter();
210 213
211 filterMessages(); 214 filterMessages();
212 215
213 this.logger.removeListener(listenerId); 216 this.logger.removeListener(listenerId);
214 this.logger.addListener(listenerId, messageFilter, addMessage); 217 this.logger.addListener(listenerId, messageFilter, addMessage);
215 }; 218 };
216 219
217 220
218 /** @id MochiKit.LoggingPane.loadMessages */ 221 /** @id MochiKit.LoggingPane.loadMessages */
219 var loadMessages = bind(function () { 222 var loadMessages = bind(function () {
220 messages = this.logger.getMessages(); 223 messages = this.logger.getMessages();
221 filterMessages(); 224 filterMessages();
222 }, this); 225 }, this);
223 226
224 /** @id MochiKit.LoggingPane.filterOnEnter */ 227 /** @id MochiKit.LoggingPane.filterOnEnter */
225 var filterOnEnter = bind(function (event) { 228 var filterOnEnter = bind(function (event) {
226 event = event || window.event; 229 event = event || window.event;
227 key = event.which || event.keyCode; 230 var key = event.which || event.keyCode;
228 if (key == 13) { 231 if (key == 13) {
229 this.buildAndApplyFilter(); 232 this.buildAndApplyFilter();
230 } 233 }
231 }, this); 234 }, this);
232 235
233 /* Create the debug pane */ 236 /* Create the debug pane */
234 var style = "display: block; z-index: 1000; left: 0px; bottom: 0px; position: fixed; width: 100%; background-color: white; font: " + this.logFont; 237 var style = "display: block; z-index: 1000; left: 0px; bottom: 0px; position: fixed; width: 100%; background-color: white; font: " + this.logFont;
235 if (inline) { 238 if (inline) {
236 style += "; height: 10em; border-top: 2px solid black"; 239 style += "; height: 10em; border-top: 2px solid black";
237 } else { 240 } else {
238 style += "; height: 100%;"; 241 style += "; height: 100%;";
239 } 242 }
240 debugPane.style.cssText = style; 243 debugPane.style.cssText = style;
241 244
242 if (!existing_pane) { 245 if (!existing_pane) {
243 doc.body.appendChild(debugPane); 246 doc.body.appendChild(debugPane);
244 } 247 }
245 248
246 /* Create the filter fields */ 249 /* Create the filter fields */
247 style = {"cssText": "width: 33%; display: inline; font: " + this.logFont}; 250 style = {"cssText": "width: 33%; display: inline; font: " + this.logFont};
248 251
249 updatetree(levelFilterField, { 252 updatetree(levelFilterField, {
250 "value": "FATAL|ERROR|WARNING|INFO|DEBUG", 253 "value": "FATAL|ERROR|WARNING|INFO|DEBUG",
251 "onkeypress": filterOnEnter, 254 "onkeypress": filterOnEnter,
252 "style": style 255 "style": style
253 }); 256 });
254 debugPane.appendChild(levelFilterField); 257 debugPane.appendChild(levelFilterField);
255 258
256 updatetree(infoFilterField, { 259 updatetree(infoFilterField, {
257 "value": ".*", 260 "value": ".*",
258 "onkeypress": filterOnEnter, 261 "onkeypress": filterOnEnter,
259 "style": style 262 "style": style
260 }); 263 });
261 debugPane.appendChild(infoFilterField); 264 debugPane.appendChild(infoFilterField);
262 265
263 /* Create the buttons */ 266 /* Create the buttons */
264 style = "width: 8%; display:inline; font: " + this.logFont; 267 style = "width: 8%; display:inline; font: " + this.logFont;
265 268
266 filterButton.appendChild(doc.createTextNode("Filter")); 269 filterButton.appendChild(doc.createTextNode("Filter"));
267 filterButton.onclick = bind("buildAndApplyFilter", this); 270 filterButton.onclick = bind("buildAndApplyFilter", this);
268 filterButton.style.cssText = style; 271 filterButton.style.cssText = style;
269 debugPane.appendChild(filterButton); 272 debugPane.appendChild(filterButton);
270 273
271 loadButton.appendChild(doc.createTextNode("Load")); 274 loadButton.appendChild(doc.createTextNode("Load"));
272 loadButton.onclick = loadMessages; 275 loadButton.onclick = loadMessages;
273 loadButton.style.cssText = style; 276 loadButton.style.cssText = style;
274 debugPane.appendChild(loadButton); 277 debugPane.appendChild(loadButton);
275 278