blob: 9406b16ee70947da3ebbb68d5ee1d30991cba99e [file] [log] [blame]
Felix Meschberger4c664132008-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 Pavlov Valchev366f91c2010-03-17 08:13:39 +000017// ui elements
18var uploadDialog = false;
19var bundlesTable = false;
20var bundlesBody = false;
21var bundlesTemplate = false;
Valentin Pavlov Valchev2fafa582010-04-13 11:01:11 +000022var bundleOpError = false;
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000023
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000024function renderData( eventData, filter ) {
25 lastBundleData = eventData;
Felix Meschberger775025e2010-02-18 15:29:39 +000026 var s = eventData.s;
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000027 $('.statline').html(i18n.statline.msgFormat(s[0], s[1], s[2], s[3], s[4]));
28 bundlesBody.empty();
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000029 for ( var idx in eventData.data ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000030 if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) {
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000031 entry( eventData.data[idx], filter );
Felix Meschberger775025e2010-02-18 15:29:39 +000032 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000033 }
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +000034 if ( drawDetails && eventData.data.length == 1 ) {
Valentin Pavlov Valchevb2a498b2010-03-19 07:54:14 +000035 $('.filterBox input, .filterBox button').addClass('ui-state-disabled');
Felix Meschberger775025e2010-02-18 15:29:39 +000036 renderDetails(eventData.data[0]);
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +000037 } else if ( currentBundle != null ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000038 var id = currentBundle;
39 hideDetails(id);
40 showDetails(id);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000041 }
Felix Meschberger775025e2010-02-18 15:29:39 +000042 initStaticWidgets();
Valentin Pavlov Valchev15fb1fa2010-04-14 13:15:06 +000043
Felix Meschbergera2b77382011-12-22 12:53:44 +000044 var cv = getCookie("bundlelist");
45 if (cv) {
46 bundlesTable.trigger('sorton', [cv]);
47 }
Valentin Pavlov Valchev15fb1fa2010-04-14 13:15:06 +000048
Valentin Pavlov Valchev2fafa582010-04-13 11:01:11 +000049 // show dialog on error
50 if (eventData.error) bundleOpError.dialog('open').find('pre').text(eventData.error)
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000051}
52
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000053function entry( /* Object */ bundle, filter ) {
54 var matches = !(filter && typeof filter.test == 'function') ? true :
Valentin Pavlov Valchevb2a498b2010-03-19 07:54:14 +000055 filter.test(bundle.id) || filter.test(bundle.name) || filter.test(bundle.symbolicName) || filter.test(bundle.version) || filter.test(bundle.category);
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000056
57 if (matches) entryInternal( bundle ).appendTo(bundlesBody);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000058}
59
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000060function hasStart(b) { return (!b.fragment) && (b.stateRaw == 2 || b.stateRaw == 4) } // !isFragment && (installed | resolved)
61function hasStop(b) { return (!b.fragment) && (b.stateRaw == 32) } // !isFragment && active
62function hasUninstall(b) { return b.stateRaw == 2 || b.stateRaw == 4 || b.stateRaw == 32 } // installed | resolved | active
63function 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 Ziegeler6577bfa2009-02-05 10:45:35 +000068}
69
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000070function entryInternal( /* Object */ bundle ) {
71 var tr = bundlesTemplate.clone();
72 var id = bundle.id;
Valentin Pavlov Valchevb2a498b2010-03-19 07:54:14 +000073 var name = bundle.name + '<span class="symName">' + bundle.symbolicName + '</span>';
Felix Meschberger775025e2010-02-18 15:29:39 +000074
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000075 tr.attr('id', 'entry'+id);
76 tr.find('td:eq(0)').text(id);
Valentin Pavlov Valchevc21c0d42010-04-15 08:45:47 +000077 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 Valchev366f91c2010-03-17 08:13:39 +000079 tr.find('td:eq(2)').text( bundle.version );
Valentin Pavlov Valchevb2a498b2010-03-19 07:54:14 +000080 tr.find('td:eq(3)').text( bundle.category );
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000081 if (id == 0) { // system bundle has no actions
Valentin Pavlov Valchev2fafa582010-04-13 11:01:11 +000082 tr.find('td:eq(4)').text( stateString(bundle) );
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000083 tr.find('td:eq(5) ul').addClass('ui-helper-hidden');
84 } else {
Valentin Pavlov Valchev2fafa582010-04-13 11:01:11 +000085 entrySetupState( bundle, tr, id );
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000086 }
87 return tr;
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000088}
Valentin Pavlov Valchev2fafa582010-04-13 11:01:11 +000089function 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 Ziegeler6577bfa2009-02-05 10:45:35 +0000106
107function loadData() {
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000108 $.get(pluginRoot + "/.json", null, renderData, "json");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000109}
110
111function changeDataEntryState(/* long */ id, /* String */ action) {
Valentin Pavlov Valchev2fafa582010-04-13 11:01:11 +0000112 $.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 Ziegeler6577bfa2009-02-05 10:45:35 +0000121}
122
123function refreshPackages() {
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000124 $.post(pluginRoot, {"action": "refreshPackages"}, renderData, "json");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000125}
126
127function showDetails( id ) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000128 currentBundle = id;
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000129 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000130 renderDetails(data.data[0]);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000131 }, "json");
132}
133
134function hideDetails( id ) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000135 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 Ziegeler6577bfa2009-02-05 10:45:35 +0000145}
146
147function renderDetails( data ) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000148 $("#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 Ziegeler6577bfa2009-02-05 10:45:35 +0000169 var details = data.props;
170 for (var idx in details) {
171 var prop = details[idx];
Felix Meschberger775025e2010-02-18 15:29:39 +0000172 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 Ziegeler6577bfa2009-02-05 10:45:35 +0000175 if (prop.value) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000176 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 Ziegelera406db72010-10-12 07:31:50 +0000184 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 Meschberger775025e2010-02-18 15:29:39 +0000192 i++;
193 }
194 } else {
195 txt = txt + prop.value;
196 }
197 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000198 } else {
Felix Meschberger775025e2010-02-18 15:29:39 +0000199 txt = txt + "\u00a0";
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000200 }
201 txt = txt + "</td></tr>";
Felix Meschberger16dd9882010-02-18 08:08:47 +0000202 $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt);
Felix Meschberger775025e2010-02-18 15:29:39 +0000203 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000204}
205
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000206
Felix Meschberger775025e2010-02-18 15:29:39 +0000207$(document).ready(function(){
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000208 $('.refreshPackages').click(refreshPackages);
209 $('.reloadButton').click(loadData);
210 $('.installButton').click(function() {
211 uploadDialog.dialog('open');
212 return false;
Felix Meschberger775025e2010-02-18 15:29:39 +0000213 });
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000214
Valentin Pavlov Valchev2fafa582010-04-13 11:01:11 +0000215 bundleOpError = $('#bundleOpError').dialog({
216 autoOpen: false,
217 modal : true,
218 width : '80%'
219 });
220 bundleOpError.parent().addClass('ui-state-error');
221
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000222 // filter
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000223 $('.filterApply').click(function() {
Valentin Pavlov Valchevb2a498b2010-03-19 07:54:14 +0000224 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000225 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 Valchevb2a498b2010-03-19 07:54:14 +0000234 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000235 $('input.filter').val('');
Valentin Pavlov Valchevb2a498b2010-03-19 07:54:14 +0000236 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 Valchev008c0a32010-04-01 09:26:49 +0000243 return false;
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000244 });
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 Meschberger775025e2010-02-18 15:29:39 +0000257
258 // check for cookie
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000259 bundlesTable = $("#plugin_table").tablesorter({
Felix Meschberger775025e2010-02-18 15:29:39 +0000260 headers: {
261 0: { sorter:"digit" },
262 5: { sorter: false }
263 },
Valentin Pavlov Valchevc21c0d42010-04-15 08:45:47 +0000264 textExtraction:mixedLinksExtraction
Felix Meschberger775025e2010-02-18 15:29:39 +0000265 }).bind("sortEnd", function() {
Felix Meschbergera2b77382011-12-22 12:53:44 +0000266 var t = bundlesTable.eq(0).attr("config");
267 if (t.sortList) {
268 setCookie("bundlelist", t.sortList);
269 }
270 });
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000271 bundlesBody = bundlesTable.find('tbody');
272 bundlesTemplate = bundlesBody.find('tr').clone();
273
274 renderData(lastBundleData);
Felix Meschberger775025e2010-02-18 15:29:39 +0000275});
276