blob: 6cb010e8c1bc5d008b9d445d57eb36563eece7cd [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 Valchev88dbf702010-04-14 13:15:06 +000043
44 var cv = $.cookies.get("webconsolebundlelist");
45 if (cv) bundlesTable.trigger('sorton', [cv]);
46
Valentin Valchev984d4662010-04-13 11:01:11 +000047 // show dialog on error
48 if (eventData.error) bundleOpError.dialog('open').find('pre').text(eventData.error)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000049}
50
Valentin Valchevce0a4322010-03-17 08:13:39 +000051function entry( /* Object */ bundle, filter ) {
52 var matches = !(filter && typeof filter.test == 'function') ? true :
Valentin Valchev8d9f1032010-03-19 07:54:14 +000053 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 +000054
55 if (matches) entryInternal( bundle ).appendTo(bundlesBody);
Carsten Ziegelerf9879152009-02-05 10:45:35 +000056}
57
Valentin Valchevce0a4322010-03-17 08:13:39 +000058function hasStart(b) { return (!b.fragment) && (b.stateRaw == 2 || b.stateRaw == 4) } // !isFragment && (installed | resolved)
59function hasStop(b) { return (!b.fragment) && (b.stateRaw == 32) } // !isFragment && active
60function hasUninstall(b) { return b.stateRaw == 2 || b.stateRaw == 4 || b.stateRaw == 32 } // installed | resolved | active
61function stateString(b) {
62 var s = b.stateRaw;
63 return b.fragment && s == 4 ?
64 i18n.state.fragment : // fragment & resolved
65 i18n.state[s] ? i18n.state[s] : i18n.state.unknown.msgFormat(s)
Carsten Ziegelerf9879152009-02-05 10:45:35 +000066}
67
Valentin Valchevce0a4322010-03-17 08:13:39 +000068function entryInternal( /* Object */ bundle ) {
69 var tr = bundlesTemplate.clone();
70 var id = bundle.id;
Valentin Valchev8d9f1032010-03-19 07:54:14 +000071 var name = bundle.name + '<span class="symName">' + bundle.symbolicName + '</span>';
Felix Meschberger63d692a2010-02-18 15:29:39 +000072
Valentin Valchevce0a4322010-03-17 08:13:39 +000073 tr.attr('id', 'entry'+id);
74 tr.find('td:eq(0)').text(id);
75 tr.find('td:eq(1) span:eq(0)').attr('id', 'img'+id).click(function() {showDetails(id)});
76 tr.find('td:eq(1) span:eq(1)').html( drawDetails ? name : '<a href="' + pluginRoot + '/' + id + '">' + name + '</a>' );
77 tr.find('td:eq(2)').text( bundle.version );
Valentin Valchev8d9f1032010-03-19 07:54:14 +000078 tr.find('td:eq(3)').text( bundle.category );
Valentin Valchevce0a4322010-03-17 08:13:39 +000079 if (id == 0) { // system bundle has no actions
Valentin Valchev984d4662010-04-13 11:01:11 +000080 tr.find('td:eq(4)').text( stateString(bundle) );
Valentin Valchevce0a4322010-03-17 08:13:39 +000081 tr.find('td:eq(5) ul').addClass('ui-helper-hidden');
82 } else {
Valentin Valchev984d4662010-04-13 11:01:11 +000083 entrySetupState( bundle, tr, id );
Valentin Valchevce0a4322010-03-17 08:13:39 +000084 }
85 return tr;
Carsten Ziegelerf9879152009-02-05 10:45:35 +000086}
Valentin Valchev984d4662010-04-13 11:01:11 +000087function entrySetupState( /* Object */ bundle, tr, id) {
88 var start = tr.find('td:eq(5) ul li:eq(0)').removeClass('ui-helper-hidden').unbind('click');
89 var stop = tr.find('td:eq(5) ul li:eq(1)').removeClass('ui-helper-hidden').unbind('click');
90 var refresh = tr.find('td:eq(5) ul li:eq(2)').unbind('click').click(function() {return changeDataEntryState(id, 'refresh')});
91 var update = tr.find('td:eq(5) ul li:eq(3)').unbind('click').click(function() {return changeDataEntryState(id, 'update')});
92 var remove = tr.find('td:eq(5) ul li:eq(4)').removeClass('ui-helper-hidden').unbind('click');
93 start = hasStart(bundle) ?
94 start.click(function() {return changeDataEntryState(id, 'start')}) :
95 start.addClass('ui-helper-hidden');
96 stop = hasStop(bundle) ?
97 stop.click(function() {return changeDataEntryState(id, 'stop')}) :
98 stop.addClass('ui-helper-hidden');
99 remove = hasUninstall(bundle) ?
100 remove.click(function() {return changeDataEntryState(id, 'uninstall')}) :
101 remove.addClass('ui-helper-hidden');
102 tr.find('td:eq(4)').text( stateString(bundle) );
103}
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000104
105function loadData() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000106 $.get(pluginRoot + "/.json", null, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000107}
108
109function changeDataEntryState(/* long */ id, /* String */ action) {
Valentin Valchev984d4662010-04-13 11:01:11 +0000110 $.post(pluginRoot + '/' + id, {'action':action}, function(b) {
111 var _tr = bundlesBody.find('#entry' + id);
112 if (1 == b.stateRaw) { // uninstalled
113 _tr.remove();
114 } else {
115 entrySetupState( b, _tr, id );
116 }
117 }, 'json');
118 return false;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000119}
120
121function refreshPackages() {
Valentin Valchevce0a4322010-03-17 08:13:39 +0000122 $.post(pluginRoot, {"action": "refreshPackages"}, renderData, "json");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000123}
124
125function showDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000126 currentBundle = id;
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000127 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000128 renderDetails(data.data[0]);
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000129 }, "json");
130}
131
132function hideDetails( id ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000133 currentBundle = null;
134 $("#img" + id).each(function() {
135 $("#pluginInlineDetails" + id).remove();
136 $(this).
137 removeClass('ui-icon-triangle-1-w').//left
138 removeClass('ui-icon-triangle-1-s').//down
139 addClass('ui-icon-triangle-1-e').//right
140 attr("title", "Details").
141 unbind('click').click(function() {showDetails(id)});
142 });
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000143}
144
145function renderDetails( data ) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000146 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>");
147 $("#img" + data.id).each(function() {
148 if ( drawDetails ) {
149 var ref = window.location.pathname;
150 ref = ref.substring(0, ref.lastIndexOf('/'));
151 $(this).
152 removeClass('ui-icon-triangle-1-e').//right
153 removeClass('ui-icon-triangle-1-s').//down
154 addClass('ui-icon-triangle-1-w').//left
155 attr("title", "Back").
156 unbind('click').click(function() {window.location = ref});
157 } else {
158 $(this).
159 removeClass('ui-icon-triangle-1-w').//left
160 removeClass('ui-icon-triangle-1-e').//right
161 addClass('ui-icon-triangle-1-s').//down
162 attr("title", "Hide Details").
163 unbind('click').click(function() {hideDetails(data.id)});
164 }
165 });
166 $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>");
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000167 var details = data.props;
168 for (var idx in details) {
169 var prop = details[idx];
Felix Meschberger63d692a2010-02-18 15:29:39 +0000170 var key = i18n[prop.key] ? i18n[prop.key] : prop.key;
171
172 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 +0000173 if (prop.value) {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000174 if ( prop.key == 'Bundle Documentation' ) {
175 txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>";
176 } else {
177 if ( $.isArray(prop.value) ) {
178 var i = 0;
179 for(var pi in prop.value) {
180 var value = prop.value[pi];
181 if (i > 0) { txt = txt + "<br/>"; }
182 txt = txt + value;
183 i++;
184 }
185 } else {
186 txt = txt + prop.value;
187 }
188 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000189 } else {
Felix Meschberger63d692a2010-02-18 15:29:39 +0000190 txt = txt + "\u00a0";
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000191 }
192 txt = txt + "</td></tr>";
Felix Meschberger6107fc12010-02-18 08:08:47 +0000193 $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt);
Felix Meschberger63d692a2010-02-18 15:29:39 +0000194 }
Carsten Ziegelerf9879152009-02-05 10:45:35 +0000195}
196
Valentin Valchevce0a4322010-03-17 08:13:39 +0000197
Felix Meschberger63d692a2010-02-18 15:29:39 +0000198$(document).ready(function(){
Valentin Valchevce0a4322010-03-17 08:13:39 +0000199 $('.refreshPackages').click(refreshPackages);
200 $('.reloadButton').click(loadData);
201 $('.installButton').click(function() {
202 uploadDialog.dialog('open');
203 return false;
Felix Meschberger63d692a2010-02-18 15:29:39 +0000204 });
Valentin Valchevce0a4322010-03-17 08:13:39 +0000205
Valentin Valchev984d4662010-04-13 11:01:11 +0000206 bundleOpError = $('#bundleOpError').dialog({
207 autoOpen: false,
208 modal : true,
209 width : '80%'
210 });
211 bundleOpError.parent().addClass('ui-state-error');
212
Valentin Valchevce0a4322010-03-17 08:13:39 +0000213 // filter
Valentin Valchevce0a4322010-03-17 08:13:39 +0000214 $('.filterApply').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000215 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000216 var el = $(this).parent().find('input.filter');
217 var filter = el.length && el.val() ? new RegExp(el.val()) : false;
218 renderData(lastBundleData, filter);
219 });
220 $('.filterForm').submit(function() {
221 $(this).find('.filterApply').click();
222 return false;
223 });
224 $('.filterClear').click(function() {
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000225 if ($(this).hasClass('ui-state-disabled')) return;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000226 $('input.filter').val('');
Valentin Valchev8d9f1032010-03-19 07:54:14 +0000227 loadData();
228 });
229 $('.filterLDAP').click(function() {
230 if ($(this).hasClass('ui-state-disabled')) return;
231 var el = $(this).parent().find('input.filter');
232 var filter = el.val();
233 if (filter) $.get(pluginRoot + '/.json', { 'filter' : filter }, renderData, 'json');
Valentin Valcheve569ba22010-04-01 09:26:49 +0000234 return false;
Valentin Valchevce0a4322010-03-17 08:13:39 +0000235 });
236
237 // upload dialog
238 var uploadDialogButtons = {};
239 uploadDialogButtons[i18n.install_update] = function() {
240 $(this).find('form').submit();
241 }
242 uploadDialog = $('#uploadDialog').dialog({
243 autoOpen: false,
244 modal : true,
245 width : '50%',
246 buttons : uploadDialogButtons
247 });
Felix Meschberger63d692a2010-02-18 15:29:39 +0000248
249 // check for cookie
Valentin Valchevce0a4322010-03-17 08:13:39 +0000250 bundlesTable = $("#plugin_table").tablesorter({
Felix Meschberger63d692a2010-02-18 15:29:39 +0000251 headers: {
252 0: { sorter:"digit" },
253 5: { sorter: false }
254 },
255 textExtraction:mixedLinksExtraction,
Felix Meschberger63d692a2010-02-18 15:29:39 +0000256 }).bind("sortEnd", function() {
Valentin Valchev88dbf702010-04-14 13:15:06 +0000257 var t = bundlesTable.eq(0).attr("config");
258 if (t.sortList) $.cookies.set("webconsolebundlelist", t.sortList);
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