blob: c948b94a6ad6dfc00fa1cd3aa6db42c29daf3316 [file] [log] [blame]
Carsten Ziegelerd524ac92008-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 */
17
18function header( /* int */ columns )
19{
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000020 document.write( "<div class='fullwidth tablelayout'>");
21 renderButtons();
22 document.write( "<div class='table'>");
23 document.write( "<table id='events' class='tablelayout'>" );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000024
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000025 document.write( "<thead><tr>" );
26 document.write( "<th>Received</th>" );
27 document.write( "<th>Topic</th>" );
28 document.write( "<th>Properties</th>" );
29 document.write( "</tr></thead><tbody>" );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000030
31}
32
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000033function renderData( eventData )
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000034{
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000035 $(".statusline").empty().append(eventData.status);
36 data ( eventData.data );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000037}
38
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000039function data( /* Array of Object */ dataArray )
40{
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000041 $("#events > tbody > tr").remove();
42 for ( var idx in dataArray )
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000043 {
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000044 entry( dataArray[idx] );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000045 }
46}
47
48
49function footer( /* int */ columns )
50{
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000051 document.write( "</tbody></table>" );
52 document.write( "</div>");
53 renderButtons();
54 document.write( "</div>");
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000055}
56
57
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000058function entry( /* Object */ dataEntry )
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000059{
60 var trElement = tr( null, { id: "entry" + dataEntry.id } );
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000061 entryInternal( trElement, dataEntry );
62 $("#events > tbody").append(trElement);
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000063}
64
65
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000066function entryInternal( /* Element */ parent, /* Object */ dataEntry )
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000067{
68
69 var id = dataEntry.id;
70 var topic = dataEntry.topic;
71 var properties = dataEntry.properties;
72
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000073 parent.appendChild( td( null, null, [ text( new Date(dataEntry.received) ) ] ) );
74 parent.appendChild( td( null, null, [ text( topic ) ] ) );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000075
76 var tableE = createElement("table");
77 var bodyE = createElement("tbody");
78 tableE.appendChild(bodyE);
79
80 for( var p in dataEntry.properties ) {
Carsten Ziegeler7ba2bfe2008-10-24 05:23:56 +000081 bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ),
82 td(null, null, [text(dataEntry.properties[p])])]));
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000083 }
84
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000085 parent.appendChild( td( null, null, [tableE] ) );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000086}
87
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000088function renderStatusLine() {
89 document.write( "<div class='fullwidth'>");
90 document.write( "<div class='statusline'>" );
91 document.write( "</div>" );
92 document.write( "</div>" );
93}
94
95function renderButtons( )
Carsten Ziegelerfd175782008-10-24 10:12:08 +000096{
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000097 document.write( "<div class='fullwidth'>");
98 document.write( "<div class='buttons'>" );
99 document.write( "<div class='button'><button id='reloadButton' type='button' name='reload'>Reload</button></div>" );
100 document.write( "<div class='button'><button id='clearButton' type='button' name='clear'>Clear List</button></div>" );
101 document.write( "</div>" );
102 document.write( "</div>" );
Carsten Ziegelerfd175782008-10-24 10:12:08 +0000103}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000104
Carsten Ziegeler7876ef92008-10-26 17:47:51 +0000105function loadData()
106{
107 $.get(pluginRoot + "/data.json", null, function(data) {
108 renderData(data);
109 }, "json");
110}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000111
Carsten Ziegeler7876ef92008-10-26 17:47:51 +0000112function renderEvents( )
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000113{
114
Carsten Ziegeler91b8b042008-10-24 09:34:29 +0000115 // date, topic and properties
116 var columns = 3;
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000117
Carsten Ziegeler7876ef92008-10-26 17:47:51 +0000118 renderStatusLine();
119
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000120 header( columns );
121
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000122 footer( columns );
Carsten Ziegeler7876ef92008-10-26 17:47:51 +0000123
124 renderStatusLine();
125
126 loadData();
127
128 $("#events").tablesorter();
129 $("#reloadButton").click(loadData);
130 $("#clearButton").click(function () {
131 $("#events > tbody > tr").remove();
132 $.post(pluginRoot, { "action":"clear" }, function(data) {
133 renderData(data);
134 }, "json");
135 });
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000136}