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 | |
Carsten Ziegeler | 0f77a57 | 2008-10-27 16:30:38 +0000 | [diff] [blame^] | 78 | var propE; |
| 79 | if ( dataEntry.info ) { |
| 80 | propE = text(dataEntry.info); |
| 81 | } else { |
| 82 | var tableE = createElement("table"); |
| 83 | var bodyE = createElement("tbody"); |
| 84 | tableE.appendChild(bodyE); |
| 85 | |
| 86 | for( var p in dataEntry.properties ) { |
| 87 | bodyE.appendChild(tr(null, null, [td(null, null, [text(p)] ), |
| 88 | td(null, null, [text(dataEntry.properties[p])])])); |
| 89 | } |
| 90 | propE = tableE; |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Carsten Ziegeler | 0f77a57 | 2008-10-27 16:30:38 +0000 | [diff] [blame^] | 93 | parent.appendChild( td( null, null, [propE] ) ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Carsten Ziegeler | 94ccb53 | 2008-10-27 11:36:46 +0000 | [diff] [blame] | 96 | function loadData() { |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame] | 97 | $.get(pluginRoot + "/data.json", null, function(data) { |
| 98 | renderData(data); |
| 99 | }, "json"); |
| 100 | } |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 101 | |
Carsten Ziegeler | 94ccb53 | 2008-10-27 11:36:46 +0000 | [diff] [blame] | 102 | function renderEvents() { |
| 103 | render(); |
| 104 | |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame] | 105 | loadData(); |
| 106 | |
| 107 | $("#events").tablesorter(); |
| 108 | $("#reloadButton").click(loadData); |
| 109 | $("#clearButton").click(function () { |
| 110 | $("#events > tbody > tr").remove(); |
| 111 | $.post(pluginRoot, { "action":"clear" }, function(data) { |
| 112 | renderData(data); |
| 113 | }, "json"); |
| 114 | }); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 115 | } |