blob: 028d8b4793257644e0b58cf638b7e2a3347e0a0e [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 */
Carsten Ziegelerf9879152009-02-05 10:45:35 +000017function renderStatusLine() {
18 $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" );
Felix Meschberger9b3c4e02008-06-02 13:52:15 +000019}
20
Carsten Ziegeler21e54022009-03-05 16:38:26 +000021function renderView( /* Array of String */ columns, /* String */ buttons ) {
Carsten Ziegelerf9879152009-02-05 10:45:35 +000022 renderStatusLine();
23 renderButtons(buttons);
Carsten Ziegeler21e54022009-03-05 16:38:26 +000024 var txt = "<div class='table'><table id='plugin_table' class='tablelayout'><thead><tr>";
Carsten Ziegelerf9879152009-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 Ziegeler7ecffce2009-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 Ziegelerf9879152009-02-05 10:45:35 +000037}
38
39function renderData( eventData ) {
40 $(".statusline").empty().append(eventData.status);
Carsten Ziegeler21e54022009-03-05 16:38:26 +000041 $("#plugin_table > tbody > tr").remove();
Carsten Ziegelerf9879152009-02-05 10:45:35 +000042 for ( var idx in eventData.data ) {
43 entry( eventData.data[idx] );
44 }
Carsten Ziegeler21e54022009-03-05 16:38:26 +000045 $("#plugin_table").trigger("update");
Carsten Ziegelerf9879152009-02-05 10:45:35 +000046 if ( drawDetails ) {
47 renderDetails(eventData);
48 }
49}
50
51function entry( /* Object */ dataEntry ) {
52 var trElement = tr( null, { id: "entry" + dataEntry.id } );
53 entryInternal( trElement, dataEntry );
Carsten Ziegeler21e54022009-03-05 16:38:26 +000054 $("#plugin_table > tbody").append(trElement);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000055}
56
57function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action ) {
Carsten Ziegelerf90898a2009-04-27 20:35:53 +000058 if ( !action.enabled ) {
59 return;
60 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +000061 var enabled = action.enabled;
62 var op = action.link;
63 var opLabel = action.name;
64 var img = action.image;
65
66 var input = createElement( "input", null, {
67 type: 'image',
Carsten Ziegeler21359442009-03-05 16:14:55 +000068 style: {"margin-left": "10px"},
Carsten Ziegelerf9879152009-02-05 10:45:35 +000069 title: opLabel,
70 alt: opLabel,
Carsten Ziegeler21359442009-03-05 16:14:55 +000071 src: imgRoot + '/bundle_' + img + '.png'
Carsten Ziegelerf9879152009-02-05 10:45:35 +000072 });
Carsten Ziegeler21359442009-03-05 16:14:55 +000073 $(input).click(function() {changeDataEntryState(id, op)});
Carsten Ziegelerf9879152009-02-05 10:45:35 +000074
75 if (!enabled) {
Carsten Ziegeler21359442009-03-05 16:14:55 +000076 $(input).attr("disabled", true);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000077 }
Carsten Ziegeler21359442009-03-05 16:14:55 +000078 parent.appendChild( input );
Carsten Ziegelerf9879152009-02-05 10:45:35 +000079}
80
81function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
82 var id = dataEntry.id;
83 var name = dataEntry.name;
84 var state = dataEntry.state;
85
86 var inputElement = createElement("img", "rightButton", {
87 src: appRoot + "/res/imgs/arrow_right.png",
Carsten Ziegeler21359442009-03-05 16:14:55 +000088 style: {border: "none"},
Carsten Ziegelerf9879152009-02-05 10:45:35 +000089 id: 'img' + id,
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000090 title: "Details",
91 alt: "Details",
Carsten Ziegelerf9879152009-02-05 10:45:35 +000092 width: 14,
Carsten Ziegeler21359442009-03-05 16:14:55 +000093 height: 14
Carsten Ziegelerf9879152009-02-05 10:45:35 +000094 });
Carsten Ziegeler21359442009-03-05 16:14:55 +000095 $(inputElement).click(function() {showDetails(id)});
Carsten Ziegelerf9879152009-02-05 10:45:35 +000096 var titleElement;
97 if ( drawDetails ) {
98 titleElement = text(name);
99 } else {
100 titleElement = createElement ("a", null, {
101 href: window.location.pathname + "/" + id
102 });
103 titleElement.appendChild(text(name));
104 }
105
106 parent.appendChild( td( null, null, [ text( id ) ] ) );
107 parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) );
Carsten Ziegeler577fac12009-04-27 20:45:09 +0000108 parent.appendChild( td( null, null, [ text( dataEntry.version ) ] ) );
109 parent.appendChild( td( null, null, [ text( dataEntry.symbolicName ) ] ) );
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000110 parent.appendChild( td( null, null, [ text( state ) ] ) );
111 var actionsTd = td( null, null );
Carsten Ziegeler21359442009-03-05 16:14:55 +0000112 var div = createElement("div", null, {
113 style: { "text-align" : "left"}
114 });
115 actionsTd.appendChild(div);
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000116
117 for ( var a in dataEntry.actions ) {
Carsten Ziegeler21359442009-03-05 16:14:55 +0000118 actionButton( div, id, dataEntry.actions[a] );
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000119 }
120 parent.appendChild( actionsTd );
121}
122
123function loadData() {
124 $.get(pluginRoot + "/.json", null, function(data) {
125 renderData(data);
126 }, "json");
127}
128
129function changeDataEntryState(/* long */ id, /* String */ action) {
130 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
131 renderData(data);
132 }, "json");
133}
134
135function refreshPackages() {
136 $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) {
137 renderData(data);
138 }, "json");
139}
140
141function showDetails( id ) {
142 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
143 renderDetails(data);
144 }, "json");
145}
146
147function hideDetails( id ) {
148 $("#img" + id).each(function() {
Carsten Ziegeler7cc941e2009-02-16 16:42:07 +0000149 $("#pluginInlineDetails").remove();
Carsten Ziegeler21359442009-03-05 16:14:55 +0000150 $(this).attr("src", appRoot + "/res/imgs/arrow_right.png");
151 $(this).attr("title", "Details");
152 $(this).attr("alt", "Details");
153 $(this).unbind('click').click(function() {showDetails(id)});
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000154 });
155}
156
157function renderDetails( data ) {
158 data = data.data[0];
Carsten Ziegeler7cc941e2009-02-16 16:42:07 +0000159 $("#pluginInlineDetails").remove();
160 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000161 $("#img" + data.id).each(function() {
162 if ( drawDetails ) {
Carsten Ziegeler21359442009-03-05 16:14:55 +0000163 $(this).attr("src", appRoot + "/res/imgs/arrow_left.png");
164 $(this).attr("title", "Back");
165 $(this).attr("alt", "Back");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000166 var ref = window.location.pathname;
167 ref = ref.substring(0, ref.lastIndexOf('/'));
Carsten Ziegeler21359442009-03-05 16:14:55 +0000168 $(this).unbind('click').click(function() {window.location = ref;});
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000169 } else {
Carsten Ziegeler21359442009-03-05 16:14:55 +0000170 $(this).attr("src", appRoot + "/res/imgs/arrow_down.png");
171 $(this).attr("title", "Hide Details");
172 $(this).attr("alt", "Hide Details");
173 $(this).unbind('click').click(function() {hideDetails(data.id)});
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000174 }
175 });
Carsten Ziegeler7cc941e2009-02-16 16:42:07 +0000176 $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000177 var details = data.props;
178 for (var idx in details) {
179 var prop = details[idx];
180
181 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + prop.key + "</td><td class='aligntop' style='border:0px none'>";
182 if (prop.value) {
183 if ( prop.key == 'Bundle Documentation' ) {
184 txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>";
185 } else {
186 if ( $.isArray(prop.value) ) {
187 var i = 0;
188 for(var pi in prop.value) {
189 var value = prop.value[pi];
190 if (i > 0) { txt = txt + "<br/>"; }
191 var span;
Carsten Ziegeler621b99f2009-02-10 14:18:21 +0000192 if (value.substring(0, 6) == "INFO: ") {
193 txt = txt + "<span style='color: grey;'>!!" + value.substring(5) + "</span>";
194 } else if (value.substring(0, 7) == "ERROR: ") {
195 txt = txt + "<span style='color: red;'>!!" + value.substring(6) + "</span>";
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000196 } else {
197 txt = txt + value;
198 }
199 i++;
200 }
201 } else {
202 txt = txt + prop.value;
203 }
204 }
205 } else {
206 txt = txt + "\u00a0";
207 }
208 txt = txt + "</td></tr>";
Carsten Ziegeler7cc941e2009-02-16 16:42:07 +0000209 $("#pluginInlineDetails > table > tbody").append(txt);
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000210 }
211}
212
Carsten Ziegelerac36cf62009-02-05 19:38:34 +0000213function renderBundles(data) {
214 $(document).ready(function(){
Carsten Ziegeler577fac12009-04-27 20:45:09 +0000215 renderView( ["Id", "Name", "Version", "Symbolic Name", "Status", "Actions"],
Carsten Ziegeler1122a322009-02-05 19:56:36 +0000216 "<input type='hidden' name='action' value='install'/>" +
Carsten Ziegeler19f2de52009-06-11 13:57:46 +0000217 "<input type='hidden' name='bundlestart' value='start'/>" +
218 "<input type='hidden' name='bundlestartlevel' value='" + startLevel + "'/>" +
Carsten Ziegeler718f7fd2009-02-05 20:02:07 +0000219 "<input class='fileinput' type='file' name='bundlefile' style='margin-left:10px'/>" +
Carsten Ziegeler19f2de52009-06-11 13:57:46 +0000220 "<input type='submit' value='Install or Update' style='margin-left:10px'/>" +
221 "<button class='reloadButton' type='button' name='reload' style='margin-left:60px'>Reload</button>" +
222 "<button class='installButton' type='button' name='install'>Install/Update...</button>" +
223 "<button class='refreshPackages' type='button' name='refresh'>Refresh Packages</button>"
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000224 );
Carsten Ziegeler19f2de52009-06-11 13:57:46 +0000225 $(".refreshPackages").click(refreshPackages);
226 $(".reloadButton").click(loadData);
227 $(".installButton").click(function() {
228 document.location = pluginRoot + "/upload";
229 });
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000230 renderData(data);
231
Carsten Ziegelerac36cf62009-02-05 19:38:34 +0000232 var extractMethod = function(node) {
233 var link = node.getElementsByTagName("a");
234 if ( link && link.length == 1 ) {
235 return link[0].innerHTML;
236 }
237 return node.innerHTML;
238 };
Carsten Ziegeler21e54022009-03-05 16:38:26 +0000239 $("#plugin_table").tablesorter({
Carsten Ziegelerac36cf62009-02-05 19:38:34 +0000240 headers: {
241 0: { sorter:"digit"},
Carsten Ziegeler577fac12009-04-27 20:45:09 +0000242 5: { sorter: false }
Carsten Ziegelerac36cf62009-02-05 19:38:34 +0000243 },
244 sortList: [[1,0]],
245 textExtraction:extractMethod
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000246 });
247 });
Felix Meschberger9b3c4e02008-06-02 13:52:15 +0000248}