Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | function 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'> </th>" ); |
| 24 | document.write( "</tr>" ); |
| 25 | |
| 26 | document.write( "<tr class='content'>" ); |
Carsten Ziegeler | 46fb24e | 2008-10-24 08:04:31 +0000 | [diff] [blame^] | 27 | document.write( "<th class='content' width='20%'>Topic</th>" ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 28 | document.write( "<th class='content'>Properties</th>" ); |
| 29 | document.write( "</tr>" ); |
| 30 | |
| 31 | } |
| 32 | |
| 33 | |
| 34 | function error( /* int */ columns, /* String */ message ) |
| 35 | { |
| 36 | document.write( "<tr class='content'>" ); |
| 37 | document.write( "<td class='content'> </td>" ); |
| 38 | document.write( "<td class='content' colspan='" + (columns - 1) + "'>" + message + "</td>" ); |
| 39 | document.write( "</tr>" ); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | function 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 | |
| 59 | function footer( /* int */ columns ) |
| 60 | { |
| 61 | document.write( "<tr class='content'>" ); |
| 62 | document.write( "<td colspan='" + columns + "' class='content'> </th>" ); |
| 63 | document.write( "</tr>" ); |
| 64 | |
| 65 | document.write( "</table>" ); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | function 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 | |
| 77 | function 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 ) { |
Carsten Ziegeler | 7ba2bfe | 2008-10-24 05:23:56 +0000 | [diff] [blame] | 91 | bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ), |
| 92 | td(null, null, [text(dataEntry.properties[p])])])); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | parent.appendChild( td( "content", null, [tableE] ) ); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | |
| 100 | function renderEvents( /* Array of Data Objects */ bundleData ) |
| 101 | { |
| 102 | |
| 103 | // topic and properties |
| 104 | var columns = 2; |
| 105 | |
| 106 | header( columns ); |
| 107 | |
| 108 | if (bundleData.error) |
| 109 | { |
| 110 | error( columns, bundleData.error ); |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | data ( bundleData.data ); |
| 115 | } |
| 116 | |
| 117 | footer( columns ); |
| 118 | } |