blob: 2d043af8852170df8cd6d12a7e3388b2879ecb6c [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;
59
60 parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) );
61 parent.appendChild( td( null, null, [ text( topic ) ] ) );
62
63 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 ) {
72 var c1 = td(null, null, [text(p)]);
73 $(c1).css("border", "0px none");
74 $(c1).css("padding", "0 4px 0 0");
75 var c2 = td(null, null, [text(dataEntry.properties[p])]);
76 $(c2).css("border", "0px none");
77 $(c2).css("padding", "0 0 0 4px");
78 bodyE.appendChild(tr(null, null, [ c1, c2 ]));
79 }
80 propE = tableE;
81 }
82
83 parent.appendChild( td( null, null, [propE] ) );
84}
85
86/* 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
92function loadData() {
93 $.get(pluginRoot + "/data.json", null, function(data) {
94 renderData(data);
95 }, "json");
96}
97
98function renderEvents() {
99 $(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 });
114}