blob: a04426b15107d3a82113dc435ad0b5385b65a6b4 [file] [log] [blame]
Felix Meschberger9b3c4e02008-06-02 13:52:15 +00001/*
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 Valchevce0a4322010-03-17 08:13:39 +000017// ui elements
18var uploadDialog = false;
19var bundlesTable = false;
20var bundlesBody = false;
21var bundlesTemplate = false;
Valentin Valchev984d4662010-04-13 11:01:11 +000022var bundleOpError = false;
Valentin Valchev46e3c9c2012-04-26 12:15:55 +000023var bundleOpSuccess = false;
Carsten Ziegelerf9879152009-02-05 10:45:35 +000024
Valentin Valchevce0a4322010-03-17 08:13:39 +000025function renderData( eventData, filter ) {
26 lastBundleData = eventData;
Felix Meschberger63d692a2010-02-18 15:29:39 +000027 var s = eventData.s;
Carsten Ziegeler3566a9f2013-01-30 16:20:33 +000028 var statline = i18n.statlinePrefix + ' ' + i18n.statlineTotal.msgFormat(s[0]);
Carsten Ziegeler322d8742013-01-30 15:56:09 +000029 if ( s[0] == s[1] || s[0] == s[1] + s[2]) {
30 statline += ' - ' + i18n.statlineAll.msgFormat(s[0]);
31 } else {
32 if ( s[1] > 0 ) {
Carsten Ziegeler3566a9f2013-01-30 16:20:33 +000033 statline += ', ' + i18n.statlineActive.msgFormat(s[1]);
Carsten Ziegeler322d8742013-01-30 15:56:09 +000034 }
35 if ( s[2] > 0 ) {
Carsten Ziegeler3566a9f2013-01-30 16:20:33 +000036 statline += ', ' + i18n.statlineFragments.msgFormat(s[2]);
Carsten Ziegeler322d8742013-01-30 15:56:09 +000037 }
38 if ( s[3] > 0 ) {
Carsten Ziegeler3566a9f2013-01-30 16:20:33 +000039 statline += ', ' + i18n.statlineResolved.msgFormat(s[3]);
Carsten Ziegeler322d8742013-01-30 15:56:09 +000040 }
41 if ( s[4] > 0 ) {
Carsten Ziegeler3566a9f2013-01-30 16:20:33 +000042 statline += ', ' + i18n.statlineInstalled.msgFormat(s[4]);
Carsten Ziegeler322d8742013-01-30 15:56:09 +000043 }
44 }
45 $('.statline').html(statline);
Valentin Valchevce0a4322010-03-17 08:13:39 +000046 bundlesBody.empty();
Carsten Ziegelerf9879152009-02-05 10:45:35 +000047 for ( var idx in eventData.data ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +000048 if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) {
Valentin Valchevce0a4322010-03-17 08:13:39 +000049 entry( eventData.data[idx], filter );
Felix Meschberger63d692a2010-02-18 15:29:39 +000050 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +000051 }
Carsten Ziegeler176aee42009-12-11 09:19:50 +000052 if ( drawDetails && eventData.data.length == 1 ) {
Valentin Valchev8d9f1032010-03-19 07:54:14 +000053 $('.filterBox input, .filterBox button').addClass('ui-state-disabled');
Felix Meschberger63d692a2010-02-18 15:29:39 +000054 renderDetails(eventData.data[0]);
Carsten Ziegeler176aee42009-12-11 09:19:50 +000055 } else if ( currentBundle != null ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +000056 var id = currentBundle;
57 hideDetails(id);
58 showDetails(id);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000059 }
Felix Meschberger63d692a2010-02-18 15:29:39 +000060 initStaticWidgets();
Valentin Valchev88dbf702010-04-14 13:15:06 +000061
Felix Meschberger7efb5462011-12-22 12:53:44 +000062 var cv = getCookie("bundlelist");
A. J. David Bosschaert197992b2015-02-18 14:51:06 +000063 if (cv && bundlesTable.find("tr").size() > 1) {
Felix Meschberger7efb5462011-12-22 12:53:44 +000064 bundlesTable.trigger('sorton', [cv]);
65 }
Valentin Valchev88dbf702010-04-14 13:15:06 +000066
Valentin Valchev7032d352015-03-10 08:35:19 +000067 if (bundlesBody.find('tr').size() == 0) {
68 bundlesBody.html('<tr><td colspan="6">' + i18n.filterNoMatch + '</td></tr>');
69 }
70
Valentin Valchev984d4662010-04-13 11:01:11 +000071 // show dialog on error
72 if (eventData.error) bundleOpError.dialog('open').find('pre').text(eventData.error)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000073}
74
Valentin Valchevce0a4322010-03-17 08:13:39 +000075function entry( /* Object */ bundle, filter ) {
76 var matches = !(filter && typeof filter.test == 'function') ? true :
Valentin Valchev8d9f1032010-03-19 07:54:14 +000077 filter.test(bundle.id) || filter.test(bundle.name) || filter.test(bundle.symbolicName) || filter.test(bundle.version) || filter.test(bundle.category);
Valentin Valchevce0a4322010-03-17 08:13:39 +000078
79 if (matches) entryInternal( bundle ).appendTo(bundlesBody);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000080}
81
Valentin Valchevce0a4322010-03-17 08:13:39 +000082function hasStart(b) { return (!b.fragment) && (b.stateRaw == 2 || b.stateRaw == 4) } // !isFragment && (installed | resolved)
83function hasStop(b) { return (!b.fragment) && (b.stateRaw == 32) } // !isFragment && active
84function hasUninstall(b) { return b.stateRaw == 2 || b.stateRaw == 4 || b.stateRaw == 32 } // installed | resolved | active
85function stateString(b) {
86 var s = b.stateRaw;
87 return b.fragment && s == 4 ?
88 i18n.state.fragment : // fragment & resolved
89 i18n.state[s] ? i18n.state[s] : i18n.state.unknown.msgFormat(s)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000090}
91
Valentin Valchevce0a4322010-03-17 08:13:39 +000092function entryInternal( /* Object */ bundle ) {
93 var tr = bundlesTemplate.clone();
94 var id = bundle.id;
Valentin Valchev8d9f1032010-03-19 07:54:14 +000095 var name = bundle.name + '<span class="symName">' + bundle.symbolicName + '</span>';
Felix Meschberger63d692a2010-02-18 15:29:39 +000096
Valentin Valchevce0a4322010-03-17 08:13:39 +000097 tr.attr('id', 'entry'+id);
Felix Meschberger8285c422012-03-26 20:10:45 +000098 tr.children('td:eq(0)').text(id);
Valentin Valchev16bef4a2010-04-15 08:45:47 +000099 tr.find('.bIcon').attr('id', 'img'+id).click(function() {showDetails(id)});
100 tr.find('.bName').html( drawDetails ? name : '<a href="' + pluginRoot + '/' + id + '">' + name + '</a>' );
Felix Meschberger8285c422012-03-26 20:10:45 +0000101 tr.children('td:eq(2)').text( bundle.version );
102 tr.children('td:eq(3)').text( bundle.category );
Valentin Valchevce0a4322010-03-17 08:13:39 +0000103 if (id == 0) { // system bundle has no actions
Felix Meschberger8285c422012-03-26 20:10:45 +0000104 tr.children('td:eq(4)').text( stateString(bundle) );
105 tr.children('td:eq(5)').find('ul').addClass('ui-helper-hidden');
Valentin Valchevce0a4322010-03-17 08:13:39 +0000106 } else {
Valentin Valchev984d4662010-04-13 11:01:11 +0000107 entrySetupState( bundle, tr, id );
Valentin Valchevce0a4322010-03-17 08:13:39 +0000108 }
109 return tr;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000110}
Valentin Valchev984d4662010-04-13 11:01:11 +0000111function entrySetupState( /* Object */ bundle, tr, id) {
Felix Meschberger8285c422012-03-26 20:10:45 +0000112 var start = tr.children('td:eq(5)').find('ul li:eq(0)').removeClass('ui-helper-hidden').unbind('click');
113 var stop = tr.children('td:eq(5)').find('ul li:eq(1)').removeClass('ui-helper-hidden').unbind('click');
114 var refresh = tr.children('td:eq(5)').find('ul li:eq(2)').unbind('click').click(function() {return changeDataEntryState(id, 'refresh')});
115 var update = tr.children('td:eq(5)').find('ul li:eq(3)').unbind('click').click(function() {return changeDataEntryState(id, 'update')});
116 var remove = tr.children('td:eq(5)').find('ul li:eq(4)').removeClass('ui-helper-hidden').unbind('click');
Valentin Valchev984d4662010-04-13 11:01:11 +0000117 start = hasStart(bundle) ?
118 start.click(function() {return changeDataEntryState(id, 'start')}) :
119 start.addClass('ui-helper-hidden');
120 stop = hasStop(bundle) ?
121 stop.click(function() {return changeDataEntryState(id, 'stop')}) :
122 stop.addClass('ui-helper-hidden');
123 remove = hasUninstall(bundle) ?
124 remove.click(function() {return changeDataEntryState(id, 'uninstall')}) :
125 remove.addClass('ui-helper-hidden');
Felix Meschberger8285c422012-03-26 20:10:45 +0000126 tr.children('td:eq(4)').text( stateString(bundle) );
Valentin Valchev984d4662010-04-13 11:01:11 +0000127}
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000128
129function loadData() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000130 $.get(pluginRoot + "/.json", null, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000131}
132
133function changeDataEntryState(/* long */ id, /* String */ action) {
Valentin Valchev984d4662010-04-13 11:01:11 +0000134 $.post(pluginRoot + '/' + id, {'action':action}, function(b) {
135 var _tr = bundlesBody.find('#entry' + id);
136 if (1 == b.stateRaw) { // uninstalled
137 _tr.remove();
138 } else {
139 entrySetupState( b, _tr, id );
140 }
Valentin Valchev46e3c9c2012-04-26 12:15:55 +0000141 if ('refresh' == action || 'update' == action) {
142 bundleOpSuccess.dialog('open');
143 // TODO:
144
145 }
Valentin Valchev984d4662010-04-13 11:01:11 +0000146 }, 'json');
147 return false;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000148}
149
150function refreshPackages() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000151 $.post(pluginRoot, {"action": "refreshPackages"}, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000152}
153
154function showDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000155 currentBundle = id;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000156 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000157 renderDetails(data.data[0]);
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000158 }, "json");
159}
160
161function hideDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000162 currentBundle = null;
163 $("#img" + id).each(function() {
164 $("#pluginInlineDetails" + id).remove();
165 $(this).
166 removeClass('ui-icon-triangle-1-w').//left
167 removeClass('ui-icon-triangle-1-s').//down
168 addClass('ui-icon-triangle-1-e').//right
169 attr("title", "Details").
170 unbind('click').click(function() {showDetails(id)});
171 });
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000172}
173
174function renderDetails( data ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000175 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>");
176 $("#img" + data.id).each(function() {
177 if ( drawDetails ) {
178 var ref = window.location.pathname;
179 ref = ref.substring(0, ref.lastIndexOf('/'));
180 $(this).
181 removeClass('ui-icon-triangle-1-e').//right
182 removeClass('ui-icon-triangle-1-s').//down
183 addClass('ui-icon-triangle-1-w').//left
184 attr("title", "Back").
185 unbind('click').click(function() {window.location = ref});
186 } else {
187 $(this).
188 removeClass('ui-icon-triangle-1-w').//left
189 removeClass('ui-icon-triangle-1-e').//right
190 addClass('ui-icon-triangle-1-s').//down
191 attr("title", "Hide Details").
192 unbind('click').click(function() {hideDetails(data.id)});
193 }
194 });
195 $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000196 var details = data.props;
197 for (var idx in details) {
198 var prop = details[idx];
Valentin Valchev57ba7bc2012-08-15 12:48:53 +0000199
200 if (prop.key == 'nfo') {
201 $.each(prop.value, function(name, bundleInfo) {
202 var txt = '';
203 $.each(bundleInfo, function(idx, ie) {
204 txt += '<div title="' + makeSafe(ie.description) + '">';
205 if (ie.type == 'link' || ie.type == 'resource') {
206 txt += '<a href="' + ie.value + '">' + ie.name + '</a>';
207 } else {
208 txt += ie.name + " = " + ie.value;
209 }
210 txt += '</div>';
211 });
212 $("#pluginInlineDetails" + data.id + " > table > tbody").append(
213 renderDetailsEntry(name, txt) );
214 });
215 } else
216 $("#pluginInlineDetails" + data.id + " > table > tbody").append(
217 renderDetailsEntry(prop.key, prop.value) );
Felix Meschberger63d692a2010-02-18 15:29:39 +0000218 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000219}
Valentin Valchev57ba7bc2012-08-15 12:48:53 +0000220function makeSafe(text) {
221 return text.replace(/\W/g, function (chr) {
222 return '&#' + chr.charCodeAt(0) + ';';
223 });
224};
225
226function renderDetailsEntry(key, value) {
227 var key18 = i18n[key] ? i18n[key] : key;
228 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + key18 + "</td><td class='aligntop' style='border:0px none'>";
229 if (value) {
230 if ( key == 'Bundle Documentation' ) {
231 txt += "<a href='" + value + "' target='_blank'>" + value + "</a>";
232 } else {
233 if ( $.isArray(value) ) {
234 var i = 0;
235 for(var pi in value) {
236 var xv = value[pi];
237 if (i > 0) { txt = txt + "<br/>"; }
238 var span;
239 if (xv.substring(0, 6) == "INFO: ") {
240 txt += "<span class='ui-state-info-text'>" + xv.substring(5) + "</span>";
241 } else if (xv.substring(0, 7) == "ERROR: ") {
242 txt += "<span class='ui-state-error-text'>" + xv.substring(6) + "</span>";
243 } else {
244 txt += xv;
245 }
246 i++;
247 }
248 } else {
249 txt += value;
250 }
251 }
252 } else {
253 txt += "\u00a0";
254 }
255 return txt + "</td></tr>";
256}
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000257
Valentin Valchevce0a4322010-03-17 08:13:39 +0000258
Felix Meschberger63d692a2010-02-18 15:29:39 +0000259$(document).ready(function(){
Valentin Valchevce0a4322010-03-17 08:13:39 +0000260 $('.refreshPackages').click(refreshPackages);
261 $('.reloadButton').click(loadData);
262 $('.installButton').click(function() {
263 uploadDialog.dialog('open');
264 return false;
Felix Meschberger63d692a2010-02-18 15:29:39 +0000265 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000266
Valentin Valchev984d4662010-04-13 11:01:11 +0000267 bundleOpError = $('#bundleOpError').dialog({
268 autoOpen: false,
269 modal : true,
270 width : '80%'
271 });
272 bundleOpError.parent().addClass('ui-state-error');
Valentin Valchev46e3c9c2012-04-26 12:15:55 +0000273 bundleOpSuccess = $('#bundleOpSuccess').dialog({
274 autoOpen: false,
275 modal : true,
276 width : '80%'
277 });
Valentin Valchev984d4662010-04-13 11:01:11 +0000278
Valentin Valchevce0a4322010-03-17 08:13:39 +0000279 // filter
Valentin Valchevce0a4322010-03-17 08:13:39 +0000280 $('.filterApply').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000281 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000282 var el = $(this).parent().find('input.filter');
283 var filter = el.length && el.val() ? new RegExp(el.val()) : false;
284 renderData(lastBundleData, filter);
285 });
286 $('.filterForm').submit(function() {
287 $(this).find('.filterApply').click();
288 return false;
289 });
290 $('.filterClear').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000291 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000292 $('input.filter').val('');
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000293 loadData();
294 });
295 $('.filterLDAP').click(function() {
296 if ($(this).hasClass('ui-state-disabled')) return;
297 var el = $(this).parent().find('input.filter');
298 var filter = el.val();
299 if (filter) $.get(pluginRoot + '/.json', { 'filter' : filter }, renderData, 'json');
Valentin Valcheve569ba22010-04-01 09:26:49 +0000300 return false;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000301 });
302
303 // upload dialog
304 var uploadDialogButtons = {};
305 uploadDialogButtons[i18n.install_update] = function() {
306 $(this).find('form').submit();
307 }
308 uploadDialog = $('#uploadDialog').dialog({
309 autoOpen: false,
310 modal : true,
311 width : '50%',
312 buttons : uploadDialogButtons
313 });
Felix Meschberger63d692a2010-02-18 15:29:39 +0000314
315 // check for cookie
Valentin Valchevce0a4322010-03-17 08:13:39 +0000316 bundlesTable = $("#plugin_table").tablesorter({
Felix Meschberger63d692a2010-02-18 15:29:39 +0000317 headers: {
318 0: { sorter:"digit" },
319 5: { sorter: false }
320 },
Valentin Valchev16bef4a2010-04-15 08:45:47 +0000321 textExtraction:mixedLinksExtraction
Felix Meschbergerefc5de52012-12-02 18:44:51 +0000322 }).bind("sortEnd", function(/* Event */ e) {
323 var t = e.target.config;
324 if (t && t.sortList) {
Felix Meschberger7efb5462011-12-22 12:53:44 +0000325 setCookie("bundlelist", t.sortList);
326 }
327 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000328 bundlesBody = bundlesTable.find('tbody');
329 bundlesTemplate = bundlesBody.find('tr').clone();
330
331 renderData(lastBundleData);
Felix Meschberger63d692a2010-02-18 15:29:39 +0000332});
333