blob: 0bebc674a353b584ddbbfd0e5aa307abade8101f [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 Ziegeler6577bfa2009-02-05 10:45:35 +000021function renderView( /* Array of String */ columns, /* Array of String */ buttons ) {
22 renderStatusLine();
23 renderButtons(buttons);
24 var txt = "<div class='table'><table id='bundles' class='tablelayout'><thead><tr>";
25 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);
41 $("#bundles > tbody > tr").remove();
42 for ( var idx in eventData.data ) {
43 entry( eventData.data[idx] );
44 }
45 $("#bundles").trigger("update");
46 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 );
54 $("#bundles > tbody").append(trElement);
55}
56
57function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action ) {
58 var enabled = action.enabled;
59 var op = action.link;
60 var opLabel = action.name;
61 var img = action.image;
62
63 var input = createElement( "input", null, {
64 type: 'image',
65 title: opLabel,
66 alt: opLabel,
67 src: imgRoot + '/bundle_' + img + '.png',
68 onClick: 'changeDataEntryState(' + id + ', "' + op + '");'
69 });
70
71 if (!enabled) {
72 input.setAttribute( "disabled", true );
73 }
74 var div = createElement("div");
75 div.setAttribute("style", "float:left; margin-left:10px;");
76 div.appendChild(input);
77 parent.appendChild( div );
78}
79
80function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
81 var id = dataEntry.id;
82 var name = dataEntry.name;
83 var state = dataEntry.state;
84
85 var inputElement = createElement("img", "rightButton", {
86 src: appRoot + "/res/imgs/arrow_right.png",
87 border: "none",
88 id: 'img' + id,
Carsten Ziegeler83fbe442009-02-09 20:48:31 +000089 title: "Details",
90 alt: "Details",
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000091 width: 14,
92 height: 14,
93 onClick: 'showDetails(' + id + ');'
94 });
95 var titleElement;
96 if ( drawDetails ) {
97 titleElement = text(name);
98 } else {
99 titleElement = createElement ("a", null, {
100 href: window.location.pathname + "/" + id
101 });
102 titleElement.appendChild(text(name));
103 }
104
105 parent.appendChild( td( null, null, [ text( id ) ] ) );
106 parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) );
107 parent.appendChild( td( null, null, [ text( state ) ] ) );
108 var actionsTd = td( null, null );
109
110 for ( var a in dataEntry.actions ) {
111 actionButton( actionsTd, id, dataEntry.actions[a] );
112 }
113 parent.appendChild( actionsTd );
114}
115
116function loadData() {
117 $.get(pluginRoot + "/.json", null, function(data) {
118 renderData(data);
119 }, "json");
120}
121
122function changeDataEntryState(/* long */ id, /* String */ action) {
123 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
124 renderData(data);
125 }, "json");
126}
127
128function refreshPackages() {
129 $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) {
130 renderData(data);
131 }, "json");
132}
133
134function showDetails( id ) {
135 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
136 renderDetails(data);
137 }, "json");
138}
139
140function hideDetails( id ) {
141 $("#img" + id).each(function() {
142 $("#bundleInlineDetails").remove();
143 this.setAttribute("src", appRoot + "/res/imgs/arrow_right.png");
144 this.setAttribute("onClick", "showDetails('" + id + "')");
145 this.setAttribute("title", "Details");
146 this.setAttribute("alt", "Details");
147 });
148}
149
150function renderDetails( data ) {
151 data = data.data[0];
152 $("#entry" + data.id + " > td").eq(1).append("<div id='bundleInlineDetails'/>");
153 $("#img" + data.id).each(function() {
154 if ( drawDetails ) {
155 this.setAttribute("src", appRoot + "/res/imgs/arrow_left.png");
156 var ref = window.location.pathname;
157 ref = ref.substring(0, ref.lastIndexOf('/'));
158 this.setAttribute("onClick", "window.location = '" + ref + "';");
159 this.setAttribute("title", "Back");
160 this.setAttribute("alt", "Back");
161 } else {
162 this.setAttribute("src", appRoot + "/res/imgs/arrow_down.png");
163 this.setAttribute("onClick", "hideDetails('" + data.id + "')");
164 this.setAttribute("title", "Hide Details");
165 this.setAttribute("alt", "Hide Details");
166 }
167 });
168 $("#bundleInlineDetails").append("<table border='0'><tbody></tbody></table>");
169 var details = data.props;
170 for (var idx in details) {
171 var prop = details[idx];
172
173 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + prop.key + "</td><td class='aligntop' style='border:0px none'>";
174 if (prop.value) {
175 if ( prop.key == 'Bundle Documentation' ) {
176 txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>";
177 } else {
178 if ( $.isArray(prop.value) ) {
179 var i = 0;
180 for(var pi in prop.value) {
181 var value = prop.value[pi];
182 if (i > 0) { txt = txt + "<br/>"; }
183 var span;
Carsten Ziegelera9a7af82009-02-10 14:18:21 +0000184 if (value.substring(0, 6) == "INFO: ") {
185 txt = txt + "<span style='color: grey;'>!!" + value.substring(5) + "</span>";
186 } else if (value.substring(0, 7) == "ERROR: ") {
187 txt = txt + "<span style='color: red;'>!!" + value.substring(6) + "</span>";
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000188 } else {
189 txt = txt + value;
190 }
191 i++;
192 }
193 } else {
194 txt = txt + prop.value;
195 }
196 }
197 } else {
198 txt = txt + "\u00a0";
199 }
200 txt = txt + "</td></tr>";
201 $("#bundleInlineDetails > table > tbody").append(txt);
202 }
203}
204
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000205function renderBundles(data) {
206 $(document).ready(function(){
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000207 renderView( ["Id", "Name", "Status", "Actions"],
Carsten Ziegeler52558d12009-02-05 19:56:36 +0000208 "<input type='hidden' name='action' value='install'/>" +
Carsten Ziegelera308d932009-02-05 20:02:07 +0000209 "<input class='fileinput' type='file' name='bundlefile' style='margin-left:10px'/>" +
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000210 " - Start <input class='checkradio' type='checkbox' name='bundlestart' value='start' style='vertical-align:middle;'/>" +
211 " - Start Level <input class='input' type='input' name='bundlestartlevel' value='" + startLevel + "' size='4'/>" +
212 "<input type='submit' value='Install or Update' style='margin-left:60px'/>" +
213 "<button id='refreshPackages' type='button' name='refresh' style='margin-left:10px'>Refresh Packages</button>"
214 );
215 $("#refreshPackages").click(refreshPackages);
216 renderData(data);
217
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000218 var extractMethod = function(node) {
219 var link = node.getElementsByTagName("a");
220 if ( link && link.length == 1 ) {
221 return link[0].innerHTML;
222 }
223 return node.innerHTML;
224 };
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000225 $("#bundles").tablesorter({
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000226 headers: {
227 0: { sorter:"digit"},
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000228 3: { sorter: false }
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000229 },
230 sortList: [[1,0]],
231 textExtraction:extractMethod
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000232 });
233 });
Felix Meschberger4c664132008-06-02 13:52:15 +0000234}