blob: be87a8e9df6645e6c6df05f3e6d06ee74e9da2ae [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
Carsten Ziegelerd0a6f362008-08-20 12:54:13 +000018function header( /* int */ columns )
19{
20 document.write( "<table class='content' cellpadding='0' cellspacing='0' width='100%'>" );
21
22 document.write( "<tr class='content'>" );
23 document.write( "<td colspan='" + columns + "' class='content'>&nbsp;</th>" );
24 document.write( "</tr>" );
25
26 document.write( "<tr class='content'>" );
27 document.write( "<th class='content'>Name</th>" );
28 document.write( "<th class='content' width='100%'>Details</th>" );
29 document.write( "<th class='content'>Version</th>" );
30 document.write( "<th class='content' colspan='" + (columns - 3) + "'>Actions</th>" );
31 document.write( "</tr>" );
32
33}
34
35
36function error( /* int */ columns, /* String */ message )
37{
38 document.write( "<tr class='content'>" );
39 document.write( "<td class='content'>&nbsp;</td>" );
40 document.write( "<td class='content' colspan='" + (columns - 1) + "'>" + message + "</td>" );
41 document.write( "</tr>" );
42}
43
44
45function data( /* Array of Object */ dataArray )
46{
47 // render components
48 if (dataArray.length == 1)
49 {
50 entry( dataArray[0], true );
51 }
52 else {
53 for ( var idx in dataArray )
54 {
55 entry( dataArray[idx] );
56 }
57 }
58}
59
60
61function footer( /* int */ columns )
62{
63 document.write( "<tr class='content'>" );
64 document.write( "<td colspan='" + columns + "' class='content'>&nbsp;</th>" );
65 document.write( "</tr>" );
66
67 document.write( "</table>" );
68}
69
70
71function entry( /* Object */ dataEntry, /* boolean */ singleEntry )
72{
73 var trElement = tr( null, { id: "entry" + dataEntry.id } );
74 entryInternal( trElement, dataEntry, singleEntry );
75 document.write( serialize( trElement ) );
76
77 // dataEntry detailed properties
78 trElement = tr( null, { id: "entry" + dataEntry.id + "_details" } );
79 if (dataEntry.props)
80 {
81 getDataEntryDetails( trElement, dataEntry.props );
82 }
83 document.write( serialize( trElement ) );
84}
85
86
87function entryInternal( /* Element */ parent, /* Object */ dataEntry, /* boolean */ singleEntry )
88{
89
90 var id = dataEntry.id;
91 var name = dataEntry.name;
92 var state = dataEntry.state;
93 var icon = singleEntry ? "left" : (dataEntry.props ? "down" : "right");
94 var event = singleEntry ? "history.back()" : "showDataEntryDetails(" + id + ")";
95
96 parent.appendChild( td( "content right", null, [ text( id ) ] ) );
97
98 parent.appendChild( td( "content", null, [
99 createElement( "img", null, {
100 src: appRoot + "/res/imgs/" + icon + ".gif",
101 onClick: event,
102 id: "entry" + id + "_inline"
103 } ),
104 text( "\u00a0" ),
105 createElement( "a", null, {
106 href: pluginRoot + "/" + id
107 }, [ text( name ) ]
108 )]
109 )
110 );
111
112 parent.appendChild( td( "content center", null, [ text( state ) ] ) );
113
114 for ( var aidx in dataEntry.actions )
115 {
116 var action = dataEntry.actions[aidx];
117 parent.appendChild( actionButton( action.enabled, id, action.link, action.name ) );
118 }
119}
120
121
122/* Element */ function actionButton( /* boolean */ enabled, /* long */ id, /* String */ op, /* String */ opLabel )
123{
124 var buttonTd = td( "content", { align: "right" } );
125 if ( op )
126 {
127 var input = createElement( "input", "submit", {
128 type: 'button',
129 value: opLabel,
130 onClick: 'changeDataEntryState("' + id + '", "' + op + '");'
131 });
132 if (!enabled)
133 {
134 input.setAttribute( "disabled", true );
135 }
136 buttonTd.appendChild( input );
137 }
138 else
139 {
140 addText( buttonTd, "\u00a0" );
141 }
142
143 return buttonTd;
144}
145
146
147function getDataEntryDetails( /* Element */ parent, /* Array of Object */ details )
148{
149 parent.appendChild( addText( td( "content"), "\u00a0" ) );
150
151 var tdEl = td( "content", { colspan: 4 } );
152 parent.appendChild( tdEl );
153
154 var tableEl = createElement( "table", null, { border: 0 } );
155 tdEl.appendChild( tableEl );
156
157 var tbody = createElement( "tbody" );
158 tableEl.appendChild( tbody );
159 for (var idx in details)
160 {
161 var prop = details[idx];
162
163
164 var trEl = tr();
165 trEl.appendChild( addText( td( "aligntop", { noWrap: true } ), prop.key ) );
166
167 var proptd = td( "aligntop" );
168 trEl.appendChild( proptd );
169
170 if (prop.value )
171 {
172 var values = new String( prop.value ).split( "<br />" );
173 for (var i=0; i < values.length; i++)
174 {
175 if (i > 0) { proptd.appendChild( createElement( "br" ) ); }
176 addText( proptd, values[i] );
177 }
178 }
179 else
180 {
181 addText( proptd, "\u00a0" );
182 }
183
184 tbody.appendChild( trEl );
185 }
186 }
187
188
189function showDetails(bundleId)
190{
191 var span = document.getElementById('bundle' + bundleId + '_details');
192}
193
194
195function showDataEntryDetails( id )
196{
197 var span = document.getElementById( 'entry' + id + '_details' );
198 if (span)
199 {
200 if (span.firstChild)
201 {
202 clearChildren( span );
203 newLinkValue( id, appRoot + "/res/imgs/right.gif" );
204 }
205 else
206 {
207 sendRequest( 'POST', pluginRoot + '/' + id, displayDataEntryDetails );
208 newLinkValue( id, appRoot + "/res/imgs/down.gif" );
209 }
210 }
211}
212
213
214function newLinkValue( /* long */ id, /* String */ newLinkValue )
215{
216
217 var link = document.getElementById( "entry" + id + "_inline" );
218 if (link)
219 {
220 link.src = newLinkValue;
221 }
222}
223
224
225function displayDataEntryDetails( obj )
226{
227 var span = document.getElementById('entry' + obj.id + '_details');
228 if (span)
229 {
230 clearChildren( span );
231 getDataEntryDetails( span, obj.props );
232 }
233
234}
235
236
237function changeDataEntryState(/* long */ id, /* String */ action)
238{
239 var parm = pluginRoot + "/" + id + "?action=" + action;
240 sendRequest('POST', parm, dataEntryStateChanged);
241}
242
243
244function dataEntryStateChanged(obj)
245{
246 if (obj.reload)
247 {
248 document.location = document.location;
249 }
250 else
251 {
252 var id = obj.id;
253 if (obj.state)
254 {
255 // has status, so draw the line
256 if (obj.props)
257 {
258 var span = document.getElementById('entry' + id + '_details');
259 if (span && span.firstChild)
260 {
261 clearChildren( span );
262 getDataEntryDetails( span, obj.props );
263 }
264 else
265 {
266 obj.props = false;
267 }
268 }
269
270 var span = document.getElementById('entry' + id);
271 if (span)
272 {
273 clearChildren( span );
274 entryInternal( span, obj );
275 }
276 }
277 else
278 {
279 // no status, dataEntry has been removed/uninstalled
280 var span = document.getElementById('entry' + id);
281 if (span)
282 {
283 span.parentNode.removeChild(span);
284 }
285 var span = document.getElementById('entry' + id + '_details');
286 if (span)
287 {
288 span.parentNode.removeChild(span);
289 }
290 }
291 }
292}
293
294function renderPackage( /* Array of Data Objects */ bundleData )
295{
296
297 // number of actions plus 3 -- id, name and state
298 var columns = 4;
299
300 header( columns );
301
302 installForm( );
303
304 if (bundleData.error)
305 {
306 error( columns, bundleData.error );
307 }
308 else
309 {
310 data ( bundleData.data );
311 }
312
313 installForm( );
314
315 footer( columns );
316}
317
318function installForm( )
319{
320 document.write( "<form method='post' enctype='multipart/form-data'>" );
321 document.write( "<tr class='content'>" );
322 document.write( "<td class='content'>&nbsp;</td>" );
323 document.write( "<td class='content'>" );
324 document.write( "<input type='hidden' name='action' value='deploydp' />" );
325 document.write( "<input class='input' type='file' name='pckfile' size='50'>" );
326 document.write( "</td>" );
327 document.write( "<td class='content' align='right' colspan='5' noWrap>" );
328 document.write( "<input class='submit' style='width:auto' type='submit' value='Install or Update'>" );
329 document.write( "</td>" );
330 document.write( "</tr>" );
331 document.write( "</form>" );
332}