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 renderStatusLine() { |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 18 | $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" ); |
Carsten Ziegeler | 94ccb53 | 2008-10-27 11:36:46 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 21 | function renderView( /* Array of String */ columns, /* String */ buttons ) { |
Carsten Ziegeler | c75546e | 2008-11-12 05:20:15 +0000 | [diff] [blame] | 22 | renderStatusLine(); |
| 23 | renderButtons(buttons); |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 24 | var txt = "<div class='table'><table id='plugin_table' class='tablelayout'><thead><tr>"; |
Carsten Ziegeler | 94ccb53 | 2008-10-27 11:36:46 +0000 | [diff] [blame] | 25 | for ( var name in columns ) { |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 26 | txt = txt + "<th class='col_" + columns[name] + "'>" + columns[name] + "</th>"; |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 27 | } |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 28 | txt = txt + "</tr></thead><tbody></tbody></table></div>"; |
| 29 | $("#plugin_content").append( txt ); |
Carsten Ziegeler | c75546e | 2008-11-12 05:20:15 +0000 | [diff] [blame] | 30 | renderButtons(buttons); |
| 31 | renderStatusLine(); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Carsten Ziegeler | c75546e | 2008-11-12 05:20:15 +0000 | [diff] [blame] | 34 | function renderButtons( buttons ) { |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 35 | $("#plugin_content").append( "<form method='post' enctype='multipart/form-data'><div class='fullwidth'><div class='buttons'>" + |
| 36 | buttons + "</div></div></form>" ); |
Carsten Ziegeler | 94ccb53 | 2008-10-27 11:36:46 +0000 | [diff] [blame] | 37 | } |
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 | function renderData( eventData ) { |
| 40 | $(".statusline").empty().append(eventData.status); |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 41 | $("#plugin_table > tbody > tr").remove(); |
Carsten Ziegeler | 94ccb53 | 2008-10-27 11:36:46 +0000 | [diff] [blame] | 42 | for ( var idx in eventData.data ) { |
| 43 | entry( eventData.data[idx] ); |
| 44 | } |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 45 | $("#plugin_table").trigger("update"); |
Carsten Ziegeler | 94ccb53 | 2008-10-27 11:36:46 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | function entry( /* Object */ dataEntry ) { |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 49 | var trElement = tr( null, { id: "entry" + dataEntry.id } ); |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame] | 50 | entryInternal( trElement, dataEntry ); |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 51 | $("#plugin_table > tbody").append(trElement); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | |
Carsten Ziegeler | 94ccb53 | 2008-10-27 11:36:46 +0000 | [diff] [blame] | 55 | function entryInternal( /* Element */ parent, /* Object */ dataEntry ) { |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 56 | var id = dataEntry.id; |
| 57 | var topic = dataEntry.topic; |
| 58 | var properties = dataEntry.properties; |
| 59 | |
Carsten Ziegeler | c75546e | 2008-11-12 05:20:15 +0000 | [diff] [blame] | 60 | parent.appendChild( td( null, null, [ text( printDate(dataEntry.received) ) ] ) ); |
Carsten Ziegeler | 7876ef9 | 2008-10-26 17:47:51 +0000 | [diff] [blame] | 61 | parent.appendChild( td( null, null, [ text( topic ) ] ) ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 62 | |
Carsten Ziegeler | 0f77a57 | 2008-10-27 16:30:38 +0000 | [diff] [blame] | 63 | var propE; |
| 64 | if ( dataEntry.info ) { |
| 65 | propE = text(dataEntry.info); |
| 66 | } else { |
| 67 | var tableE = createElement("table"); |
| 68 | var bodyE = createElement("tbody"); |
| 69 | tableE.appendChild(bodyE); |
| 70 | |
| 71 | for( var p in dataEntry.properties ) { |
Carsten Ziegeler | 93add2f | 2008-12-22 11:31:23 +0000 | [diff] [blame] | 72 | var c1 = td(null, null, [text(p)]); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 73 | $(c1).css("border", "0px none"); |
Carsten Ziegeler | 93add2f | 2008-12-22 11:31:23 +0000 | [diff] [blame] | 74 | var c2 = td(null, null, [text(dataEntry.properties[p])]); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 75 | $(c2).css("border", "0px none"); |
Carsten Ziegeler | 93add2f | 2008-12-22 11:31:23 +0000 | [diff] [blame] | 76 | bodyE.appendChild(tr(null, null, [ c1, c2 ])); |
Carsten Ziegeler | 0f77a57 | 2008-10-27 16:30:38 +0000 | [diff] [blame] | 77 | } |
| 78 | propE = tableE; |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Carsten Ziegeler | 0f77a57 | 2008-10-27 16:30:38 +0000 | [diff] [blame] | 81 | parent.appendChild( td( null, null, [propE] ) ); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Carsten Ziegeler | c75546e | 2008-11-12 05:20:15 +0000 | [diff] [blame] | 84 | /* displays a date in the user's local timezone */ |
| 85 | function printDate(time) { |
| 86 | var date = time ? new Date(time) : new Date(); |
| 87 | return date.toLocaleString(); |
| 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() { |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 97 | $(document).ready(function(){ |
| 98 | renderView( ["Received", "Topic", "Properties"], |
| 99 | "<button class='clearButton' type='button' name='clear'>Clear List</button>" + |
| 100 | "<button class='reloadButton' type='button' name='reload'>Reload</button>"); |
| 101 | loadData(); |
| 102 | |
| 103 | $("#plugin_table").tablesorter(); |
| 104 | $(".reloadButton").click(loadData); |
| 105 | $(".clearButton").click(function () { |
| 106 | $("#plugin_table > tbody > tr").remove(); |
| 107 | $.post(pluginRoot, { "action":"clear" }, function(data) { |
| 108 | renderData(data); |
| 109 | }, "json"); |
| 110 | }); |
| 111 | }); |
Carsten Ziegeler | d524ac9 | 2008-10-23 16:44:07 +0000 | [diff] [blame] | 112 | } |