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 | { |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 20 | document.write( "<div class='fullwidth tablelayout'>"); |
| 21 | renderButtons(); |
| 22 | document.write( "<div class='table'>"); |
| 23 | document.write( "<table id='events' class='tablelayout'>" ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 24 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 25 | document.write( "<thead><tr>" ); |
| 26 | document.write( "<th>Received</th>" ); |
| 27 | document.write( "<th>Topic</th>" ); |
| 28 | document.write( "<th>Properties</th>" ); |
| 29 | document.write( "</tr></thead><tbody>" ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 30 | |
| 31 | } |
| 32 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 33 | function renderData( eventData ) |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 34 | { |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 35 | $(".statusline").empty().append(eventData.status); |
| 36 | data ( eventData.data ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 39 | function data( /* Array of Object */ dataArray ) |
| 40 | { |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 41 | $("#events > tbody > tr").remove(); |
| 42 | for ( var idx in dataArray ) |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 43 | { |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 44 | entry( dataArray[idx] ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
| 48 | |
| 49 | function footer( /* int */ columns ) |
| 50 | { |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 51 | document.write( "</tbody></table>" ); |
| 52 | document.write( "</div>"); |
| 53 | renderButtons(); |
| 54 | document.write( "</div>"); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 58 | function entry( /* Object */ dataEntry ) |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 59 | { |
| 60 | var trElement = tr( null, { id: "entry" + dataEntry.id } ); |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 61 | entryInternal( trElement, dataEntry ); |
| 62 | $("#events > tbody").append(trElement); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 66 | function entryInternal( /* Element */ parent, /* Object */ dataEntry ) |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 67 | { |
| 68 | |
| 69 | var id = dataEntry.id; |
| 70 | var topic = dataEntry.topic; |
| 71 | var properties = dataEntry.properties; |
| 72 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 73 | parent.appendChild( td( null, null, [ text( new Date(dataEntry.received) ) ] ) ); |
| 74 | parent.appendChild( td( null, null, [ text( topic ) ] ) ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 75 | |
| 76 | var tableE = createElement("table"); |
| 77 | var bodyE = createElement("tbody"); |
| 78 | tableE.appendChild(bodyE); |
| 79 | |
| 80 | for( var p in dataEntry.properties ) { |
Carsten Ziegeler | 7ba2bfe | 2008-10-24 05:23:56 +0000 | [diff] [blame] | 81 | bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ), |
| 82 | td(null, null, [text(dataEntry.properties[p])])])); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 85 | parent.appendChild( td( null, null, [tableE] ) ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 88 | function renderStatusLine() { |
| 89 | document.write( "<div class='fullwidth'>"); |
| 90 | document.write( "<div class='statusline'>" ); |
| 91 | document.write( "</div>" ); |
| 92 | document.write( "</div>" ); |
| 93 | } |
| 94 | |
| 95 | function renderButtons( ) |
Carsten Ziegeler | fd17578 | 2008-10-24 10:12:08 +0000 | [diff] [blame] | 96 | { |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 97 | document.write( "<div class='fullwidth'>"); |
| 98 | document.write( "<div class='buttons'>" ); |
| 99 | document.write( "<div class='button'><button id='reloadButton' type='button' name='reload'>Reload</button></div>" ); |
| 100 | document.write( "<div class='button'><button id='clearButton' type='button' name='clear'>Clear List</button></div>" ); |
| 101 | document.write( "</div>" ); |
| 102 | document.write( "</div>" ); |
Carsten Ziegeler | fd17578 | 2008-10-24 10:12:08 +0000 | [diff] [blame] | 103 | } |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 104 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 105 | function loadData() |
| 106 | { |
| 107 | $.get(pluginRoot + "/data.json", null, function(data) { |
| 108 | renderData(data); |
| 109 | }, "json"); |
| 110 | } |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 111 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 112 | function renderEvents( ) |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 113 | { |
| 114 | |
Carsten Ziegeler | 91b8b04 | 2008-10-24 09:34:29 +0000 | [diff] [blame] | 115 | // date, topic and properties |
| 116 | var columns = 3; |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 117 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 118 | renderStatusLine(); |
| 119 | |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 120 | header( columns ); |
| 121 | |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 122 | footer( columns ); |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame^] | 123 | |
| 124 | renderStatusLine(); |
| 125 | |
| 126 | loadData(); |
| 127 | |
| 128 | $("#events").tablesorter(); |
| 129 | $("#reloadButton").click(loadData); |
| 130 | $("#clearButton").click(function () { |
| 131 | $("#events > tbody > tr").remove(); |
| 132 | $.post(pluginRoot, { "action":"clear" }, function(data) { |
| 133 | renderData(data); |
| 134 | }, "json"); |
| 135 | }); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 136 | } |