blob: ceea6aaaade8d56c7556efb432a65e13934000c1 [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 ) {
85 bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ),
86 td(null, null, [text(dataEntry.properties[p])])]));
87 }
88 propE = tableE;
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000089 }
90
Carsten Ziegeler0e1e3cb2008-10-27 16:30:38 +000091 parent.appendChild( td( null, null, [propE] ) );
Carsten Ziegeler616cd8102008-10-23 16:44:07 +000092}
93
Carsten Ziegeler5639f2a2008-11-12 05:20:15 +000094/* displays a date in the user's local timezone */
95function printDate(time) {
96 var date = time ? new Date(time) : new Date();
97 return date.toLocaleString();
98}
99
Carsten Ziegelerf990c952008-10-27 11:36:46 +0000100function loadData() {
Carsten Ziegelerd2de88c2008-10-26 17:47:51 +0000101 $.get(pluginRoot + "/data.json", null, function(data) {
102 renderData(data);
103 }, "json");
104}
Carsten Ziegeler616cd8102008-10-23 16:44:07 +0000105
Carsten Ziegelerf990c952008-10-27 11:36:46 +0000106function renderEvents() {
Carsten Ziegeler5639f2a2008-11-12 05:20:15 +0000107 renderView( ["Received", "Topic", "Properties"],
108 ["<button id='reloadButton' type='button' name='reload'>Reload</button>",
109 "<button id='clearButton' type='button' name='clear'>Clear List</button>"]);
Carsten Ziegelerf990c952008-10-27 11:36:46 +0000110
Carsten Ziegelerd2de88c2008-10-26 17:47:51 +0000111 loadData();
112
113 $("#events").tablesorter();
114 $("#reloadButton").click(loadData);
115 $("#clearButton").click(function () {
116 $("#events > tbody > tr").remove();
117 $.post(pluginRoot, { "action":"clear" }, function(data) {
118 renderData(data);
119 }, "json");
120 });
Carsten Ziegeler616cd8102008-10-23 16:44:07 +0000121}