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 | */ |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 17 | // ui elements |
| 18 | var uploadDialog = false; |
| 19 | var bundlesTable = false; |
| 20 | var bundlesBody = false; |
| 21 | var bundlesTemplate = false; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 22 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 23 | function renderData( eventData, filter ) { |
| 24 | lastBundleData = eventData; |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 25 | var s = eventData.s; |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 26 | $('.statline').html(i18n.statline.msgFormat(s[0], s[1], s[2], s[3], s[4])); |
| 27 | bundlesBody.empty(); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 28 | for ( var idx in eventData.data ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 29 | if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) { |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 30 | entry( eventData.data[idx], filter ); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 31 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 32 | } |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 33 | if ( drawDetails && eventData.data.length == 1 ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 34 | renderDetails(eventData.data[0]); |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 35 | } else if ( currentBundle != null ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 36 | var id = currentBundle; |
| 37 | hideDetails(id); |
| 38 | showDetails(id); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 39 | } |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 40 | initStaticWidgets(); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 43 | function entry( /* Object */ bundle, filter ) { |
| 44 | var matches = !(filter && typeof filter.test == 'function') ? true : |
| 45 | filter.test(bundle.id) || filter.test(bundle.name) || filter.test(bundle.symbolicName) || filter.test(bundle.version); |
| 46 | |
| 47 | if (matches) entryInternal( bundle ).appendTo(bundlesBody); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 50 | function hasStart(b) { return (!b.fragment) && (b.stateRaw == 2 || b.stateRaw == 4) } // !isFragment && (installed | resolved) |
| 51 | function hasStop(b) { return (!b.fragment) && (b.stateRaw == 32) } // !isFragment && active |
| 52 | function hasUninstall(b) { return b.stateRaw == 2 || b.stateRaw == 4 || b.stateRaw == 32 } // installed | resolved | active |
| 53 | function stateString(b) { |
| 54 | var s = b.stateRaw; |
| 55 | return b.fragment && s == 4 ? |
| 56 | i18n.state.fragment : // fragment & resolved |
| 57 | i18n.state[s] ? i18n.state[s] : i18n.state.unknown.msgFormat(s) |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 60 | function entryInternal( /* Object */ bundle ) { |
| 61 | var tr = bundlesTemplate.clone(); |
| 62 | var id = bundle.id; |
| 63 | var name = bundle.name; |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 64 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 65 | tr.attr('id', 'entry'+id); |
| 66 | tr.find('td:eq(0)').text(id); |
| 67 | tr.find('td:eq(1) span:eq(0)').attr('id', 'img'+id).click(function() {showDetails(id)}); |
| 68 | tr.find('td:eq(1) span:eq(1)').html( drawDetails ? name : '<a href="' + pluginRoot + '/' + id + '">' + name + '</a>' ); |
| 69 | tr.find('td:eq(2)').text( bundle.version ); |
| 70 | tr.find('td:eq(3)').text( bundle.symbolicName ); |
| 71 | tr.find('td:eq(4)').text( stateString(bundle) ); |
| 72 | if (id == 0) { // system bundle has no actions |
| 73 | tr.find('td:eq(5) ul').addClass('ui-helper-hidden'); |
| 74 | } else { |
| 75 | var start = tr.find('td:eq(5) ul li:eq(0)'); |
| 76 | var stop = tr.find('td:eq(5) ul li:eq(1)'); |
| 77 | var refresh = tr.find('td:eq(5) ul li:eq(2)').click(function() {changeDataEntryState(id, 'refresh')}); |
| 78 | var update = tr.find('td:eq(5) ul li:eq(3)').click(function() {changeDataEntryState(id, 'update')}); |
| 79 | var remove = tr.find('td:eq(5) ul li:eq(4)'); |
| 80 | start = hasStart(bundle) ? |
| 81 | start.click(function() {changeDataEntryState(id, 'start')}) : |
| 82 | start.addClass('ui-helper-hidden'); |
| 83 | stop = hasStop(bundle) ? |
| 84 | stop.click(function() {changeDataEntryState(id, 'stop')}) : |
| 85 | stop.addClass('ui-helper-hidden'); |
| 86 | remove = hasUninstall(bundle) ? |
| 87 | remove.click(function() {changeDataEntryState(id, 'uninstall')}) : |
| 88 | remove.addClass('ui-helper-hidden'); |
| 89 | } |
| 90 | return tr; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | function loadData() { |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 94 | $.get(pluginRoot + "/.json", null, renderData, "json"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | function changeDataEntryState(/* long */ id, /* String */ action) { |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 98 | $.post(pluginRoot + "/" + id, {"action":action}, renderData, "json"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | function refreshPackages() { |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 102 | $.post(pluginRoot, {"action": "refreshPackages"}, renderData, "json"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | function showDetails( id ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 106 | currentBundle = id; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 107 | $.get(pluginRoot + "/" + id + ".json", null, function(data) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 108 | renderDetails(data.data[0]); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 109 | }, "json"); |
| 110 | } |
| 111 | |
| 112 | function hideDetails( id ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 113 | currentBundle = null; |
| 114 | $("#img" + id).each(function() { |
| 115 | $("#pluginInlineDetails" + id).remove(); |
| 116 | $(this). |
| 117 | removeClass('ui-icon-triangle-1-w').//left |
| 118 | removeClass('ui-icon-triangle-1-s').//down |
| 119 | addClass('ui-icon-triangle-1-e').//right |
| 120 | attr("title", "Details"). |
| 121 | unbind('click').click(function() {showDetails(id)}); |
| 122 | }); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | function renderDetails( data ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 126 | $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>"); |
| 127 | $("#img" + data.id).each(function() { |
| 128 | if ( drawDetails ) { |
| 129 | var ref = window.location.pathname; |
| 130 | ref = ref.substring(0, ref.lastIndexOf('/')); |
| 131 | $(this). |
| 132 | removeClass('ui-icon-triangle-1-e').//right |
| 133 | removeClass('ui-icon-triangle-1-s').//down |
| 134 | addClass('ui-icon-triangle-1-w').//left |
| 135 | attr("title", "Back"). |
| 136 | unbind('click').click(function() {window.location = ref}); |
| 137 | } else { |
| 138 | $(this). |
| 139 | removeClass('ui-icon-triangle-1-w').//left |
| 140 | removeClass('ui-icon-triangle-1-e').//right |
| 141 | addClass('ui-icon-triangle-1-s').//down |
| 142 | attr("title", "Hide Details"). |
| 143 | unbind('click').click(function() {hideDetails(data.id)}); |
| 144 | } |
| 145 | }); |
| 146 | $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 147 | var details = data.props; |
| 148 | for (var idx in details) { |
| 149 | var prop = details[idx]; |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 150 | var key = i18n[prop.key] ? i18n[prop.key] : prop.key; |
| 151 | |
| 152 | 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] | 153 | if (prop.value) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 154 | if ( prop.key == 'Bundle Documentation' ) { |
| 155 | txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>"; |
| 156 | } else { |
| 157 | if ( $.isArray(prop.value) ) { |
| 158 | var i = 0; |
| 159 | for(var pi in prop.value) { |
| 160 | var value = prop.value[pi]; |
| 161 | if (i > 0) { txt = txt + "<br/>"; } |
| 162 | txt = txt + value; |
| 163 | i++; |
| 164 | } |
| 165 | } else { |
| 166 | txt = txt + prop.value; |
| 167 | } |
| 168 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 169 | } else { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 170 | txt = txt + "\u00a0"; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 171 | } |
| 172 | txt = txt + "</td></tr>"; |
Felix Meschberger | 16dd988 | 2010-02-18 08:08:47 +0000 | [diff] [blame] | 173 | $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 174 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 177 | |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 178 | $(document).ready(function(){ |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 179 | $('.refreshPackages').click(refreshPackages); |
| 180 | $('.reloadButton').click(loadData); |
| 181 | $('.installButton').click(function() { |
| 182 | uploadDialog.dialog('open'); |
| 183 | return false; |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 184 | }); |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 185 | |
| 186 | // filter |
| 187 | $('input.filter').click(function() {$(this).val('')}); |
| 188 | $('.filterApply').click(function() { |
| 189 | var el = $(this).parent().find('input.filter'); |
| 190 | var filter = el.length && el.val() ? new RegExp(el.val()) : false; |
| 191 | renderData(lastBundleData, filter); |
| 192 | }); |
| 193 | $('.filterForm').submit(function() { |
| 194 | $(this).find('.filterApply').click(); |
| 195 | return false; |
| 196 | }); |
| 197 | $('.filterClear').click(function() { |
| 198 | $('input.filter').val(''); |
| 199 | renderData(lastBundleData); |
| 200 | }); |
| 201 | |
| 202 | // upload dialog |
| 203 | var uploadDialogButtons = {}; |
| 204 | uploadDialogButtons[i18n.install_update] = function() { |
| 205 | $(this).find('form').submit(); |
| 206 | } |
| 207 | uploadDialog = $('#uploadDialog').dialog({ |
| 208 | autoOpen: false, |
| 209 | modal : true, |
| 210 | width : '50%', |
| 211 | buttons : uploadDialogButtons |
| 212 | }); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 213 | |
| 214 | // check for cookie |
| 215 | var cv = $.cookies.get("webconsolebundlelist"); |
| 216 | var lo = (cv ? cv.split(",") : [1,0]); |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 217 | bundlesTable = $("#plugin_table").tablesorter({ |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 218 | headers: { |
| 219 | 0: { sorter:"digit" }, |
| 220 | 5: { sorter: false } |
| 221 | }, |
| 222 | textExtraction:mixedLinksExtraction, |
| 223 | sortList: cv ? [lo] : false |
| 224 | }).bind("sortEnd", function() { |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 225 | bundlesTable.eq(0).attr("config"); |
| 226 | $.cookies.set("webconsolebundlelist", bundlesTable.sortList.toString()); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 227 | }); |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame^] | 228 | bundlesBody = bundlesTable.find('tbody'); |
| 229 | bundlesTemplate = bundlesBody.find('tr').clone(); |
| 230 | |
| 231 | renderData(lastBundleData); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 232 | }); |
| 233 | |