blob: 7a274df834ef0fb1fd1b138a971089f91a31ee94 [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',
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000065 style: {"margin-left": "10px"},
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000066 title: opLabel,
67 alt: opLabel,
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000068 src: imgRoot + '/bundle_' + img + '.png'
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000069 });
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000070 $(input).click(function() {changeDataEntryState(id, op)});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000071
72 if (!enabled) {
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000073 $(input).attr("disabled", true);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000074 }
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000075 parent.appendChild( input );
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000076}
77
78function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
79 var id = dataEntry.id;
80 var name = dataEntry.name;
81 var state = dataEntry.state;
82
83 var inputElement = createElement("img", "rightButton", {
84 src: appRoot + "/res/imgs/arrow_right.png",
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000085 style: {border: "none"},
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000086 id: 'img' + id,
Carsten Ziegeler83fbe442009-02-09 20:48:31 +000087 title: "Details",
88 alt: "Details",
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000089 width: 14,
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000090 height: 14
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000091 });
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000092 $(inputElement).click(function() {showDetails(id)});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000093 var titleElement;
94 if ( drawDetails ) {
95 titleElement = text(name);
96 } else {
97 titleElement = createElement ("a", null, {
98 href: window.location.pathname + "/" + id
99 });
100 titleElement.appendChild(text(name));
101 }
102
103 parent.appendChild( td( null, null, [ text( id ) ] ) );
104 parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) );
105 parent.appendChild( td( null, null, [ text( state ) ] ) );
106 var actionsTd = td( null, null );
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000107 var div = createElement("div", null, {
108 style: { "text-align" : "left"}
109 });
110 actionsTd.appendChild(div);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000111
112 for ( var a in dataEntry.actions ) {
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000113 actionButton( div, id, dataEntry.actions[a] );
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000114 }
115 parent.appendChild( actionsTd );
116}
117
118function loadData() {
119 $.get(pluginRoot + "/.json", null, function(data) {
120 renderData(data);
121 }, "json");
122}
123
124function changeDataEntryState(/* long */ id, /* String */ action) {
125 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
126 renderData(data);
127 }, "json");
128}
129
130function refreshPackages() {
131 $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) {
132 renderData(data);
133 }, "json");
134}
135
136function showDetails( id ) {
137 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
138 renderDetails(data);
139 }, "json");
140}
141
142function hideDetails( id ) {
143 $("#img" + id).each(function() {
Carsten Ziegelerd721c962009-02-16 16:42:07 +0000144 $("#pluginInlineDetails").remove();
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000145 $(this).attr("src", appRoot + "/res/imgs/arrow_right.png");
146 $(this).attr("title", "Details");
147 $(this).attr("alt", "Details");
148 $(this).unbind('click').click(function() {showDetails(id)});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000149 });
150}
151
152function renderDetails( data ) {
153 data = data.data[0];
Carsten Ziegelerd721c962009-02-16 16:42:07 +0000154 $("#pluginInlineDetails").remove();
155 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000156 $("#img" + data.id).each(function() {
157 if ( drawDetails ) {
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000158 $(this).attr("src", appRoot + "/res/imgs/arrow_left.png");
159 $(this).attr("title", "Back");
160 $(this).attr("alt", "Back");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000161 var ref = window.location.pathname;
162 ref = ref.substring(0, ref.lastIndexOf('/'));
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000163 $(this).unbind('click').click(function() {window.location = ref;});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000164 } else {
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000165 $(this).attr("src", appRoot + "/res/imgs/arrow_down.png");
166 $(this).attr("title", "Hide Details");
167 $(this).attr("alt", "Hide Details");
168 $(this).unbind('click').click(function() {hideDetails(data.id)});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000169 }
170 });
Carsten Ziegelerd721c962009-02-16 16:42:07 +0000171 $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000172 var details = data.props;
173 for (var idx in details) {
174 var prop = details[idx];
175
176 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + prop.key + "</td><td class='aligntop' style='border:0px none'>";
177 if (prop.value) {
178 if ( prop.key == 'Bundle Documentation' ) {
179 txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>";
180 } else {
181 if ( $.isArray(prop.value) ) {
182 var i = 0;
183 for(var pi in prop.value) {
184 var value = prop.value[pi];
185 if (i > 0) { txt = txt + "<br/>"; }
186 var span;
Carsten Ziegelera9a7af82009-02-10 14:18:21 +0000187 if (value.substring(0, 6) == "INFO: ") {
188 txt = txt + "<span style='color: grey;'>!!" + value.substring(5) + "</span>";
189 } else if (value.substring(0, 7) == "ERROR: ") {
190 txt = txt + "<span style='color: red;'>!!" + value.substring(6) + "</span>";
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000191 } else {
192 txt = txt + value;
193 }
194 i++;
195 }
196 } else {
197 txt = txt + prop.value;
198 }
199 }
200 } else {
201 txt = txt + "\u00a0";
202 }
203 txt = txt + "</td></tr>";
Carsten Ziegelerd721c962009-02-16 16:42:07 +0000204 $("#pluginInlineDetails > table > tbody").append(txt);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000205 }
206}
207
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000208function renderBundles(data) {
209 $(document).ready(function(){
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000210 renderView( ["Id", "Name", "Status", "Actions"],
Carsten Ziegeler52558d12009-02-05 19:56:36 +0000211 "<input type='hidden' name='action' value='install'/>" +
Carsten Ziegelera308d932009-02-05 20:02:07 +0000212 "<input class='fileinput' type='file' name='bundlefile' style='margin-left:10px'/>" +
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000213 " - Start <input class='checkradio' type='checkbox' name='bundlestart' value='start' style='vertical-align:middle;'/>" +
214 " - Start Level <input class='input' type='input' name='bundlestartlevel' value='" + startLevel + "' size='4'/>" +
215 "<input type='submit' value='Install or Update' style='margin-left:60px'/>" +
216 "<button id='refreshPackages' type='button' name='refresh' style='margin-left:10px'>Refresh Packages</button>"
217 );
218 $("#refreshPackages").click(refreshPackages);
219 renderData(data);
220
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000221 var extractMethod = function(node) {
222 var link = node.getElementsByTagName("a");
223 if ( link && link.length == 1 ) {
224 return link[0].innerHTML;
225 }
226 return node.innerHTML;
227 };
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000228 $("#bundles").tablesorter({
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000229 headers: {
230 0: { sorter:"digit"},
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000231 3: { sorter: false }
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000232 },
233 sortList: [[1,0]],
234 textExtraction:extractMethod
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000235 });
236 });
Felix Meschberger4c664132008-06-02 13:52:15 +0000237}