blob: 07efab4ac87ebd0b19591bbb48597a24b5da6500 [file] [log] [blame]
Felix Meschberger9b3c4e02008-06-02 13:52:15 +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 render(/* int */ startlevel, /* Array of Bundle Object */ bundles)
19{
20
21 header();
22
23 installForm( startlevel );
24
25 document.write( "<tr class='content'>" );
26 document.write( "<td colspan='7' class='content'>&nbsp;</th>" );
27 document.write( "</tr>" );
28
29 tableHeader();
30
31 if ( !bundles )
32 {
33 document.write( "<tr class='content'>" );
34 document.write( "<td class='content' colspan='6'>No Bundles installed currently</td>" );
35 document.write( "</tr>" );
36 }
37 else
38 {
39 for ( var i = 0; i < bundles.length; i++ )
40 {
41 bundle( bundles[i] );
42 }
43 }
44
45 document.write( "<tr class='content'>" );
46 document.write( "<td colspan='7' class='content'>&nbsp;</th>" );
47 document.write( "</tr>" );
48
49 installForm( startlevel );
50
51 footer();
52}
53
54
55function header()
56{
57 document.write( "<table class='content' cellpadding='0' cellspacing='0' width='100%'>" );
58}
59
60
61function tableHeader()
62{
63 document.write( "<tr class='content'>" );
64 document.write( "<th class='content'>ID</th>" );
65 document.write( "<th class='content' width='100%'>Name</th>" );
66 document.write( "<th class='content'>Status</th>" );
67 document.write( "<th class='content' colspan='4'>Actions</th>" );
68 document.write( "</tr>" );
69}
70
71
72function footer()
73{
74 document.write( "</table>" );
75}
76
77
78function bundle( /* Bundle */ bundle )
79{
80 document.write( "<tr id='bundle" + bundle.bundleId + "'>" );
81 document.write( bundleInternal( bundle ) );
82 document.write( "</tr>" );
83 document.write( "<tr id='bundle" + bundle.bundleId + "_details'>" );
84 if (bundle.props)
85 {
86 document.write( bundleDetails( bundle.props ) );
87 }
88 document.write( "</tr>" );
89}
90
91
92/* String */ function bundleInternal( /* Bundle */ bundle )
93{
94 var theBundle = "<td class='content right'>" + bundle.bundleId + "</td>";
95 theBundle += "<td class='content'><a href='javascript:showDetails(" + bundle.bundleId + ")'>" + bundle.name + "</a></td>";
96 theBundle += "<td class='content center'>" + bundle.state + "</td>";
97
98 // no buttons for system bundle
99 if ( bundle.bundleId == 0 )
100 {
101 theBundle += "<td class='content' colspan='4'>&nbsp;</td>";
102 }
103 else
104 {
105 theBundle += actionForm( bundle.hasStart, bundle.bundleId, "start", "Start" );
106 theBundle += actionForm( bundle.hasStop, bundle.bundleId, "stop", "Stop" );
107 theBundle += actionForm( bundle.hasUpdate, bundle.bundleId, "update", "Update" );
108 theBundle += actionForm( bundle.hasUninstall, bundle.bundleId, "uninstall", "Uninstall" );
109 }
110
111 return theBundle;
112}
113
114
115/* String */ function actionForm( /* boolean */ enabled, /* long */ bundleId, /* String */ action, /* String */ actionLabel )
116{
117 var theButton = "<td class='content' align='right'>";
118 theButton += "<input class='submit' type='button' value='" + actionLabel + "'" + ( enabled ? "" : "disabled" ) + " onClick='changeBundle(" + bundleId + ", \"" + action + "\");' />";
119 theButton += "</td>";
120 return theButton;
121}
122
123
124function installForm( /* int */ startLevel )
125{
126 document.write( "<form method='post' enctype='multipart/form-data'>" );
127 document.write( "<tr class='content'>" );
128 document.write( "<td class='content'>&nbsp;</td>" );
129 document.write( "<td class='content'>" );
130 document.write( "<input type='hidden' name='action' value='install' />" );
131 document.write( "<input class='input' type='file' name='bundlefile'>" );
132 document.write( " - Start <input class='checkradio' type='checkbox' name='bundlestart' value='start'>" );
133 document.write( " - Start Level <input class='input' type='input' name='bundlestartelevel' value='" + startLevel + "' width='4'>" );
134 document.write( "</td>" );
135 document.write( "<td class='content' align='right' colspan='5' noWrap>" );
136 document.write( "<input class='submit' style='width:auto' type='submit' value='Install or Update'>" );
137 document.write( "&nbsp;" );
Felix Meschbergerfbdec452008-06-12 22:18:03 +0000138 document.write( "<input class='submit' style='width:auto' type='button' value='Refresh Packages' onClick='changeBundle(0, \"refreshPackages\");'>" );
Felix Meschberger9b3c4e02008-06-02 13:52:15 +0000139 document.write( "</td>" );
140 document.write( "</tr>" );
141 document.write( "</form>" );
142}
143
144
145function changeBundle(/* long */ bundleId, /* String */ action)
146{
147 var parm = "bundles/" + bundleId + "?action=" + action;
148 sendRequest('POST', parm, bundleChanged);
149}
150
151
152function bundleChanged(obj)
153{
Felix Meschbergerfbdec452008-06-12 22:18:03 +0000154 if (obj.reload)
Felix Meschberger9b3c4e02008-06-02 13:52:15 +0000155 {
Felix Meschbergerfbdec452008-06-12 22:18:03 +0000156 document.location = document.location;
Felix Meschberger9b3c4e02008-06-02 13:52:15 +0000157 }
158 else
159 {
Felix Meschbergerfbdec452008-06-12 22:18:03 +0000160 var bundleId = obj.bundleId;
161 if (obj.state)
Felix Meschberger9b3c4e02008-06-02 13:52:15 +0000162 {
Felix Meschbergerfbdec452008-06-12 22:18:03 +0000163 // has status, so draw the line
164 var span = document.getElementById('bundle' + bundleId);
165 if (span)
166 {
167 span.innerHTML = bundleInternal( obj );
168 }
169
170 if (obj.props)
171 {
172 var span = document.getElementById('bundle' + bundleId + '_details');
173 if (span && span.innerHTML)
174 {
175 span.innerHTML = bundleDetails( obj.props );
176 }
177 }
178
Felix Meschberger9b3c4e02008-06-02 13:52:15 +0000179 }
Felix Meschbergerfbdec452008-06-12 22:18:03 +0000180 else
Felix Meschberger9b3c4e02008-06-02 13:52:15 +0000181 {
Felix Meschbergerfbdec452008-06-12 22:18:03 +0000182 // no status, bundle has been uninstalled
183 var span = document.getElementById('bundle' + bundleId);
184 if (span)
185 {
186 span.parentNode.removeChild(span);
187 }
188 var span = document.getElementById('bundle' + bundleId + '_details');
189 if (span)
190 {
191 span.parentNode.removeChild(span);
192 }
Felix Meschberger9b3c4e02008-06-02 13:52:15 +0000193 }
Felix Meschbergerfbdec452008-06-12 22:18:03 +0000194 }
Felix Meschberger9b3c4e02008-06-02 13:52:15 +0000195}
196
197
198function showDetails(bundleId) {
199 var span = document.getElementById('bundle' + bundleId + '_details');
200 if (span)
201 {
202 if (span.innerHTML)
203 {
204 span.innerHTML = '';
205 }
206 else
207 {
208 sendRequest('GET', "bundles/" + bundleId + ".json", displayBundleDetails);
209 }
210 }
211}
212
213
214function displayBundleDetails(obj) {
215 var span = document.getElementById('bundle' + obj.bundleId + '_details');
216 if (span)
217 {
218 span.innerHTML = bundleDetails( obj.props );
219 }
220}
221
222
223/* String */ function bundleDetails( props )
224{
225 var innerHtml = '<td class=\"content\">&nbsp;</td><td class=\"content\" colspan=\"6\"><table broder=\"0\">';
226 for (var i=0; i < props.length; i++)
227 {
228 innerHtml += '<tr><td valign=\"top\" noWrap>' + props[i].key + '</td><td valign=\"top\">' + props[i].value + '</td></tr>';
229 }
230 innerHtml += '</table></td>';
231
232 return innerHtml;
233}
234