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 ) { |
| 43 | entry( eventData.data[idx] ); |
| 44 | } |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 45 | $("#plugin_table").trigger("update"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 46 | if ( drawDetails ) { |
| 47 | renderDetails(eventData); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | function entry( /* Object */ dataEntry ) { |
| 52 | var trElement = tr( null, { id: "entry" + dataEntry.id } ); |
| 53 | entryInternal( trElement, dataEntry ); |
Carsten Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 54 | $("#plugin_table > tbody").append(trElement); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | function 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 Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 65 | style: {"margin-left": "10px"}, |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 66 | title: opLabel, |
| 67 | alt: opLabel, |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 68 | src: imgRoot + '/bundle_' + img + '.png' |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 69 | }); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 70 | $(input).click(function() {changeDataEntryState(id, op)}); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 71 | |
| 72 | if (!enabled) { |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 73 | $(input).attr("disabled", true); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 74 | } |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 75 | parent.appendChild( input ); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | function 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 Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 85 | style: {border: "none"}, |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 86 | id: 'img' + id, |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 87 | title: "Details", |
| 88 | alt: "Details", |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 89 | width: 14, |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 90 | height: 14 |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 91 | }); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 92 | $(inputElement).click(function() {showDetails(id)}); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 93 | 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 Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 107 | var div = createElement("div", null, { |
| 108 | style: { "text-align" : "left"} |
| 109 | }); |
| 110 | actionsTd.appendChild(div); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 111 | |
| 112 | for ( var a in dataEntry.actions ) { |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 113 | actionButton( div, id, dataEntry.actions[a] ); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 114 | } |
| 115 | parent.appendChild( actionsTd ); |
| 116 | } |
| 117 | |
| 118 | function loadData() { |
| 119 | $.get(pluginRoot + "/.json", null, function(data) { |
| 120 | renderData(data); |
| 121 | }, "json"); |
| 122 | } |
| 123 | |
| 124 | function changeDataEntryState(/* long */ id, /* String */ action) { |
| 125 | $.post(pluginRoot + "/" + id, {"action":action}, function(data) { |
| 126 | renderData(data); |
| 127 | }, "json"); |
| 128 | } |
| 129 | |
| 130 | function refreshPackages() { |
| 131 | $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) { |
| 132 | renderData(data); |
| 133 | }, "json"); |
| 134 | } |
| 135 | |
| 136 | function showDetails( id ) { |
| 137 | $.get(pluginRoot + "/" + id + ".json", null, function(data) { |
| 138 | renderDetails(data); |
| 139 | }, "json"); |
| 140 | } |
| 141 | |
| 142 | function hideDetails( id ) { |
| 143 | $("#img" + id).each(function() { |
Carsten Ziegeler | d721c96 | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 144 | $("#pluginInlineDetails").remove(); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 145 | $(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 Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 149 | }); |
| 150 | } |
| 151 | |
| 152 | function renderDetails( data ) { |
| 153 | data = data.data[0]; |
Carsten Ziegeler | d721c96 | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 154 | $("#pluginInlineDetails").remove(); |
| 155 | $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 156 | $("#img" + data.id).each(function() { |
| 157 | if ( drawDetails ) { |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 158 | $(this).attr("src", appRoot + "/res/imgs/arrow_left.png"); |
| 159 | $(this).attr("title", "Back"); |
| 160 | $(this).attr("alt", "Back"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 161 | var ref = window.location.pathname; |
| 162 | ref = ref.substring(0, ref.lastIndexOf('/')); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 163 | $(this).unbind('click').click(function() {window.location = ref;}); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 164 | } else { |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 165 | $(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 Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 169 | } |
| 170 | }); |
Carsten Ziegeler | d721c96 | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 171 | $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 172 | 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 Ziegeler | a9a7af8 | 2009-02-10 14:18:21 +0000 | [diff] [blame] | 187 | 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 Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 191 | } 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 Ziegeler | d721c96 | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 204 | $("#pluginInlineDetails > table > tbody").append(txt); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 208 | function renderBundles(data) { |
| 209 | $(document).ready(function(){ |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 210 | renderView( ["Id", "Name", "Status", "Actions"], |
Carsten Ziegeler | 52558d1 | 2009-02-05 19:56:36 +0000 | [diff] [blame] | 211 | "<input type='hidden' name='action' value='install'/>" + |
Carsten Ziegeler | a308d93 | 2009-02-05 20:02:07 +0000 | [diff] [blame] | 212 | "<input class='fileinput' type='file' name='bundlefile' style='margin-left:10px'/>" + |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 213 | " - 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 Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 221 | 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 Ziegeler | 1001af1 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 228 | $("#plugin_table").tablesorter({ |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 229 | headers: { |
| 230 | 0: { sorter:"digit"}, |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 231 | 3: { sorter: false } |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 232 | }, |
| 233 | sortList: [[1,0]], |
| 234 | textExtraction:extractMethod |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 235 | }); |
| 236 | }); |
Felix Meschberger | 4c66413 | 2008-06-02 13:52:15 +0000 | [diff] [blame] | 237 | } |