blob: 2660b74e4179959bb8daca16b66cc16a2a5ab174 [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 */
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000017
18function renderData( eventData ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000019 var s = eventData.s;
20 $(".statline").html(i18n.statline.msgFormat(s[0], s[1], s[2], s[3], s[4]));
21 $("#plugin_table > tbody > tr").remove();
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000022 for ( var idx in eventData.data ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000023 if ( currentBundle == null || !drawDetails || currentBundle == eventData.data[idx].id) {
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +000024 entry( eventData.data[idx] );
Felix Meschberger775025e2010-02-18 15:29:39 +000025 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000026 }
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +000027 if ( drawDetails && eventData.data.length == 1 ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000028 renderDetails(eventData.data[0]);
Carsten Ziegeler3bbfee42009-12-11 09:19:50 +000029 } else if ( currentBundle != null ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000030 var id = currentBundle;
31 hideDetails(id);
32 showDetails(id);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000033 }
Felix Meschberger775025e2010-02-18 15:29:39 +000034 initStaticWidgets();
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000035}
36
37function entry( /* Object */ dataEntry ) {
38 var trElement = tr( null, { id: "entry" + dataEntry.id } );
39 entryInternal( trElement, dataEntry );
Felix Meschberger775025e2010-02-18 15:29:39 +000040 $("#plugin_table > tbody").append(trElement);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000041}
42
43function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000044 if ( !action.enabled ) {
45 return;
46 }
47 var enabled = action.enabled;
48 var op = action.link;
49 var opLabel = action.name;
50 var img = action.image;
51 // fixup JQuery UI icons
52 if(img == "start" ) img = "play";
53 if(img == "update") img = "transferthick-e-w";
54 if(img == "delete") img = "trash";
55
56 // apply i18n
57 opLabel = i18n[opLabel] ? i18n[opLabel] : opLabel;
58
59 var input = createElement('li', 'dynhover', {
60 title: opLabel
61 });
62 $(input)
63 .html('<span class="ui-icon ui-icon-'+img+'"></span>')
64 .click(function() {changeDataEntryState(id, op)});
65
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000066 if (!enabled) {
Felix Meschberger775025e2010-02-18 15:29:39 +000067 $(input).attr("disabled", true).addClass("ui-state-disabled");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000068 }
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000069 parent.appendChild( input );
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000070}
71
72function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
73 var id = dataEntry.id;
74 var name = dataEntry.name;
75 var state = dataEntry.state;
Felix Meschberger775025e2010-02-18 15:29:39 +000076
77 // right arrow
78 var inputElement = createElement('span', 'ui-icon ui-icon-triangle-1-e', {
79 title: "Details",
80 id: 'img' + id,
81 style: {display: "inline-block"}
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000082 });
Carsten Ziegeler0b83c012009-03-05 16:14:55 +000083 $(inputElement).click(function() {showDetails(id)});
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000084 var titleElement;
85 if ( drawDetails ) {
Felix Meschberger775025e2010-02-18 15:29:39 +000086 titleElement = text(name);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000087 } else {
88 titleElement = createElement ("a", null, {
Felix Meschberger775025e2010-02-18 15:29:39 +000089 href: window.location.pathname + "/" + id
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000090 });
91 titleElement.appendChild(text(name));
92 }
93
94 parent.appendChild( td( null, null, [ text( id ) ] ) );
95 parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) );
Carsten Ziegelerca26b522009-04-27 20:45:09 +000096 parent.appendChild( td( null, null, [ text( dataEntry.version ) ] ) );
97 parent.appendChild( td( null, null, [ text( dataEntry.symbolicName ) ] ) );
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +000098 parent.appendChild( td( null, null, [ text( state ) ] ) );
99 var actionsTd = td( null, null );
Felix Meschberger775025e2010-02-18 15:29:39 +0000100 var div = createElement('ul', 'icons ui-widget');
Carsten Ziegeler0b83c012009-03-05 16:14:55 +0000101 actionsTd.appendChild(div);
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000102
103 for ( var a in dataEntry.actions ) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000104 actionButton( div, id, dataEntry.actions[a] );
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000105 }
106 parent.appendChild( actionsTd );
107}
108
109function loadData() {
Felix Meschberger775025e2010-02-18 15:29:39 +0000110 $.get(pluginRoot + "/.json", null, function(data) {
111 renderData(data);
112 }, "json");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000113}
114
115function changeDataEntryState(/* long */ id, /* String */ action) {
Felix Meschberger775025e2010-02-18 15:29:39 +0000116 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
117 renderData(data);
118 }, "json");
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000119}
120
121function refreshPackages() {
Felix Meschberger775025e2010-02-18 15:29:39 +0000122 $.post(window.location.pathname, {"action": "refreshPackages"}, function(data) {
123 renderData(data);
124 }, "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/>"; }
184 txt = txt + value;
185 i++;
186 }
187 } else {
188 txt = txt + prop.value;
189 }
190 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000191 } else {
Felix Meschberger775025e2010-02-18 15:29:39 +0000192 txt = txt + "\u00a0";
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000193 }
194 txt = txt + "</td></tr>";
Felix Meschberger16dd9882010-02-18 08:08:47 +0000195 $("#pluginInlineDetails" + data.id + " > table > tbody").append(txt);
Felix Meschberger775025e2010-02-18 15:29:39 +0000196 }
Carsten Ziegeler6577bfa2009-02-05 10:45:35 +0000197}
198
Felix Meschberger775025e2010-02-18 15:29:39 +0000199$(document).ready(function(){
200 $(".refreshPackages").click(refreshPackages);
201 $(".reloadButton").click(loadData);
202 $(".installButton").click(function() {
203 document.location = pluginRoot + "/upload";
204 });
205 renderData(__bundles__);
206
207 // check for cookie
208 var cv = $.cookies.get("webconsolebundlelist");
209 var lo = (cv ? cv.split(",") : [1,0]);
210 $("#plugin_table").tablesorter({
211 headers: {
212 0: { sorter:"digit" },
213 5: { sorter: false }
214 },
215 textExtraction:mixedLinksExtraction,
216 sortList: cv ? [lo] : false
217 }).bind("sortEnd", function() {
218 var table = $("#plugin_table").eq(0).attr("config");
219 $.cookies.set("webconsolebundlelist", table.sortList.toString());
220 });
221});
222