blob: 29691e56e4711707a64ef0f18403b1d70d29b8b7 [file] [log] [blame]
Felix Meschberger7b023db2009-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 */
17function renderStatusLine() {
18 $("#plugin_content").append(
19 "<div class='fullwidth'><div class='statusline'/></div>");
20}
21
22function renderView( /* Array of String */columns) {
23 renderStatusLine();
24 var txt = "<div class='table'><table id='plugin_table' class='tablelayout'><thead><tr>";
25 for ( var name in columns) {
26 txt = txt + "<th class='col_" + columns[name] + "'>" + columns[name]
27 + "</th>";
28 }
29 txt = txt + "</tr></thead><tbody></tbody></table></div>";
30 $("#plugin_content").append(txt);
31 renderStatusLine();
32}
33
34function renderData(eventData) {
35 $(".statusline").empty().append(eventData.status);
36 $("#plugin_table > tbody > tr").remove();
37 for ( var idx in eventData.data) {
38 entry(eventData.data[idx]);
39 }
40 $("#plugin_table").trigger("update");
41 if (drawDetails) {
42 renderDetails(eventData);
43 }
44}
45
46function entry( /* Object */dataEntry) {
47 var trElement = tr(null, {
48 id : "entry" + dataEntry.id
49 });
50 entryInternal(trElement, dataEntry);
51 $("#plugin_table > tbody").append(trElement);
52}
53
54function entryInternal( /* Element */parent, /* Object */dataEntry) {
55 var id = dataEntry.id;
56 var name = dataEntry.id;
57
58 var inputElement = createElement("img", "rightButton", {
59 src : appRoot + "/res/imgs/arrow_right.png",
60 style : {
61 border : "none"
62 },
63 id : 'img' + id,
64 title : "Details",
65 alt : "Details",
66 width : 14,
67 height : 14
68 });
69 $(inputElement).click(function() {
70 showDetails(id)
71 });
72 var titleElement;
73 if (drawDetails) {
74 titleElement = text(name);
75 } else {
76 titleElement = createElement("a", null, {
77 href : window.location.pathname + "/" + id
78 });
79 titleElement.appendChild(text(name));
80 }
81 var bundleElement = createElement("a", null, {
82 href : bundlePath + dataEntry.bundleId
83 });
84 bundleElement.appendChild(text(dataEntry.bundleSymbolicName + " ("
85 + dataEntry.bundleId + ")"));
86
87 parent
88 .appendChild(td(null, null,
89 [ inputElement, text(" "), titleElement ]));
90 parent.appendChild(td(null, null, [ text(dataEntry.types) ]));
91 parent.appendChild(td(null, null, [ bundleElement ]));
92}
93
94function showDetails(id) {
95 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
96 renderDetails(data);
97 }, "json");
98}
99
100function hideDetails(id) {
101 $("#img" + id).each(function() {
102 $("#pluginInlineDetails").remove();
103 $(this).attr("src", appRoot + "/res/imgs/arrow_right.png");
104 $(this).attr("title", "Details");
105 $(this).attr("alt", "Details");
106 $(this).unbind('click').click(function() {
107 showDetails(id)
108 });
109 });
110}
111
112function renderDetails(data) {
113 data = data.data[0];
114 $("#pluginInlineDetails").remove();
115 $("#entry" + data.id + " > td").eq(1).append(
116 "<div id='pluginInlineDetails'/>");
117 $("#img" + data.id).each(function() {
118 if (drawDetails) {
119 $(this).attr("src", appRoot + "/res/imgs/arrow_left.png");
120 $(this).attr("title", "Back");
121 $(this).attr("alt", "Back");
122 var ref = window.location.pathname;
123 ref = ref.substring(0, ref.lastIndexOf('/'));
124 $(this).unbind('click').click(function() {
125 window.location = ref;
126 });
127 } else {
128 $(this).attr("src", appRoot + "/res/imgs/arrow_down.png");
129 $(this).attr("title", "Hide Details");
130 $(this).attr("alt", "Hide Details");
131 $(this).unbind('click').click(function() {
132 hideDetails(data.id)
133 });
134 }
135 });
136 $("#pluginInlineDetails").append(
137 "<table border='0'><tbody></tbody></table>");
138 var details = data.props;
139 for ( var idx in details) {
140 var prop = details[idx];
141
142 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>"
143 + prop.key
144 + "</td><td class='aligntop' style='border:0px none'>";
145 if (prop.value) {
146 if ($.isArray(prop.value)) {
147 var i = 0;
148 for ( var pi in prop.value) {
149 var value = prop.value[pi];
150 if (i > 0) {
151 txt = txt + "<br/>";
152 }
153 var span;
154 if (value.substring(0, 6) == "INFO: ") {
155 txt = txt + "<span style='color: grey;'>!!"
156 + value.substring(5) + "</span>";
157 } else if (value.substring(0, 7) == "ERROR: ") {
158 txt = txt + "<span style='color: red;'>!!"
159 + value.substring(6) + "</span>";
160 } else {
161 txt = txt + value;
162 }
163 i++;
164 }
165 } else {
166 txt = txt + prop.value;
167 }
168 } else {
169 txt = txt + "\u00a0";
170 }
171 txt = txt + "</td></tr>";
172 $("#pluginInlineDetails > table > tbody").append(txt);
173
174 }
175}
176
177function renderServices(data) {
178 $(document).ready(function() {
179 renderView( [ "Id", "Type(s)", "Bundle" ]);
180 renderData(data);
181
182 var extractMethod = function(node) {
183 var link = node.getElementsByTagName("a");
184 if (link && link.length == 1) {
185 return link[0].innerHTML;
186 }
187 return node.innerHTML;
188 };
189 $("#plugin_table").tablesorter( {
190 headers : {
191 0 : {
192 sorter : "digit"
193 }
194 },
195 sortList : [ [ 1, 0 ] ],
196 textExtraction : extractMethod
197 });
198 });
199}