blob: 2d043af8852170df8cd6d12a7e3388b2879ecb6c [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 renderStatusLine() {
Carsten Ziegeler1001af12009-03-05 16:38:26 +000018 $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" );
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000019}
20
Carsten Ziegeler1001af12009-03-05 16:38:26 +000021function renderView( /* Array of String */ columns, /* String */ buttons ) {
Carsten Ziegelerc75546e2008-11-12 05:20:15 +000022 renderStatusLine();
23 renderButtons(buttons);
Carsten Ziegeler1001af12009-03-05 16:38:26 +000024 var txt = "<div class='table'><table id='plugin_table' class='tablelayout'><thead><tr>";
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000025 for ( var name in columns ) {
Carsten Ziegeler1001af12009-03-05 16:38:26 +000026 txt = txt + "<th class='col_" + columns[name] + "'>" + columns[name] + "</th>";
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000027 }
Carsten Ziegeler1001af12009-03-05 16:38:26 +000028 txt = txt + "</tr></thead><tbody></tbody></table></div>";
29 $("#plugin_content").append( txt );
Carsten Ziegelerc75546e2008-11-12 05:20:15 +000030 renderButtons(buttons);
31 renderStatusLine();
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000032}
33
Carsten Ziegelerc75546e2008-11-12 05:20:15 +000034function renderButtons( buttons ) {
Carsten Ziegeler1001af12009-03-05 16:38:26 +000035 $("#plugin_content").append( "<form method='post' enctype='multipart/form-data'><div class='fullwidth'><div class='buttons'>" +
36 buttons + "</div></div></form>" );
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000037}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000038
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000039function renderData( eventData ) {
40 $(".statusline").empty().append(eventData.status);
Carsten Ziegeler1001af12009-03-05 16:38:26 +000041 $("#plugin_table > tbody > tr").remove();
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000042 for ( var idx in eventData.data ) {
43 entry( eventData.data[idx] );
44 }
Carsten Ziegeler1001af12009-03-05 16:38:26 +000045 $("#plugin_table").trigger("update");
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000046}
47
48function entry( /* Object */ dataEntry ) {
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000049 var trElement = tr( null, { id: "entry" + dataEntry.id } );
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000050 entryInternal( trElement, dataEntry );
Carsten Ziegeler1001af12009-03-05 16:38:26 +000051 $("#plugin_table > tbody").append(trElement);
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000052}
53
54
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000055function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000056 var id = dataEntry.id;
57 var topic = dataEntry.topic;
58 var properties = dataEntry.properties;
59
Carsten Ziegelerc75546e2008-11-12 05:20:15 +000060 parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) );
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000061 parent.appendChild( td( null, null, [ text( topic ) ] ) );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000062
Carsten Ziegeler0f77a572008-10-27 16:30:38 +000063 var propE;
64 if ( dataEntry.info ) {
65 propE = text(dataEntry.info);
66 } else {
67 var tableE = createElement("table");
68 var bodyE = createElement("tbody");
69 tableE.appendChild(bodyE);
70
71 for( var p in dataEntry.properties ) {
Carsten Ziegeler93add2f2008-12-22 11:31:23 +000072 var c1 = td(null, null, [text(p)]);
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000073 $(c1).css("border", "0px none");
Felix Meschbergerb1134c72009-09-23 08:30:49 +000074 $(c1).css("padding", "0 4px 0 0");
Carsten Ziegeler93add2f2008-12-22 11:31:23 +000075 var c2 = td(null, null, [text(dataEntry.properties[p])]);
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000076 $(c2).css("border", "0px none");
Felix Meschbergerb1134c72009-09-23 08:30:49 +000077 $(c2).css("padding", "0 0 0 4px");
Carsten Ziegeler93add2f2008-12-22 11:31:23 +000078 bodyE.appendChild(tr(null, null, [ c1, c2 ]));
Carsten Ziegeler0f77a572008-10-27 16:30:38 +000079 }
80 propE = tableE;
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000081 }
82
Carsten Ziegeler0f77a572008-10-27 16:30:38 +000083 parent.appendChild( td( null, null, [propE] ) );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000084}
85
Carsten Ziegelerc75546e2008-11-12 05:20:15 +000086/* displays a date in the user's local timezone */
87function printDate(time) {
88 var date = time ? new Date(time) : new Date();
89 return date.toLocaleString();
90}
91
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000092function loadData() {
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000093 $.get(pluginRoot + "/data.json", null, function(data) {
94 renderData(data);
95 }, "json");
96}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000097
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000098function renderEvents() {
Carsten Ziegeler1001af12009-03-05 16:38:26 +000099 $(document).ready(function(){
100 renderView( ["Received", "Topic", "Properties"],
101 "<button class='clearButton' type='button' name='clear'>Clear List</button>" +
102 "<button class='reloadButton' type='button' name='reload'>Reload</button>");
103 loadData();
104
105 $("#plugin_table").tablesorter();
106 $(".reloadButton").click(loadData);
107 $(".clearButton").click(function () {
108 $("#plugin_table > tbody > tr").remove();
109 $.post(pluginRoot, { "action":"clear" }, function(data) {
110 renderData(data);
111 }, "json");
112 });
113 });
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000114}