blob: 9b2ba33f9b6ada1404fd65d04e829eae444b57ba [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 *
Felix Meschbergerfb708822010-02-18 15:42:31 +00009 * http://www.apache.org/licenses/LICENSE-2.0
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000010 *
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 Ziegeler7ecffce2009-02-09 20:48:31 +000017function renderData( eventData ) {
Felix Meschbergerfb708822010-02-18 15:42:31 +000018 switch(eventData.status) {
19 case -1: // no event admin
20 $(".statline").html(i18n.stat_no_service);
21 $("#scr").addClass('ui-helper-hidden');
22 break;
23 case 0: // no components
24 $(".statline").html(i18n.stat_no_components);
25 $('#scr').addClass('ui-helper-hidden');
26 break;
27 default:
28 $(".statline").html(i18n.stat_ok.msgFormat(eventData.status));
29 $('#scr').removeClass('ui-helper-hidden');
30
31 $("#plugin_table > tbody > tr").remove();
32 for ( var idx in eventData.data ) {
33 entry( eventData.data[idx] );
34 }
35 $("#plugin_table").trigger("update");
36 if ( drawDetails ) renderDetails(eventData);
37 initStaticWidgets();
38 }
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000039}
40
41function entry( /* Object */ dataEntry ) {
Felix Meschbergerfb708822010-02-18 15:42:31 +000042 var trElement = tr( null, { id: "entry" + dataEntry.id } );
43 entryInternal( trElement, dataEntry );
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000044 $("#plugin_table > tbody").append(trElement);
45}
46
47function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action, /* string */ pid ) {
48 var enabled = action.enabled;
49 var op = action.link;
50 var opLabel = action.name;
51 var img = action.image;
Felix Meschbergerfb708822010-02-18 15:42:31 +000052 // fixup JQuery UI icons
53 if (img == 'configure') { img = 'wrench'
54 } else if (img == 'disable') { img = 'stop' //locked
55 } else if (img == 'enable') { img = 'play' //unlocked
56 }
57
58 // apply i18n
59 opLabel = i18n[opLabel] ? i18n[opLabel] : opLabel;
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000060
61 var arg = id;
Carsten Ziegeler86ca51a2009-02-10 13:08:50 +000062 if ( op == "configure" ) {
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000063 arg = pid
64 }
Felix Meschbergerfb708822010-02-18 15:42:31 +000065 var input = createElement('li', 'dynhover', {
66 title: opLabel
67 });
68 $(input)
69 .html('<span class="ui-icon ui-icon-'+img+'"></span>')
70 .click(function() {changeDataEntryState(arg, op)});
71
72 if (!enabled) {
73 $(input).attr('disabled', true).addClass('ui-state-disabled');
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000074
Felix Meschbergerfb708822010-02-18 15:42:31 +000075 }
76 parent.appendChild( input );
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000077}
78
79function entryInternal( /* Element */ parent, /* Object */ dataEntry ) {
Felix Meschbergerfb708822010-02-18 15:42:31 +000080 var id = dataEntry.id;
81 var name = dataEntry.name;
82 var state = dataEntry.state;
83
84 var inputElement = createElement('span', 'ui-icon ui-icon-triangle-1-e', {
85 title: "Details",
86 id: 'img' + id,
87 style: {display: "inline-block"}
88 });
Carsten Ziegeler21359442009-03-05 16:14:55 +000089 $(inputElement).click(function() {showDetails(id)});
Felix Meschbergerfb708822010-02-18 15:42:31 +000090 var titleElement;
91 if ( drawDetails ) {
92 titleElement = text(name);
93 } else {
94 titleElement = createElement ("a", null, {
95 href: window.location.pathname + "/" + id
96 });
97 titleElement.appendChild(text(name));
98 }
99
100 parent.appendChild( td( null, null, [ text( id ) ] ) );
101 parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) );
102 parent.appendChild( td( null, null, [ text( state ) ] ) );
103 var actionsTd = td( null, null );
104 var div = createElement('ul', 'icons ui-widget');
105 actionsTd.appendChild(div);
106
107 for ( var a in dataEntry.actions ) {
108 actionButton( div, id, dataEntry.actions[a], dataEntry.pid );
109 }
110 parent.appendChild( actionsTd );
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000111}
112
113function changeDataEntryState(/* long */ id, /* String */ action) {
Carsten Ziegeler86ca51a2009-02-10 13:08:50 +0000114 if ( action == "configure") {
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000115 window.location = appRoot + "/configMgr/" + id;
116 return;
117 }
118 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
Felix Meschbergerfb708822010-02-18 15:42:31 +0000119 renderData(data);
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000120 }, "json");
121}
122
123function showDetails( id ) {
Felix Meschbergerfb708822010-02-18 15:42:31 +0000124 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
125 renderDetails(data);
126 }, "json");
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000127}
128
129function loadData() {
130 $.get(pluginRoot + "/.json", null, function(data) {
Felix Meschbergerfb708822010-02-18 15:42:31 +0000131 renderData(data);
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000132 }, "json");
133}
134
135function hideDetails( id ) {
136 $("#img" + id).each(function() {
137 $("#pluginInlineDetails").remove();
Felix Meschbergerfb708822010-02-18 15:42:31 +0000138 $(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)});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000144 });
145}
146
147function renderDetails( data ) {
148 data = data.data[0];
Carsten Ziegeler7cc941e2009-02-16 16:42:07 +0000149 $("#pluginInlineDetails").remove();
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000150 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>");
151 $("#img" + data.id).each(function() {
152 if ( drawDetails ) {
Felix Meschbergerfb708822010-02-18 15:42:31 +0000153 var ref = window.location.pathname;
154 ref = ref.substring(0, ref.lastIndexOf('/'));
155 $(this).
156 removeClass('ui-icon-triangle-1-e').//right
157 removeClass('ui-icon-triangle-1-s').//down
158 addClass('ui-icon-triangle-1-w').//left
159 attr("title", "Back").
160 unbind('click').click(function() {window.location = ref});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000161 } else {
Felix Meschbergerfb708822010-02-18 15:42:31 +0000162 $(this).
163 removeClass('ui-icon-triangle-1-w').//left
164 removeClass('ui-icon-triangle-1-e').//right
165 addClass('ui-icon-triangle-1-s').//down
166 attr("title", "Hide Details").
167 unbind('click').click(function() {hideDetails(data.id)});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000168 }
169 });
170 $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>");
Felix Meschbergerfb708822010-02-18 15:42:31 +0000171 var details = data.props;
172 for (var idx in details) {
173 var prop = details[idx];
174 var key = i18n[prop.key] ? i18n[prop.key] : prop.key; // i18n
175
176 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + 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);
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000199 }
200}
201
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000202
Felix Meschbergerfb708822010-02-18 15:42:31 +0000203$(document).ready(function(){
204 renderData (scrData);
205
206 $(".reloadButton").click(loadData);
207
208 var extractMethod = function(node) {
209 var link = node.getElementsByTagName("a");
210 if ( link && link.length == 1 ) {
211 return link[0].innerHTML;
212 }
213 return node.innerHTML;
214 };
215 $("#plugin_table").tablesorter({
216 headers: {
217 0: { sorter:"digit"},
218 3: { sorter: false }
219 },
220 sortList: [[1,0]],
221 textExtraction:extractMethod
222 });
223});
224