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