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 | 91b8b04 | 2008-10-24 09:34:29 +0000 | [diff] [blame^] | 27 | document.write( "<th class='content'>Received</th>" ); |
| 28 | document.write( "<th class='content'>Topic</th>" ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 29 | document.write( "<th class='content'>Properties</th>" ); |
| 30 | document.write( "</tr>" ); |
| 31 | |
| 32 | } |
| 33 | |
| 34 | |
| 35 | function error( /* int */ columns, /* String */ message ) |
| 36 | { |
| 37 | document.write( "<tr class='content'>" ); |
| 38 | document.write( "<td class='content'> </td>" ); |
| 39 | document.write( "<td class='content' colspan='" + (columns - 1) + "'>" + message + "</td>" ); |
| 40 | document.write( "</tr>" ); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | function 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 | |
| 60 | function footer( /* int */ columns ) |
| 61 | { |
| 62 | document.write( "<tr class='content'>" ); |
| 63 | document.write( "<td colspan='" + columns + "' class='content'> </th>" ); |
| 64 | document.write( "</tr>" ); |
| 65 | |
| 66 | document.write( "</table>" ); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | function 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 | |
| 78 | function 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 Ziegeler | 91b8b04 | 2008-10-24 09:34:29 +0000 | [diff] [blame^] | 85 | parent.appendChild( td( "content", null, [ text( new Date(dataEntry.received) ) ] ) ); |
| 86 | parent.appendChild( td( "content", { "width": "20%", [ text( topic ) ] ) ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 87 | |
| 88 | var tableE = createElement("table"); |
| 89 | var bodyE = createElement("tbody"); |
| 90 | tableE.appendChild(bodyE); |
| 91 | |
| 92 | for( var p in dataEntry.properties ) { |
Carsten Ziegeler | 7ba2bfe | 2008-10-24 05:23:56 +0000 | [diff] [blame] | 93 | bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ), |
| 94 | td(null, null, [text(dataEntry.properties[p])])])); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | parent.appendChild( td( "content", null, [tableE] ) ); |
| 98 | } |
| 99 | |
| 100 | |
| 101 | |
| 102 | function renderEvents( /* Array of Data Objects */ bundleData ) |
| 103 | { |
| 104 | |
Carsten Ziegeler | 91b8b04 | 2008-10-24 09:34:29 +0000 | [diff] [blame^] | 105 | // date, topic and properties |
| 106 | var columns = 3; |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 107 | |
| 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 | } |