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