blob: c1432e8d4594879436fda59daeec3ff5922a30d1 [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 *
Felix Meschbergerb722be52010-02-18 15:42:31 +00009 * http://www.apache.org/licenses/LICENSE-2.0
Carsten Ziegeler83fbe442009-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 Ziegeler83fbe442009-02-09 20:48:31 +000017function renderData( eventData ) {
Felix Meschbergerb722be52010-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
Valentin Pavlov Valchev90d662b2010-04-15 12:01:33 +000031 tableBody.empty();
Felix Meschbergerb722be52010-02-18 15:42:31 +000032 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 Ziegeler83fbe442009-02-09 20:48:31 +000039}
40
Felix Meschberger2ad2a1f2010-08-03 09:47:04 +000041function getEntryId(/* Object */ dataEntry) {
42 var id = dataEntry.id;
43 if (id < 0) {
44 id = dataEntry.name;
45 if (dataEntry.pid) {
46 id += "/" + dataEntry.pid;
47 }
48 }
49 return id;
50}
Felix Meschbergerb722be52010-02-18 15:42:31 +000051
Felix Meschberger2ad2a1f2010-08-03 09:47:04 +000052function entry( /* Object */ dataEntry ) {
53 var idPath = getEntryId(dataEntry);
54 var id = idPath.replace(/[./-]/g, "_");
55 var name = dataEntry.name;
56 var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'entry' + id);
Valentin Pavlov Valchev90d662b2010-04-15 12:01:33 +000057
58 _.find('.bIcon').attr('id', 'img' + id).click(function() {
Felix Meschberger2ad2a1f2010-08-03 09:47:04 +000059 showDetails(idPath);
60 }).after(drawDetails ? name : ('<a href="' + pluginRoot + '/' + idPath + '">' + name + '</a>'));
Valentin Pavlov Valchev90d662b2010-04-15 12:01:33 +000061
Felix Meschberger2ad2a1f2010-08-03 09:47:04 +000062 _.find('td:eq(0)').text( dataEntry.id );
Valentin Pavlov Valchev90d662b2010-04-15 12:01:33 +000063 _.find('td:eq(2)').text( dataEntry.state );
64
65 // setup buttons
66 if ( dataEntry.stateRaw == 1 || dataEntry.stateRaw == 1024 ) { // disabled or disabling
Felix Meschberger2ad2a1f2010-08-03 09:47:04 +000067 _.find('li:eq(0)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'enable') });
Felix Meschbergerb722be52010-02-18 15:42:31 +000068 } else {
Felix Meschberger2ad2a1f2010-08-03 09:47:04 +000069 _.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'disable') });
Felix Meschbergerb722be52010-02-18 15:42:31 +000070 }
Valentin Pavlov Valchev90d662b2010-04-15 12:01:33 +000071 if ( dataEntry.configurable ) _.find('li:eq(2)').removeClass('ui-helper-hidden').click(function() { // configure
72 changeDataEntryState(dataEntry.pid, 'configure');
73 });
Carsten Ziegeler83fbe442009-02-09 20:48:31 +000074}
75
76function changeDataEntryState(/* long */ id, /* String */ action) {
Carsten Ziegeler83ff0442009-02-10 13:08:50 +000077 if ( action == "configure") {
Carsten Ziegeler83fbe442009-02-09 20:48:31 +000078 window.location = appRoot + "/configMgr/" + id;
79 return;
80 }
81 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
Felix Meschbergerb722be52010-02-18 15:42:31 +000082 renderData(data);
Carsten Ziegeler83fbe442009-02-09 20:48:31 +000083 }, "json");
84}
85
86function showDetails( id ) {
Felix Meschbergerb722be52010-02-18 15:42:31 +000087 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
88 renderDetails(data);
89 }, "json");
Carsten Ziegeler83fbe442009-02-09 20:48:31 +000090}
91
92function loadData() {
93 $.get(pluginRoot + "/.json", null, function(data) {
Felix Meschbergerb722be52010-02-18 15:42:31 +000094 renderData(data);
Carsten Ziegeler83fbe442009-02-09 20:48:31 +000095 }, "json");
96}
97
98function hideDetails( id ) {
Felix Meschberger2ad2a1f2010-08-03 09:47:04 +000099 var __test__ = $("#img" + id);
Carsten Ziegeler83fbe442009-02-09 20:48:31 +0000100 $("#img" + id).each(function() {
101 $("#pluginInlineDetails").remove();
Felix Meschbergerb722be52010-02-18 15:42:31 +0000102 $(this).
103 removeClass('ui-icon-triangle-1-w').//left
104 removeClass('ui-icon-triangle-1-s').//down
105 addClass('ui-icon-triangle-1-e').//right
106 attr("title", "Details").
107 unbind('click').click(function() {showDetails(id)});
Carsten Ziegeler83fbe442009-02-09 20:48:31 +0000108 });
109}
110
111function renderDetails( data ) {
112 data = data.data[0];
Felix Meschberger2ad2a1f2010-08-03 09:47:04 +0000113 var id = getEntryId(data).replace(/[./-]/g, "_");
Carsten Ziegelerd721c962009-02-16 16:42:07 +0000114 $("#pluginInlineDetails").remove();
Felix Meschberger2ad2a1f2010-08-03 09:47:04 +0000115 var __test__ = $("#entry" + id);
116 $("#entry" + id + " > td").eq(1).append("<div id='pluginInlineDetails'/>");
117 $("#img" + id).each(function() {
Carsten Ziegeler83fbe442009-02-09 20:48:31 +0000118 if ( drawDetails ) {
Felix Meschbergerb722be52010-02-18 15:42:31 +0000119 var ref = window.location.pathname;
120 ref = ref.substring(0, ref.lastIndexOf('/'));
121 $(this).
122 removeClass('ui-icon-triangle-1-e').//right
123 removeClass('ui-icon-triangle-1-s').//down
124 addClass('ui-icon-triangle-1-w').//left
125 attr("title", "Back").
126 unbind('click').click(function() {window.location = ref});
Carsten Ziegeler83fbe442009-02-09 20:48:31 +0000127 } else {
Felix Meschbergerb722be52010-02-18 15:42:31 +0000128 $(this).
129 removeClass('ui-icon-triangle-1-w').//left
130 removeClass('ui-icon-triangle-1-e').//right
131 addClass('ui-icon-triangle-1-s').//down
132 attr("title", "Hide Details").
Felix Meschberger2ad2a1f2010-08-03 09:47:04 +0000133 unbind('click').click(function() {hideDetails(id)});
Carsten Ziegeler83fbe442009-02-09 20:48:31 +0000134 }
135 });
136 $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>");
Felix Meschbergerb722be52010-02-18 15:42:31 +0000137 var details = data.props;
138 for (var idx in details) {
139 var prop = details[idx];
140 var key = i18n[prop.key] ? i18n[prop.key] : prop.key; // i18n
141
142 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + key + "</td><td class='aligntop' style='border:0px none'>";
143 if (prop.value) {
144 if ( $.isArray(prop.value) ) {
145 var i = 0;
146 for(var pi in prop.value) {
147 var value = prop.value[pi];
148 if (i > 0) { txt = txt + "<br/>"; }
149 var span;
150 if (value.substring(0, 2) == "!!") {
151 txt = txt + "<span style='color: red;'>" + value + "</span>";
152 } else {
153 txt = txt + value;
154 }
155 i++;
156 }
157 } else {
158 txt = txt + prop.value;
159 }
160 } else {
161 txt = txt + "\u00a0";
162 }
163 txt = txt + "</td></tr>";
164 $("#pluginInlineDetails > table > tbody").append(txt);
Carsten Ziegeler83fbe442009-02-09 20:48:31 +0000165 }
166}
167
Valentin Pavlov Valchev90d662b2010-04-15 12:01:33 +0000168var tableBody = false;
169var tableEntryTemplate = false;
Carsten Ziegeler83fbe442009-02-09 20:48:31 +0000170
Felix Meschbergerb722be52010-02-18 15:42:31 +0000171$(document).ready(function(){
Valentin Pavlov Valchev90d662b2010-04-15 12:01:33 +0000172 tableBody = $('#plugin_table tbody');
173 tableEntryTemplate = tableBody.find('tr').clone();
174
175 renderData(scrData);
Felix Meschbergerb722be52010-02-18 15:42:31 +0000176
177 $(".reloadButton").click(loadData);
178
179 var extractMethod = function(node) {
180 var link = node.getElementsByTagName("a");
181 if ( link && link.length == 1 ) {
182 return link[0].innerHTML;
183 }
184 return node.innerHTML;
185 };
186 $("#plugin_table").tablesorter({
187 headers: {
188 0: { sorter:"digit"},
189 3: { sorter: false }
190 },
191 sortList: [[1,0]],
192 textExtraction:extractMethod
193 });
194});
195