blob: 703b96176864a2f60d53f0da13424845fd675f95 [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;
Valentin Valchevce0a4322010-03-17 08:13:39 +000028 $('.statline').html(i18n.statline.msgFormat(s[0], s[1], s[2], s[3], s[4]));
29 bundlesBody.empty();
Carsten Ziegelerf9879152009-02-05 10:45:35 +000030 for ( var idx in eventData.data ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +000031 if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) {
Valentin Valchevce0a4322010-03-17 08:13:39 +000032 entry( eventData.data[idx], filter );
Felix Meschberger63d692a2010-02-18 15:29:39 +000033 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +000034 }
Carsten Ziegeler176aee42009-12-11 09:19:50 +000035 if ( drawDetails && eventData.data.length == 1 ) {
Valentin Valchev8d9f1032010-03-19 07:54:14 +000036 $('.filterBox input, .filterBox button').addClass('ui-state-disabled');
Felix Meschberger63d692a2010-02-18 15:29:39 +000037 renderDetails(eventData.data[0]);
Carsten Ziegeler176aee42009-12-11 09:19:50 +000038 } else if ( currentBundle != null ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +000039 var id = currentBundle;
40 hideDetails(id);
41 showDetails(id);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000042 }
Felix Meschberger63d692a2010-02-18 15:29:39 +000043 initStaticWidgets();
Valentin Valchev88dbf702010-04-14 13:15:06 +000044
Felix Meschberger7efb5462011-12-22 12:53:44 +000045 var cv = getCookie("bundlelist");
46 if (cv) {
47 bundlesTable.trigger('sorton', [cv]);
48 }
Valentin Valchev88dbf702010-04-14 13:15:06 +000049
Valentin Valchev984d4662010-04-13 11:01:11 +000050 // show dialog on error
51 if (eventData.error) bundleOpError.dialog('open').find('pre').text(eventData.error)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000052}
53
Valentin Valchevce0a4322010-03-17 08:13:39 +000054function entry( /* Object */ bundle, filter ) {
55 var matches = !(filter && typeof filter.test == 'function') ? true :
Valentin Valchev8d9f1032010-03-19 07:54:14 +000056 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 +000057
58 if (matches) entryInternal( bundle ).appendTo(bundlesBody);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000059}
60
Valentin Valchevce0a4322010-03-17 08:13:39 +000061function hasStart(b) { return (!b.fragment) && (b.stateRaw == 2 || b.stateRaw == 4) } // !isFragment && (installed | resolved)
62function hasStop(b) { return (!b.fragment) && (b.stateRaw == 32) } // !isFragment && active
63function hasUninstall(b) { return b.stateRaw == 2 || b.stateRaw == 4 || b.stateRaw == 32 } // installed | resolved | active
64function stateString(b) {
65 var s = b.stateRaw;
66 return b.fragment && s == 4 ?
67 i18n.state.fragment : // fragment & resolved
68 i18n.state[s] ? i18n.state[s] : i18n.state.unknown.msgFormat(s)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000069}
70
Valentin Valchevce0a4322010-03-17 08:13:39 +000071function entryInternal( /* Object */ bundle ) {
72 var tr = bundlesTemplate.clone();
73 var id = bundle.id;
Valentin Valchev8d9f1032010-03-19 07:54:14 +000074 var name = bundle.name + '<span class="symName">' + bundle.symbolicName + '</span>';
Felix Meschberger63d692a2010-02-18 15:29:39 +000075
Valentin Valchevce0a4322010-03-17 08:13:39 +000076 tr.attr('id', 'entry'+id);
Felix Meschberger8285c422012-03-26 20:10:45 +000077 tr.children('td:eq(0)').text(id);
Valentin Valchev16bef4a2010-04-15 08:45:47 +000078 tr.find('.bIcon').attr('id', 'img'+id).click(function() {showDetails(id)});
79 tr.find('.bName').html( drawDetails ? name : '<a href="' + pluginRoot + '/' + id + '">' + name + '</a>' );
Felix Meschberger8285c422012-03-26 20:10:45 +000080 tr.children('td:eq(2)').text( bundle.version );
81 tr.children('td:eq(3)').text( bundle.category );
Valentin Valchevce0a4322010-03-17 08:13:39 +000082 if (id == 0) { // system bundle has no actions
Felix Meschberger8285c422012-03-26 20:10:45 +000083 tr.children('td:eq(4)').text( stateString(bundle) );
84 tr.children('td:eq(5)').find('ul').addClass('ui-helper-hidden');
Valentin Valchevce0a4322010-03-17 08:13:39 +000085 } else {
Valentin Valchev984d4662010-04-13 11:01:11 +000086 entrySetupState( bundle, tr, id );
Valentin Valchevce0a4322010-03-17 08:13:39 +000087 }
88 return tr;
Carsten Ziegelerf9879152009-02-05 10:45:35 +000089}
Valentin Valchev984d4662010-04-13 11:01:11 +000090function entrySetupState( /* Object */ bundle, tr, id) {
Felix Meschberger8285c422012-03-26 20:10:45 +000091 var start = tr.children('td:eq(5)').find('ul li:eq(0)').removeClass('ui-helper-hidden').unbind('click');
92 var stop = tr.children('td:eq(5)').find('ul li:eq(1)').removeClass('ui-helper-hidden').unbind('click');
93 var refresh = tr.children('td:eq(5)').find('ul li:eq(2)').unbind('click').click(function() {return changeDataEntryState(id, 'refresh')});
94 var update = tr.children('td:eq(5)').find('ul li:eq(3)').unbind('click').click(function() {return changeDataEntryState(id, 'update')});
95 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 +000096 start = hasStart(bundle) ?
97 start.click(function() {return changeDataEntryState(id, 'start')}) :
98 start.addClass('ui-helper-hidden');
99 stop = hasStop(bundle) ?
100 stop.click(function() {return changeDataEntryState(id, 'stop')}) :
101 stop.addClass('ui-helper-hidden');
102 remove = hasUninstall(bundle) ?
103 remove.click(function() {return changeDataEntryState(id, 'uninstall')}) :
104 remove.addClass('ui-helper-hidden');
Felix Meschberger8285c422012-03-26 20:10:45 +0000105 tr.children('td:eq(4)').text( stateString(bundle) );
Valentin Valchev984d4662010-04-13 11:01:11 +0000106}
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000107
108function loadData() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000109 $.get(pluginRoot + "/.json", null, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000110}
111
112function changeDataEntryState(/* long */ id, /* String */ action) {
Valentin Valchev984d4662010-04-13 11:01:11 +0000113 $.post(pluginRoot + '/' + id, {'action':action}, function(b) {
114 var _tr = bundlesBody.find('#entry' + id);
115 if (1 == b.stateRaw) { // uninstalled
116 _tr.remove();
117 } else {
118 entrySetupState( b, _tr, id );
119 }
Valentin Valchev46e3c9c2012-04-26 12:15:55 +0000120 if ('refresh' == action || 'update' == action) {
121 bundleOpSuccess.dialog('open');
122 // TODO:
123
124 }
Valentin Valchev984d4662010-04-13 11:01:11 +0000125 }, 'json');
126 return false;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000127}
128
129function refreshPackages() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000130 $.post(pluginRoot, {"action": "refreshPackages"}, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000131}
132
133function showDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000134 currentBundle = id;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000135 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000136 renderDetails(data.data[0]);
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000137 }, "json");
138}
139
140function hideDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000141 currentBundle = null;
142 $("#img" + id).each(function() {
143 $("#pluginInlineDetails" + id).remove();
144 $(this).
145 removeClass('ui-icon-triangle-1-w').//left
146 removeClass('ui-icon-triangle-1-s').//down
147 addClass('ui-icon-triangle-1-e').//right
148 attr("title", "Details").
149 unbind('click').click(function() {showDetails(id)});
150 });
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000151}
152
153function renderDetails( data ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000154 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>");
155 $("#img" + data.id).each(function() {
156 if ( drawDetails ) {
157 var ref = window.location.pathname;
158 ref = ref.substring(0, ref.lastIndexOf('/'));
159 $(this).
160 removeClass('ui-icon-triangle-1-e').//right
161 removeClass('ui-icon-triangle-1-s').//down
162 addClass('ui-icon-triangle-1-w').//left
163 attr("title", "Back").
164 unbind('click').click(function() {window.location = ref});
165 } else {
166 $(this).
167 removeClass('ui-icon-triangle-1-w').//left
168 removeClass('ui-icon-triangle-1-e').//right
169 addClass('ui-icon-triangle-1-s').//down
170 attr("title", "Hide Details").
171 unbind('click').click(function() {hideDetails(data.id)});
172 }
173 });
174 $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000175 var details = data.props;
176 for (var idx in details) {
177 var prop = details[idx];
Valentin Valchev57ba7bc2012-08-15 12:48:53 +0000178
179 if (prop.key == 'nfo') {
180 $.each(prop.value, function(name, bundleInfo) {
181 var txt = '';
182 $.each(bundleInfo, function(idx, ie) {
183 txt += '<div title="' + makeSafe(ie.description) + '">';
184 if (ie.type == 'link' || ie.type == 'resource') {
185 txt += '<a href="' + ie.value + '">' + ie.name + '</a>';
186 } else {
187 txt += ie.name + " = " + ie.value;
188 }
189 txt += '</div>';
190 });
191 $("#pluginInlineDetails" + data.id + " > table > tbody").append(
192 renderDetailsEntry(name, txt) );
193 });
194 } else
195 $("#pluginInlineDetails" + data.id + " > table > tbody").append(
196 renderDetailsEntry(prop.key, prop.value) );
Felix Meschberger63d692a2010-02-18 15:29:39 +0000197 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000198}
Valentin Valchev57ba7bc2012-08-15 12:48:53 +0000199function makeSafe(text) {
200 return text.replace(/\W/g, function (chr) {
201 return '&#' + chr.charCodeAt(0) + ';';
202 });
203};
204
205function renderDetailsEntry(key, value) {
206 var key18 = i18n[key] ? i18n[key] : key;
207 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + key18 + "</td><td class='aligntop' style='border:0px none'>";
208 if (value) {
209 if ( key == 'Bundle Documentation' ) {
210 txt += "<a href='" + value + "' target='_blank'>" + value + "</a>";
211 } else {
212 if ( $.isArray(value) ) {
213 var i = 0;
214 for(var pi in value) {
215 var xv = value[pi];
216 if (i > 0) { txt = txt + "<br/>"; }
217 var span;
218 if (xv.substring(0, 6) == "INFO: ") {
219 txt += "<span class='ui-state-info-text'>" + xv.substring(5) + "</span>";
220 } else if (xv.substring(0, 7) == "ERROR: ") {
221 txt += "<span class='ui-state-error-text'>" + xv.substring(6) + "</span>";
222 } else {
223 txt += xv;
224 }
225 i++;
226 }
227 } else {
228 txt += value;
229 }
230 }
231 } else {
232 txt += "\u00a0";
233 }
234 return txt + "</td></tr>";
235}
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000236
Valentin Valchevce0a4322010-03-17 08:13:39 +0000237
Felix Meschberger63d692a2010-02-18 15:29:39 +0000238$(document).ready(function(){
Valentin Valchevce0a4322010-03-17 08:13:39 +0000239 $('.refreshPackages').click(refreshPackages);
240 $('.reloadButton').click(loadData);
241 $('.installButton').click(function() {
242 uploadDialog.dialog('open');
243 return false;
Felix Meschberger63d692a2010-02-18 15:29:39 +0000244 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000245
Valentin Valchev984d4662010-04-13 11:01:11 +0000246 bundleOpError = $('#bundleOpError').dialog({
247 autoOpen: false,
248 modal : true,
249 width : '80%'
250 });
251 bundleOpError.parent().addClass('ui-state-error');
Valentin Valchev46e3c9c2012-04-26 12:15:55 +0000252 bundleOpSuccess = $('#bundleOpSuccess').dialog({
253 autoOpen: false,
254 modal : true,
255 width : '80%'
256 });
Valentin Valchev984d4662010-04-13 11:01:11 +0000257
Valentin Valchevce0a4322010-03-17 08:13:39 +0000258 // filter
Valentin Valchevce0a4322010-03-17 08:13:39 +0000259 $('.filterApply').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000260 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000261 var el = $(this).parent().find('input.filter');
262 var filter = el.length && el.val() ? new RegExp(el.val()) : false;
263 renderData(lastBundleData, filter);
264 });
265 $('.filterForm').submit(function() {
266 $(this).find('.filterApply').click();
267 return false;
268 });
269 $('.filterClear').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000270 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000271 $('input.filter').val('');
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000272 loadData();
273 });
274 $('.filterLDAP').click(function() {
275 if ($(this).hasClass('ui-state-disabled')) return;
276 var el = $(this).parent().find('input.filter');
277 var filter = el.val();
278 if (filter) $.get(pluginRoot + '/.json', { 'filter' : filter }, renderData, 'json');
Valentin Valcheve569ba22010-04-01 09:26:49 +0000279 return false;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000280 });
281
282 // upload dialog
283 var uploadDialogButtons = {};
284 uploadDialogButtons[i18n.install_update] = function() {
285 $(this).find('form').submit();
286 }
287 uploadDialog = $('#uploadDialog').dialog({
288 autoOpen: false,
289 modal : true,
290 width : '50%',
291 buttons : uploadDialogButtons
292 });
Felix Meschberger63d692a2010-02-18 15:29:39 +0000293
294 // check for cookie
Valentin Valchevce0a4322010-03-17 08:13:39 +0000295 bundlesTable = $("#plugin_table").tablesorter({
Felix Meschberger63d692a2010-02-18 15:29:39 +0000296 headers: {
297 0: { sorter:"digit" },
298 5: { sorter: false }
299 },
Valentin Valchev16bef4a2010-04-15 08:45:47 +0000300 textExtraction:mixedLinksExtraction
Felix Meschberger63d692a2010-02-18 15:29:39 +0000301 }).bind("sortEnd", function() {
Felix Meschberger7efb5462011-12-22 12:53:44 +0000302 var t = bundlesTable.eq(0).attr("config");
303 if (t.sortList) {
304 setCookie("bundlelist", t.sortList);
305 }
306 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000307 bundlesBody = bundlesTable.find('tbody');
308 bundlesTemplate = bundlesBody.find('tr').clone();
309
310 renderData(lastBundleData);
Felix Meschberger63d692a2010-02-18 15:29:39 +0000311});
312