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 | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 21 | function 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 | |
| 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); |
| 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 | |
| 51 | function entry( /* Object */ dataEntry ) { |
| 52 | var trElement = tr( null, { id: "entry" + dataEntry.id } ); |
| 53 | entryInternal( trElement, dataEntry ); |
| 54 | $("#bundles > tbody").append(trElement); |
| 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', |
| 65 | title: opLabel, |
| 66 | alt: opLabel, |
| 67 | src: imgRoot + '/bundle_' + img + '.png', |
| 68 | onClick: 'changeDataEntryState(' + id + ', "' + op + '");' |
| 69 | }); |
| 70 | |
| 71 | if (!enabled) { |
| 72 | input.setAttribute( "disabled", true ); |
| 73 | } |
| 74 | var div = createElement("div"); |
| 75 | div.setAttribute("style", "float:left; margin-left:10px;"); |
| 76 | div.appendChild(input); |
| 77 | parent.appendChild( div ); |
| 78 | } |
| 79 | |
| 80 | function entryInternal( /* Element */ parent, /* Object */ dataEntry ) { |
| 81 | var id = dataEntry.id; |
| 82 | var name = dataEntry.name; |
| 83 | var state = dataEntry.state; |
| 84 | |
| 85 | var inputElement = createElement("img", "rightButton", { |
| 86 | src: appRoot + "/res/imgs/arrow_right.png", |
| 87 | border: "none", |
| 88 | id: 'img' + id, |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 89 | title: "Details", |
| 90 | alt: "Details", |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 91 | width: 14, |
| 92 | height: 14, |
| 93 | onClick: 'showDetails(' + id + ');' |
| 94 | }); |
| 95 | var titleElement; |
| 96 | if ( drawDetails ) { |
| 97 | titleElement = text(name); |
| 98 | } else { |
| 99 | titleElement = createElement ("a", null, { |
| 100 | href: window.location.pathname + "/" + id |
| 101 | }); |
| 102 | titleElement.appendChild(text(name)); |
| 103 | } |
| 104 | |
| 105 | parent.appendChild( td( null, null, [ text( id ) ] ) ); |
| 106 | parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) ); |
| 107 | parent.appendChild( td( null, null, [ text( state ) ] ) ); |
| 108 | var actionsTd = td( null, null ); |
| 109 | |
| 110 | for ( var a in dataEntry.actions ) { |
| 111 | actionButton( actionsTd, id, dataEntry.actions[a] ); |
| 112 | } |
| 113 | parent.appendChild( actionsTd ); |
| 114 | } |
| 115 | |
| 116 | function loadData() { |
| 117 | $.get(pluginRoot + "/.json", null, function(data) { |
| 118 | renderData(data); |
| 119 | }, "json"); |
| 120 | } |
| 121 | |
| 122 | function changeDataEntryState(/* long */ id, /* String */ action) { |
| 123 | $.post(pluginRoot + "/" + id, {"action":action}, function(data) { |
| 124 | renderData(data); |
| 125 | }, "json"); |
| 126 | } |
| 127 | |
| 128 | function refreshPackages() { |
| 129 | $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) { |
| 130 | renderData(data); |
| 131 | }, "json"); |
| 132 | } |
| 133 | |
| 134 | function showDetails( id ) { |
| 135 | $.get(pluginRoot + "/" + id + ".json", null, function(data) { |
| 136 | renderDetails(data); |
| 137 | }, "json"); |
| 138 | } |
| 139 | |
| 140 | function hideDetails( id ) { |
| 141 | $("#img" + id).each(function() { |
| 142 | $("#bundleInlineDetails").remove(); |
| 143 | this.setAttribute("src", appRoot + "/res/imgs/arrow_right.png"); |
| 144 | this.setAttribute("onClick", "showDetails('" + id + "')"); |
| 145 | this.setAttribute("title", "Details"); |
| 146 | this.setAttribute("alt", "Details"); |
| 147 | }); |
| 148 | } |
| 149 | |
| 150 | function renderDetails( data ) { |
| 151 | data = data.data[0]; |
| 152 | $("#entry" + data.id + " > td").eq(1).append("<div id='bundleInlineDetails'/>"); |
| 153 | $("#img" + data.id).each(function() { |
| 154 | if ( drawDetails ) { |
| 155 | this.setAttribute("src", appRoot + "/res/imgs/arrow_left.png"); |
| 156 | var ref = window.location.pathname; |
| 157 | ref = ref.substring(0, ref.lastIndexOf('/')); |
| 158 | this.setAttribute("onClick", "window.location = '" + ref + "';"); |
| 159 | this.setAttribute("title", "Back"); |
| 160 | this.setAttribute("alt", "Back"); |
| 161 | } else { |
| 162 | this.setAttribute("src", appRoot + "/res/imgs/arrow_down.png"); |
| 163 | this.setAttribute("onClick", "hideDetails('" + data.id + "')"); |
| 164 | this.setAttribute("title", "Hide Details"); |
| 165 | this.setAttribute("alt", "Hide Details"); |
| 166 | } |
| 167 | }); |
| 168 | $("#bundleInlineDetails").append("<table border='0'><tbody></tbody></table>"); |
| 169 | var details = data.props; |
| 170 | for (var idx in details) { |
| 171 | var prop = details[idx]; |
| 172 | |
| 173 | var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + prop.key + "</td><td class='aligntop' style='border:0px none'>"; |
| 174 | if (prop.value) { |
| 175 | if ( prop.key == 'Bundle Documentation' ) { |
| 176 | txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>"; |
| 177 | } else { |
| 178 | if ( $.isArray(prop.value) ) { |
| 179 | var i = 0; |
| 180 | for(var pi in prop.value) { |
| 181 | var value = prop.value[pi]; |
| 182 | if (i > 0) { txt = txt + "<br/>"; } |
| 183 | var span; |
| 184 | if (value.substring(0, 2) == "!!") { |
Carsten Ziegeler | 90c3d50 | 2009-02-06 15:53:44 +0000 | [diff] [blame] | 185 | txt = txt + "<span style='color: red;'>" + value + "</span>"; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 186 | } else { |
| 187 | txt = txt + value; |
| 188 | } |
| 189 | i++; |
| 190 | } |
| 191 | } else { |
| 192 | txt = txt + prop.value; |
| 193 | } |
| 194 | } |
| 195 | } else { |
| 196 | txt = txt + "\u00a0"; |
| 197 | } |
| 198 | txt = txt + "</td></tr>"; |
| 199 | $("#bundleInlineDetails > table > tbody").append(txt); |
| 200 | } |
| 201 | } |
| 202 | |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 203 | function renderBundles(data) { |
| 204 | $(document).ready(function(){ |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 205 | renderView( ["Id", "Name", "Status", "Actions"], |
Carsten Ziegeler | 52558d1 | 2009-02-05 19:56:36 +0000 | [diff] [blame] | 206 | "<input type='hidden' name='action' value='install'/>" + |
Carsten Ziegeler | a308d93 | 2009-02-05 20:02:07 +0000 | [diff] [blame] | 207 | "<input class='fileinput' type='file' name='bundlefile' style='margin-left:10px'/>" + |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 208 | " - Start <input class='checkradio' type='checkbox' name='bundlestart' value='start' style='vertical-align:middle;'/>" + |
| 209 | " - Start Level <input class='input' type='input' name='bundlestartlevel' value='" + startLevel + "' size='4'/>" + |
| 210 | "<input type='submit' value='Install or Update' style='margin-left:60px'/>" + |
| 211 | "<button id='refreshPackages' type='button' name='refresh' style='margin-left:10px'>Refresh Packages</button>" |
| 212 | ); |
| 213 | $("#refreshPackages").click(refreshPackages); |
| 214 | renderData(data); |
| 215 | |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 216 | var extractMethod = function(node) { |
| 217 | var link = node.getElementsByTagName("a"); |
| 218 | if ( link && link.length == 1 ) { |
| 219 | return link[0].innerHTML; |
| 220 | } |
| 221 | return node.innerHTML; |
| 222 | }; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 223 | $("#bundles").tablesorter({ |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 224 | headers: { |
| 225 | 0: { sorter:"digit"}, |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 226 | 3: { sorter: false } |
Carsten Ziegeler | 21f096b | 2009-02-05 19:38:34 +0000 | [diff] [blame] | 227 | }, |
| 228 | sortList: [[1,0]], |
| 229 | textExtraction:extractMethod |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 230 | }); |
| 231 | }); |
Felix Meschberger | 4c66413 | 2008-06-02 13:52:15 +0000 | [diff] [blame] | 232 | } |