blob: 094131408953d43c04180303da08f7227b68ecea [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 */
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000017function render() {
18 renderStatusLine();
19 renderTable( ["Received", "Topic", "Properties"] );
20 renderStatusLine();
21}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000022
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000023function renderStatusLine() {
24 document.write( "<div class='fullwidth'>");
25 document.write( "<div class='statusline'></div>" );
26 document.write( "</div>" );
27}
28
29function renderTable( /* Array of String */ columns ) {
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000030 document.write( "<div class='fullwidth tablelayout'>");
31 renderButtons();
32 document.write( "<div class='table'>");
33 document.write( "<table id='events' class='tablelayout'>" );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000034
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000035 document.write( "<thead><tr>" );
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000036 for ( var name in columns ) {
37 document.write( "<th>" + columns[name] + "</th>" );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000038 }
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000039 document.write( "</tr></thead><tbody>" );
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000040 document.write( "</tbody></table>" );
41 document.write( "</div>");
42 renderButtons();
43 document.write( "</div>");
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000044}
45
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000046function renderButtons( ) {
47 document.write( "<div class='fullwidth'>");
48 document.write( "<div class='buttons'>" );
49 document.write( "<div class='button'><button id='reloadButton' type='button' name='reload'>Reload</button></div>" );
50 document.write( "<div class='button'><button id='clearButton' type='button' name='clear'>Clear List</button></div>" );
51 document.write( "</div>" );
52 document.write( "</div>" );
53}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000054
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000055function renderData( eventData ) {
56 $(".statusline").empty().append(eventData.status);
57 $("#events > tbody > tr").remove();
58 for ( var idx in eventData.data ) {
59 entry( eventData.data[idx] );
60 }
61}
62
63function entry( /* Object */ dataEntry ) {
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000064 var trElement = tr( null, { id: "entry" + dataEntry.id } );
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000065 entryInternal( trElement, dataEntry );
66 $("#events > tbody").append(trElement);
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000067}
68
69
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000070function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000071 var id = dataEntry.id;
72 var topic = dataEntry.topic;
73 var properties = dataEntry.properties;
74
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000075 parent.appendChild( td( null, null, [ text( new Date(dataEntry.received) ) ] ) );
76 parent.appendChild( td( null, null, [ text( topic ) ] ) );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000077
Carsten Ziegeler0f77a572008-10-27 16:30:38 +000078 var propE;
79 if ( dataEntry.info ) {
80 propE = text(dataEntry.info);
81 } else {
82 var tableE = createElement("table");
83 var bodyE = createElement("tbody");
84 tableE.appendChild(bodyE);
85
86 for( var p in dataEntry.properties ) {
87 bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ),
88 td(null, null, [text(dataEntry.properties[p])])]));
89 }
90 propE = tableE;
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000091 }
92
Carsten Ziegeler0f77a572008-10-27 16:30:38 +000093 parent.appendChild( td( null, null, [propE] ) );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000094}
95
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000096function loadData() {
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000097 $.get(pluginRoot + "/data.json", null, function(data) {
98 renderData(data);
99 }, "json");
100}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000101
Carsten Ziegeler94ccb532008-10-27 11:36:46 +0000102function renderEvents() {
103 render();
104
Carsten Ziegeler7876ef92008-10-26 17:47:51 +0000105 loadData();
106
107 $("#events").tablesorter();
108 $("#reloadButton").click(loadData);
109 $("#clearButton").click(function () {
110 $("#events > tbody > tr").remove();
111 $.post(pluginRoot, { "action":"clear" }, function(data) {
112 renderData(data);
113 }, "json");
114 });
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000115}