blob: 8ffb4d826a4b919c631232a4a3de76105b2a7ecc [file] [log] [blame]
Felix Meschbergera3214dd2008-06-19 11:08:47 +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 */
17
18function renderDataTable( /* Array of Data Objects */ components )
19{
20 // number of actions plus 3 -- id, name and state
21 var columns = components.numActions + 3;
22
23 header( columns );
24
25 if (components.error)
26 {
27 error( columns, components.error );
28 }
29 else
30 {
31 data ( components.data );
32 }
33
34 footer( columns );
35}
36
37
38function header( /* int */ columns )
39{
40 document.write( "<table class='content' cellpadding='0' cellspacing='0' width='100%'>" );
41
42 document.write( "<tr class='content'>" );
43 document.write( "<td colspan='" + columns + "' class='content'>&nbsp;</th>" );
44 document.write( "</tr>" );
45
46 document.write( "<tr class='content'>" );
47 document.write( "<th class='content'>ID</th>" );
48 document.write( "<th class='content' width='100%'>Name</th>" );
49 document.write( "<th class='content'>Status</th>" );
50 document.write( "<th class='content' colspan='" + (columns - 3) + "'>Actions</th>" );
51 document.write( "</tr>" );
52
53}
54
55
56function error( /* int */ columns, /* String */ message )
57{
58 document.write( "<tr class='content'>" );
59 document.write( "<td class='content'>&nbsp;</td>" );
60 document.write( "<td class='content' colspan='" + (columns - 1) + "'>" + message + "</td>" );
61 document.write( "</tr>" );
62}
63
64
65function data( /* Array of Object */ dataArray )
66{
67 // render components
68 for ( var idx in dataArray )
69 {
70 entry( dataArray[idx] );
71 }
72}
73
74
75function footer( /* int */ columns )
76{
77 document.write( "<tr class='content'>" );
78 document.write( "<td colspan='" + columns + "' class='content'>&nbsp;</th>" );
79 document.write( "</tr>" );
80
81 document.write( "</table>" );
82}
83
84
85function entry( /* Object */ dataEntry )
86{
87 document.write( "<tr id='entry" + dataEntry.id + "'>" );
88 document.write( entryInternal( dataEntry ) );
89 document.write( "</tr>" );
90
91 // dataEntry detailed properties
92 document.write( "<tr id='entry" + dataEntry.id + "_details'>" );
93 if (dataEntry.props)
94 {
95 document.write( getDataEntryDetails( dataEntry.props ) );
96 }
97 document.write( "</tr>" );
98}
99
100
101/* String */ function entryInternal( /* Object */ dataEntry )
102{
103 var id = dataEntry.id;
104 var name = dataEntry.name;
105 var state = dataEntry.state;
106 var icon = (dataEntry.props) ? "down" : "right";
107
108 var html = "<td class='content right'>" + id + "</td>";
109 html += "<td class='content'>";
110 html += "<img src='" + appRoot + "/res/imgs/" + icon + ".gif' onClick='showDataEntryDetails(" + id + ")' id='entry" + id + "_inline' />";
111 html += "<a href='" + pluginRoot + "/" + id + "'>" + name + "</a></td>";
112
113 html += "<td class='content center'>" + state + "</td>";
114
115 for ( var aidx in dataEntry.actions )
116 {
117 var action = dataEntry.actions[aidx];
118 html += actionButton( action.enabled, id, action.link, action.name );
119 }
120
121 return html;
122}
123
124
125/* String */ function actionButton( /* boolean */ enabled, /* long */ id, /* String */ op, /* String */ opLabel )
126{
127 var theButton = "<td class='content' align='right'>";
128 if ( op )
129 {
130 theButton += "<input class='submit' type='button' value='" + opLabel + "'" + ( enabled ? "" : "disabled" ) + " onClick='changeDataEntryState(" + id + ", \"" + op + "\");' />";
131 }
132 else
133 {
134 theButton += "&nbsp;";
135 }
136 theButton += "</td>";
137 return theButton;
138}
139
140
141/* String */ function getDataEntryDetails( /* Array of Object */ details )
142{
143 var innerHtml = '<td class=\"content\">&nbsp;</td><td class=\"content\" colspan=\"4\"><table broder=\"0\">';
144 for (var idx in details)
145 {
146 var prop = details[idx];
147 innerHtml += '<tr><td valign=\"top\" noWrap>' + prop.key + '</td><td valign=\"top\">' + prop.value + '</td></tr>';
148 }
149 innerHtml += '</table></td>';
150 return innerHtml;
151 }
152
153
154function showDetails(bundleId) {
155 var span = document.getElementById('bundle' + bundleId + '_details');
156}
157
158
159function showDataEntryDetails( id )
160{
161 var span = document.getElementById( 'entry' + id + '_details' );
162 if (span)
163 {
164 if (span.innerHTML)
165 {
166 span.innerHTML = '';
167 newLinkValue( id, appRoot + "/res/imgs/right.gif" );
168 }
169 else
170 {
171 sendRequest( 'POST', pluginRoot + '/' + id, displayDataEntryDetails );
172 newLinkValue( id, appRoot + "/res/imgs/down.gif" );
173 }
174 }
175}
176
177
178function newLinkValue( /* long */ id, /* String */ newLinkValue )
179{
180
181 var link = document.getElementById( "entry" + id + "_inline" );
182 if (link)
183 {
184 link.src = newLinkValue;
185 }
186}
187
188
189function displayDataEntryDetails( obj )
190{
191 var span = document.getElementById('entry' + obj.id + '_details');
192 if (!span)
193 {
194 return;
195 }
196
197 span.innerHTML = getDataEntryDetails( obj.props );
198}
199
200
201function changeDataEntryState(/* long */ id, /* String */ action)
202{
203 var parm = pluginRoot + "/" + id + "?action=" + action;
204 sendRequest('POST', parm, dataEntryStateChanged);
205}
206
207
208function dataEntryStateChanged(obj)
209{
210 if (obj.reload)
211 {
212 document.location = document.location;
213 }
214 else
215 {
216 var id = obj.id;
217 if (obj.state)
218 {
219 // has status, so draw the line
220 if (obj.props)
221 {
222 var span = document.getElementById('entry' + id + '_details');
223 if (span && span.innerHTML)
224 {
225 span.innerHTML = getDataEntryDetails( obj.props );
226 }
227 else
228 {
229 obj.props = false;
230 }
231 }
232
233 var span = document.getElementById('entry' + id);
234 if (span)
235 {
236 span.innerHTML = entryInternal( obj );
237 }
238
239
240 }
241 else
242 {
243 // no status, dataEntry has been removed/uninstalled
244 var span = document.getElementById('entry' + id);
245 if (span)
246 {
247 span.parentNode.removeChild(span);
248 }
249 var span = document.getElementById('entry' + id + '_details');
250 if (span)
251 {
252 span.parentNode.removeChild(span);
253 }
254 }
255 }
256}
257
258