Felix Meschberger | 4c66413 | 2008-06-02 13:52:15 +0000 | [diff] [blame] | 1 | /* |
| 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 Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 17 | function renderStatusLine() { |
| 18 | $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" ); |
Felix Meschberger | 4c66413 | 2008-06-02 13:52:15 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 21 | function renderView( /* Array of String */ columns, /* String */ buttons ) { |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 22 | renderStatusLine(); |
| 23 | renderButtons(buttons); |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 24 | var txt = "<div class='table'><table id='plugin_table' class='tablelayout'><thead><tr>"; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 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 | |
| 34 | function renderButtons( buttons ) { |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 35 | $("#plugin_content").append( "<form method='post' enctype='multipart/form-data'><div class='fullwidth'><div class='buttons'>" + |
| 36 | buttons + "</div></div></form>" ); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | function renderData( eventData ) { |
| 40 | $(".statusline").empty().append(eventData.status); |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 41 | $("#plugin_table > tbody > tr").remove(); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 42 | for ( var idx in eventData.data ) { |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 43 | if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) { |
| 44 | entry( eventData.data[idx] ); |
| 45 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 46 | } |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 47 | $("#plugin_table").trigger("update"); |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 48 | 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 Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
| 57 | function entry( /* Object */ dataEntry ) { |
| 58 | var trElement = tr( null, { id: "entry" + dataEntry.id } ); |
| 59 | entryInternal( trElement, dataEntry ); |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 60 | $("#plugin_table > tbody").append(trElement); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action ) { |
Carsten Ziegeler | 2cd0742 | 2009-04-27 20:35:53 +0000 | [diff] [blame] | 64 | if ( !action.enabled ) { |
| 65 | return; |
| 66 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 67 | 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 Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 74 | style: {"margin-left": "10px"}, |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 75 | title: opLabel, |
| 76 | alt: opLabel, |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 77 | src: imgRoot + '/bundle_' + img + '.png' |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 78 | }); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 79 | $(input).click(function() {changeDataEntryState(id, op)}); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 80 | |
| 81 | if (!enabled) { |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 82 | $(input).attr("disabled", true); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 83 | } |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 84 | parent.appendChild( input ); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | function 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 Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 94 | style: {border: "none"}, |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 95 | id: 'img' + id, |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 96 | title: "Details", |
| 97 | alt: "Details", |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 98 | width: 14, |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 99 | height: 14 |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 100 | }); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 101 | $(inputElement).click(function() {showDetails(id)}); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 102 | 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 Ziegeler | ca26b52 | 2009-04-27 20:45:09 +0000 | [diff] [blame] | 114 | parent.appendChild( td( null, null, [ text( dataEntry.version ) ] ) ); |
| 115 | parent.appendChild( td( null, null, [ text( dataEntry.symbolicName ) ] ) ); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 116 | parent.appendChild( td( null, null, [ text( state ) ] ) ); |
| 117 | var actionsTd = td( null, null ); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 118 | var div = createElement("div", null, { |
| 119 | style: { "text-align" : "left"} |
| 120 | }); |
| 121 | actionsTd.appendChild(div); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 122 | |
| 123 | for ( var a in dataEntry.actions ) { |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 124 | actionButton( div, id, dataEntry.actions[a] ); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 125 | } |
| 126 | parent.appendChild( actionsTd ); |
| 127 | } |
| 128 | |
| 129 | function loadData() { |
| 130 | $.get(pluginRoot + "/.json", null, function(data) { |
| 131 | renderData(data); |
| 132 | }, "json"); |
| 133 | } |
| 134 | |
| 135 | function changeDataEntryState(/* long */ id, /* String */ action) { |
| 136 | $.post(pluginRoot + "/" + id, {"action":action}, function(data) { |
| 137 | renderData(data); |
| 138 | }, "json"); |
| 139 | } |
| 140 | |
| 141 | function refreshPackages() { |
| 142 | $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) { |
| 143 | renderData(data); |
| 144 | }, "json"); |
| 145 | } |
| 146 | |
| 147 | function showDetails( id ) { |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 148 | currentBundle = id; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 149 | $.get(pluginRoot + "/" + id + ".json", null, function(data) { |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 150 | renderDetails(data.data[0]); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 151 | }, "json"); |
| 152 | } |
| 153 | |
| 154 | function hideDetails( id ) { |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 155 | currentBundle = null; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 156 | $("#img" + id).each(function() { |
Felix Meschberger | 16dd988 | 2010-02-18 08:08:47 +0000 | [diff] [blame] | 157 | $("#pluginInlineDetails" + id).remove(); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 158 | $(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 Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 162 | }); |
| 163 | } |
| 164 | |
| 165 | function renderDetails( data ) { |
Felix Meschberger | 16dd988 | 2010-02-18 08:08:47 +0000 | [diff] [blame] | 166 | $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 167 | $("#img" + data.id).each(function() { |
| 168 | if ( drawDetails ) { |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 169 | $(this).attr("src", appRoot + "/res/imgs/arrow_left.png"); |
| 170 | $(this).attr("title", "Back"); |
| 171 | $(this).attr("alt", "Back"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 172 | var ref = window.location.pathname; |
| 173 | ref = ref.substring(0, ref.lastIndexOf('/')); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 174 | $(this).unbind('click').click(function() {window.location = ref;}); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 175 | } else { |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 176 | $(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 Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 180 | } |
| 181 | }); |
Felix Meschberger | 16dd988 | 2010-02-18 08:08:47 +0000 | [diff] [blame] | 182 | $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 183 | 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 Ziegeler | a9a7af8 | 2009-02-10 14:18:21 +0000 | [diff] [blame] | 198 | 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 Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 202 | } 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 Meschberger | 16dd988 | 2010-02-18 08:08:47 +0000 | [diff] [blame] | 215 | $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 219 | function renderBundles(data) { |
| 220 | $(document).ready(function(){ |
Carsten Ziegeler | ca26b52 | 2009-04-27 20:45:09 +0000 | [diff] [blame] | 221 | renderView( ["Id", "Name", "Version", "Symbolic Name", "Status", "Actions"], |
Carsten Ziegeler | 52558d1 | 2009-02-05 19:56:36 +0000 | [diff] [blame] | 222 | "<input type='hidden' name='action' value='install'/>" + |
Carsten Ziegeler | 60b9b35 | 2009-06-11 13:57:46 +0000 | [diff] [blame] | 223 | "<input type='hidden' name='bundlestart' value='start'/>" + |
| 224 | "<input type='hidden' name='bundlestartlevel' value='" + startLevel + "'/>" + |
Carsten Ziegeler | a308d93 | 2009-02-05 20:02:07 +0000 | [diff] [blame] | 225 | "<input class='fileinput' type='file' name='bundlefile' style='margin-left:10px'/>" + |
Carsten Ziegeler | 60b9b35 | 2009-06-11 13:57:46 +0000 | [diff] [blame] | 226 | "<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 Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 230 | ); |
Carsten Ziegeler | 60b9b35 | 2009-06-11 13:57:46 +0000 | [diff] [blame] | 231 | $(".refreshPackages").click(refreshPackages); |
| 232 | $(".reloadButton").click(loadData); |
| 233 | $(".installButton").click(function() { |
| 234 | document.location = pluginRoot + "/upload"; |
| 235 | }); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 236 | renderData(data); |
| 237 | |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 238 | 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 Ziegeler | fd23310 | 2009-12-11 10:56:15 +0000 | [diff] [blame] | 245 | // check for cookie |
| 246 | var cv = $.cookies.get("webconsolebundlelist"); |
| 247 | var lo = (cv ? cv.split(",") : [1,0]); |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 248 | $("#plugin_table").tablesorter({ |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 249 | headers: { |
| 250 | 0: { sorter:"digit"}, |
Carsten Ziegeler | ca26b52 | 2009-04-27 20:45:09 +0000 | [diff] [blame] | 251 | 5: { sorter: false } |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 252 | }, |
Carsten Ziegeler | cefffcb | 2010-01-26 12:59:54 +0000 | [diff] [blame] | 253 | sortList: [lo], |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 254 | textExtraction:extractMethod |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 255 | }); |
Carsten Ziegeler | fd23310 | 2009-12-11 10:56:15 +0000 | [diff] [blame] | 256 | $("#plugin_table").bind("sortEnd", function() { |
| 257 | var table = $("#plugin_table").eq(0).attr("config"); |
| 258 | $.cookies.set("webconsolebundlelist", table.sortList.toString()); |
| 259 | }); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 260 | }); |
Felix Meschberger | 4c66413 | 2008-06-02 13:52:15 +0000 | [diff] [blame] | 261 | } |