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