blob: 6728e04e11520637a77be088e0897b67302972c1 [file] [log] [blame]
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +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 */
17function renderStatusLine() {
18 $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" );
19}
20
21function renderView( /* Array of String */ columns, /* Array of String */ buttons ) {
22 renderStatusLine();
23 renderButtons(buttons);
24 var txt = "<div class='table'><table id='plugin_table' class='tablelayout'><thead><tr>";
25 for ( var name in columns ) {
26 txt = txt + "<th class='col_" + columns[name] + "'>" + columns[name] + "</th>";
27 }
28 txt = txt + "</tr></thead><tbody></tbody></table></div>";
29 $("#plugin_content").append( txt );
30 renderButtons(buttons);
31 renderStatusLine();
32}
33
34function renderButtons( buttons ) {
35 $("#plugin_content").append( "<form method='post' enctype='multipart/form-data'><div class='fullwidth'><div class='buttons'>" +
36 buttons + "</div></div></form>" );
37}
38
39function renderData( eventData ) {
40 $(".statusline").empty().append(eventData.status);
41 $("#plugin_table > tbody > tr").remove();
42 for ( var idx in eventData.data ) {
43 entry( eventData.data[idx] );
44 }
45 $("#plugin_table").trigger("update");
46 if ( drawDetails ) {
47 renderDetails(eventData);
48 }
49}
50
51function entry( /* Object */ dataEntry ) {
52 var trElement = tr( null, { id: "entry" + dataEntry.id } );
53 entryInternal( trElement, dataEntry );
54 $("#plugin_table > tbody").append(trElement);
55}
56
57function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action, /* string */ pid ) {
58 var enabled = action.enabled;
59 var op = action.link;
60 var opLabel = action.name;
61 var img = action.image;
62
63 var arg = id;
Carsten Ziegeler86ca51a2009-02-10 13:08:50 +000064 if ( op == "configure" ) {
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000065 arg = pid
66 }
67 var input = createElement( "input", null, {
68 type: 'image',
69 title: opLabel,
70 alt: opLabel,
71 src: imgRoot + '/component_' + img + '.png',
Carsten Ziegeler21359442009-03-05 16:14:55 +000072 style: {"margin-left": "10px"}
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000073 });
Carsten Ziegeler21359442009-03-05 16:14:55 +000074 $(input).click(function() {changeDataEntryState(arg, op)});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000075
76 if (!enabled) {
Carsten Ziegeler21359442009-03-05 16:14:55 +000077 $(input).attr("disabled", true);
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000078 }
Carsten Ziegeler21359442009-03-05 16:14:55 +000079 parent.appendChild( input );
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000080}
81
82function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
83 var id = dataEntry.id;
84 var name = dataEntry.name;
85 var state = dataEntry.state;
86
87 var inputElement = createElement("img", "rightButton", {
88 src: appRoot + "/res/imgs/arrow_right.png",
Carsten Ziegeler21359442009-03-05 16:14:55 +000089 style: {"border": "none"},
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000090 id: 'img' + id,
91 title: "Details",
92 alt: "Details",
93 width: 14,
Carsten Ziegeler21359442009-03-05 16:14:55 +000094 height: 14
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000095 });
Carsten Ziegeler21359442009-03-05 16:14:55 +000096 $(inputElement).click(function() {showDetails(id)});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000097 var titleElement;
98 if ( drawDetails ) {
99 titleElement = text(name);
100 } else {
101 titleElement = createElement ("a", null, {
102 href: window.location.pathname + "/" + id
103 });
104 titleElement.appendChild(text(name));
105 }
106
107 parent.appendChild( td( null, null, [ text( id ) ] ) );
108 parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) );
109 parent.appendChild( td( null, null, [ text( state ) ] ) );
110 var actionsTd = td( null, null );
Carsten Ziegeler21359442009-03-05 16:14:55 +0000111 var div = createElement("div", null, {
112 style: { "text-align" : "left"}
113 });
114 actionsTd.appendChild(div);
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000115
116 for ( var a in dataEntry.actions ) {
Carsten Ziegeler21359442009-03-05 16:14:55 +0000117 actionButton( div, id, dataEntry.actions[a], dataEntry.pid );
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000118 }
119 parent.appendChild( actionsTd );
120}
121
122function changeDataEntryState(/* long */ id, /* String */ action) {
Carsten Ziegeler86ca51a2009-02-10 13:08:50 +0000123 if ( action == "configure") {
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000124 window.location = appRoot + "/configMgr/" + id;
125 return;
126 }
127 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
128 renderData(data);
129 }, "json");
130}
131
132function showDetails( id ) {
133 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
134 renderDetails(data);
135 }, "json");
136}
137
138function loadData() {
139 $.get(pluginRoot + "/.json", null, function(data) {
140 renderData(data);
141 }, "json");
142}
143
144function hideDetails( id ) {
145 $("#img" + id).each(function() {
146 $("#pluginInlineDetails").remove();
Carsten Ziegeler21359442009-03-05 16:14:55 +0000147 $(this).attr("src", appRoot + "/res/imgs/arrow_right.png");
148 $(this).attr("title", "Details");
149 $(this).attr("alt", "Details");
150 $(this).unbind('click').click(function() {showDetails(id)});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000151 });
152}
153
154function renderDetails( data ) {
155 data = data.data[0];
Carsten Ziegeler7cc941e2009-02-16 16:42:07 +0000156 $("#pluginInlineDetails").remove();
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000157 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>");
158 $("#img" + data.id).each(function() {
159 if ( drawDetails ) {
Carsten Ziegeler21359442009-03-05 16:14:55 +0000160 $(this).attr("src", appRoot + "/res/imgs/arrow_left.png");
161 $(this).attr("title", "Back");
162 $(this).attr("alt", "Back");
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000163 var ref = window.location.pathname;
164 ref = ref.substring(0, ref.lastIndexOf('/'));
Carsten Ziegeler21359442009-03-05 16:14:55 +0000165 $(this).unbind('click').click(function() {window.location = ref;});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000166 } else {
Carsten Ziegeler21359442009-03-05 16:14:55 +0000167 $(this).attr("src", appRoot + "/res/imgs/arrow_down.png");
168 $(this).attr("title", "Hide Details");
169 $(this).attr("alt", "Hide Details");
170 $(this).unbind('click').click(function() {hideDetails(data.id)});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000171 }
172 });
173 $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>");
174 var details = data.props;
175 for (var idx in details) {
176 var prop = details[idx];
177
178 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + prop.key + "</td><td class='aligntop' style='border:0px none'>";
179 if (prop.value) {
180 if ( $.isArray(prop.value) ) {
181 var i = 0;
182 for(var pi in prop.value) {
183 var value = prop.value[pi];
184 if (i > 0) { txt = txt + "<br/>"; }
185 var span;
186 if (value.substring(0, 2) == "!!") {
187 txt = txt + "<span style='color: red;'>" + value + "</span>";
188 } else {
189 txt = txt + value;
190 }
191 i++;
192 }
193 } else {
194 txt = txt + prop.value;
195 }
196 } else {
197 txt = txt + "\u00a0";
198 }
199 txt = txt + "</td></tr>";
200 $("#pluginInlineDetails > table > tbody").append(txt);
201 }
202}
203
204function renderComponents(data) {
205 $(document).ready(function(){
206 renderView( ["Id", "Name", "Status", "Actions"],
207 "<div class='button'><button class='reloadButton' type='button' name='reload'>Reload</button></div>");
208 renderData(data);
209
210 $(".reloadButton").click(loadData);
211
212 var extractMethod = function(node) {
213 var link = node.getElementsByTagName("a");
214 if ( link && link.length == 1 ) {
215 return link[0].innerHTML;
216 }
217 return node.innerHTML;
218 };
219 $("#plugin_table").tablesorter({
220 headers: {
221 0: { sorter:"digit"},
222 3: { sorter: false }
223 },
224 sortList: [[1,0]],
225 textExtraction:extractMethod
226 });
227 });
228}
229