Felix Meschberger | 9b3c4e0 | 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 | f987915 | 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 | 9b3c4e0 | 2008-06-02 13:52:15 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Carsten Ziegeler | 21e5402 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 21 | function renderView( /* Array of String */ columns, /* String */ buttons ) { |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 22 | renderStatusLine(); |
| 23 | renderButtons(buttons); |
Carsten Ziegeler | 21e5402 | 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 | f987915 | 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 | 7ecffce | 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 | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | function renderData( eventData ) { |
| 40 | $(".statusline").empty().append(eventData.status); |
Carsten Ziegeler | 21e5402 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 41 | $("#plugin_table > tbody > tr").remove(); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 42 | for ( var idx in eventData.data ) { |
| 43 | entry( eventData.data[idx] ); |
| 44 | } |
Carsten Ziegeler | 21e5402 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 45 | $("#plugin_table").trigger("update"); |
Carsten Ziegeler | f987915 | 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 | 21e5402 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 54 | $("#plugin_table > tbody").append(trElement); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action ) { |
Carsten Ziegeler | f90898a | 2009-04-27 20:35:53 +0000 | [diff] [blame] | 58 | if ( !action.enabled ) { |
| 59 | return; |
| 60 | } |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 61 | var enabled = action.enabled; |
| 62 | var op = action.link; |
| 63 | var opLabel = action.name; |
| 64 | var img = action.image; |
| 65 | |
| 66 | var input = createElement( "input", null, { |
| 67 | type: 'image', |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 68 | style: {"margin-left": "10px"}, |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 69 | title: opLabel, |
| 70 | alt: opLabel, |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 71 | src: imgRoot + '/bundle_' + img + '.png' |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 72 | }); |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 73 | $(input).click(function() {changeDataEntryState(id, op)}); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 74 | |
| 75 | if (!enabled) { |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 76 | $(input).attr("disabled", true); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 77 | } |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 78 | parent.appendChild( input ); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | function 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", |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 88 | style: {border: "none"}, |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 89 | id: 'img' + id, |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 90 | title: "Details", |
| 91 | alt: "Details", |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 92 | width: 14, |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 93 | height: 14 |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 94 | }); |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 95 | $(inputElement).click(function() {showDetails(id)}); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 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 ] ) ); |
Carsten Ziegeler | 577fac1 | 2009-04-27 20:45:09 +0000 | [diff] [blame^] | 108 | parent.appendChild( td( null, null, [ text( dataEntry.version ) ] ) ); |
| 109 | parent.appendChild( td( null, null, [ text( dataEntry.symbolicName ) ] ) ); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 110 | parent.appendChild( td( null, null, [ text( state ) ] ) ); |
| 111 | var actionsTd = td( null, null ); |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 112 | var div = createElement("div", null, { |
| 113 | style: { "text-align" : "left"} |
| 114 | }); |
| 115 | actionsTd.appendChild(div); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 116 | |
| 117 | for ( var a in dataEntry.actions ) { |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 118 | actionButton( div, id, dataEntry.actions[a] ); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 119 | } |
| 120 | parent.appendChild( actionsTd ); |
| 121 | } |
| 122 | |
| 123 | function loadData() { |
| 124 | $.get(pluginRoot + "/.json", null, function(data) { |
| 125 | renderData(data); |
| 126 | }, "json"); |
| 127 | } |
| 128 | |
| 129 | function changeDataEntryState(/* long */ id, /* String */ action) { |
| 130 | $.post(pluginRoot + "/" + id, {"action":action}, function(data) { |
| 131 | renderData(data); |
| 132 | }, "json"); |
| 133 | } |
| 134 | |
| 135 | function refreshPackages() { |
| 136 | $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) { |
| 137 | renderData(data); |
| 138 | }, "json"); |
| 139 | } |
| 140 | |
| 141 | function showDetails( id ) { |
| 142 | $.get(pluginRoot + "/" + id + ".json", null, function(data) { |
| 143 | renderDetails(data); |
| 144 | }, "json"); |
| 145 | } |
| 146 | |
| 147 | function hideDetails( id ) { |
| 148 | $("#img" + id).each(function() { |
Carsten Ziegeler | 7cc941e | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 149 | $("#pluginInlineDetails").remove(); |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 150 | $(this).attr("src", appRoot + "/res/imgs/arrow_right.png"); |
| 151 | $(this).attr("title", "Details"); |
| 152 | $(this).attr("alt", "Details"); |
| 153 | $(this).unbind('click').click(function() {showDetails(id)}); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 154 | }); |
| 155 | } |
| 156 | |
| 157 | function renderDetails( data ) { |
| 158 | data = data.data[0]; |
Carsten Ziegeler | 7cc941e | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 159 | $("#pluginInlineDetails").remove(); |
| 160 | $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>"); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 161 | $("#img" + data.id).each(function() { |
| 162 | if ( drawDetails ) { |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 163 | $(this).attr("src", appRoot + "/res/imgs/arrow_left.png"); |
| 164 | $(this).attr("title", "Back"); |
| 165 | $(this).attr("alt", "Back"); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 166 | var ref = window.location.pathname; |
| 167 | ref = ref.substring(0, ref.lastIndexOf('/')); |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 168 | $(this).unbind('click').click(function() {window.location = ref;}); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 169 | } else { |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 170 | $(this).attr("src", appRoot + "/res/imgs/arrow_down.png"); |
| 171 | $(this).attr("title", "Hide Details"); |
| 172 | $(this).attr("alt", "Hide Details"); |
| 173 | $(this).unbind('click').click(function() {hideDetails(data.id)}); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 174 | } |
| 175 | }); |
Carsten Ziegeler | 7cc941e | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 176 | $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>"); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 177 | var details = data.props; |
| 178 | for (var idx in details) { |
| 179 | var prop = details[idx]; |
| 180 | |
| 181 | var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + prop.key + "</td><td class='aligntop' style='border:0px none'>"; |
| 182 | if (prop.value) { |
| 183 | if ( prop.key == 'Bundle Documentation' ) { |
| 184 | txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>"; |
| 185 | } else { |
| 186 | if ( $.isArray(prop.value) ) { |
| 187 | var i = 0; |
| 188 | for(var pi in prop.value) { |
| 189 | var value = prop.value[pi]; |
| 190 | if (i > 0) { txt = txt + "<br/>"; } |
| 191 | var span; |
Carsten Ziegeler | 621b99f | 2009-02-10 14:18:21 +0000 | [diff] [blame] | 192 | if (value.substring(0, 6) == "INFO: ") { |
| 193 | txt = txt + "<span style='color: grey;'>!!" + value.substring(5) + "</span>"; |
| 194 | } else if (value.substring(0, 7) == "ERROR: ") { |
| 195 | txt = txt + "<span style='color: red;'>!!" + value.substring(6) + "</span>"; |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 196 | } else { |
| 197 | txt = txt + value; |
| 198 | } |
| 199 | i++; |
| 200 | } |
| 201 | } else { |
| 202 | txt = txt + prop.value; |
| 203 | } |
| 204 | } |
| 205 | } else { |
| 206 | txt = txt + "\u00a0"; |
| 207 | } |
| 208 | txt = txt + "</td></tr>"; |
Carsten Ziegeler | 7cc941e | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 209 | $("#pluginInlineDetails > table > tbody").append(txt); |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
Carsten Ziegeler | ac36cf6 | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 213 | function renderBundles(data) { |
| 214 | $(document).ready(function(){ |
Carsten Ziegeler | 577fac1 | 2009-04-27 20:45:09 +0000 | [diff] [blame^] | 215 | renderView( ["Id", "Name", "Version", "Symbolic Name", "Status", "Actions"], |
Carsten Ziegeler | 1122a32 | 2009-02-05 19:56:36 +0000 | [diff] [blame] | 216 | "<input type='hidden' name='action' value='install'/>" + |
Carsten Ziegeler | 718f7fd | 2009-02-05 20:02:07 +0000 | [diff] [blame] | 217 | "<input class='fileinput' type='file' name='bundlefile' style='margin-left:10px'/>" + |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 218 | " - Start <input class='checkradio' type='checkbox' name='bundlestart' value='start' style='vertical-align:middle;'/>" + |
| 219 | " - Start Level <input class='input' type='input' name='bundlestartlevel' value='" + startLevel + "' size='4'/>" + |
| 220 | "<input type='submit' value='Install or Update' style='margin-left:60px'/>" + |
| 221 | "<button id='refreshPackages' type='button' name='refresh' style='margin-left:10px'>Refresh Packages</button>" |
| 222 | ); |
| 223 | $("#refreshPackages").click(refreshPackages); |
| 224 | renderData(data); |
| 225 | |
Carsten Ziegeler | ac36cf6 | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 226 | var extractMethod = function(node) { |
| 227 | var link = node.getElementsByTagName("a"); |
| 228 | if ( link && link.length == 1 ) { |
| 229 | return link[0].innerHTML; |
| 230 | } |
| 231 | return node.innerHTML; |
| 232 | }; |
Carsten Ziegeler | 21e5402 | 2009-03-05 16:38:26 +0000 | [diff] [blame] | 233 | $("#plugin_table").tablesorter({ |
Carsten Ziegeler | ac36cf6 | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 234 | headers: { |
| 235 | 0: { sorter:"digit"}, |
Carsten Ziegeler | 577fac1 | 2009-04-27 20:45:09 +0000 | [diff] [blame^] | 236 | 5: { sorter: false } |
Carsten Ziegeler | ac36cf6 | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 237 | }, |
| 238 | sortList: [[1,0]], |
| 239 | textExtraction:extractMethod |
Carsten Ziegeler | f987915 | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 240 | }); |
| 241 | }); |
Felix Meschberger | 9b3c4e0 | 2008-06-02 13:52:15 +0000 | [diff] [blame] | 242 | } |