blob: e3b8ef23a0e30922d50edcf4a07286ddfdc26db6 [file] [log] [blame]
Carsten Ziegeler580814b2009-09-24 12:09:34 +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 */
17function renderStatusLine() {
18 $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" );
19}
20
21function renderView( /* Array of String */ columns, /* String */ buttons ) {
22 renderStatusLine();
23 renderButtons(buttons);
24 var txt = "<div class='table'><table id='plugin_table' class='tablelayout'><thead><tr>";
25 for ( var name in columns ) {
26 txt = txt + "<th class='col_" + columns[name] + "'>" + columns[name] + "</th>";
27 }
28 txt = txt + "</tr></thead><tbody></tbody></table></div>";
29 $("#plugin_content").append( txt );
30 renderButtons(buttons);
31 renderStatusLine();
32}
33
34function renderButtons( buttons ) {
35 $("#plugin_content").append( "<form method='post' enctype='multipart/form-data'><div class='fullwidth'><div class='buttons'>" +
36 buttons + "</div></div></form>" );
37}
38
39function renderData( eventData ) {
40 $(".statusline").empty().append(eventData.status);
41 $("#plugin_table > tbody > tr").remove();
42 for ( var idx in eventData.data ) {
43 entry( eventData.data[idx] );
44 }
45 $("#plugin_table").trigger("update");
46}
47
48function entry( /* Object */ dataEntry ) {
49 var trElement = tr( null, { id: "entry" + dataEntry.id } );
50 entryInternal( trElement, dataEntry );
51 $("#plugin_table > tbody").append(trElement);
52}
53
54
55function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
56 var id = dataEntry.id;
57 var topic = dataEntry.topic;
58 var properties = dataEntry.properties;
Carsten Ziegelerb940bc22009-09-24 13:25:25 +000059 var styleClass = dataEntry.category;
60 if ( styleClass.length == 0 ) styleClass = null; else styleClass = "event" + styleClass;
61
62 parent.appendChild( td( styleClass, null, [ text( printDate(dataEntry.received) ) ] ) );
63 parent.appendChild( td( styleClass, null, [ text( topic ) ] ) );
Carsten Ziegeler580814b2009-09-24 12:09:34 +000064
65 var propE;
66 if ( dataEntry.info ) {
67 propE = text(dataEntry.info);
68 } else {
69 var tableE = createElement("table");
70 var bodyE = createElement("tbody");
71 tableE.appendChild(bodyE);
72
73 for( var p in dataEntry.properties ) {
Carsten Ziegelerb940bc22009-09-24 13:25:25 +000074 var c1 = td(styleClass, null, [text(p)]);
Carsten Ziegeler580814b2009-09-24 12:09:34 +000075 $(c1).css("border", "0px none");
76 $(c1).css("padding", "0 4px 0 0");
Carsten Ziegelerb940bc22009-09-24 13:25:25 +000077 var c2 = td(styleClass, null, [text(dataEntry.properties[p])]);
Carsten Ziegeler580814b2009-09-24 12:09:34 +000078 $(c2).css("border", "0px none");
79 $(c2).css("padding", "0 0 0 4px");
80 bodyE.appendChild(tr(null, null, [ c1, c2 ]));
81 }
82 propE = tableE;
83 }
84
Carsten Ziegelerb940bc22009-09-24 13:25:25 +000085 parent.appendChild( td( styleClass, null, [propE] ) );
Carsten Ziegeler580814b2009-09-24 12:09:34 +000086}
87
88/* displays a date in the user's local timezone */
89function printDate(time) {
90 var date = time ? new Date(time) : new Date();
91 return date.toLocaleString();
92}
93
94function loadData() {
95 $.get(pluginRoot + "/data.json", null, function(data) {
96 renderData(data);
97 }, "json");
98}
99
100function renderEvents() {
101 $(document).ready(function(){
102 renderView( ["Received", "Topic", "Properties"],
103 "<button class='clearButton' type='button' name='clear'>Clear List</button>" +
104 "<button class='reloadButton' type='button' name='reload'>Reload</button>");
105 loadData();
106
107 $("#plugin_table").tablesorter();
108 $(".reloadButton").click(loadData);
109 $(".clearButton").click(function () {
110 $("#plugin_table > tbody > tr").remove();
111 $.post(pluginRoot, { "action":"clear" }, function(data) {
112 renderData(data);
113 }, "json");
114 });
115 });
116}