Carsten Ziegeler | 580814b | 2009-09-24 12:09:34 +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 | */ |
Valentin Pavlov Valchev | ee54b8b | 2010-03-15 14:17:58 +0000 | [diff] [blame] | 17 | var eventsTable = false; |
Carsten Ziegeler | 580814b | 2009-09-24 12:09:34 +0000 | [diff] [blame] | 18 | |
| 19 | /* displays a date in the user's local timezone */ |
| 20 | function printDate(time) { |
| 21 | var date = time ? new Date(time) : new Date(); |
| 22 | return date.toLocaleString(); |
| 23 | } |
| 24 | |
Valentin Pavlov Valchev | ee54b8b | 2010-03-15 14:17:58 +0000 | [diff] [blame] | 25 | function renderData( eventData ) { |
| 26 | $('.statline').html(eventData.status); // FIXME: |
| 27 | |
| 28 | // append table view |
| 29 | eventsBody.empty(); |
| 30 | for ( var i in eventData.data ) entry( eventData.data[i] ); |
| 31 | eventsTable.trigger('update').trigger('applyWidgets'); |
| 32 | |
| 33 | // append timeline view |
| 34 | timeline.empty(); |
| 35 | for ( var i in eventData.data ) entryTimeline( eventData.data[i] ); |
Carsten Ziegeler | 580814b | 2009-09-24 12:09:34 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Valentin Pavlov Valchev | ee54b8b | 2010-03-15 14:17:58 +0000 | [diff] [blame] | 38 | |
| 39 | function entryTimeline( /* Object */ dataEntry ) { |
| 40 | var txt = '<div class="event event' + dataEntry.category + '" style="width:' + dataEntry.width + '%">' + |
| 41 | '<b>' + dataEntry.offset + '</b> <b>' + dataEntry.topic + '</b>'; |
| 42 | if ( dataEntry.info ) txt += ' : ' + dataEntry.info; |
| 43 | txt += '</div>'; |
| 44 | timeline.prepend(txt); |
Carsten Ziegeler | af592a5 | 2009-09-24 14:33:35 +0000 | [diff] [blame] | 45 | } |
Valentin Pavlov Valchev | ee54b8b | 2010-03-15 14:17:58 +0000 | [diff] [blame] | 46 | |
| 47 | function entry( /* Object */ dataEntry ) { |
| 48 | var properties = dataEntry.properties; |
| 49 | |
| 50 | var propE; |
| 51 | if ( dataEntry.info ) { |
| 52 | propE = text(dataEntry.info); |
| 53 | } else { |
| 54 | var propE = createElement('table', 'nicetable'); |
| 55 | var bodyE = createElement('tbody'); |
| 56 | propE.appendChild(bodyE); |
| 57 | |
| 58 | for( var p in dataEntry.properties ) { |
| 59 | bodyE.appendChild(tr(null, null, [ |
| 60 | td(null, 'propName', [text(p)]), |
| 61 | td(null, 'propVal', [text(dataEntry.properties[p])]) |
| 62 | ])); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | $(tr( null, { id: 'entry' + dataEntry.id }, [ |
| 67 | td( null, null, [ text( printDate(dataEntry.received) ) ] ), |
| 68 | td( null, null, [ text( dataEntry.topic ) ] ), |
| 69 | propE |
| 70 | ])).appendTo(eventsBody); |
| 71 | } |
| 72 | |
| 73 | var timeline = false; |
| 74 | $(document).ready(function(){ |
| 75 | eventsTable = $('#eventsTable'); |
| 76 | eventsBody = eventsTable.find('tbody'); |
| 77 | timeline = $('#timeline'); |
| 78 | |
| 79 | $('#clear').click(function () { |
| 80 | $.post(pluginRoot, { 'action':'clear' }, renderData, 'json'); |
Carsten Ziegeler | 580814b | 2009-09-24 12:09:34 +0000 | [diff] [blame] | 81 | }); |
Valentin Pavlov Valchev | ee54b8b | 2010-03-15 14:17:58 +0000 | [diff] [blame] | 82 | $('#switch').click(function() { |
| 83 | var timelineHidden = timeline.hasClass('ui-helper-hidden'); |
| 84 | if (timelineHidden) { |
| 85 | $(this).text(i18n.displayList); |
| 86 | timeline.removeClass('ui-helper-hidden'); |
| 87 | eventsTable.addClass('ui-helper-hidden'); |
| 88 | } else { |
| 89 | $(this).text(i18n.displayTimeline); |
| 90 | timeline.addClass('ui-helper-hidden'); |
| 91 | eventsTable.removeClass('ui-helper-hidden'); |
| 92 | } |
| 93 | }); |
| 94 | $('#reload').click(function() { |
| 95 | $.get(pluginRoot + '/data.json', null, renderData, 'json'); |
| 96 | //renderData(eventData); |
| 97 | }).click(); |
| 98 | }); |