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 | |
| 18 | function renderData( eventData ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 19 | var s = eventData.s; |
| 20 | $(".statline").html(i18n.statline.msgFormat(s[0], s[1], s[2], s[3], s[4])); |
| 21 | $("#plugin_table > tbody > tr").remove(); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 22 | for ( var idx in eventData.data ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 23 | if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) { |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 24 | entry( eventData.data[idx] ); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 25 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 26 | } |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 27 | if ( drawDetails && eventData.data.length == 1 ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 28 | renderDetails(eventData.data[0]); |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 29 | } else if ( currentBundle != null ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 30 | var id = currentBundle; |
| 31 | hideDetails(id); |
| 32 | showDetails(id); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 33 | } |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 34 | initStaticWidgets(); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | function entry( /* Object */ dataEntry ) { |
| 38 | var trElement = tr( null, { id: "entry" + dataEntry.id } ); |
| 39 | entryInternal( trElement, dataEntry ); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 40 | $("#plugin_table > tbody").append(trElement); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 44 | if ( !action.enabled ) { |
| 45 | return; |
| 46 | } |
| 47 | var enabled = action.enabled; |
| 48 | var op = action.link; |
| 49 | var opLabel = action.name; |
| 50 | var img = action.image; |
| 51 | // fixup JQuery UI icons |
| 52 | if(img == "start" ) img = "play"; |
| 53 | if(img == "update") img = "transferthick-e-w"; |
| 54 | if(img == "delete") img = "trash"; |
| 55 | |
| 56 | // apply i18n |
| 57 | opLabel = i18n[opLabel] ? i18n[opLabel] : opLabel; |
| 58 | |
| 59 | var input = createElement('li', 'dynhover', { |
| 60 | title: opLabel |
| 61 | }); |
| 62 | $(input) |
| 63 | .html('<span class="ui-icon ui-icon-'+img+'"></span>') |
| 64 | .click(function() {changeDataEntryState(id, op)}); |
| 65 | |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 66 | if (!enabled) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 67 | $(input).attr("disabled", true).addClass("ui-state-disabled"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 68 | } |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 69 | parent.appendChild( input ); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | function entryInternal( /* Element */ parent, /* Object */ dataEntry ) { |
| 73 | var id = dataEntry.id; |
| 74 | var name = dataEntry.name; |
| 75 | var state = dataEntry.state; |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 76 | |
| 77 | // right arrow |
| 78 | var inputElement = createElement('span', 'ui-icon ui-icon-triangle-1-e', { |
| 79 | title: "Details", |
| 80 | id: 'img' + id, |
| 81 | style: {display: "inline-block"} |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 82 | }); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 83 | $(inputElement).click(function() {showDetails(id)}); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 84 | var titleElement; |
| 85 | if ( drawDetails ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 86 | titleElement = text(name); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 87 | } else { |
| 88 | titleElement = createElement ("a", null, { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 89 | href: window.location.pathname + "/" + id |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 90 | }); |
| 91 | titleElement.appendChild(text(name)); |
| 92 | } |
| 93 | |
| 94 | parent.appendChild( td( null, null, [ text( id ) ] ) ); |
| 95 | parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) ); |
Carsten Ziegeler | ca26b52 | 2009-04-27 20:45:09 +0000 | [diff] [blame] | 96 | parent.appendChild( td( null, null, [ text( dataEntry.version ) ] ) ); |
| 97 | parent.appendChild( td( null, null, [ text( dataEntry.symbolicName ) ] ) ); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 98 | parent.appendChild( td( null, null, [ text( state ) ] ) ); |
| 99 | var actionsTd = td( null, null ); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 100 | var div = createElement('ul', 'icons ui-widget'); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 101 | actionsTd.appendChild(div); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 102 | |
| 103 | for ( var a in dataEntry.actions ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 104 | actionButton( div, id, dataEntry.actions[a] ); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 105 | } |
| 106 | parent.appendChild( actionsTd ); |
| 107 | } |
| 108 | |
| 109 | function loadData() { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 110 | $.get(pluginRoot + "/.json", null, function(data) { |
| 111 | renderData(data); |
| 112 | }, "json"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | function changeDataEntryState(/* long */ id, /* String */ action) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 116 | $.post(pluginRoot + "/" + id, {"action":action}, function(data) { |
| 117 | renderData(data); |
| 118 | }, "json"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | function refreshPackages() { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 122 | $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) { |
| 123 | renderData(data); |
| 124 | }, "json"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | function showDetails( id ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 128 | currentBundle = id; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 129 | $.get(pluginRoot + "/" + id + ".json", null, function(data) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 130 | renderDetails(data.data[0]); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 131 | }, "json"); |
| 132 | } |
| 133 | |
| 134 | function hideDetails( id ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 135 | currentBundle = null; |
| 136 | $("#img" + id).each(function() { |
| 137 | $("#pluginInlineDetails" + id).remove(); |
| 138 | $(this). |
| 139 | removeClass('ui-icon-triangle-1-w').//left |
| 140 | removeClass('ui-icon-triangle-1-s').//down |
| 141 | addClass('ui-icon-triangle-1-e').//right |
| 142 | attr("title", "Details"). |
| 143 | unbind('click').click(function() {showDetails(id)}); |
| 144 | }); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | function renderDetails( data ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 148 | $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>"); |
| 149 | $("#img" + data.id).each(function() { |
| 150 | if ( drawDetails ) { |
| 151 | var ref = window.location.pathname; |
| 152 | ref = ref.substring(0, ref.lastIndexOf('/')); |
| 153 | $(this). |
| 154 | removeClass('ui-icon-triangle-1-e').//right |
| 155 | removeClass('ui-icon-triangle-1-s').//down |
| 156 | addClass('ui-icon-triangle-1-w').//left |
| 157 | attr("title", "Back"). |
| 158 | unbind('click').click(function() {window.location = ref}); |
| 159 | } else { |
| 160 | $(this). |
| 161 | removeClass('ui-icon-triangle-1-w').//left |
| 162 | removeClass('ui-icon-triangle-1-e').//right |
| 163 | addClass('ui-icon-triangle-1-s').//down |
| 164 | attr("title", "Hide Details"). |
| 165 | unbind('click').click(function() {hideDetails(data.id)}); |
| 166 | } |
| 167 | }); |
| 168 | $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 169 | var details = data.props; |
| 170 | for (var idx in details) { |
| 171 | var prop = details[idx]; |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 172 | var key = i18n[prop.key] ? i18n[prop.key] : prop.key; |
| 173 | |
| 174 | var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + key + "</td><td class='aligntop' style='border:0px none'>"; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 175 | if (prop.value) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 176 | if ( prop.key == 'Bundle Documentation' ) { |
| 177 | txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>"; |
| 178 | } else { |
| 179 | if ( $.isArray(prop.value) ) { |
| 180 | var i = 0; |
| 181 | for(var pi in prop.value) { |
| 182 | var value = prop.value[pi]; |
| 183 | if (i > 0) { txt = txt + "<br/>"; } |
| 184 | txt = txt + value; |
| 185 | i++; |
| 186 | } |
| 187 | } else { |
| 188 | txt = txt + prop.value; |
| 189 | } |
| 190 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 191 | } else { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 192 | txt = txt + "\u00a0"; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 193 | } |
| 194 | txt = txt + "</td></tr>"; |
Felix Meschberger | 16dd988 | 2010-02-18 08:08:47 +0000 | [diff] [blame] | 195 | $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 196 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 199 | $(document).ready(function(){ |
| 200 | $(".refreshPackages").click(refreshPackages); |
| 201 | $(".reloadButton").click(loadData); |
| 202 | $(".installButton").click(function() { |
| 203 | document.location = pluginRoot + "/upload"; |
| 204 | }); |
| 205 | renderData(__bundles__); |
| 206 | |
| 207 | // check for cookie |
| 208 | var cv = $.cookies.get("webconsolebundlelist"); |
| 209 | var lo = (cv ? cv.split(",") : [1,0]); |
| 210 | $("#plugin_table").tablesorter({ |
| 211 | headers: { |
| 212 | 0: { sorter:"digit" }, |
| 213 | 5: { sorter: false } |
| 214 | }, |
| 215 | textExtraction:mixedLinksExtraction, |
| 216 | sortList: cv ? [lo] : false |
| 217 | }).bind("sortEnd", function() { |
| 218 | var table = $("#plugin_table").eq(0).attr("config"); |
| 219 | $.cookies.set("webconsolebundlelist", table.sortList.toString()); |
| 220 | }); |
| 221 | }); |
| 222 | |