blob: 2a895b726898a669c41583147a1a389651796fda [file] [log] [blame]
Carsten Ziegelerd0a6f362008-08-20 12:54:13 +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'>Name</th>" );
48 document.write( "<th class='content' width='100%'>Details</th>" );
49 document.write( "<th class='content'>Version</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 if (dataArray.length == 1)
69 {
70 entry( dataArray[0], true );
71 }
72 else {
73 for ( var idx in dataArray )
74 {
75 entry( dataArray[idx] );
76 }
77 }
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
91function entry( /* Object */ dataEntry, /* boolean */ singleEntry )
92{
93 var trElement = tr( null, { id: "entry" + dataEntry.id } );
94 entryInternal( trElement, dataEntry, singleEntry );
95 document.write( serialize( trElement ) );
96
97 // dataEntry detailed properties
98 trElement = tr( null, { id: "entry" + dataEntry.id + "_details" } );
99 if (dataEntry.props)
100 {
101 getDataEntryDetails( trElement, dataEntry.props );
102 }
103 document.write( serialize( trElement ) );
104}
105
106
107function entryInternal( /* Element */ parent, /* Object */ dataEntry, /* boolean */ singleEntry )
108{
109
110 var id = dataEntry.id;
111 var name = dataEntry.name;
112 var state = dataEntry.state;
113 var icon = singleEntry ? "left" : (dataEntry.props ? "down" : "right");
114 var event = singleEntry ? "history.back()" : "showDataEntryDetails(" + id + ")";
115
116 parent.appendChild( td( "content right", null, [ text( id ) ] ) );
117
118 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 );
131
132 parent.appendChild( td( "content center", null, [ text( state ) ] ) );
133
134 for ( var aidx in dataEntry.actions )
135 {
136 var action = dataEntry.actions[aidx];
137 parent.appendChild( actionButton( action.enabled, id, action.link, action.name ) );
138 }
139}
140
141
142/* Element */ function actionButton( /* boolean */ enabled, /* long */ id, /* String */ op, /* String */ opLabel )
143{
144 var buttonTd = td( "content", { align: "right" } );
145 if ( op )
146 {
147 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 }
156 buttonTd.appendChild( input );
157 }
158 else
159 {
160 addText( buttonTd, "\u00a0" );
161 }
162
163 return buttonTd;
164}
165
166
167function getDataEntryDetails( /* Element */ parent, /* Array of Object */ details )
168{
169 parent.appendChild( addText( td( "content"), "\u00a0" ) );
170
171 var tdEl = td( "content", { colspan: 4 } );
172 parent.appendChild( tdEl );
173
174 var tableEl = createElement( "table", null, { border: 0 } );
175 tdEl.appendChild( tableEl );
176
177 var tbody = createElement( "tbody" );
178 tableEl.appendChild( tbody );
179 for (var idx in details)
180 {
181 var prop = details[idx];
182
183
184 var trEl = tr();
185 trEl.appendChild( addText( td( "aligntop", { noWrap: true } ), prop.key ) );
186
187 var proptd = td( "aligntop" );
188 trEl.appendChild( proptd );
189
190 if (prop.value )
191 {
192 var values = new String( prop.value ).split( "<br />" );
193 for (var i=0; i < values.length; i++)
194 {
195 if (i > 0) { proptd.appendChild( createElement( "br" ) ); }
196 addText( proptd, values[i] );
197 }
198 }
199 else
200 {
201 addText( proptd, "\u00a0" );
202 }
203
204 tbody.appendChild( trEl );
205 }
206 }
207
208
209function showDetails(bundleId)
210{
211 var span = document.getElementById('bundle' + bundleId + '_details');
212}
213
214
215function showDataEntryDetails( id )
216{
217 var span = document.getElementById( 'entry' + id + '_details' );
218 if (span)
219 {
220 if (span.firstChild)
221 {
222 clearChildren( span );
223 newLinkValue( id, appRoot + "/res/imgs/right.gif" );
224 }
225 else
226 {
227 sendRequest( 'POST', pluginRoot + '/' + id, displayDataEntryDetails );
228 newLinkValue( id, appRoot + "/res/imgs/down.gif" );
229 }
230 }
231}
232
233
234function newLinkValue( /* long */ id, /* String */ newLinkValue )
235{
236
237 var link = document.getElementById( "entry" + id + "_inline" );
238 if (link)
239 {
240 link.src = newLinkValue;
241 }
242}
243
244
245function displayDataEntryDetails( obj )
246{
247 var span = document.getElementById('entry' + obj.id + '_details');
248 if (span)
249 {
250 clearChildren( span );
251 getDataEntryDetails( span, obj.props );
252 }
253
254}
255
256
257function changeDataEntryState(/* long */ id, /* String */ action)
258{
259 var parm = pluginRoot + "/" + id + "?action=" + action;
260 sendRequest('POST', parm, dataEntryStateChanged);
261}
262
263
264function dataEntryStateChanged(obj)
265{
266 if (obj.reload)
267 {
268 document.location = document.location;
269 }
270 else
271 {
272 var id = obj.id;
273 if (obj.state)
274 {
275 // has status, so draw the line
276 if (obj.props)
277 {
278 var span = document.getElementById('entry' + id + '_details');
279 if (span && span.firstChild)
280 {
281 clearChildren( span );
282 getDataEntryDetails( span, obj.props );
283 }
284 else
285 {
286 obj.props = false;
287 }
288 }
289
290 var span = document.getElementById('entry' + id);
291 if (span)
292 {
293 clearChildren( span );
294 entryInternal( span, obj );
295 }
296 }
297 else
298 {
299 // no status, dataEntry has been removed/uninstalled
300 var span = document.getElementById('entry' + id);
301 if (span)
302 {
303 span.parentNode.removeChild(span);
304 }
305 var span = document.getElementById('entry' + id + '_details');
306 if (span)
307 {
308 span.parentNode.removeChild(span);
309 }
310 }
311 }
312}
313
314function renderPackage( /* Array of Data Objects */ bundleData )
315{
316
317 // number of actions plus 3 -- id, name and state
318 var columns = 4;
319
320 header( columns );
321
322 installForm( );
323
324 if (bundleData.error)
325 {
326 error( columns, bundleData.error );
327 }
328 else
329 {
330 data ( bundleData.data );
331 }
332
333 installForm( );
334
335 footer( columns );
336}
337
338function installForm( )
339{
340 document.write( "<form method='post' enctype='multipart/form-data'>" );
341 document.write( "<tr class='content'>" );
342 document.write( "<td class='content'>&nbsp;</td>" );
343 document.write( "<td class='content'>" );
344 document.write( "<input type='hidden' name='action' value='deploydp' />" );
345 document.write( "<input class='input' type='file' name='pckfile' size='50'>" );
346 document.write( "</td>" );
347 document.write( "<td class='content' align='right' colspan='5' noWrap>" );
348 document.write( "<input class='submit' style='width:auto' type='submit' value='Install or Update'>" );
349 document.write( "</td>" );
350 document.write( "</tr>" );
351 document.write( "</form>" );
352}