blob: b888d8833a2408eba1f7bc2f5c4964ed7781146f [file] [log] [blame]
Carsten Ziegeler616cd8102008-10-23 16:44:07 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
Carsten Ziegelerf990c952008-10-27 11:36:46 +000017function renderStatusLine() {
Carsten Ziegeler5639f2a2008-11-12 05:20:15 +000018 document.write( "<div class='fullwidth'>");
Carsten Ziegelerf990c952008-10-27 11:36:46 +000019 document.write( "<div class='statusline'></div>" );
20 document.write( "</div>" );
21}
22
Carsten Ziegeler5639f2a2008-11-12 05:20:15 +000023function renderView( /* Array of String */ columns, /* Array of String */ buttons ) {
24 renderStatusLine();
25 renderButtons(buttons);
Carsten Ziegelerd2de88c2008-10-26 17:47:51 +000026 document.write( "<div class='table'>");
27 document.write( "<table id='events' class='tablelayout'>" );
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000028
Carsten Ziegelerd2de88c2008-10-26 17:47:51 +000029 document.write( "<thead><tr>" );
Carsten Ziegelerf990c952008-10-27 11:36:46 +000030 for ( var name in columns ) {
31 document.write( "<th>" + columns[name] + "</th>" );
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000032 }
Carsten Ziegelerf990c952008-10-27 11:36:46 +000033 document.write( "</tr></thead><tbody>" );
Carsten Ziegelerd2de88c2008-10-26 17:47:51 +000034 document.write( "</tbody></table>" );
35 document.write( "</div>");
Carsten Ziegeler5639f2a2008-11-12 05:20:15 +000036 renderButtons(buttons);
37 renderStatusLine();
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000038}
39
Carsten Ziegeler5639f2a2008-11-12 05:20:15 +000040function renderButtons( buttons ) {
Carsten Ziegelerf990c952008-10-27 11:36:46 +000041 document.write( "<div class='fullwidth'>");
42 document.write( "<div class='buttons'>" );
Carsten Ziegeler5639f2a2008-11-12 05:20:15 +000043 for( var b in buttons ) {
44 document.write( "<div class='button'>");
45 document.write(buttons[b]);
46 document.write( "</div>");
47 }
Carsten Ziegelerf990c952008-10-27 11:36:46 +000048 document.write( "</div>" );
49 document.write( "</div>" );
50}
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000051
Carsten Ziegelerf990c952008-10-27 11:36:46 +000052function renderData( eventData ) {
53 $(".statusline").empty().append(eventData.status);
54 $("#events > tbody > tr").remove();
55 for ( var idx in eventData.data ) {
56 entry( eventData.data[idx] );
57 }
Carsten Ziegelerb8b8f312008-12-16 21:39:53 +000058 $("#events").trigger("update");
Carsten Ziegelerf990c952008-10-27 11:36:46 +000059}
60
61function entry( /* Object */ dataEntry ) {
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000062 var trElement = tr( null, { id: "entry" + dataEntry.id } );
Carsten Ziegelerd2de88c2008-10-26 17:47:51 +000063 entryInternal( trElement, dataEntry );
64 $("#events > tbody").append(trElement);
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000065}
66
67
Carsten Ziegelerf990c952008-10-27 11:36:46 +000068function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000069 var id = dataEntry.id;
70 var topic = dataEntry.topic;
71 var properties = dataEntry.properties;
72
Carsten Ziegeler5639f2a2008-11-12 05:20:15 +000073 parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) );
Carsten Ziegelerd2de88c2008-10-26 17:47:51 +000074 parent.appendChild( td( null, null, [ text( topic ) ] ) );
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000075
Carsten Ziegeler0e1e3cb2008-10-27 16:30:38 +000076 var propE;
77 if ( dataEntry.info ) {
78 propE = text(dataEntry.info);
79 } else {
80 var tableE = createElement("table");
81 var bodyE = createElement("tbody");
82 tableE.appendChild(bodyE);
83
84 for( var p in dataEntry.properties ) {
Carsten Ziegeler220e7912008-12-22 11:31:23 +000085 var c1 = td(null, null, [text(p)]);
86 c1.setAttribute("style", "border:0px none;");
87 var c2 = td(null, null, [text(dataEntry.properties[p])]);
88 c2.setAttribute("style", "border:0px none;");
89 bodyE.appendChild(tr(null, null, [ c1, c2 ]));
Carsten Ziegeler0e1e3cb2008-10-27 16:30:38 +000090 }
91 propE = tableE;
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000092 }
93
Carsten Ziegeler0e1e3cb2008-10-27 16:30:38 +000094 parent.appendChild( td( null, null, [propE] ) );
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000095}
96
Carsten Ziegeler5639f2a2008-11-12 05:20:15 +000097/* displays a date in the user's local timezone */
98function printDate(time) {
99 var date = time ? new Date(time) : new Date();
100 return date.toLocaleString();
101}
102
Carsten Ziegelerf990c952008-10-27 11:36:46 +0000103function loadData() {
Carsten Ziegelerd2de88c2008-10-26 17:47:51 +0000104 $.get(pluginRoot + "/data.json", null, function(data) {
105 renderData(data);
106 }, "json");
107}
Carsten Ziegeler616cd8102008-10-23 16:44:07 +0000108
Carsten Ziegelerf990c952008-10-27 11:36:46 +0000109function renderEvents() {
Carsten Ziegeler5639f2a2008-11-12 05:20:15 +0000110 renderView( ["Received", "Topic", "Properties"],
111 ["<button id='reloadButton' type='button' name='reload'>Reload</button>",
112 "<button id='clearButton' type='button' name='clear'>Clear List</button>"]);
Carsten Ziegelerf990c952008-10-27 11:36:46 +0000113
Carsten Ziegelerd2de88c2008-10-26 17:47:51 +0000114 loadData();
115
116 $("#events").tablesorter();
117 $("#reloadButton").click(loadData);
118 $("#clearButton").click(function () {
119 $("#events > tbody > tr").remove();
120 $.post(pluginRoot, { "action":"clear" }, function(data) {
121 renderData(data);
122 }, "json");
123 });
Carsten Ziegeler616cd8102008-10-23 16:44:07 +0000124}