blob: 830af0df0a06a65d7b40d09360ea0c970a791bad [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 ) {
35 $("#plugin_content").append( "<div class='fullwidth'><div class='buttons'>" +
36 "<form method='post' enctype='multipart/form-data'><div style='padding-top:5px;'>" +
37 buttons + "</div></form></div></div>" );
38}
39
40function renderData( eventData ) {
41 $(".statusline").empty().append(eventData.status);
42 $("#bundles > tbody > tr").remove();
43 for ( var idx in eventData.data ) {
44 entry( eventData.data[idx] );
45 }
46 $("#bundles").trigger("update");
47 if ( drawDetails ) {
48 renderDetails(eventData);
49 }
50}
51
52function entry( /* Object */ dataEntry ) {
53 var trElement = tr( null, { id: "entry" + dataEntry.id } );
54 entryInternal( trElement, dataEntry );
55 $("#bundles > tbody").append(trElement);
56}
57
58function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action ) {
59 var enabled = action.enabled;
60 var op = action.link;
61 var opLabel = action.name;
62 var img = action.image;
63
64 var input = createElement( "input", null, {
65 type: 'image',
66 title: opLabel,
67 alt: opLabel,
68 src: imgRoot + '/bundle_' + img + '.png',
69 onClick: 'changeDataEntryState(' + id + ', "' + op + '");'
70 });
71
72 if (!enabled) {
73 input.setAttribute( "disabled", true );
74 }
75 var div = createElement("div");
76 div.setAttribute("style", "float:left; margin-left:10px;");
77 div.appendChild(input);
78 parent.appendChild( div );
79}
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",
88 border: "none",
89 id: 'img' + id,
90 title: "Back",
91 alt: "Back",
92 width: 14,
93 height: 14,
94 onClick: 'showDetails(' + id + ');'
95 });
96 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 ] ) );
108 parent.appendChild( td( null, null, [ text( state ) ] ) );
109 var actionsTd = td( null, null );
110
111 for ( var a in dataEntry.actions ) {
112 actionButton( actionsTd, id, dataEntry.actions[a] );
113 }
114 parent.appendChild( actionsTd );
115}
116
117function loadData() {
118 $.get(pluginRoot + "/.json", null, function(data) {
119 renderData(data);
120 }, "json");
121}
122
123function changeDataEntryState(/* long */ id, /* String */ action) {
124 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
125 renderData(data);
126 }, "json");
127}
128
129function refreshPackages() {
130 $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) {
131 renderData(data);
132 }, "json");
133}
134
135function showDetails( id ) {
136 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
137 renderDetails(data);
138 }, "json");
139}
140
141function hideDetails( id ) {
142 $("#img" + id).each(function() {
143 $("#bundleInlineDetails").remove();
144 this.setAttribute("src", appRoot + "/res/imgs/arrow_right.png");
145 this.setAttribute("onClick", "showDetails('" + id + "')");
146 this.setAttribute("title", "Details");
147 this.setAttribute("alt", "Details");
148 });
149}
150
151function renderDetails( data ) {
152 data = data.data[0];
153 $("#entry" + data.id + " > td").eq(1).append("<div id='bundleInlineDetails'/>");
154 $("#img" + data.id).each(function() {
155 if ( drawDetails ) {
156 this.setAttribute("src", appRoot + "/res/imgs/arrow_left.png");
157 var ref = window.location.pathname;
158 ref = ref.substring(0, ref.lastIndexOf('/'));
159 this.setAttribute("onClick", "window.location = '" + ref + "';");
160 this.setAttribute("title", "Back");
161 this.setAttribute("alt", "Back");
162 } else {
163 this.setAttribute("src", appRoot + "/res/imgs/arrow_down.png");
164 this.setAttribute("onClick", "hideDetails('" + data.id + "')");
165 this.setAttribute("title", "Hide Details");
166 this.setAttribute("alt", "Hide Details");
167 }
168 });
169 $("#bundleInlineDetails").append("<table border='0'><tbody></tbody></table>");
170 var details = data.props;
171 for (var idx in details) {
172 var prop = details[idx];
173
174 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + prop.key + "</td><td class='aligntop' style='border:0px none'>";
175 if (prop.value) {
176 if ( prop.key == 'Bundle Documentation' ) {
177 txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>";
178 } else {
179 if ( $.isArray(prop.value) ) {
180 var i = 0;
181 for(var pi in prop.value) {
182 var value = prop.value[pi];
183 if (i > 0) { txt = txt + "<br/>"; }
184 var span;
185 if (value.substring(0, 2) == "!!") {
Carsten Ziegeler90c3d502009-02-06 15:53:44 +0000186 txt = txt + "<span style='color: red;'>" + value + "</span>";
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000187 } else {
188 txt = txt + value;
189 }
190 i++;
191 }
192 } else {
193 txt = txt + prop.value;
194 }
195 }
196 } else {
197 txt = txt + "\u00a0";
198 }
199 txt = txt + "</td></tr>";
200 $("#bundleInlineDetails > table > tbody").append(txt);
201 }
202}
203
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000204function renderBundles(data) {
205 $(document).ready(function(){
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000206 renderView( ["Id", "Name", "Status", "Actions"],
Carsten Ziegeler52558d12009-02-05 19:56:36 +0000207 "<input type='hidden' name='action' value='install'/>" +
Carsten Ziegelera308d932009-02-05 20:02:07 +0000208 "<input class='fileinput' type='file' name='bundlefile' style='margin-left:10px'/>" +
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000209 " - Start <input class='checkradio' type='checkbox' name='bundlestart' value='start' style='vertical-align:middle;'/>" +
210 " - Start Level <input class='input' type='input' name='bundlestartlevel' value='" + startLevel + "' size='4'/>" +
211 "<input type='submit' value='Install or Update' style='margin-left:60px'/>" +
212 "<button id='refreshPackages' type='button' name='refresh' style='margin-left:10px'>Refresh Packages</button>"
213 );
214 $("#refreshPackages").click(refreshPackages);
215 renderData(data);
216
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000217 var extractMethod = function(node) {
218 var link = node.getElementsByTagName("a");
219 if ( link && link.length == 1 ) {
220 return link[0].innerHTML;
221 }
222 return node.innerHTML;
223 };
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000224 $("#bundles").tablesorter({
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000225 headers: {
226 0: { sorter:"digit"},
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000227 3: { sorter: false }
Carsten Ziegeler21f096b2009-02-05 19:38:34 +0000228 },
229 sortList: [[1,0]],
230 textExtraction:extractMethod
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000231 });
232 });
Felix Meschberger4c664132008-06-02 13:52:15 +0000233}