blob: 537577fdd4b9c4a120f235d5a9300bd7f59ee3ed [file] [log] [blame]
Felix Meschberger4c664132008-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;" );
138 document.write( "<input class='submit' style='width:auto' type='submit' value='Refresh Packages' onClick='this.form.action.value=\"refreshPackages\"; return true;'>" );
139 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{
154 var bundleId = obj.bundleId;
155 if (obj.state)
156 {
157 // has status, so draw the line
158 var span = document.getElementById('bundle' + bundleId);
159 if (span)
160 {
161 span.innerHTML = bundleInternal( obj );
162 }
163
164 if (obj.props)
165 {
166 var span = document.getElementById('bundle' + bundleId + '_details');
167 if (span && span.innerHTML)
168 {
169 span.innerHTML = bundleDetails( obj.props );
170 }
171 }
172
173 }
174 else
175 {
176 // no status, bundle has been uninstalled
177 var span = document.getElementById('bundle' + bundleId);
178 if (span)
179 {
180 span.parentNode.removeChild(span);
181 }
182 var span = document.getElementById('bundle' + bundleId + '_details');
183 if (span)
184 {
185 span.parentNode.removeChild(span);
186 }
187 }
188
189 // reload --- should do better and only update the bundle
190 // document.location = document.location;
191}
192
193
194function showDetails(bundleId) {
195 var span = document.getElementById('bundle' + bundleId + '_details');
196 if (span)
197 {
198 if (span.innerHTML)
199 {
200 span.innerHTML = '';
201 }
202 else
203 {
204 sendRequest('GET', "bundles/" + bundleId + ".json", displayBundleDetails);
205 }
206 }
207}
208
209
210function displayBundleDetails(obj) {
211 var span = document.getElementById('bundle' + obj.bundleId + '_details');
212 if (span)
213 {
214 span.innerHTML = bundleDetails( obj.props );
215 }
216}
217
218
219/* String */ function bundleDetails( props )
220{
221 var innerHtml = '<td class=\"content\">&nbsp;</td><td class=\"content\" colspan=\"6\"><table broder=\"0\">';
222 for (var i=0; i < props.length; i++)
223 {
224 innerHtml += '<tr><td valign=\"top\" noWrap>' + props[i].key + '</td><td valign=\"top\">' + props[i].value + '</td></tr>';
225 }
226 innerHtml += '</table></td>';
227
228 return innerHtml;
229}
230