blob: c6b1fac299c946cb55dcd0b99e935e29861ad551 [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;
64 if ( op == "edit" ) {
65 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) {
121 if ( action == "edit") {
122 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];
154 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>");
155 $("#img" + data.id).each(function() {
156 if ( drawDetails ) {
157 this.setAttribute("src", appRoot + "/res/imgs/arrow_left.png");
158 var ref = window.location.pathname;
159 ref = ref.substring(0, ref.lastIndexOf('/'));
160 this.setAttribute("onClick", "window.location = '" + ref + "';");
161 this.setAttribute("title", "Back");
162 this.setAttribute("alt", "Back");
163 } else {
164 this.setAttribute("src", appRoot + "/res/imgs/arrow_down.png");
165 this.setAttribute("onClick", "hideDetails('" + data.id + "')");
166 this.setAttribute("title", "Hide Details");
167 this.setAttribute("alt", "Hide Details");
168 }
169 });
170 $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>");
171 var details = data.props;
172 for (var idx in details) {
173 var prop = details[idx];
174
175 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + prop.key + "</td><td class='aligntop' style='border:0px none'>";
176 if (prop.value) {
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 var span;
183 if (value.substring(0, 2) == "!!") {
184 txt = txt + "<span style='color: red;'>" + value + "</span>";
185 } else {
186 txt = txt + value;
187 }
188 i++;
189 }
190 } else {
191 txt = txt + prop.value;
192 }
193 } else {
194 txt = txt + "\u00a0";
195 }
196 txt = txt + "</td></tr>";
197 $("#pluginInlineDetails > table > tbody").append(txt);
198 }
199}
200
201function renderComponents(data) {
202 $(document).ready(function(){
203 renderView( ["Id", "Name", "Status", "Actions"],
204 "<div class='button'><button class='reloadButton' type='button' name='reload'>Reload</button></div>");
205 renderData(data);
206
207 $(".reloadButton").click(loadData);
208
209 var extractMethod = function(node) {
210 var link = node.getElementsByTagName("a");
211 if ( link && link.length == 1 ) {
212 return link[0].innerHTML;
213 }
214 return node.innerHTML;
215 };
216 $("#plugin_table").tablesorter({
217 headers: {
218 0: { sorter:"digit"},
219 3: { sorter: false }
220 },
221 sortList: [[1,0]],
222 textExtraction:extractMethod
223 });
224 });
225}
226