blob: 2dfbf073e76c776a243e20ee807227785c2aac51 [file] [log] [blame]
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +00001/*
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 Meschbergerd46d5ac2009-11-26 12:28:54 +000017
18function renderData(eventData) {
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000019 $('.statline').empty().append(i18n.statline.msgFormat(eventData.serviceCount));
20 $('#plugin_table > tbody > tr').remove();
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000021 for ( var idx in eventData.data) {
22 entry(eventData.data[idx]);
23 }
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000024 $('#plugin_table').trigger('update');
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000025 if (drawDetails) {
26 renderDetails(eventData);
27 }
28}
29
30function entry( /* Object */dataEntry) {
31 var trElement = tr(null, {
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000032 id : 'entry' + dataEntry.id
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000033 });
34 entryInternal(trElement, dataEntry);
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000035 $('#plugin_table > tbody').append(trElement);
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000036}
37
38function entryInternal( /* Element */parent, /* Object */dataEntry) {
39 var id = dataEntry.id;
40 var name = dataEntry.id;
41
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000042 // 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 Meschbergerd46d5ac2009-11-26 12:28:54 +000047 });
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000048
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000049 $(inputElement).click(function() {
50 showDetails(id)
51 });
52 var titleElement;
53 if (drawDetails) {
54 titleElement = text(name);
55 } else {
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000056 titleElement = createElement('a', null, {
57 href : window.location.pathname + '/' + id
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000058 });
59 titleElement.appendChild(text(name));
60 }
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000061 var bundleElement = createElement('a', null, {
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000062 href : bundlePath + dataEntry.bundleId
63 });
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000064 bundleElement.appendChild(text(dataEntry.bundleSymbolicName + ' ('
65 + dataEntry.bundleId + ')'));
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000066
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000067 parent.appendChild(td(null, null, [ inputElement, text(' '), titleElement ]));
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000068 parent.appendChild(td(null, null, [ text(dataEntry.types) ]));
69 parent.appendChild(td(null, null, [ bundleElement ]));
70}
71
72function showDetails(id) {
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000073 $.get(pluginRoot + '/' + id + '.json', null, function(data) {
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000074 renderDetails(data);
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000075 }, 'json');
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000076}
77
78function hideDetails(id) {
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000079 $('#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 Meschbergerd46d5ac2009-11-26 12:28:54 +000086 });
87}
88
89function renderDetails(data) {
90 data = data.data[0];
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000091 $('#entry' + data.id + ' > td').eq(1).append('<div id="pluginInlineDetails' + data.id + '"/>');
92 $('#img' + data.id).each(function() {
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000093 if (drawDetails) {
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +000094 var ref = window.location.pathname;
95 ref = ref.substring(0, ref.lastIndexOf('/'));
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +000096 $(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 Meschbergerd46d5ac2009-11-26 12:28:54 +0000102 } else {
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +0000103 $(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 Meschbergerd46d5ac2009-11-26 12:28:54 +0000109 }
110 });
Felix Meschbergerde0ceed2010-04-08 08:05:20 +0000111 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 Meschberger2fc6a6e2010-02-18 08:12:37 +0000122}
123
124function renderObjectAsTable(/* Object*/ details) {
125 var txt = '';
126
127 for (var idx in details) {
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000128 var prop = details[idx];
129
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +0000130 txt += '<tr><td class="aligntop" noWrap="true" style="border:0px none">'
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000131 + prop.key
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +0000132 + '</td><td class="aligntop" style="border:0px none">';
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000133 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 Meschberger2fc6a6e2010-02-18 08:12:37 +0000139 txt = txt + '<br/>';
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000140 }
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +0000141 txt = txt + value;
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000142 i++;
143 }
144 } else {
145 txt = txt + prop.value;
146 }
147 } else {
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +0000148 txt = txt + '\u00a0';
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000149 }
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +0000150 txt = txt + '</td></tr>';
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000151 }
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +0000152
Felix Meschbergerde0ceed2010-04-08 08:05:20 +0000153 return txt;
154}
155
156function 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 Meschberger2fc6a6e2010-02-18 08:12:37 +0000164 }
165
Felix Meschbergerde0ceed2010-04-08 08:05:20 +0000166 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 Meschberger2fc6a6e2010-02-18 08:12:37 +0000174 return txt;
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000175}
176
177function renderServices(data) {
178 $(document).ready(function() {
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000179 renderData(data);
180
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +0000181 $('#plugin_table').tablesorter( {
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000182 headers : {
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +0000183 0 : { sorter : 'digit' }
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000184 },
185 sortList : [ [ 1, 0 ] ],
Felix Meschberger2fc6a6e2010-02-18 08:12:37 +0000186 textExtraction : mixedLinksExtraction,
187 widgets: ['zebra']
Felix Meschbergerd46d5ac2009-11-26 12:28:54 +0000188 });
189 });
190}