blob: 35ff677054193c2637dfabfff5aa61aea74b57a6 [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{
Felix Meschberger0ca87d92008-06-13 15:27:57 +000094 var icon = (bundle.props) ? "down" : "right";
Felix Meschberger4c664132008-06-02 13:52:15 +000095 var theBundle = "<td class='content right'>" + bundle.bundleId + "</td>";
Felix Meschberger0ca87d92008-06-13 15:27:57 +000096 theBundle += "<td class='content'><img src='" + appRoot + "/res/imgs/" + icon + ".gif' onClick='showDetails(" + bundle.bundleId + ")' id='bundle" + bundle.bundleId + "_inline' />";
97 theBundle += " <a href='" + appRoot + "/bundles/" + bundle.bundleId + "'>" + bundle.name + "</a></td>";
Felix Meschberger4c664132008-06-02 13:52:15 +000098 theBundle += "<td class='content center'>" + bundle.state + "</td>";
99
100 // no buttons for system bundle
101 if ( bundle.bundleId == 0 )
102 {
103 theBundle += "<td class='content' colspan='4'>&nbsp;</td>";
104 }
105 else
106 {
107 theBundle += actionForm( bundle.hasStart, bundle.bundleId, "start", "Start" );
108 theBundle += actionForm( bundle.hasStop, bundle.bundleId, "stop", "Stop" );
109 theBundle += actionForm( bundle.hasUpdate, bundle.bundleId, "update", "Update" );
110 theBundle += actionForm( bundle.hasUninstall, bundle.bundleId, "uninstall", "Uninstall" );
111 }
112
113 return theBundle;
114}
115
116
117/* String */ function actionForm( /* boolean */ enabled, /* long */ bundleId, /* String */ action, /* String */ actionLabel )
118{
119 var theButton = "<td class='content' align='right'>";
120 theButton += "<input class='submit' type='button' value='" + actionLabel + "'" + ( enabled ? "" : "disabled" ) + " onClick='changeBundle(" + bundleId + ", \"" + action + "\");' />";
121 theButton += "</td>";
122 return theButton;
123}
124
125
126function installForm( /* int */ startLevel )
127{
128 document.write( "<form method='post' enctype='multipart/form-data'>" );
129 document.write( "<tr class='content'>" );
130 document.write( "<td class='content'>&nbsp;</td>" );
131 document.write( "<td class='content'>" );
132 document.write( "<input type='hidden' name='action' value='install' />" );
133 document.write( "<input class='input' type='file' name='bundlefile'>" );
134 document.write( " - Start <input class='checkradio' type='checkbox' name='bundlestart' value='start'>" );
135 document.write( " - Start Level <input class='input' type='input' name='bundlestartelevel' value='" + startLevel + "' width='4'>" );
136 document.write( "</td>" );
137 document.write( "<td class='content' align='right' colspan='5' noWrap>" );
138 document.write( "<input class='submit' style='width:auto' type='submit' value='Install or Update'>" );
139 document.write( "&nbsp;" );
Felix Meschbergerc2af07c2008-06-12 22:18:03 +0000140 document.write( "<input class='submit' style='width:auto' type='button' value='Refresh Packages' onClick='changeBundle(0, \"refreshPackages\");'>" );
Felix Meschberger4c664132008-06-02 13:52:15 +0000141 document.write( "</td>" );
142 document.write( "</tr>" );
143 document.write( "</form>" );
144}
145
146
147function changeBundle(/* long */ bundleId, /* String */ action)
148{
149 var parm = "bundles/" + bundleId + "?action=" + action;
150 sendRequest('POST', parm, bundleChanged);
151}
152
153
154function bundleChanged(obj)
155{
Felix Meschbergerc2af07c2008-06-12 22:18:03 +0000156 if (obj.reload)
Felix Meschberger4c664132008-06-02 13:52:15 +0000157 {
Felix Meschbergerc2af07c2008-06-12 22:18:03 +0000158 document.location = document.location;
Felix Meschberger4c664132008-06-02 13:52:15 +0000159 }
160 else
161 {
Felix Meschbergerc2af07c2008-06-12 22:18:03 +0000162 var bundleId = obj.bundleId;
163 if (obj.state)
Felix Meschberger4c664132008-06-02 13:52:15 +0000164 {
Felix Meschbergerc2af07c2008-06-12 22:18:03 +0000165 // has status, so draw the line
166 var span = document.getElementById('bundle' + bundleId);
167 if (span)
168 {
169 span.innerHTML = bundleInternal( obj );
170 }
171
172 if (obj.props)
173 {
174 var span = document.getElementById('bundle' + bundleId + '_details');
175 if (span && span.innerHTML)
176 {
177 span.innerHTML = bundleDetails( obj.props );
178 }
179 }
180
Felix Meschberger4c664132008-06-02 13:52:15 +0000181 }
Felix Meschbergerc2af07c2008-06-12 22:18:03 +0000182 else
Felix Meschberger4c664132008-06-02 13:52:15 +0000183 {
Felix Meschbergerc2af07c2008-06-12 22:18:03 +0000184 // no status, bundle has been uninstalled
185 var span = document.getElementById('bundle' + bundleId);
186 if (span)
187 {
188 span.parentNode.removeChild(span);
189 }
190 var span = document.getElementById('bundle' + bundleId + '_details');
191 if (span)
192 {
193 span.parentNode.removeChild(span);
194 }
Felix Meschberger4c664132008-06-02 13:52:15 +0000195 }
Felix Meschbergerc2af07c2008-06-12 22:18:03 +0000196 }
Felix Meschberger4c664132008-06-02 13:52:15 +0000197}
198
199
200function showDetails(bundleId) {
201 var span = document.getElementById('bundle' + bundleId + '_details');
202 if (span)
203 {
204 if (span.innerHTML)
205 {
206 span.innerHTML = '';
Felix Meschberger0ca87d92008-06-13 15:27:57 +0000207 newLinkValue(bundleId, appRoot + "/res/imgs/right.gif");
Felix Meschberger4c664132008-06-02 13:52:15 +0000208 }
209 else
210 {
Felix Meschberger0ca87d92008-06-13 15:27:57 +0000211 sendRequest('GET', appRoot + "/bundles/" + bundleId + ".json", displayBundleDetails);
212 newLinkValue(bundleId, appRoot + "/res/imgs/down.gif");
Felix Meschberger4c664132008-06-02 13:52:15 +0000213 }
214 }
215}
216
217
218function displayBundleDetails(obj) {
219 var span = document.getElementById('bundle' + obj.bundleId + '_details');
220 if (span)
221 {
222 span.innerHTML = bundleDetails( obj.props );
223 }
224}
225
226
Felix Meschberger0ca87d92008-06-13 15:27:57 +0000227function newLinkValue(bundleId, newLinkValue)
228{
229
230 var link = document.getElementById("bundle" + bundleId + "_inline");
231 if (link)
232 {
233 link.src = newLinkValue;
234 }
235}
236
237
Felix Meschberger4c664132008-06-02 13:52:15 +0000238/* String */ function bundleDetails( props )
239{
240 var innerHtml = '<td class=\"content\">&nbsp;</td><td class=\"content\" colspan=\"6\"><table broder=\"0\">';
241 for (var i=0; i < props.length; i++)
242 {
243 innerHtml += '<tr><td valign=\"top\" noWrap>' + props[i].key + '</td><td valign=\"top\">' + props[i].value + '</td></tr>';
244 }
245 innerHtml += '</table></td>';
246
247 return innerHtml;
248}
249