blob: b7467d3a861c7d7e60dc9a4771d07d53e91a1c64 [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;
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000022
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000023function renderData( eventData, filter ) {
24 lastBundleData = eventData;
Felix Meschberger775025e2010-02-18 15:29:39 +000025 var s = eventData.s;
Valentin Pavlov Valchev366f91c2010-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 Ziegeler6577bfa2009-02-05 10:45:35 +000028 for ( var idx in eventData.data ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000029 if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) {
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000030 entry( eventData.data[idx], filter );
Felix Meschberger775025e2010-02-18 15:29:39 +000031 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000032 }
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +000033 if ( drawDetails && eventData.data.length == 1 ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000034 renderDetails(eventData.data[0]);
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +000035 } else if ( currentBundle != null ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000036 var id = currentBundle;
37 hideDetails(id);
38 showDetails(id);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000039 }
Felix Meschberger775025e2010-02-18 15:29:39 +000040 initStaticWidgets();
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000041}
42
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000043function entry( /* Object */ bundle, filter ) {
44 var matches = !(filter && typeof filter.test == 'function') ? true :
45 filter.test(bundle.id) || filter.test(bundle.name) || filter.test(bundle.symbolicName) || filter.test(bundle.version);
46
47 if (matches) entryInternal( bundle ).appendTo(bundlesBody);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000048}
49
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000050function hasStart(b) { return (!b.fragment) && (b.stateRaw == 2 || b.stateRaw == 4) } // !isFragment && (installed | resolved)
51function hasStop(b) { return (!b.fragment) && (b.stateRaw == 32) } // !isFragment && active
52function hasUninstall(b) { return b.stateRaw == 2 || b.stateRaw == 4 || b.stateRaw == 32 } // installed | resolved | active
53function stateString(b) {
54 var s = b.stateRaw;
55 return b.fragment && s == 4 ?
56 i18n.state.fragment : // fragment & resolved
57 i18n.state[s] ? i18n.state[s] : i18n.state.unknown.msgFormat(s)
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000058}
59
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000060function entryInternal( /* Object */ bundle ) {
61 var tr = bundlesTemplate.clone();
62 var id = bundle.id;
63 var name = bundle.name;
Felix Meschberger775025e2010-02-18 15:29:39 +000064
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000065 tr.attr('id', 'entry'+id);
66 tr.find('td:eq(0)').text(id);
67 tr.find('td:eq(1) span:eq(0)').attr('id', 'img'+id).click(function() {showDetails(id)});
68 tr.find('td:eq(1) span:eq(1)').html( drawDetails ? name : '<a href="' + pluginRoot + '/' + id + '">' + name + '</a>' );
69 tr.find('td:eq(2)').text( bundle.version );
70 tr.find('td:eq(3)').text( bundle.symbolicName );
71 tr.find('td:eq(4)').text( stateString(bundle) );
72 if (id == 0) { // system bundle has no actions
73 tr.find('td:eq(5) ul').addClass('ui-helper-hidden');
74 } else {
75 var start = tr.find('td:eq(5) ul li:eq(0)');
76 var stop = tr.find('td:eq(5) ul li:eq(1)');
77 var refresh = tr.find('td:eq(5) ul li:eq(2)').click(function() {changeDataEntryState(id, 'refresh')});
78 var update = tr.find('td:eq(5) ul li:eq(3)').click(function() {changeDataEntryState(id, 'update')});
79 var remove = tr.find('td:eq(5) ul li:eq(4)');
80 start = hasStart(bundle) ?
81 start.click(function() {changeDataEntryState(id, 'start')}) :
82 start.addClass('ui-helper-hidden');
83 stop = hasStop(bundle) ?
84 stop.click(function() {changeDataEntryState(id, 'stop')}) :
85 stop.addClass('ui-helper-hidden');
86 remove = hasUninstall(bundle) ?
87 remove.click(function() {changeDataEntryState(id, 'uninstall')}) :
88 remove.addClass('ui-helper-hidden');
89 }
90 return tr;
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000091}
92
93function loadData() {
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000094 $.get(pluginRoot + "/.json", null, renderData, "json");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000095}
96
97function changeDataEntryState(/* long */ id, /* String */ action) {
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +000098 $.post(pluginRoot + "/" + id, {"action":action}, renderData, "json");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000099}
100
101function refreshPackages() {
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000102 $.post(pluginRoot, {"action": "refreshPackages"}, renderData, "json");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000103}
104
105function showDetails( id ) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000106 currentBundle = id;
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000107 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000108 renderDetails(data.data[0]);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000109 }, "json");
110}
111
112function hideDetails( id ) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000113 currentBundle = null;
114 $("#img" + id).each(function() {
115 $("#pluginInlineDetails" + id).remove();
116 $(this).
117 removeClass('ui-icon-triangle-1-w').//left
118 removeClass('ui-icon-triangle-1-s').//down
119 addClass('ui-icon-triangle-1-e').//right
120 attr("title", "Details").
121 unbind('click').click(function() {showDetails(id)});
122 });
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000123}
124
125function renderDetails( data ) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000126 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails" + data.id + "'/>");
127 $("#img" + data.id).each(function() {
128 if ( drawDetails ) {
129 var ref = window.location.pathname;
130 ref = ref.substring(0, ref.lastIndexOf('/'));
131 $(this).
132 removeClass('ui-icon-triangle-1-e').//right
133 removeClass('ui-icon-triangle-1-s').//down
134 addClass('ui-icon-triangle-1-w').//left
135 attr("title", "Back").
136 unbind('click').click(function() {window.location = ref});
137 } else {
138 $(this).
139 removeClass('ui-icon-triangle-1-w').//left
140 removeClass('ui-icon-triangle-1-e').//right
141 addClass('ui-icon-triangle-1-s').//down
142 attr("title", "Hide Details").
143 unbind('click').click(function() {hideDetails(data.id)});
144 }
145 });
146 $("#pluginInlineDetails" + data.id).append("<table border='0'><tbody></tbody></table>");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000147 var details = data.props;
148 for (var idx in details) {
149 var prop = details[idx];
Felix Meschberger775025e2010-02-18 15:29:39 +0000150 var key = i18n[prop.key] ? i18n[prop.key] : prop.key;
151
152 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 +0000153 if (prop.value) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000154 if ( prop.key == 'Bundle Documentation' ) {
155 txt = txt + "<a href='" + prop.value + "' target='_blank'>" + prop.value + "</a>";
156 } else {
157 if ( $.isArray(prop.value) ) {
158 var i = 0;
159 for(var pi in prop.value) {
160 var value = prop.value[pi];
161 if (i > 0) { txt = txt + "<br/>"; }
162 txt = txt + value;
163 i++;
164 }
165 } else {
166 txt = txt + prop.value;
167 }
168 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000169 } else {
Felix Meschberger775025e2010-02-18 15:29:39 +0000170 txt = txt + "\u00a0";
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000171 }
172 txt = txt + "</td></tr>";
Felix Meschberger16dd9882010-02-18 08:08:47 +0000173 $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt);
Felix Meschberger775025e2010-02-18 15:29:39 +0000174 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000175}
176
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000177
Felix Meschberger775025e2010-02-18 15:29:39 +0000178$(document).ready(function(){
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000179 $('.refreshPackages').click(refreshPackages);
180 $('.reloadButton').click(loadData);
181 $('.installButton').click(function() {
182 uploadDialog.dialog('open');
183 return false;
Felix Meschberger775025e2010-02-18 15:29:39 +0000184 });
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000185
186 // filter
187 $('input.filter').click(function() {$(this).val('')});
188 $('.filterApply').click(function() {
189 var el = $(this).parent().find('input.filter');
190 var filter = el.length && el.val() ? new RegExp(el.val()) : false;
191 renderData(lastBundleData, filter);
192 });
193 $('.filterForm').submit(function() {
194 $(this).find('.filterApply').click();
195 return false;
196 });
197 $('.filterClear').click(function() {
198 $('input.filter').val('');
199 renderData(lastBundleData);
200 });
201
202 // upload dialog
203 var uploadDialogButtons = {};
204 uploadDialogButtons[i18n.install_update] = function() {
205 $(this).find('form').submit();
206 }
207 uploadDialog = $('#uploadDialog').dialog({
208 autoOpen: false,
209 modal : true,
210 width : '50%',
211 buttons : uploadDialogButtons
212 });
Felix Meschberger775025e2010-02-18 15:29:39 +0000213
214 // check for cookie
215 var cv = $.cookies.get("webconsolebundlelist");
216 var lo = (cv ? cv.split(",") : [1,0]);
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000217 bundlesTable = $("#plugin_table").tablesorter({
Felix Meschberger775025e2010-02-18 15:29:39 +0000218 headers: {
219 0: { sorter:"digit" },
220 5: { sorter: false }
221 },
222 textExtraction:mixedLinksExtraction,
223 sortList: cv ? [lo] : false
224 }).bind("sortEnd", function() {
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000225 bundlesTable.eq(0).attr("config");
226 $.cookies.set("webconsolebundlelist", bundlesTable.sortList.toString());
Felix Meschberger775025e2010-02-18 15:29:39 +0000227 });
Valentin Pavlov Valchev366f91c2010-03-17 08:13:39 +0000228 bundlesBody = bundlesTable.find('tbody');
229 bundlesTemplate = bundlesBody.find('tr').clone();
230
231 renderData(lastBundleData);
Felix Meschberger775025e2010-02-18 15:29:39 +0000232});
233