blob: b263597935c941bee97289b753a29445c034374b [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;
Carsten Ziegelerf9879152009-02-05 10:45:35 +000022
Valentin Valchevce0a4322010-03-17 08:13:39 +000023function renderData( eventData, filter ) {
24 lastBundleData = eventData;
Felix Meschberger63d692a2010-02-18 15:29:39 +000025 var s = eventData.s;
Valentin Valchevce0a4322010-03-17 08:13:39 +000026 $('.statline').html(i18n.statline.msgFormat(s[0], s[1], s[2], s[3], s[4]));
27 bundlesBody.empty();
Carsten Ziegelerf9879152009-02-05 10:45:35 +000028 for ( var idx in eventData.data ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +000029 if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) {
Valentin Valchevce0a4322010-03-17 08:13:39 +000030 entry( eventData.data[idx], filter );
Felix Meschberger63d692a2010-02-18 15:29:39 +000031 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +000032 }
Carsten Ziegeler176aee42009-12-11 09:19:50 +000033 if ( drawDetails && eventData.data.length == 1 ) {
Valentin Valchev8d9f1032010-03-19 07:54:14 +000034 $('.filterBox input, .filterBox button').addClass('ui-state-disabled');
Felix Meschberger63d692a2010-02-18 15:29:39 +000035 renderDetails(eventData.data[0]);
Carsten Ziegeler176aee42009-12-11 09:19:50 +000036 } else if ( currentBundle != null ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +000037 var id = currentBundle;
38 hideDetails(id);
39 showDetails(id);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000040 }
Felix Meschberger63d692a2010-02-18 15:29:39 +000041 initStaticWidgets();
Carsten Ziegelerf9879152009-02-05 10:45:35 +000042}
43
Valentin Valchevce0a4322010-03-17 08:13:39 +000044function entry( /* Object */ bundle, filter ) {
45 var matches = !(filter && typeof filter.test == 'function') ? true :
Valentin Valchev8d9f1032010-03-19 07:54:14 +000046 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 +000047
48 if (matches) entryInternal( bundle ).appendTo(bundlesBody);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000049}
50
Valentin Valchevce0a4322010-03-17 08:13:39 +000051function hasStart(b) { return (!b.fragment) && (b.stateRaw == 2 || b.stateRaw == 4) } // !isFragment && (installed | resolved)
52function hasStop(b) { return (!b.fragment) && (b.stateRaw == 32) } // !isFragment && active
53function hasUninstall(b) { return b.stateRaw == 2 || b.stateRaw == 4 || b.stateRaw == 32 } // installed | resolved | active
54function stateString(b) {
55 var s = b.stateRaw;
56 return b.fragment && s == 4 ?
57 i18n.state.fragment : // fragment & resolved
58 i18n.state[s] ? i18n.state[s] : i18n.state.unknown.msgFormat(s)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000059}
60
Valentin Valchevce0a4322010-03-17 08:13:39 +000061function entryInternal( /* Object */ bundle ) {
62 var tr = bundlesTemplate.clone();
63 var id = bundle.id;
Valentin Valchev8d9f1032010-03-19 07:54:14 +000064 var name = bundle.name + '<span class="symName">' + bundle.symbolicName + '</span>';
Felix Meschberger63d692a2010-02-18 15:29:39 +000065
Valentin Valchevce0a4322010-03-17 08:13:39 +000066 tr.attr('id', 'entry'+id);
67 tr.find('td:eq(0)').text(id);
68 tr.find('td:eq(1) span:eq(0)').attr('id', 'img'+id).click(function() {showDetails(id)});
69 tr.find('td:eq(1) span:eq(1)').html( drawDetails ? name : '<a href="' + pluginRoot + '/' + id + '">' + name + '</a>' );
70 tr.find('td:eq(2)').text( bundle.version );
Valentin Valchev8d9f1032010-03-19 07:54:14 +000071 tr.find('td:eq(3)').text( bundle.category );
Valentin Valchevce0a4322010-03-17 08:13:39 +000072 tr.find('td:eq(4)').text( stateString(bundle) );
73 if (id == 0) { // system bundle has no actions
74 tr.find('td:eq(5) ul').addClass('ui-helper-hidden');
75 } else {
76 var start = tr.find('td:eq(5) ul li:eq(0)');
77 var stop = tr.find('td:eq(5) ul li:eq(1)');
78 var refresh = tr.find('td:eq(5) ul li:eq(2)').click(function() {changeDataEntryState(id, 'refresh')});
79 var update = tr.find('td:eq(5) ul li:eq(3)').click(function() {changeDataEntryState(id, 'update')});
80 var remove = tr.find('td:eq(5) ul li:eq(4)');
81 start = hasStart(bundle) ?
82 start.click(function() {changeDataEntryState(id, 'start')}) :
83 start.addClass('ui-helper-hidden');
84 stop = hasStop(bundle) ?
85 stop.click(function() {changeDataEntryState(id, 'stop')}) :
86 stop.addClass('ui-helper-hidden');
87 remove = hasUninstall(bundle) ?
88 remove.click(function() {changeDataEntryState(id, 'uninstall')}) :
89 remove.addClass('ui-helper-hidden');
90 }
91 return tr;
Carsten Ziegelerf9879152009-02-05 10:45:35 +000092}
93
94function loadData() {
Valentin Valchevce0a4322010-03-17 08:13:39 +000095 $.get(pluginRoot + "/.json", null, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +000096}
97
98function changeDataEntryState(/* long */ id, /* String */ action) {
Valentin Valchevce0a4322010-03-17 08:13:39 +000099 $.post(pluginRoot + "/" + id, {"action":action}, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000100}
101
102function refreshPackages() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000103 $.post(pluginRoot, {"action": "refreshPackages"}, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000104}
105
106function showDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000107 currentBundle = id;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000108 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000109 renderDetails(data.data[0]);
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000110 }, "json");
111}
112
113function hideDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000114 currentBundle = null;
115 $("#img" + id).each(function() {
116 $("#pluginInlineDetails" + id).remove();
117 $(this).
118 removeClass('ui-icon-triangle-1-w').//left
119 removeClass('ui-icon-triangle-1-s').//down
120 addClass('ui-icon-triangle-1-e').//right
121 attr("title", "Details").
122 unbind('click').click(function() {showDetails(id)});
123 });
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000124}
125
126function renderDetails( data ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000127 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>");
128 $("#img" + data.id).each(function() {
129 if ( drawDetails ) {
130 var ref = window.location.pathname;
131 ref = ref.substring(0, ref.lastIndexOf('/'));
132 $(this).
133 removeClass('ui-icon-triangle-1-e').//right
134 removeClass('ui-icon-triangle-1-s').//down
135 addClass('ui-icon-triangle-1-w').//left
136 attr("title", "Back").
137 unbind('click').click(function() {window.location = ref});
138 } else {
139 $(this).
140 removeClass('ui-icon-triangle-1-w').//left
141 removeClass('ui-icon-triangle-1-e').//right
142 addClass('ui-icon-triangle-1-s').//down
143 attr("title", "Hide Details").
144 unbind('click').click(function() {hideDetails(data.id)});
145 }
146 });
147 $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000148 var details = data.props;
149 for (var idx in details) {
150 var prop = details[idx];
Felix Meschberger63d692a2010-02-18 15:29:39 +0000151 var key = i18n[prop.key] ? i18n[prop.key] : prop.key;
152
153 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + key + "</td><td class='aligntop' style='border:0px none'>";
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000154 if (prop.value) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000155 if ( prop.key == 'Bundle Documentation' ) {
156 txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>";
157 } else {
158 if ( $.isArray(prop.value) ) {
159 var i = 0;
160 for(var pi in prop.value) {
161 var value = prop.value[pi];
162 if (i > 0) { txt = txt + "<br/>"; }
163 txt = txt + value;
164 i++;
165 }
166 } else {
167 txt = txt + prop.value;
168 }
169 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000170 } else {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000171 txt = txt + "\u00a0";
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000172 }
173 txt = txt + "</td></tr>";
Felix Meschberger6107fc12010-02-18 08:08:47 +0000174 $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt);
Felix Meschberger63d692a2010-02-18 15:29:39 +0000175 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000176}
177
Valentin Valchevce0a4322010-03-17 08:13:39 +0000178
Felix Meschberger63d692a2010-02-18 15:29:39 +0000179$(document).ready(function(){
Valentin Valchevce0a4322010-03-17 08:13:39 +0000180 $('.refreshPackages').click(refreshPackages);
181 $('.reloadButton').click(loadData);
182 $('.installButton').click(function() {
183 uploadDialog.dialog('open');
184 return false;
Felix Meschberger63d692a2010-02-18 15:29:39 +0000185 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000186
187 // filter
Valentin Valchevce0a4322010-03-17 08:13:39 +0000188 $('.filterApply').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000189 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000190 var el = $(this).parent().find('input.filter');
191 var filter = el.length && el.val() ? new RegExp(el.val()) : false;
192 renderData(lastBundleData, filter);
193 });
194 $('.filterForm').submit(function() {
195 $(this).find('.filterApply').click();
196 return false;
197 });
198 $('.filterClear').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000199 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000200 $('input.filter').val('');
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000201 loadData();
202 });
203 $('.filterLDAP').click(function() {
204 if ($(this).hasClass('ui-state-disabled')) return;
205 var el = $(this).parent().find('input.filter');
206 var filter = el.val();
207 if (filter) $.get(pluginRoot + '/.json', { 'filter' : filter }, renderData, 'json');
Valentin Valcheve569ba22010-04-01 09:26:49 +0000208 return false;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000209 });
210
211 // upload dialog
212 var uploadDialogButtons = {};
213 uploadDialogButtons[i18n.install_update] = function() {
214 $(this).find('form').submit();
215 }
216 uploadDialog = $('#uploadDialog').dialog({
217 autoOpen: false,
218 modal : true,
219 width : '50%',
220 buttons : uploadDialogButtons
221 });
Felix Meschberger63d692a2010-02-18 15:29:39 +0000222
223 // check for cookie
224 var cv = $.cookies.get("webconsolebundlelist");
225 var lo = (cv ? cv.split(",") : [1,0]);
Valentin Valchevce0a4322010-03-17 08:13:39 +0000226 bundlesTable = $("#plugin_table").tablesorter({
Felix Meschberger63d692a2010-02-18 15:29:39 +0000227 headers: {
228 0: { sorter:"digit" },
229 5: { sorter: false }
230 },
231 textExtraction:mixedLinksExtraction,
232 sortList: cv ? [lo] : false
233 }).bind("sortEnd", function() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000234 bundlesTable.eq(0).attr("config");
235 $.cookies.set("webconsolebundlelist", bundlesTable.sortList.toString());
Felix Meschberger63d692a2010-02-18 15:29:39 +0000236 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000237 bundlesBody = bundlesTable.find('tbody');
238 bundlesTemplate = bundlesBody.find('tr').clone();
239
240 renderData(lastBundleData);
Felix Meschberger63d692a2010-02-18 15:29:39 +0000241});
242