Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +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 | */ |
| 17 | |
| 18 | function renderDataTable( /* Array of Data Objects */ components ) |
| 19 | { |
| 20 | // number of actions plus 3 -- id, name and state |
| 21 | var columns = components.numActions + 3; |
| 22 | |
| 23 | header( columns ); |
| 24 | |
| 25 | if (components.error) |
| 26 | { |
| 27 | error( columns, components.error ); |
| 28 | } |
| 29 | else |
| 30 | { |
| 31 | data ( components.data ); |
| 32 | } |
| 33 | |
| 34 | footer( columns ); |
| 35 | } |
| 36 | |
| 37 | |
| 38 | function header( /* int */ columns ) |
| 39 | { |
| 40 | document.write( "<table class='content' cellpadding='0' cellspacing='0' width='100%'>" ); |
| 41 | |
| 42 | document.write( "<tr class='content'>" ); |
| 43 | document.write( "<td colspan='" + columns + "' class='content'> </th>" ); |
| 44 | document.write( "</tr>" ); |
| 45 | |
| 46 | document.write( "<tr class='content'>" ); |
| 47 | document.write( "<th class='content'>ID</th>" ); |
| 48 | document.write( "<th class='content' width='100%'>Name</th>" ); |
| 49 | document.write( "<th class='content'>Status</th>" ); |
| 50 | document.write( "<th class='content' colspan='" + (columns - 3) + "'>Actions</th>" ); |
| 51 | document.write( "</tr>" ); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | |
| 56 | function error( /* int */ columns, /* String */ message ) |
| 57 | { |
| 58 | document.write( "<tr class='content'>" ); |
| 59 | document.write( "<td class='content'> </td>" ); |
| 60 | document.write( "<td class='content' colspan='" + (columns - 1) + "'>" + message + "</td>" ); |
| 61 | document.write( "</tr>" ); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | function data( /* Array of Object */ dataArray ) |
| 66 | { |
| 67 | // render components |
Felix Meschberger | 3effda9 | 2008-06-26 15:00:50 +0000 | [diff] [blame] | 68 | if (dataArray.length == 1) |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 69 | { |
Felix Meschberger | 3effda9 | 2008-06-26 15:00:50 +0000 | [diff] [blame] | 70 | entry( dataArray[0], true ); |
| 71 | } |
| 72 | else { |
| 73 | for ( var idx in dataArray ) |
| 74 | { |
| 75 | entry( dataArray[idx] ); |
| 76 | } |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
| 80 | |
| 81 | function footer( /* int */ columns ) |
| 82 | { |
| 83 | document.write( "<tr class='content'>" ); |
| 84 | document.write( "<td colspan='" + columns + "' class='content'> </th>" ); |
| 85 | document.write( "</tr>" ); |
| 86 | |
| 87 | document.write( "</table>" ); |
| 88 | } |
| 89 | |
| 90 | |
Felix Meschberger | 3effda9 | 2008-06-26 15:00:50 +0000 | [diff] [blame] | 91 | function entry( /* Object */ dataEntry, /* boolean */ singleEntry ) |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 92 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 93 | var trElement = tr( null, { id: "entry" + dataEntry.id } ); |
Felix Meschberger | 3effda9 | 2008-06-26 15:00:50 +0000 | [diff] [blame] | 94 | entryInternal( trElement, dataEntry, singleEntry ); |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 95 | document.write( serialize( trElement ) ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 96 | |
| 97 | // dataEntry detailed properties |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 98 | trElement = tr( null, { id: "entry" + dataEntry.id + "_details" } ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 99 | if (dataEntry.props) |
| 100 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 101 | getDataEntryDetails( trElement, dataEntry.props ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 102 | } |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 103 | document.write( serialize( trElement ) ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | |
Felix Meschberger | 3effda9 | 2008-06-26 15:00:50 +0000 | [diff] [blame] | 107 | function entryInternal( /* Element */ parent, /* Object */ dataEntry, /* boolean */ singleEntry ) |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 108 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 109 | |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 110 | var id = dataEntry.id; |
| 111 | var name = dataEntry.name; |
| 112 | var state = dataEntry.state; |
Felix Meschberger | 3effda9 | 2008-06-26 15:00:50 +0000 | [diff] [blame] | 113 | var icon = singleEntry ? "left" : (dataEntry.props ? "down" : "right"); |
| 114 | var event = singleEntry ? "history.back()" : "showDataEntryDetails(" + id + ")"; |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 115 | |
Felix Meschberger | 3effda9 | 2008-06-26 15:00:50 +0000 | [diff] [blame] | 116 | parent.appendChild( td( "content right", null, [ text( id ) ] ) ); |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 117 | |
Felix Meschberger | 3effda9 | 2008-06-26 15:00:50 +0000 | [diff] [blame] | 118 | parent.appendChild( td( "content", null, [ |
| 119 | createElement( "img", null, { |
| 120 | src: appRoot + "/res/imgs/" + icon + ".gif", |
| 121 | onClick: event, |
| 122 | id: "entry" + id + "_inline" |
| 123 | } ), |
| 124 | text( "\u00a0" ), |
| 125 | createElement( "a", null, { |
| 126 | href: pluginRoot + "/" + id |
| 127 | }, [ text( name ) ] |
| 128 | )] |
| 129 | ) |
| 130 | ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 131 | |
Felix Meschberger | 3effda9 | 2008-06-26 15:00:50 +0000 | [diff] [blame] | 132 | parent.appendChild( td( "content center", null, [ text( state ) ] ) ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 133 | |
| 134 | for ( var aidx in dataEntry.actions ) |
| 135 | { |
| 136 | var action = dataEntry.actions[aidx]; |
Felix Meschberger | e6704c3 | 2008-12-22 13:15:29 +0000 | [diff] [blame] | 137 | parent.appendChild( actionButton( action.enabled, id, action.link, action.name, action.title ) ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 138 | } |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
Felix Meschberger | e6704c3 | 2008-12-22 13:15:29 +0000 | [diff] [blame] | 142 | /* Element */ function actionButton( /* boolean */ enabled, /* long */ id, /* String */ op, /* String */ opLabel, /* String */ title ) |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 143 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 144 | var buttonTd = td( "content", { align: "right" } ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 145 | if ( op ) |
| 146 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 147 | var input = createElement( "input", "submit", { |
| 148 | type: 'button', |
| 149 | value: opLabel, |
| 150 | onClick: 'changeDataEntryState(' + id + ', "' + op + '");' |
| 151 | }); |
| 152 | if (!enabled) |
| 153 | { |
| 154 | input.setAttribute( "disabled", true ); |
| 155 | } |
Felix Meschberger | e6704c3 | 2008-12-22 13:15:29 +0000 | [diff] [blame] | 156 | if (title) |
| 157 | { |
| 158 | input.setAttribute( "title", title ); |
| 159 | } |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 160 | buttonTd.appendChild( input ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 161 | } |
| 162 | else |
| 163 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 164 | addText( buttonTd, "\u00a0" ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 165 | } |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 166 | |
| 167 | return buttonTd; |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 171 | function getDataEntryDetails( /* Element */ parent, /* Array of Object */ details ) |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 172 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 173 | parent.appendChild( addText( td( "content"), "\u00a0" ) ); |
| 174 | |
| 175 | var tdEl = td( "content", { colspan: 4 } ); |
| 176 | parent.appendChild( tdEl ); |
| 177 | |
| 178 | var tableEl = createElement( "table", null, { border: 0 } ); |
| 179 | tdEl.appendChild( tableEl ); |
| 180 | |
| 181 | var tbody = createElement( "tbody" ); |
| 182 | tableEl.appendChild( tbody ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 183 | for (var idx in details) |
| 184 | { |
| 185 | var prop = details[idx]; |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 186 | |
| 187 | |
| 188 | var trEl = tr(); |
| 189 | trEl.appendChild( addText( td( "aligntop", { noWrap: true } ), prop.key ) ); |
| 190 | |
| 191 | var proptd = td( "aligntop" ); |
| 192 | trEl.appendChild( proptd ); |
| 193 | |
Felix Meschberger | a10aa07 | 2008-10-24 06:29:15 +0000 | [diff] [blame] | 194 | if (prop.value) |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 195 | { |
| 196 | var values = new String( prop.value ).split( "<br />" ); |
| 197 | for (var i=0; i < values.length; i++) |
| 198 | { |
| 199 | if (i > 0) { proptd.appendChild( createElement( "br" ) ); } |
Felix Meschberger | a10aa07 | 2008-10-24 06:29:15 +0000 | [diff] [blame] | 200 | |
| 201 | var span; |
| 202 | if (values[i].substring(0, 2) == "!!") { |
| 203 | span = createElement( "span", null, { style: { color: "red" } } ); |
| 204 | proptd.appendChild( span ); |
| 205 | } else { |
| 206 | span = proptd; |
| 207 | } |
| 208 | |
| 209 | addText( span, values[i] ); |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | else |
| 213 | { |
| 214 | addText( proptd, "\u00a0" ); |
| 215 | } |
| 216 | |
| 217 | tbody.appendChild( trEl ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 218 | } |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | |
Felix Meschberger | 3effda9 | 2008-06-26 15:00:50 +0000 | [diff] [blame] | 222 | function showDetails(bundleId) |
| 223 | { |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 224 | var span = document.getElementById('bundle' + bundleId + '_details'); |
| 225 | } |
| 226 | |
| 227 | |
| 228 | function showDataEntryDetails( id ) |
| 229 | { |
| 230 | var span = document.getElementById( 'entry' + id + '_details' ); |
| 231 | if (span) |
| 232 | { |
Felix Meschberger | 76f5d0a | 2008-06-25 09:19:37 +0000 | [diff] [blame] | 233 | if (span.firstChild) |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 234 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 235 | clearChildren( span ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 236 | newLinkValue( id, appRoot + "/res/imgs/right.gif" ); |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | sendRequest( 'POST', pluginRoot + '/' + id, displayDataEntryDetails ); |
| 241 | newLinkValue( id, appRoot + "/res/imgs/down.gif" ); |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | |
| 247 | function newLinkValue( /* long */ id, /* String */ newLinkValue ) |
| 248 | { |
| 249 | |
| 250 | var link = document.getElementById( "entry" + id + "_inline" ); |
| 251 | if (link) |
| 252 | { |
| 253 | link.src = newLinkValue; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | |
| 258 | function displayDataEntryDetails( obj ) |
| 259 | { |
| 260 | var span = document.getElementById('entry' + obj.id + '_details'); |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 261 | if (span) |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 262 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 263 | clearChildren( span ); |
| 264 | getDataEntryDetails( span, obj.props ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | |
| 270 | function changeDataEntryState(/* long */ id, /* String */ action) |
| 271 | { |
| 272 | var parm = pluginRoot + "/" + id + "?action=" + action; |
| 273 | sendRequest('POST', parm, dataEntryStateChanged); |
| 274 | } |
| 275 | |
| 276 | |
| 277 | function dataEntryStateChanged(obj) |
| 278 | { |
| 279 | if (obj.reload) |
| 280 | { |
| 281 | document.location = document.location; |
| 282 | } |
| 283 | else |
| 284 | { |
| 285 | var id = obj.id; |
| 286 | if (obj.state) |
| 287 | { |
| 288 | // has status, so draw the line |
| 289 | if (obj.props) |
| 290 | { |
| 291 | var span = document.getElementById('entry' + id + '_details'); |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 292 | if (span && span.firstChild) |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 293 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 294 | clearChildren( span ); |
| 295 | getDataEntryDetails( span, obj.props ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 296 | } |
| 297 | else |
| 298 | { |
| 299 | obj.props = false; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | var span = document.getElementById('entry' + id); |
| 304 | if (span) |
| 305 | { |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 306 | clearChildren( span ); |
| 307 | entryInternal( span, obj ); |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 308 | } |
Felix Meschberger | 1c33646 | 2008-06-19 11:08:47 +0000 | [diff] [blame] | 309 | } |
| 310 | else |
| 311 | { |
| 312 | // no status, dataEntry has been removed/uninstalled |
| 313 | var span = document.getElementById('entry' + id); |
| 314 | if (span) |
| 315 | { |
| 316 | span.parentNode.removeChild(span); |
| 317 | } |
| 318 | var span = document.getElementById('entry' + id + '_details'); |
| 319 | if (span) |
| 320 | { |
| 321 | span.parentNode.removeChild(span); |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | |