blob: a743f7d5f8d66721b6c80e7c580015b4cad11b7c [file] [log] [blame]
Carsten Ziegeler616cd8102008-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'>" );
27 document.write( "<th class='content' width='20%'>Topic</th>" );
28 document.write( "<th class='content'>Properties</th>" );
29 document.write( "</tr>" );
30
31}
32
33
34function error( /* int */ columns, /* String */ message )
35{
36 document.write( "<tr class='content'>" );
37 document.write( "<td class='content'>&nbsp;</td>" );
38 document.write( "<td class='content' colspan='" + (columns - 1) + "'>" + message + "</td>" );
39 document.write( "</tr>" );
40}
41
42
43function data( /* Array of Object */ dataArray )
44{
45 // render components
46 if (dataArray.length == 1)
47 {
48 entry( dataArray[0], true );
49 }
50 else {
51 for ( var idx in dataArray )
52 {
53 entry( dataArray[idx] );
54 }
55 }
56}
57
58
59function footer( /* int */ columns )
60{
61 document.write( "<tr class='content'>" );
62 document.write( "<td colspan='" + columns + "' class='content'>&nbsp;</th>" );
63 document.write( "</tr>" );
64
65 document.write( "</table>" );
66}
67
68
69function entry( /* Object */ dataEntry, /* boolean */ singleEntry )
70{
71 var trElement = tr( null, { id: "entry" + dataEntry.id } );
72 entryInternal( trElement, dataEntry, singleEntry );
73 document.write( serialize( trElement ) );
74}
75
76
77function entryInternal( /* Element */ parent, /* Object */ dataEntry, /* boolean */ singleEntry )
78{
79
80 var id = dataEntry.id;
81 var topic = dataEntry.topic;
82 var properties = dataEntry.properties;
83
84 parent.appendChild( td( "content", { width: "20%"}, [ text( topic ) ] ) );
85
86 var tableE = createElement("table");
87 var bodyE = createElement("tbody");
88 tableE.appendChild(bodyE);
89
90 for( var p in dataEntry.properties ) {
91 bodyE.appendChild(tr(null, null, [td(null, null, [text(p + " = " + dataEntry.properties[p])] )]));
92 }
93
94 parent.appendChild( td( "content", null, [tableE] ) );
95}
96
97
98
99function renderEvents( /* Array of Data Objects */ bundleData )
100{
101
102 // topic and properties
103 var columns = 2;
104
105 header( columns );
106
107 if (bundleData.error)
108 {
109 error( columns, bundleData.error );
110 }
111 else
112 {
113 data ( bundleData.data );
114 }
115
116 footer( columns );
117}