blob: 82a7093ee250587afdd64faf2f5aca4a606e4d50 [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 */
17
18function header( /* int */ columns )
19{
20 document.write( "<table class='content' cellpadding='0' cellspacing='0' width='100%'>" );
21
22 document.write( "<tr class='content'>" );
23 document.write( "<td colspan='" + columns + "' class='content'>&nbsp;</th>" );
24 document.write( "</tr>" );
25
26 document.write( "<tr class='content'>" );
Carsten Ziegeler91b8b042008-10-24 09:34:29 +000027 document.write( "<th class='content'>Received</th>" );
28 document.write( "<th class='content'>Topic</th>" );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000029 document.write( "<th class='content'>Properties</th>" );
30 document.write( "</tr>" );
31
32}
33
34
35function error( /* int */ columns, /* String */ message )
36{
37 document.write( "<tr class='content'>" );
38 document.write( "<td class='content'>&nbsp;</td>" );
39 document.write( "<td class='content' colspan='" + (columns - 1) + "'>" + message + "</td>" );
40 document.write( "</tr>" );
41}
42
43
44function data( /* Array of Object */ dataArray )
45{
46 // render components
47 if (dataArray.length == 1)
48 {
49 entry( dataArray[0], true );
50 }
51 else {
52 for ( var idx in dataArray )
53 {
54 entry( dataArray[idx] );
55 }
56 }
57}
58
59
60function footer( /* int */ columns )
61{
62 document.write( "<tr class='content'>" );
63 document.write( "<td colspan='" + columns + "' class='content'>&nbsp;</th>" );
64 document.write( "</tr>" );
65
66 document.write( "</table>" );
67}
68
69
70function entry( /* Object */ dataEntry, /* boolean */ singleEntry )
71{
72 var trElement = tr( null, { id: "entry" + dataEntry.id } );
73 entryInternal( trElement, dataEntry, singleEntry );
74 document.write( serialize( trElement ) );
75}
76
77
78function entryInternal( /* Element */ parent, /* Object */ dataEntry, /* boolean */ singleEntry )
79{
80
81 var id = dataEntry.id;
82 var topic = dataEntry.topic;
83 var properties = dataEntry.properties;
84
Carsten Ziegeler91b8b042008-10-24 09:34:29 +000085 parent.appendChild( td( "content", null, [ text( new Date(dataEntry.received) ) ] ) );
86 parent.appendChild( td( "content", { "width": "20%", [ text( topic ) ] ) );
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000087
88 var tableE = createElement("table");
89 var bodyE = createElement("tbody");
90 tableE.appendChild(bodyE);
91
92 for( var p in dataEntry.properties ) {
Carsten Ziegeler7ba2bfe2008-10-24 05:23:56 +000093 bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ),
94 td(null, null, [text(dataEntry.properties[p])])]));
Carsten Ziegelerd524ac92008-10-23 16:44:07 +000095 }
96
97 parent.appendChild( td( "content", null, [tableE] ) );
98}
99
100
101
102function renderEvents( /* Array of Data Objects */ bundleData )
103{
104
Carsten Ziegeler91b8b042008-10-24 09:34:29 +0000105 // date, topic and properties
106 var columns = 3;
Carsten Ziegelerd524ac92008-10-23 16:44:07 +0000107
108 header( columns );
109
110 if (bundleData.error)
111 {
112 error( columns, bundleData.error );
113 }
114 else
115 {
116 data ( bundleData.data );
117 }
118
119 footer( columns );
120}