blob: e234a57c89f4e1c1f4fb8849d84d9bdee78cc58f [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");
Carsten Ziegeler93add2f2008-12-22 11:31:23 +000074 var c2 = td(null, null, [text(dataEntry.properties[p])]);
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000075 $(c2).css("border", "0px none");
Carsten Ziegeler93add2f2008-12-22 11:31:23 +000076 bodyE.appendChild(tr(null, null, [ c1, c2 ]));
Carsten Ziegeler0f77a572008-10-27 16:30:38 +000077 }
78 propE = tableE;
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000079 }
80
Carsten Ziegeler0f77a572008-10-27 16:30:38 +000081 parent.appendChild( td( null, null, [propE] ) );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000082}
83
Carsten Ziegelerc75546e2008-11-12 05:20:15 +000084/* displays a date in the user's local timezone */
85function printDate(time) {
86 var date = time ? new Date(time) : new Date();
87 return date.toLocaleString();
88}
89
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000090function loadData() {
Carsten Ziegeler7876ef92008-10-26 17:47:51 +000091 $.get(pluginRoot + "/data.json", null, function(data) {
92 renderData(data);
93 }, "json");
94}
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000095
Carsten Ziegeler94ccb532008-10-27 11:36:46 +000096function renderEvents() {
Carsten Ziegeler1001af12009-03-05 16:38:26 +000097 $(document).ready(function(){
98 renderView( ["Received", "Topic", "Properties"],
99 "<button class='clearButton' type='button' name='clear'>Clear List</button>" +
100 "<button class='reloadButton' type='button' name='reload'>Reload</button>");
101 loadData();
102
103 $("#plugin_table").tablesorter();
104 $(".reloadButton").click(loadData);
105 $(".clearButton").click(function () {
106 $("#plugin_table > tbody > tr").remove();
107 $.post(pluginRoot, { "action":"clear" }, function(data) {
108 renderData(data);
109 }, "json");
110 });
111 });
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000112}