blob: 1a671e4165103ac6b46c5b78f7acf05e6aa84a7d [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");
63 if (cv) {
64 bundlesTable.trigger('sorton', [cv]);
65 }
Valentin Valchev88dbf702010-04-14 13:15:06 +000066
Valentin Valchev984d4662010-04-13 11:01:11 +000067 // show dialog on error
68 if (eventData.error) bundleOpError.dialog('open').find('pre').text(eventData.error)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000069}
70
Valentin Valchevce0a4322010-03-17 08:13:39 +000071function entry( /* Object */ bundle, filter ) {
72 var matches = !(filter && typeof filter.test == 'function') ? true :
Valentin Valchev8d9f1032010-03-19 07:54:14 +000073 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 +000074
75 if (matches) entryInternal( bundle ).appendTo(bundlesBody);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000076}
77
Valentin Valchevce0a4322010-03-17 08:13:39 +000078function hasStart(b) { return (!b.fragment) && (b.stateRaw == 2 || b.stateRaw == 4) } // !isFragment && (installed | resolved)
79function hasStop(b) { return (!b.fragment) && (b.stateRaw == 32) } // !isFragment && active
80function hasUninstall(b) { return b.stateRaw == 2 || b.stateRaw == 4 || b.stateRaw == 32 } // installed | resolved | active
81function stateString(b) {
82 var s = b.stateRaw;
83 return b.fragment && s == 4 ?
84 i18n.state.fragment : // fragment & resolved
85 i18n.state[s] ? i18n.state[s] : i18n.state.unknown.msgFormat(s)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000086}
87
Valentin Valchevce0a4322010-03-17 08:13:39 +000088function entryInternal( /* Object */ bundle ) {
89 var tr = bundlesTemplate.clone();
90 var id = bundle.id;
Valentin Valchev8d9f1032010-03-19 07:54:14 +000091 var name = bundle.name + '<span class="symName">' + bundle.symbolicName + '</span>';
Felix Meschberger63d692a2010-02-18 15:29:39 +000092
Valentin Valchevce0a4322010-03-17 08:13:39 +000093 tr.attr('id', 'entry'+id);
Felix Meschberger8285c422012-03-26 20:10:45 +000094 tr.children('td:eq(0)').text(id);
Valentin Valchev16bef4a2010-04-15 08:45:47 +000095 tr.find('.bIcon').attr('id', 'img'+id).click(function() {showDetails(id)});
96 tr.find('.bName').html( drawDetails ? name : '<a href="' + pluginRoot + '/' + id + '">' + name + '</a>' );
Felix Meschberger8285c422012-03-26 20:10:45 +000097 tr.children('td:eq(2)').text( bundle.version );
98 tr.children('td:eq(3)').text( bundle.category );
Valentin Valchevce0a4322010-03-17 08:13:39 +000099 if (id == 0) { // system bundle has no actions
Felix Meschberger8285c422012-03-26 20:10:45 +0000100 tr.children('td:eq(4)').text( stateString(bundle) );
101 tr.children('td:eq(5)').find('ul').addClass('ui-helper-hidden');
Valentin Valchevce0a4322010-03-17 08:13:39 +0000102 } else {
Valentin Valchev984d4662010-04-13 11:01:11 +0000103 entrySetupState( bundle, tr, id );
Valentin Valchevce0a4322010-03-17 08:13:39 +0000104 }
105 return tr;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000106}
Valentin Valchev984d4662010-04-13 11:01:11 +0000107function entrySetupState( /* Object */ bundle, tr, id) {
Felix Meschberger8285c422012-03-26 20:10:45 +0000108 var start = tr.children('td:eq(5)').find('ul li:eq(0)').removeClass('ui-helper-hidden').unbind('click');
109 var stop = tr.children('td:eq(5)').find('ul li:eq(1)').removeClass('ui-helper-hidden').unbind('click');
110 var refresh = tr.children('td:eq(5)').find('ul li:eq(2)').unbind('click').click(function() {return changeDataEntryState(id, 'refresh')});
111 var update = tr.children('td:eq(5)').find('ul li:eq(3)').unbind('click').click(function() {return changeDataEntryState(id, 'update')});
112 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 +0000113 start = hasStart(bundle) ?
114 start.click(function() {return changeDataEntryState(id, 'start')}) :
115 start.addClass('ui-helper-hidden');
116 stop = hasStop(bundle) ?
117 stop.click(function() {return changeDataEntryState(id, 'stop')}) :
118 stop.addClass('ui-helper-hidden');
119 remove = hasUninstall(bundle) ?
120 remove.click(function() {return changeDataEntryState(id, 'uninstall')}) :
121 remove.addClass('ui-helper-hidden');
Felix Meschberger8285c422012-03-26 20:10:45 +0000122 tr.children('td:eq(4)').text( stateString(bundle) );
Valentin Valchev984d4662010-04-13 11:01:11 +0000123}
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000124
125function loadData() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000126 $.get(pluginRoot + "/.json", null, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000127}
128
129function changeDataEntryState(/* long */ id, /* String */ action) {
Valentin Valchev984d4662010-04-13 11:01:11 +0000130 $.post(pluginRoot + '/' + id, {'action':action}, function(b) {
131 var _tr = bundlesBody.find('#entry' + id);
132 if (1 == b.stateRaw) { // uninstalled
133 _tr.remove();
134 } else {
135 entrySetupState( b, _tr, id );
136 }
Valentin Valchev46e3c9c2012-04-26 12:15:55 +0000137 if ('refresh' == action || 'update' == action) {
138 bundleOpSuccess.dialog('open');
139 // TODO:
140
141 }
Valentin Valchev984d4662010-04-13 11:01:11 +0000142 }, 'json');
143 return false;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000144}
145
146function refreshPackages() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000147 $.post(pluginRoot, {"action": "refreshPackages"}, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000148}
149
150function showDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000151 currentBundle = id;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000152 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000153 renderDetails(data.data[0]);
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000154 }, "json");
155}
156
157function hideDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000158 currentBundle = null;
159 $("#img" + id).each(function() {
160 $("#pluginInlineDetails" + id).remove();
161 $(this).
162 removeClass('ui-icon-triangle-1-w').//left
163 removeClass('ui-icon-triangle-1-s').//down
164 addClass('ui-icon-triangle-1-e').//right
165 attr("title", "Details").
166 unbind('click').click(function() {showDetails(id)});
167 });
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000168}
169
170function renderDetails( data ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000171 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>");
172 $("#img" + data.id).each(function() {
173 if ( drawDetails ) {
174 var ref = window.location.pathname;
175 ref = ref.substring(0, ref.lastIndexOf('/'));
176 $(this).
177 removeClass('ui-icon-triangle-1-e').//right
178 removeClass('ui-icon-triangle-1-s').//down
179 addClass('ui-icon-triangle-1-w').//left
180 attr("title", "Back").
181 unbind('click').click(function() {window.location = ref});
182 } else {
183 $(this).
184 removeClass('ui-icon-triangle-1-w').//left
185 removeClass('ui-icon-triangle-1-e').//right
186 addClass('ui-icon-triangle-1-s').//down
187 attr("title", "Hide Details").
188 unbind('click').click(function() {hideDetails(data.id)});
189 }
190 });
191 $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000192 var details = data.props;
193 for (var idx in details) {
194 var prop = details[idx];
Valentin Valchev57ba7bc2012-08-15 12:48:53 +0000195
196 if (prop.key == 'nfo') {
197 $.each(prop.value, function(name, bundleInfo) {
198 var txt = '';
199 $.each(bundleInfo, function(idx, ie) {
200 txt += '<div title="' + makeSafe(ie.description) + '">';
201 if (ie.type == 'link' || ie.type == 'resource') {
202 txt += '<a href="' + ie.value + '">' + ie.name + '</a>';
203 } else {
204 txt += ie.name + " = " + ie.value;
205 }
206 txt += '</div>';
207 });
208 $("#pluginInlineDetails" + data.id + " > table > tbody").append(
209 renderDetailsEntry(name, txt) );
210 });
211 } else
212 $("#pluginInlineDetails" + data.id + " > table > tbody").append(
213 renderDetailsEntry(prop.key, prop.value) );
Felix Meschberger63d692a2010-02-18 15:29:39 +0000214 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000215}
Valentin Valchev57ba7bc2012-08-15 12:48:53 +0000216function makeSafe(text) {
217 return text.replace(/\W/g, function (chr) {
218 return '&#' + chr.charCodeAt(0) + ';';
219 });
220};
221
222function renderDetailsEntry(key, value) {
223 var key18 = i18n[key] ? i18n[key] : key;
224 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + key18 + "</td><td class='aligntop' style='border:0px none'>";
225 if (value) {
226 if ( key == 'Bundle Documentation' ) {
227 txt += "<a href='" + value + "' target='_blank'>" + value + "</a>";
228 } else {
229 if ( $.isArray(value) ) {
230 var i = 0;
231 for(var pi in value) {
232 var xv = value[pi];
233 if (i > 0) { txt = txt + "<br/>"; }
234 var span;
235 if (xv.substring(0, 6) == "INFO: ") {
236 txt += "<span class='ui-state-info-text'>" + xv.substring(5) + "</span>";
237 } else if (xv.substring(0, 7) == "ERROR: ") {
238 txt += "<span class='ui-state-error-text'>" + xv.substring(6) + "</span>";
239 } else {
240 txt += xv;
241 }
242 i++;
243 }
244 } else {
245 txt += value;
246 }
247 }
248 } else {
249 txt += "\u00a0";
250 }
251 return txt + "</td></tr>";
252}
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000253
Valentin Valchevce0a4322010-03-17 08:13:39 +0000254
Felix Meschberger63d692a2010-02-18 15:29:39 +0000255$(document).ready(function(){
Valentin Valchevce0a4322010-03-17 08:13:39 +0000256 $('.refreshPackages').click(refreshPackages);
257 $('.reloadButton').click(loadData);
258 $('.installButton').click(function() {
259 uploadDialog.dialog('open');
260 return false;
Felix Meschberger63d692a2010-02-18 15:29:39 +0000261 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000262
Valentin Valchev984d4662010-04-13 11:01:11 +0000263 bundleOpError = $('#bundleOpError').dialog({
264 autoOpen: false,
265 modal : true,
266 width : '80%'
267 });
268 bundleOpError.parent().addClass('ui-state-error');
Valentin Valchev46e3c9c2012-04-26 12:15:55 +0000269 bundleOpSuccess = $('#bundleOpSuccess').dialog({
270 autoOpen: false,
271 modal : true,
272 width : '80%'
273 });
Valentin Valchev984d4662010-04-13 11:01:11 +0000274
Valentin Valchevce0a4322010-03-17 08:13:39 +0000275 // filter
Valentin Valchevce0a4322010-03-17 08:13:39 +0000276 $('.filterApply').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000277 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000278 var el = $(this).parent().find('input.filter');
279 var filter = el.length && el.val() ? new RegExp(el.val()) : false;
280 renderData(lastBundleData, filter);
281 });
282 $('.filterForm').submit(function() {
283 $(this).find('.filterApply').click();
284 return false;
285 });
286 $('.filterClear').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000287 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000288 $('input.filter').val('');
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000289 loadData();
290 });
291 $('.filterLDAP').click(function() {
292 if ($(this).hasClass('ui-state-disabled')) return;
293 var el = $(this).parent().find('input.filter');
294 var filter = el.val();
295 if (filter) $.get(pluginRoot + '/.json', { 'filter' : filter }, renderData, 'json');
Valentin Valcheve569ba22010-04-01 09:26:49 +0000296 return false;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000297 });
298
299 // upload dialog
300 var uploadDialogButtons = {};
301 uploadDialogButtons[i18n.install_update] = function() {
302 $(this).find('form').submit();
303 }
304 uploadDialog = $('#uploadDialog').dialog({
305 autoOpen: false,
306 modal : true,
307 width : '50%',
308 buttons : uploadDialogButtons
309 });
Felix Meschberger63d692a2010-02-18 15:29:39 +0000310
311 // check for cookie
Valentin Valchevce0a4322010-03-17 08:13:39 +0000312 bundlesTable = $("#plugin_table").tablesorter({
Felix Meschberger63d692a2010-02-18 15:29:39 +0000313 headers: {
314 0: { sorter:"digit" },
315 5: { sorter: false }
316 },
Valentin Valchev16bef4a2010-04-15 08:45:47 +0000317 textExtraction:mixedLinksExtraction
Felix Meschbergerefc5de52012-12-02 18:44:51 +0000318 }).bind("sortEnd", function(/* Event */ e) {
319 var t = e.target.config;
320 if (t && t.sortList) {
Felix Meschberger7efb5462011-12-22 12:53:44 +0000321 setCookie("bundlelist", t.sortList);
322 }
323 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000324 bundlesBody = bundlesTable.find('tbody');
325 bundlesTemplate = bundlesBody.find('tr').clone();
326
327 renderData(lastBundleData);
Felix Meschberger63d692a2010-02-18 15:29:39 +0000328});
329