blob: cef5de4ac815dc9e319eefcd7602ad76106b6cae [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 */
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000017function renderStatusLine() {
18 $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" );
Felix Meschberger4c664132008-06-02 13:52:15 +000019}
20
Carsten Ziegeler1001af12009-03-05 16:38:26 +000021function renderView( /* Array of String */ columns, /* String */ buttons ) {
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000022 renderStatusLine();
23 renderButtons(buttons);
Carsten Ziegeler1001af12009-03-05 16:38:26 +000024 var txt = "<div class='table'><table id='plugin_table' class='tablelayout'><thead><tr>";
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000025 for ( var name in columns ) {
26 txt = txt + "<th class='col_" + columns[name] + "'>" + columns[name] + "</th>";
27 }
28 txt = txt + "</tr></thead><tbody></tbody></table></div>";
29 $("#plugin_content").append( txt );
30 renderButtons(buttons);
31 renderStatusLine();
32}
33
34function renderButtons( buttons ) {
Carsten Ziegeler83fbe442009-02-09 20:48:31 +000035 $("#plugin_content").append( "<form method='post' enctype='multipart/form-data'><div class='fullwidth'><div class='buttons'>" +
36 buttons + "</div></div></form>" );
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000037}
38
39function renderData( eventData ) {
40 $(".statusline").empty().append(eventData.status);
Carsten Ziegeler1001af12009-03-05 16:38:26 +000041 $("#plugin_table > tbody > tr").remove();
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000042 for ( var idx in eventData.data ) {
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +000043 if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) {
44 entry( eventData.data[idx] );
45 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000046 }
Carsten Ziegeler1001af12009-03-05 16:38:26 +000047 $("#plugin_table").trigger("update");
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +000048 if ( drawDetails && eventData.data.length == 1 ) {
49 renderDetails(eventData.data[0]);
50 } else if ( currentBundle != null ) {
51 var id = currentBundle;
52 hideDetails(id);
53 showDetails(id);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000054 }
55}
56
57function entry( /* Object */ dataEntry ) {
58 var trElement = tr( null, { id: "entry" + dataEntry.id } );
59 entryInternal( trElement, dataEntry );
Carsten Ziegeler1001af12009-03-05 16:38:26 +000060 $("#plugin_table > tbody").append(trElement);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000061}
62
63function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action ) {
Carsten Ziegeler2cd07422009-04-27 20:35:53 +000064 if ( !action.enabled ) {
65 return;
66 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000067 var enabled = action.enabled;
68 var op = action.link;
69 var opLabel = action.name;
70 var img = action.image;
71
72 var input = createElement( "input", null, {
73 type: 'image',
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000074 style: {"margin-left": "10px"},
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000075 title: opLabel,
76 alt: opLabel,
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000077 src: imgRoot + '/bundle_' + img + '.png'
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000078 });
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000079 $(input).click(function() {changeDataEntryState(id, op)});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000080
81 if (!enabled) {
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000082 $(input).attr("disabled", true);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000083 }
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000084 parent.appendChild( input );
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000085}
86
87function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
88 var id = dataEntry.id;
89 var name = dataEntry.name;
90 var state = dataEntry.state;
91
92 var inputElement = createElement("img", "rightButton", {
93 src: appRoot + "/res/imgs/arrow_right.png",
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000094 style: {border: "none"},
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000095 id: 'img' + id,
Carsten Ziegeler83fbe442009-02-09 20:48:31 +000096 title: "Details",
97 alt: "Details",
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000098 width: 14,
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000099 height: 14
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000100 });
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000101 $(inputElement).click(function() {showDetails(id)});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000102 var titleElement;
103 if ( drawDetails ) {
104 titleElement = text(name);
105 } else {
106 titleElement = createElement ("a", null, {
107 href: window.location.pathname + "/" + id
108 });
109 titleElement.appendChild(text(name));
110 }
111
112 parent.appendChild( td( null, null, [ text( id ) ] ) );
113 parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) );
Carsten Ziegelerca26b522009-04-27 20:45:09 +0000114 parent.appendChild( td( null, null, [ text( dataEntry.version ) ] ) );
115 parent.appendChild( td( null, null, [ text( dataEntry.symbolicName ) ] ) );
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000116 parent.appendChild( td( null, null, [ text( state ) ] ) );
117 var actionsTd = td( null, null );
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000118 var div = createElement("div", null, {
119 style: { "text-align" : "left"}
120 });
121 actionsTd.appendChild(div);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000122
123 for ( var a in dataEntry.actions ) {
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000124 actionButton( div, id, dataEntry.actions[a] );
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000125 }
126 parent.appendChild( actionsTd );
127}
128
129function loadData() {
130 $.get(pluginRoot + "/.json", null, function(data) {
131 renderData(data);
132 }, "json");
133}
134
135function changeDataEntryState(/* long */ id, /* String */ action) {
136 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
137 renderData(data);
138 }, "json");
139}
140
141function refreshPackages() {
142 $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) {
143 renderData(data);
144 }, "json");
145}
146
147function showDetails( id ) {
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +0000148 currentBundle = id;
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000149 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +0000150 renderDetails(data.data[0]);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000151 }, "json");
152}
153
154function hideDetails( id ) {
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +0000155 currentBundle = null;
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000156 $("#img" + id).each(function() {
Felix Meschberger16dd9882010-02-18 08:08:47 +0000157 $("#pluginInlineDetails" + id).remove();
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000158 $(this).attr("src", appRoot + "/res/imgs/arrow_right.png");
159 $(this).attr("title", "Details");
160 $(this).attr("alt", "Details");
161 $(this).unbind('click').click(function() {showDetails(id)});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000162 });
163}
164
165function renderDetails( data ) {
Felix Meschberger16dd9882010-02-18 08:08:47 +0000166 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000167 $("#img" + data.id).each(function() {
168 if ( drawDetails ) {
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000169 $(this).attr("src", appRoot + "/res/imgs/arrow_left.png");
170 $(this).attr("title", "Back");
171 $(this).attr("alt", "Back");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000172 var ref = window.location.pathname;
173 ref = ref.substring(0, ref.lastIndexOf('/'));
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000174 $(this).unbind('click').click(function() {window.location = ref;});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000175 } else {
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000176 $(this).attr("src", appRoot + "/res/imgs/arrow_down.png");
177 $(this).attr("title", "Hide Details");
178 $(this).attr("alt", "Hide Details");
179 $(this).unbind('click').click(function() {hideDetails(data.id)});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000180 }
181 });
Felix Meschberger16dd9882010-02-18 08:08:47 +0000182 $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000183 var details = data.props;
184 for (var idx in details) {
185 var prop = details[idx];
186
187 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + prop.key + "</td><td class='aligntop' style='border:0px none'>";
188 if (prop.value) {
189 if ( prop.key == 'Bundle Documentation' ) {
190 txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>";
191 } else {
192 if ( $.isArray(prop.value) ) {
193 var i = 0;
194 for(var pi in prop.value) {
195 var value = prop.value[pi];
196 if (i > 0) { txt = txt + "<br/>"; }
197 var span;
Carsten Ziegelera9a7af82009-02-10 14:18:21 +0000198 if (value.substring(0, 6) == "INFO: ") {
199 txt = txt + "<span style='color: grey;'>!!" + value.substring(5) + "</span>";
200 } else if (value.substring(0, 7) == "ERROR: ") {
201 txt = txt + "<span style='color: red;'>!!" + value.substring(6) + "</span>";
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000202 } else {
203 txt = txt + value;
204 }
205 i++;
206 }
207 } else {
208 txt = txt + prop.value;
209 }
210 }
211 } else {
212 txt = txt + "\u00a0";
213 }
214 txt = txt + "</td></tr>";
Felix Meschberger16dd9882010-02-18 08:08:47 +0000215 $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000216 }
217}
218
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000219function renderBundles(data) {
220 $(document).ready(function(){
Carsten Ziegelerca26b522009-04-27 20:45:09 +0000221 renderView( ["Id", "Name", "Version", "Symbolic Name", "Status", "Actions"],
Carsten Ziegeler52558d12009-02-05 19:56:36 +0000222 "<input type='hidden' name='action' value='install'/>" +
Carsten Ziegeler60b9b352009-06-11 13:57:46 +0000223 "<input type='hidden' name='bundlestart' value='start'/>" +
224 "<input type='hidden' name='bundlestartlevel' value='" + startLevel + "'/>" +
Carsten Ziegelera308d932009-02-05 20:02:07 +0000225 "<input class='fileinput' type='file' name='bundlefile' style='margin-left:10px'/>" +
Carsten Ziegeler60b9b352009-06-11 13:57:46 +0000226 "<input type='submit' value='Install or Update' style='margin-left:10px'/>" +
227 "<button class='reloadButton' type='button' name='reload' style='margin-left:60px'>Reload</button>" +
228 "<button class='installButton' type='button' name='install'>Install/Update...</button>" +
229 "<button class='refreshPackages' type='button' name='refresh'>Refresh Packages</button>"
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000230 );
Carsten Ziegeler60b9b352009-06-11 13:57:46 +0000231 $(".refreshPackages").click(refreshPackages);
232 $(".reloadButton").click(loadData);
233 $(".installButton").click(function() {
234 document.location = pluginRoot + "/upload";
235 });
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000236 renderData(data);
237
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000238 var extractMethod = function(node) {
239 var link = node.getElementsByTagName("a");
240 if ( link && link.length == 1 ) {
241 return link[0].innerHTML;
242 }
243 return node.innerHTML;
244 };
Carsten Ziegelerfd233102009-12-11 10:56:15 +0000245 // check for cookie
246 var cv = $.cookies.get("webconsolebundlelist");
247 var lo = (cv ? cv.split(",") : [1,0]);
Carsten Ziegeler1001af12009-03-05 16:38:26 +0000248 $("#plugin_table").tablesorter({
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000249 headers: {
250 0: { sorter:"digit"},
Carsten Ziegelerca26b522009-04-27 20:45:09 +0000251 5: { sorter: false }
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000252 },
Carsten Ziegelercefffcb2010-01-26 12:59:54 +0000253 sortList: [lo],
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000254 textExtraction:extractMethod
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000255 });
Carsten Ziegelerfd233102009-12-11 10:56:15 +0000256 $("#plugin_table").bind("sortEnd", function() {
257 var table = $("#plugin_table").eq(0).attr("config");
258 $.cookies.set("webconsolebundlelist", table.sortList.toString());
259 });
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000260 });
Felix Meschberger4c664132008-06-02 13:52:15 +0000261}