blob: 6631cd3a57db4c8de3dab5ca5ef8398192d0f2dd [file] [log] [blame]
Carsten Ziegeler83fbe442009-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 Ziegeler83ff0442009-02-10 13:08:50 +000064 if ( op == "configure" ) {
Carsten Ziegeler83fbe442009-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',
72 onClick: 'changeDataEntryState("' + arg + '", "' + op + '");'
73 });
74
75 if (!enabled) {
76 input.setAttribute( "disabled", true );
77 }
78 var div = createElement("div");
79 div.setAttribute("style", "float:left; margin-left:10px;");
80 div.appendChild(input);
81 parent.appendChild( div );
82}
83
84function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
85 var id = dataEntry.id;
86 var name = dataEntry.name;
87 var state = dataEntry.state;
88
89 var inputElement = createElement("img", "rightButton", {
90 src: appRoot + "/res/imgs/arrow_right.png",
91 border: "none",
92 id: 'img' + id,
93 title: "Details",
94 alt: "Details",
95 width: 14,
96 height: 14,
97 onClick: 'showDetails(' + id + ');'
98 });
99 var titleElement;
100 if ( drawDetails ) {
101 titleElement = text(name);
102 } else {
103 titleElement = createElement ("a", null, {
104 href: window.location.pathname + "/" + id
105 });
106 titleElement.appendChild(text(name));
107 }
108
109 parent.appendChild( td( null, null, [ text( id ) ] ) );
110 parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) );
111 parent.appendChild( td( null, null, [ text( state ) ] ) );
112 var actionsTd = td( null, null );
113
114 for ( var a in dataEntry.actions ) {
115 actionButton( actionsTd, id, dataEntry.actions[a], dataEntry.pid );
116 }
117 parent.appendChild( actionsTd );
118}
119
120function changeDataEntryState(/* long */ id, /* String */ action) {
Carsten Ziegeler83ff0442009-02-10 13:08:50 +0000121 if ( action == "configure") {
Carsten Ziegeler83fbe442009-02-09 20:48:31 +0000122 window.location = appRoot + "/configMgr/" + id;
123 return;
124 }
125 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
126 renderData(data);
127 }, "json");
128}
129
130function showDetails( id ) {
131 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
132 renderDetails(data);
133 }, "json");
134}
135
136function loadData() {
137 $.get(pluginRoot + "/.json", null, function(data) {
138 renderData(data);
139 }, "json");
140}
141
142function hideDetails( id ) {
143 $("#img" + id).each(function() {
144 $("#pluginInlineDetails").remove();
145 this.setAttribute("src", appRoot + "/res/imgs/arrow_right.png");
146 this.setAttribute("onClick", "showDetails('" + id + "')");
147 this.setAttribute("title", "Details");
148 this.setAttribute("alt", "Details");
149 });
150}
151
152function renderDetails( data ) {
153 data = data.data[0];
Carsten Ziegelerd721c962009-02-16 16:42:07 +0000154 $("#pluginInlineDetails").remove();
Carsten Ziegeler83fbe442009-02-09 20:48:31 +0000155 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>");
156 $("#img" + data.id).each(function() {
157 if ( drawDetails ) {
158 this.setAttribute("src", appRoot + "/res/imgs/arrow_left.png");
159 var ref = window.location.pathname;
160 ref = ref.substring(0, ref.lastIndexOf('/'));
161 this.setAttribute("onClick", "window.location = '" + ref + "';");
162 this.setAttribute("title", "Back");
163 this.setAttribute("alt", "Back");
164 } else {
165 this.setAttribute("src", appRoot + "/res/imgs/arrow_down.png");
166 this.setAttribute("onClick", "hideDetails('" + data.id + "')");
167 this.setAttribute("title", "Hide Details");
168 this.setAttribute("alt", "Hide Details");
169 }
170 });
171 $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>");
172 var details = data.props;
173 for (var idx in details) {
174 var prop = details[idx];
175
176 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + prop.key + "</td><td class='aligntop' style='border:0px none'>";
177 if (prop.value) {
178 if ( $.isArray(prop.value) ) {
179 var i = 0;
180 for(var pi in prop.value) {
181 var value = prop.value[pi];
182 if (i > 0) { txt = txt + "<br/>"; }
183 var span;
184 if (value.substring(0, 2) == "!!") {
185 txt = txt + "<span style='color: red;'>" + value + "</span>";
186 } else {
187 txt = txt + value;
188 }
189 i++;
190 }
191 } else {
192 txt = txt + prop.value;
193 }
194 } else {
195 txt = txt + "\u00a0";
196 }
197 txt = txt + "</td></tr>";
198 $("#pluginInlineDetails > table > tbody").append(txt);
199 }
200}
201
202function renderComponents(data) {
203 $(document).ready(function(){
204 renderView( ["Id", "Name", "Status", "Actions"],
205 "<div class='button'><button class='reloadButton' type='button' name='reload'>Reload</button></div>");
206 renderData(data);
207
208 $(".reloadButton").click(loadData);
209
210 var extractMethod = function(node) {
211 var link = node.getElementsByTagName("a");
212 if ( link && link.length == 1 ) {
213 return link[0].innerHTML;
214 }
215 return node.innerHTML;
216 };
217 $("#plugin_table").tablesorter({
218 headers: {
219 0: { sorter:"digit"},
220 3: { sorter: false }
221 },
222 sortList: [[1,0]],
223 textExtraction:extractMethod
224 });
225 });
226}
227