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; |
Valentin Pavlov Valchev | 2fafa58 | 2010-04-13 11:01:11 +0000 | [diff] [blame] | 22 | var bundleOpError = false; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 23 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 24 | function renderData( eventData, filter ) { |
| 25 | lastBundleData = eventData; |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 26 | var s = eventData.s; |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 27 | $('.statline').html(i18n.statline.msgFormat(s[0], s[1], s[2], s[3], s[4])); |
| 28 | bundlesBody.empty(); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 29 | for ( var idx in eventData.data ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 30 | if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) { |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 31 | entry( eventData.data[idx], filter ); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 32 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 33 | } |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 34 | if ( drawDetails && eventData.data.length == 1 ) { |
Valentin Pavlov Valchev | b2a498b | 2010-03-19 07:54:14 +0000 | [diff] [blame] | 35 | $('.filterBox input, .filterBox button').addClass('ui-state-disabled'); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 36 | renderDetails(eventData.data[0]); |
Carsten Ziegeler | 3bbfee4 | 2009-12-11 09:19:50 +0000 | [diff] [blame] | 37 | } else if ( currentBundle != null ) { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 38 | var id = currentBundle; |
| 39 | hideDetails(id); |
| 40 | showDetails(id); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 41 | } |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 42 | initStaticWidgets(); |
Valentin Pavlov Valchev | 15fb1fa | 2010-04-14 13:15:06 +0000 | [diff] [blame] | 43 | |
Felix Meschberger | a2b7738 | 2011-12-22 12:53:44 +0000 | [diff] [blame] | 44 | var cv = getCookie("bundlelist"); |
| 45 | if (cv) { |
| 46 | bundlesTable.trigger('sorton', [cv]); |
| 47 | } |
Valentin Pavlov Valchev | 15fb1fa | 2010-04-14 13:15:06 +0000 | [diff] [blame] | 48 | |
Valentin Pavlov Valchev | 2fafa58 | 2010-04-13 11:01:11 +0000 | [diff] [blame] | 49 | // show dialog on error |
| 50 | if (eventData.error) bundleOpError.dialog('open').find('pre').text(eventData.error) |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 53 | function entry( /* Object */ bundle, filter ) { |
| 54 | var matches = !(filter && typeof filter.test == 'function') ? true : |
Valentin Pavlov Valchev | b2a498b | 2010-03-19 07:54:14 +0000 | [diff] [blame] | 55 | 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] | 56 | |
| 57 | if (matches) entryInternal( bundle ).appendTo(bundlesBody); |
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 hasStart(b) { return (!b.fragment) && (b.stateRaw == 2 || b.stateRaw == 4) } // !isFragment && (installed | resolved) |
| 61 | function hasStop(b) { return (!b.fragment) && (b.stateRaw == 32) } // !isFragment && active |
| 62 | function hasUninstall(b) { return b.stateRaw == 2 || b.stateRaw == 4 || b.stateRaw == 32 } // installed | resolved | active |
| 63 | function stateString(b) { |
| 64 | var s = b.stateRaw; |
| 65 | return b.fragment && s == 4 ? |
| 66 | i18n.state.fragment : // fragment & resolved |
| 67 | i18n.state[s] ? i18n.state[s] : i18n.state.unknown.msgFormat(s) |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 70 | function entryInternal( /* Object */ bundle ) { |
| 71 | var tr = bundlesTemplate.clone(); |
| 72 | var id = bundle.id; |
Valentin Pavlov Valchev | b2a498b | 2010-03-19 07:54:14 +0000 | [diff] [blame] | 73 | var name = bundle.name + '<span class="symName">' + bundle.symbolicName + '</span>'; |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 74 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 75 | tr.attr('id', 'entry'+id); |
| 76 | tr.find('td:eq(0)').text(id); |
Valentin Pavlov Valchev | c21c0d4 | 2010-04-15 08:45:47 +0000 | [diff] [blame] | 77 | tr.find('.bIcon').attr('id', 'img'+id).click(function() {showDetails(id)}); |
| 78 | tr.find('.bName').html( drawDetails ? name : '<a href="' + pluginRoot + '/' + id + '">' + name + '</a>' ); |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 79 | tr.find('td:eq(2)').text( bundle.version ); |
Valentin Pavlov Valchev | b2a498b | 2010-03-19 07:54:14 +0000 | [diff] [blame] | 80 | tr.find('td:eq(3)').text( bundle.category ); |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 81 | if (id == 0) { // system bundle has no actions |
Valentin Pavlov Valchev | 2fafa58 | 2010-04-13 11:01:11 +0000 | [diff] [blame] | 82 | tr.find('td:eq(4)').text( stateString(bundle) ); |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 83 | tr.find('td:eq(5) ul').addClass('ui-helper-hidden'); |
| 84 | } else { |
Valentin Pavlov Valchev | 2fafa58 | 2010-04-13 11:01:11 +0000 | [diff] [blame] | 85 | entrySetupState( bundle, tr, id ); |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 86 | } |
| 87 | return tr; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 88 | } |
Valentin Pavlov Valchev | 2fafa58 | 2010-04-13 11:01:11 +0000 | [diff] [blame] | 89 | function entrySetupState( /* Object */ bundle, tr, id) { |
| 90 | var start = tr.find('td:eq(5) ul li:eq(0)').removeClass('ui-helper-hidden').unbind('click'); |
| 91 | var stop = tr.find('td:eq(5) ul li:eq(1)').removeClass('ui-helper-hidden').unbind('click'); |
| 92 | var refresh = tr.find('td:eq(5) ul li:eq(2)').unbind('click').click(function() {return changeDataEntryState(id, 'refresh')}); |
| 93 | var update = tr.find('td:eq(5) ul li:eq(3)').unbind('click').click(function() {return changeDataEntryState(id, 'update')}); |
| 94 | var remove = tr.find('td:eq(5) ul li:eq(4)').removeClass('ui-helper-hidden').unbind('click'); |
| 95 | start = hasStart(bundle) ? |
| 96 | start.click(function() {return changeDataEntryState(id, 'start')}) : |
| 97 | start.addClass('ui-helper-hidden'); |
| 98 | stop = hasStop(bundle) ? |
| 99 | stop.click(function() {return changeDataEntryState(id, 'stop')}) : |
| 100 | stop.addClass('ui-helper-hidden'); |
| 101 | remove = hasUninstall(bundle) ? |
| 102 | remove.click(function() {return changeDataEntryState(id, 'uninstall')}) : |
| 103 | remove.addClass('ui-helper-hidden'); |
| 104 | tr.find('td:eq(4)').text( stateString(bundle) ); |
| 105 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 106 | |
| 107 | function loadData() { |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 108 | $.get(pluginRoot + "/.json", null, renderData, "json"); |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | function changeDataEntryState(/* long */ id, /* String */ action) { |
Valentin Pavlov Valchev | 2fafa58 | 2010-04-13 11:01:11 +0000 | [diff] [blame] | 112 | $.post(pluginRoot + '/' + id, {'action':action}, function(b) { |
| 113 | var _tr = bundlesBody.find('#entry' + id); |
| 114 | if (1 == b.stateRaw) { // uninstalled |
| 115 | _tr.remove(); |
| 116 | } else { |
| 117 | entrySetupState( b, _tr, id ); |
| 118 | } |
| 119 | }, 'json'); |
| 120 | return false; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | function refreshPackages() { |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 124 | $.post(pluginRoot, {"action": "refreshPackages"}, renderData, "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/>"; } |
Carsten Ziegeler | a406db7 | 2010-10-12 07:31:50 +0000 | [diff] [blame] | 184 | var span; |
| 185 | if (value.substring(0, 6) == "INFO: ") { |
| 186 | txt = txt + "<span class='ui-state-info-text'>" + value.substring(5) + "</span>"; |
| 187 | } else if (value.substring(0, 7) == "ERROR: ") { |
| 188 | txt = txt + "<span class='ui-state-error-text'>" + value.substring(6) + "</span>"; |
| 189 | } else { |
| 190 | txt = txt + value; |
| 191 | } |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 192 | i++; |
| 193 | } |
| 194 | } else { |
| 195 | txt = txt + prop.value; |
| 196 | } |
| 197 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 198 | } else { |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 199 | txt = txt + "\u00a0"; |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 200 | } |
| 201 | txt = txt + "</td></tr>"; |
Felix Meschberger | 16dd988 | 2010-02-18 08:08:47 +0000 | [diff] [blame] | 202 | $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 203 | } |
Carsten Ziegeler | 6577bfa | 2009-02-05 10:45:35 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 206 | |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 207 | $(document).ready(function(){ |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 208 | $('.refreshPackages').click(refreshPackages); |
| 209 | $('.reloadButton').click(loadData); |
| 210 | $('.installButton').click(function() { |
| 211 | uploadDialog.dialog('open'); |
| 212 | return false; |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 213 | }); |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 214 | |
Valentin Pavlov Valchev | 2fafa58 | 2010-04-13 11:01:11 +0000 | [diff] [blame] | 215 | bundleOpError = $('#bundleOpError').dialog({ |
| 216 | autoOpen: false, |
| 217 | modal : true, |
| 218 | width : '80%' |
| 219 | }); |
| 220 | bundleOpError.parent().addClass('ui-state-error'); |
| 221 | |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 222 | // filter |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 223 | $('.filterApply').click(function() { |
Valentin Pavlov Valchev | b2a498b | 2010-03-19 07:54:14 +0000 | [diff] [blame] | 224 | if ($(this).hasClass('ui-state-disabled')) return; |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 225 | var el = $(this).parent().find('input.filter'); |
| 226 | var filter = el.length && el.val() ? new RegExp(el.val()) : false; |
| 227 | renderData(lastBundleData, filter); |
| 228 | }); |
| 229 | $('.filterForm').submit(function() { |
| 230 | $(this).find('.filterApply').click(); |
| 231 | return false; |
| 232 | }); |
| 233 | $('.filterClear').click(function() { |
Valentin Pavlov Valchev | b2a498b | 2010-03-19 07:54:14 +0000 | [diff] [blame] | 234 | if ($(this).hasClass('ui-state-disabled')) return; |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 235 | $('input.filter').val(''); |
Valentin Pavlov Valchev | b2a498b | 2010-03-19 07:54:14 +0000 | [diff] [blame] | 236 | loadData(); |
| 237 | }); |
| 238 | $('.filterLDAP').click(function() { |
| 239 | if ($(this).hasClass('ui-state-disabled')) return; |
| 240 | var el = $(this).parent().find('input.filter'); |
| 241 | var filter = el.val(); |
| 242 | if (filter) $.get(pluginRoot + '/.json', { 'filter' : filter }, renderData, 'json'); |
Valentin Pavlov Valchev | 008c0a3 | 2010-04-01 09:26:49 +0000 | [diff] [blame] | 243 | return false; |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 244 | }); |
| 245 | |
| 246 | // upload dialog |
| 247 | var uploadDialogButtons = {}; |
| 248 | uploadDialogButtons[i18n.install_update] = function() { |
| 249 | $(this).find('form').submit(); |
| 250 | } |
| 251 | uploadDialog = $('#uploadDialog').dialog({ |
| 252 | autoOpen: false, |
| 253 | modal : true, |
| 254 | width : '50%', |
| 255 | buttons : uploadDialogButtons |
| 256 | }); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 257 | |
| 258 | // check for cookie |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 259 | bundlesTable = $("#plugin_table").tablesorter({ |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 260 | headers: { |
| 261 | 0: { sorter:"digit" }, |
| 262 | 5: { sorter: false } |
| 263 | }, |
Valentin Pavlov Valchev | c21c0d4 | 2010-04-15 08:45:47 +0000 | [diff] [blame] | 264 | textExtraction:mixedLinksExtraction |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 265 | }).bind("sortEnd", function() { |
Felix Meschberger | a2b7738 | 2011-12-22 12:53:44 +0000 | [diff] [blame] | 266 | var t = bundlesTable.eq(0).attr("config"); |
| 267 | if (t.sortList) { |
| 268 | setCookie("bundlelist", t.sortList); |
| 269 | } |
| 270 | }); |
Valentin Pavlov Valchev | 366f91c | 2010-03-17 08:13:39 +0000 | [diff] [blame] | 271 | bundlesBody = bundlesTable.find('tbody'); |
| 272 | bundlesTemplate = bundlesBody.find('tr').clone(); |
| 273 | |
| 274 | renderData(lastBundleData); |
Felix Meschberger | 775025e | 2010-02-18 15:29:39 +0000 | [diff] [blame] | 275 | }); |
| 276 | |