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