blob: a36c5c11a2b72b3763078702f102f000253f242a [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;
Carsten Ziegelerf9879152009-02-05 10:45:35 +000023
Valentin Valchevce0a4322010-03-17 08:13:39 +000024function renderData( eventData, filter ) {
25 lastBundleData = eventData;
Felix Meschberger63d692a2010-02-18 15:29:39 +000026 var s = eventData.s;
Valentin Valchevce0a4322010-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 Ziegelerf9879152009-02-05 10:45:35 +000029 for ( var idx in eventData.data ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +000030 if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) {
Valentin Valchevce0a4322010-03-17 08:13:39 +000031 entry( eventData.data[idx], filter );
Felix Meschberger63d692a2010-02-18 15:29:39 +000032 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +000033 }
Carsten Ziegeler176aee42009-12-11 09:19:50 +000034 if ( drawDetails && eventData.data.length == 1 ) {
Valentin Valchev8d9f1032010-03-19 07:54:14 +000035 $('.filterBox input, .filterBox button').addClass('ui-state-disabled');
Felix Meschberger63d692a2010-02-18 15:29:39 +000036 renderDetails(eventData.data[0]);
Carsten Ziegeler176aee42009-12-11 09:19:50 +000037 } else if ( currentBundle != null ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +000038 var id = currentBundle;
39 hideDetails(id);
40 showDetails(id);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000041 }
Felix Meschberger63d692a2010-02-18 15:29:39 +000042 initStaticWidgets();
Valentin Valchev984d4662010-04-13 11:01:11 +000043
44 // show dialog on error
45 if (eventData.error) bundleOpError.dialog('open').find('pre').text(eventData.error)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000046}
47
Valentin Valchevce0a4322010-03-17 08:13:39 +000048function entry( /* Object */ bundle, filter ) {
49 var matches = !(filter && typeof filter.test == 'function') ? true :
Valentin Valchev8d9f1032010-03-19 07:54:14 +000050 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 +000051
52 if (matches) entryInternal( bundle ).appendTo(bundlesBody);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000053}
54
Valentin Valchevce0a4322010-03-17 08:13:39 +000055function hasStart(b) { return (!b.fragment) && (b.stateRaw == 2 || b.stateRaw == 4) } // !isFragment && (installed | resolved)
56function hasStop(b) { return (!b.fragment) && (b.stateRaw == 32) } // !isFragment && active
57function hasUninstall(b) { return b.stateRaw == 2 || b.stateRaw == 4 || b.stateRaw == 32 } // installed | resolved | active
58function stateString(b) {
59 var s = b.stateRaw;
60 return b.fragment && s == 4 ?
61 i18n.state.fragment : // fragment & resolved
62 i18n.state[s] ? i18n.state[s] : i18n.state.unknown.msgFormat(s)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000063}
64
Valentin Valchevce0a4322010-03-17 08:13:39 +000065function entryInternal( /* Object */ bundle ) {
66 var tr = bundlesTemplate.clone();
67 var id = bundle.id;
Valentin Valchev8d9f1032010-03-19 07:54:14 +000068 var name = bundle.name + '<span class="symName">' + bundle.symbolicName + '</span>';
Felix Meschberger63d692a2010-02-18 15:29:39 +000069
Valentin Valchevce0a4322010-03-17 08:13:39 +000070 tr.attr('id', 'entry'+id);
71 tr.find('td:eq(0)').text(id);
72 tr.find('td:eq(1) span:eq(0)').attr('id', 'img'+id).click(function() {showDetails(id)});
73 tr.find('td:eq(1) span:eq(1)').html( drawDetails ? name : '<a href="' + pluginRoot + '/' + id + '">' + name + '</a>' );
74 tr.find('td:eq(2)').text( bundle.version );
Valentin Valchev8d9f1032010-03-19 07:54:14 +000075 tr.find('td:eq(3)').text( bundle.category );
Valentin Valchevce0a4322010-03-17 08:13:39 +000076 if (id == 0) { // system bundle has no actions
Valentin Valchev984d4662010-04-13 11:01:11 +000077 tr.find('td:eq(4)').text( stateString(bundle) );
Valentin Valchevce0a4322010-03-17 08:13:39 +000078 tr.find('td:eq(5) ul').addClass('ui-helper-hidden');
79 } else {
Valentin Valchev984d4662010-04-13 11:01:11 +000080 entrySetupState( bundle, tr, id );
Valentin Valchevce0a4322010-03-17 08:13:39 +000081 }
82 return tr;
Carsten Ziegelerf9879152009-02-05 10:45:35 +000083}
Valentin Valchev984d4662010-04-13 11:01:11 +000084function entrySetupState( /* Object */ bundle, tr, id) {
85 var start = tr.find('td:eq(5) ul li:eq(0)').removeClass('ui-helper-hidden').unbind('click');
86 var stop = tr.find('td:eq(5) ul li:eq(1)').removeClass('ui-helper-hidden').unbind('click');
87 var refresh = tr.find('td:eq(5) ul li:eq(2)').unbind('click').click(function() {return changeDataEntryState(id, 'refresh')});
88 var update = tr.find('td:eq(5) ul li:eq(3)').unbind('click').click(function() {return changeDataEntryState(id, 'update')});
89 var remove = tr.find('td:eq(5) ul li:eq(4)').removeClass('ui-helper-hidden').unbind('click');
90 start = hasStart(bundle) ?
91 start.click(function() {return changeDataEntryState(id, 'start')}) :
92 start.addClass('ui-helper-hidden');
93 stop = hasStop(bundle) ?
94 stop.click(function() {return changeDataEntryState(id, 'stop')}) :
95 stop.addClass('ui-helper-hidden');
96 remove = hasUninstall(bundle) ?
97 remove.click(function() {return changeDataEntryState(id, 'uninstall')}) :
98 remove.addClass('ui-helper-hidden');
99 tr.find('td:eq(4)').text( stateString(bundle) );
100}
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000101
102function loadData() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000103 $.get(pluginRoot + "/.json", null, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000104}
105
106function changeDataEntryState(/* long */ id, /* String */ action) {
Valentin Valchev984d4662010-04-13 11:01:11 +0000107 $.post(pluginRoot + '/' + id, {'action':action}, function(b) {
108 var _tr = bundlesBody.find('#entry' + id);
109 if (1 == b.stateRaw) { // uninstalled
110 _tr.remove();
111 } else {
112 entrySetupState( b, _tr, id );
113 }
114 }, 'json');
115 return false;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000116}
117
118function refreshPackages() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000119 $.post(pluginRoot, {"action": "refreshPackages"}, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000120}
121
122function showDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000123 currentBundle = id;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000124 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000125 renderDetails(data.data[0]);
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000126 }, "json");
127}
128
129function hideDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000130 currentBundle = null;
131 $("#img" + id).each(function() {
132 $("#pluginInlineDetails" + id).remove();
133 $(this).
134 removeClass('ui-icon-triangle-1-w').//left
135 removeClass('ui-icon-triangle-1-s').//down
136 addClass('ui-icon-triangle-1-e').//right
137 attr("title", "Details").
138 unbind('click').click(function() {showDetails(id)});
139 });
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000140}
141
142function renderDetails( data ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000143 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>");
144 $("#img" + data.id).each(function() {
145 if ( drawDetails ) {
146 var ref = window.location.pathname;
147 ref = ref.substring(0, ref.lastIndexOf('/'));
148 $(this).
149 removeClass('ui-icon-triangle-1-e').//right
150 removeClass('ui-icon-triangle-1-s').//down
151 addClass('ui-icon-triangle-1-w').//left
152 attr("title", "Back").
153 unbind('click').click(function() {window.location = ref});
154 } else {
155 $(this).
156 removeClass('ui-icon-triangle-1-w').//left
157 removeClass('ui-icon-triangle-1-e').//right
158 addClass('ui-icon-triangle-1-s').//down
159 attr("title", "Hide Details").
160 unbind('click').click(function() {hideDetails(data.id)});
161 }
162 });
163 $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000164 var details = data.props;
165 for (var idx in details) {
166 var prop = details[idx];
Felix Meschberger63d692a2010-02-18 15:29:39 +0000167 var key = i18n[prop.key] ? i18n[prop.key] : prop.key;
168
169 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 +0000170 if (prop.value) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000171 if ( prop.key == 'Bundle Documentation' ) {
172 txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>";
173 } else {
174 if ( $.isArray(prop.value) ) {
175 var i = 0;
176 for(var pi in prop.value) {
177 var value = prop.value[pi];
178 if (i > 0) { txt = txt + "<br/>"; }
179 txt = txt + value;
180 i++;
181 }
182 } else {
183 txt = txt + prop.value;
184 }
185 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000186 } else {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000187 txt = txt + "\u00a0";
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000188 }
189 txt = txt + "</td></tr>";
Felix Meschberger6107fc12010-02-18 08:08:47 +0000190 $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt);
Felix Meschberger63d692a2010-02-18 15:29:39 +0000191 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000192}
193
Valentin Valchevce0a4322010-03-17 08:13:39 +0000194
Felix Meschberger63d692a2010-02-18 15:29:39 +0000195$(document).ready(function(){
Valentin Valchevce0a4322010-03-17 08:13:39 +0000196 $('.refreshPackages').click(refreshPackages);
197 $('.reloadButton').click(loadData);
198 $('.installButton').click(function() {
199 uploadDialog.dialog('open');
200 return false;
Felix Meschberger63d692a2010-02-18 15:29:39 +0000201 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000202
Valentin Valchev984d4662010-04-13 11:01:11 +0000203 bundleOpError = $('#bundleOpError').dialog({
204 autoOpen: false,
205 modal : true,
206 width : '80%'
207 });
208 bundleOpError.parent().addClass('ui-state-error');
209
Valentin Valchevce0a4322010-03-17 08:13:39 +0000210 // filter
Valentin Valchevce0a4322010-03-17 08:13:39 +0000211 $('.filterApply').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000212 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000213 var el = $(this).parent().find('input.filter');
214 var filter = el.length && el.val() ? new RegExp(el.val()) : false;
215 renderData(lastBundleData, filter);
216 });
217 $('.filterForm').submit(function() {
218 $(this).find('.filterApply').click();
219 return false;
220 });
221 $('.filterClear').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000222 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000223 $('input.filter').val('');
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000224 loadData();
225 });
226 $('.filterLDAP').click(function() {
227 if ($(this).hasClass('ui-state-disabled')) return;
228 var el = $(this).parent().find('input.filter');
229 var filter = el.val();
230 if (filter) $.get(pluginRoot + '/.json', { 'filter' : filter }, renderData, 'json');
Valentin Valcheve569ba22010-04-01 09:26:49 +0000231 return false;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000232 });
233
234 // upload dialog
235 var uploadDialogButtons = {};
236 uploadDialogButtons[i18n.install_update] = function() {
237 $(this).find('form').submit();
238 }
239 uploadDialog = $('#uploadDialog').dialog({
240 autoOpen: false,
241 modal : true,
242 width : '50%',
243 buttons : uploadDialogButtons
244 });
Felix Meschberger63d692a2010-02-18 15:29:39 +0000245
246 // check for cookie
247 var cv = $.cookies.get("webconsolebundlelist");
248 var lo = (cv ? cv.split(",") : [1,0]);
Valentin Valchevce0a4322010-03-17 08:13:39 +0000249 bundlesTable = $("#plugin_table").tablesorter({
Felix Meschberger63d692a2010-02-18 15:29:39 +0000250 headers: {
251 0: { sorter:"digit" },
252 5: { sorter: false }
253 },
254 textExtraction:mixedLinksExtraction,
255 sortList: cv ? [lo] : false
256 }).bind("sortEnd", function() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000257 bundlesTable.eq(0).attr("config");
258 $.cookies.set("webconsolebundlelist", bundlesTable.sortList.toString());
Felix Meschberger63d692a2010-02-18 15:29:39 +0000259 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000260 bundlesBody = bundlesTable.find('tbody');
261 bundlesTemplate = bundlesBody.find('tr').clone();
262
263 renderData(lastBundleData);
Felix Meschberger63d692a2010-02-18 15:29:39 +0000264});
265