Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +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 | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame^] | 17 | var tableEntryTemplate = false; |
| 18 | var tableBody = false; |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 19 | |
| 20 | function renderData(eventData) { |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 21 | $('.statline').empty().append(i18n.statline.msgFormat(eventData.serviceCount)); |
| 22 | $('#plugin_table > tbody > tr').remove(); |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 23 | for ( var idx in eventData.data) { |
| 24 | entry(eventData.data[idx]); |
| 25 | } |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 26 | if (drawDetails) { |
| 27 | renderDetails(eventData); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | function entry( /* Object */dataEntry) { |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 32 | var id = dataEntry.id; |
| 33 | var name = dataEntry.id; |
| 34 | |
Valentin Pavlov Valchev | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame^] | 35 | var _ = tableEntryTemplate.clone().attr('id', 'entry' + id).appendTo(tableBody); |
| 36 | _.find('.bIcon').attr('id', 'img' + id).click(function() { |
| 37 | showDetails(id); |
| 38 | }).after(drawDetails ? name : ('<a href="' + window.location.pathname + '/' + id + '">' + name + '</a>')); |
| 39 | |
| 40 | _.find('td:eq(1)').text(dataEntry.types); |
| 41 | _.find('td:eq(2)').html('<a href="' + bundlePath + dataEntry.bundleId + '">' + dataEntry.bundleSymbolicName + ' (' + dataEntry.bundleId + ')</a>' ); |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | function showDetails(id) { |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 45 | $.get(pluginRoot + '/' + id + '.json', null, function(data) { |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 46 | renderDetails(data); |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 47 | }, 'json'); |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | function hideDetails(id) { |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 51 | $('#img' + id).each(function() { |
| 52 | $('#pluginInlineDetails' + id).remove(); |
| 53 | $(this). |
| 54 | removeClass('ui-icon-triangle-1-w').//left |
| 55 | removeClass('ui-icon-triangle-1-s').//down |
| 56 | addClass('ui-icon-triangle-1-e').//right |
| 57 | unbind('click').click(function() {showDetails(id)}); |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 58 | }); |
| 59 | } |
| 60 | |
| 61 | function renderDetails(data) { |
| 62 | data = data.data[0]; |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 63 | $('#entry' + data.id + ' > td').eq(1).append('<div id="pluginInlineDetails' + data.id + '"/>'); |
| 64 | $('#img' + data.id).each(function() { |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 65 | if (drawDetails) { |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 66 | var ref = window.location.pathname; |
| 67 | ref = ref.substring(0, ref.lastIndexOf('/')); |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 68 | $(this). |
| 69 | removeClass('ui-icon-triangle-1-e').//right |
| 70 | removeClass('ui-icon-triangle-1-s').//down |
| 71 | addClass('ui-icon-triangle-1-w').//left |
| 72 | attr('title', i18n.back). |
| 73 | unbind('click').click(function() {window.location = ref;}); |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 74 | } else { |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 75 | $(this). |
| 76 | removeClass('ui-icon-triangle-1-w').//left |
| 77 | removeClass('ui-icon-triangle-1-e').//right |
| 78 | addClass('ui-icon-triangle-1-s').//down |
| 79 | attr('title', i18n.detailsHide). |
| 80 | unbind('click').click(function() {hideDetails(data.id)}); |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 81 | } |
| 82 | }); |
Felix Meschberger | 4fe6955 | 2010-04-08 08:05:20 +0000 | [diff] [blame] | 83 | var details = ""; |
| 84 | if (data.props) { |
| 85 | details += renderObjectAsTable(data.props); |
| 86 | } |
| 87 | if (data.usingBundles) { |
| 88 | details += renderUsingBundlesAsTable(data.usingBundles); |
| 89 | } |
| 90 | if (details) { |
| 91 | details = '<table border="0"><tbody>' + details + '</tbody></table>'; |
| 92 | $('#pluginInlineDetails' + data.id).append( details ); |
| 93 | } |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | function renderObjectAsTable(/* Object*/ details) { |
| 97 | var txt = ''; |
| 98 | |
| 99 | for (var idx in details) { |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 100 | var prop = details[idx]; |
| 101 | |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 102 | txt += '<tr><td class="aligntop" noWrap="true" style="border:0px none">' |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 103 | + prop.key |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 104 | + '</td><td class="aligntop" style="border:0px none">'; |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 105 | if (prop.value) { |
| 106 | if ($.isArray(prop.value)) { |
| 107 | var i = 0; |
| 108 | for ( var pi in prop.value) { |
| 109 | var value = prop.value[pi]; |
| 110 | if (i > 0) { |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 111 | txt = txt + '<br/>'; |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 112 | } |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 113 | txt = txt + value; |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 114 | i++; |
| 115 | } |
| 116 | } else { |
| 117 | txt = txt + prop.value; |
| 118 | } |
| 119 | } else { |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 120 | txt = txt + '\u00a0'; |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 121 | } |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 122 | txt = txt + '</td></tr>'; |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 123 | } |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 124 | |
Felix Meschberger | 4fe6955 | 2010-04-08 08:05:20 +0000 | [diff] [blame] | 125 | return txt; |
| 126 | } |
| 127 | |
| 128 | function renderUsingBundlesAsTable(/* Object[] */ bundles) { |
| 129 | var txt = ''; |
| 130 | |
| 131 | for (var idx in bundles) { |
| 132 | var bundle = bundles[idx]; |
| 133 | txt += '<a href="' + bundlePath + '/' + bundle.bundleId + '">' |
| 134 | + bundle.bundleSymbolicName + ' (' + bundle.bundleId + ')' |
| 135 | + '</a><br/>'; |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Felix Meschberger | 4fe6955 | 2010-04-08 08:05:20 +0000 | [diff] [blame] | 138 | if (txt) { |
| 139 | txt = '<tr><td class="aligntop" noWrap="true" style="border:0px none">' |
| 140 | + i18n.usingBundles |
| 141 | + '</td><td class="aligntop" style="border:0px none">' |
| 142 | + txt |
| 143 | + '</td></tr>'; |
| 144 | } |
| 145 | |
Felix Meschberger | a6fe36c | 2010-02-18 08:12:37 +0000 | [diff] [blame] | 146 | return txt; |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 149 | |
Valentin Pavlov Valchev | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame^] | 150 | $(document).ready(function() { |
| 151 | tableBody = $('#plugin_table tbody'); |
| 152 | tableEntryTemplate = tableBody.find('tr').clone(); |
| 153 | tableBody.empty(); |
| 154 | |
| 155 | renderData(data); |
| 156 | |
| 157 | $('#plugin_table').tablesorter( { |
| 158 | headers : { |
| 159 | 0 : { sorter : 'digit' } |
| 160 | }, |
| 161 | sortList : [ [ 1, 0 ] ], |
| 162 | textExtraction : mixedLinksExtraction |
Felix Meschberger | 7b023db | 2009-11-26 12:28:54 +0000 | [diff] [blame] | 163 | }); |
Valentin Pavlov Valchev | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame^] | 164 | }); |