blob: fe87b983d2e192bf7c613c86e388d744d674d836 [file] [log] [blame]
Felix Meschberger1c336462008-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
Felix Meschberger3effda92008-06-26 15:00:50 +000068 if (dataArray.length == 1)
Felix Meschberger1c336462008-06-19 11:08:47 +000069 {
Felix Meschberger3effda92008-06-26 15:00:50 +000070 entry( dataArray[0], true );
71 }
72 else {
73 for ( var idx in dataArray )
74 {
75 entry( dataArray[idx] );
76 }
Felix Meschberger1c336462008-06-19 11:08:47 +000077 }
78}
79
80
81function footer( /* int */ columns )
82{
83 document.write( "<tr class='content'>" );
84 document.write( "<td colspan='" + columns + "' class='content'>&nbsp;</th>" );
85 document.write( "</tr>" );
86
87 document.write( "</table>" );
88}
89
90
Felix Meschberger3effda92008-06-26 15:00:50 +000091function entry( /* Object */ dataEntry, /* boolean */ singleEntry )
Felix Meschberger1c336462008-06-19 11:08:47 +000092{
Felix Meschberger88c3dcb2008-06-25 08:44:16 +000093 var trElement = tr( null, { id: "entry" + dataEntry.id } );
Felix Meschberger3effda92008-06-26 15:00:50 +000094 entryInternal( trElement, dataEntry, singleEntry );
Felix Meschberger88c3dcb2008-06-25 08:44:16 +000095 document.write( serialize( trElement ) );
Felix Meschberger1c336462008-06-19 11:08:47 +000096
97 // dataEntry detailed properties
Felix Meschberger88c3dcb2008-06-25 08:44:16 +000098 trElement = tr( null, { id: "entry" + dataEntry.id + "_details" } );
Felix Meschberger1c336462008-06-19 11:08:47 +000099 if (dataEntry.props)
100 {
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000101 getDataEntryDetails( trElement, dataEntry.props );
Felix Meschberger1c336462008-06-19 11:08:47 +0000102 }
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000103 document.write( serialize( trElement ) );
Felix Meschberger1c336462008-06-19 11:08:47 +0000104}
105
106
Felix Meschberger3effda92008-06-26 15:00:50 +0000107function entryInternal( /* Element */ parent, /* Object */ dataEntry, /* boolean */ singleEntry )
Felix Meschberger1c336462008-06-19 11:08:47 +0000108{
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000109
Felix Meschberger1c336462008-06-19 11:08:47 +0000110 var id = dataEntry.id;
111 var name = dataEntry.name;
112 var state = dataEntry.state;
Felix Meschberger3effda92008-06-26 15:00:50 +0000113 var icon = singleEntry ? "left" : (dataEntry.props ? "down" : "right");
114 var event = singleEntry ? "history.back()" : "showDataEntryDetails(" + id + ")";
Felix Meschberger1c336462008-06-19 11:08:47 +0000115
Felix Meschberger3effda92008-06-26 15:00:50 +0000116 parent.appendChild( td( "content right", null, [ text( id ) ] ) );
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000117
Felix Meschberger3effda92008-06-26 15:00:50 +0000118 parent.appendChild( td( "content", null, [
119 createElement( "img", null, {
120 src: appRoot + "/res/imgs/" + icon + ".gif",
121 onClick: event,
122 id: "entry" + id + "_inline"
123 } ),
124 text( "\u00a0" ),
125 createElement( "a", null, {
126 href: pluginRoot + "/" + id
127 }, [ text( name ) ]
128 )]
129 )
130 );
Felix Meschberger1c336462008-06-19 11:08:47 +0000131
Felix Meschberger3effda92008-06-26 15:00:50 +0000132 parent.appendChild( td( "content center", null, [ text( state ) ] ) );
Felix Meschberger1c336462008-06-19 11:08:47 +0000133
134 for ( var aidx in dataEntry.actions )
135 {
136 var action = dataEntry.actions[aidx];
Felix Meschbergere6704c32008-12-22 13:15:29 +0000137 parent.appendChild( actionButton( action.enabled, id, action.link, action.name, action.title ) );
Felix Meschberger1c336462008-06-19 11:08:47 +0000138 }
Felix Meschberger1c336462008-06-19 11:08:47 +0000139}
140
141
Felix Meschbergere6704c32008-12-22 13:15:29 +0000142/* Element */ function actionButton( /* boolean */ enabled, /* long */ id, /* String */ op, /* String */ opLabel, /* String */ title )
Felix Meschberger1c336462008-06-19 11:08:47 +0000143{
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000144 var buttonTd = td( "content", { align: "right" } );
Felix Meschberger1c336462008-06-19 11:08:47 +0000145 if ( op )
146 {
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000147 var input = createElement( "input", "submit", {
148 type: 'button',
149 value: opLabel,
150 onClick: 'changeDataEntryState(' + id + ', "' + op + '");'
151 });
152 if (!enabled)
153 {
154 input.setAttribute( "disabled", true );
155 }
Felix Meschbergere6704c32008-12-22 13:15:29 +0000156 if (title)
157 {
158 input.setAttribute( "title", title );
159 }
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000160 buttonTd.appendChild( input );
Felix Meschberger1c336462008-06-19 11:08:47 +0000161 }
162 else
163 {
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000164 addText( buttonTd, "\u00a0" );
Felix Meschberger1c336462008-06-19 11:08:47 +0000165 }
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000166
167 return buttonTd;
Felix Meschberger1c336462008-06-19 11:08:47 +0000168}
169
170
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000171function getDataEntryDetails( /* Element */ parent, /* Array of Object */ details )
Felix Meschberger1c336462008-06-19 11:08:47 +0000172{
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000173 parent.appendChild( addText( td( "content"), "\u00a0" ) );
174
175 var tdEl = td( "content", { colspan: 4 } );
176 parent.appendChild( tdEl );
177
178 var tableEl = createElement( "table", null, { border: 0 } );
179 tdEl.appendChild( tableEl );
180
181 var tbody = createElement( "tbody" );
182 tableEl.appendChild( tbody );
Felix Meschberger1c336462008-06-19 11:08:47 +0000183 for (var idx in details)
184 {
185 var prop = details[idx];
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000186
187
188 var trEl = tr();
189 trEl.appendChild( addText( td( "aligntop", { noWrap: true } ), prop.key ) );
190
191 var proptd = td( "aligntop" );
192 trEl.appendChild( proptd );
193
Felix Meschbergera10aa072008-10-24 06:29:15 +0000194 if (prop.value)
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000195 {
196 var values = new String( prop.value ).split( "<br />" );
197 for (var i=0; i < values.length; i++)
198 {
199 if (i > 0) { proptd.appendChild( createElement( "br" ) ); }
Felix Meschbergera10aa072008-10-24 06:29:15 +0000200
201 var span;
202 if (values[i].substring(0, 2) == "!!") {
203 span = createElement( "span", null, { style: { color: "red" } } );
204 proptd.appendChild( span );
205 } else {
206 span = proptd;
207 }
208
209 addText( span, values[i] );
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000210 }
211 }
212 else
213 {
214 addText( proptd, "\u00a0" );
215 }
216
217 tbody.appendChild( trEl );
Felix Meschberger1c336462008-06-19 11:08:47 +0000218 }
Felix Meschberger1c336462008-06-19 11:08:47 +0000219 }
220
221
Felix Meschberger3effda92008-06-26 15:00:50 +0000222function showDetails(bundleId)
223{
Felix Meschberger1c336462008-06-19 11:08:47 +0000224 var span = document.getElementById('bundle' + bundleId + '_details');
225}
226
227
228function showDataEntryDetails( id )
229{
230 var span = document.getElementById( 'entry' + id + '_details' );
231 if (span)
232 {
Felix Meschberger76f5d0a2008-06-25 09:19:37 +0000233 if (span.firstChild)
Felix Meschberger1c336462008-06-19 11:08:47 +0000234 {
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000235 clearChildren( span );
Felix Meschberger1c336462008-06-19 11:08:47 +0000236 newLinkValue( id, appRoot + "/res/imgs/right.gif" );
237 }
238 else
239 {
240 sendRequest( 'POST', pluginRoot + '/' + id, displayDataEntryDetails );
241 newLinkValue( id, appRoot + "/res/imgs/down.gif" );
242 }
243 }
244}
245
246
247function newLinkValue( /* long */ id, /* String */ newLinkValue )
248{
249
250 var link = document.getElementById( "entry" + id + "_inline" );
251 if (link)
252 {
253 link.src = newLinkValue;
254 }
255}
256
257
258function displayDataEntryDetails( obj )
259{
260 var span = document.getElementById('entry' + obj.id + '_details');
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000261 if (span)
Felix Meschberger1c336462008-06-19 11:08:47 +0000262 {
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000263 clearChildren( span );
264 getDataEntryDetails( span, obj.props );
Felix Meschberger1c336462008-06-19 11:08:47 +0000265 }
266
Felix Meschberger1c336462008-06-19 11:08:47 +0000267}
268
269
270function changeDataEntryState(/* long */ id, /* String */ action)
271{
272 var parm = pluginRoot + "/" + id + "?action=" + action;
273 sendRequest('POST', parm, dataEntryStateChanged);
274}
275
276
277function dataEntryStateChanged(obj)
278{
279 if (obj.reload)
280 {
281 document.location = document.location;
282 }
283 else
284 {
285 var id = obj.id;
286 if (obj.state)
287 {
288 // has status, so draw the line
289 if (obj.props)
290 {
291 var span = document.getElementById('entry' + id + '_details');
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000292 if (span && span.firstChild)
Felix Meschberger1c336462008-06-19 11:08:47 +0000293 {
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000294 clearChildren( span );
295 getDataEntryDetails( span, obj.props );
Felix Meschberger1c336462008-06-19 11:08:47 +0000296 }
297 else
298 {
299 obj.props = false;
300 }
301 }
302
303 var span = document.getElementById('entry' + id);
304 if (span)
305 {
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000306 clearChildren( span );
307 entryInternal( span, obj );
Felix Meschberger1c336462008-06-19 11:08:47 +0000308 }
Felix Meschberger1c336462008-06-19 11:08:47 +0000309 }
310 else
311 {
312 // no status, dataEntry has been removed/uninstalled
313 var span = document.getElementById('entry' + id);
314 if (span)
315 {
316 span.parentNode.removeChild(span);
317 }
318 var span = document.getElementById('entry' + id + '_details');
319 if (span)
320 {
321 span.parentNode.removeChild(span);
322 }
323 }
324 }
325}
326
327