blob: b0d084cf9c50531617a4a08f57dca2d5e821a910 [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
Valentin Valchevf51fe432010-04-15 12:01:33 +000031 tableBody.empty();
Felix Meschbergerfb708822010-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 Ziegeler7ecffce2009-02-09 20:48:31 +000039}
40
41function entry( /* Object */ dataEntry ) {
Felix Meschbergerfb708822010-02-18 15:42:31 +000042 var id = dataEntry.id;
43 var name = dataEntry.name;
Felix Meschbergerfb708822010-02-18 15:42:31 +000044
Valentin Valchevf51fe432010-04-15 12:01:33 +000045 var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'entry' + dataEntry.id);
46
47 _.find('.bIcon').attr('id', 'img' + id).click(function() {
48 showDetails(id);
49 }).after(drawDetails ? name : ('<a href="' + window.location.pathname + '/' + id + '">' + name + '</a>'));
50
51 _.find('td:eq(0)').text( id );
52 _.find('td:eq(2)').text( dataEntry.state );
53
54 // setup buttons
55 if ( dataEntry.stateRaw == 1 || dataEntry.stateRaw == 1024 ) { // disabled or disabling
56 _.find('li:eq(0)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(id, 'enable') });
Felix Meschbergerfb708822010-02-18 15:42:31 +000057 } else {
Valentin Valchevf51fe432010-04-15 12:01:33 +000058 _.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(id, 'disable') });
Felix Meschbergerfb708822010-02-18 15:42:31 +000059 }
Valentin Valchevf51fe432010-04-15 12:01:33 +000060 if ( dataEntry.configurable ) _.find('li:eq(2)').removeClass('ui-helper-hidden').click(function() { // configure
61 changeDataEntryState(dataEntry.pid, 'configure');
62 });
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000063}
64
65function changeDataEntryState(/* long */ id, /* String */ action) {
Carsten Ziegeler86ca51a2009-02-10 13:08:50 +000066 if ( action == "configure") {
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000067 window.location = appRoot + "/configMgr/" + id;
68 return;
69 }
70 $.post(pluginRoot + "/" + id, {"action":action}, function(data) {
Felix Meschbergerfb708822010-02-18 15:42:31 +000071 renderData(data);
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000072 }, "json");
73}
74
75function showDetails( id ) {
Felix Meschbergerfb708822010-02-18 15:42:31 +000076 $.get(pluginRoot + "/" + id + ".json", null, function(data) {
77 renderDetails(data);
78 }, "json");
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000079}
80
81function loadData() {
82 $.get(pluginRoot + "/.json", null, function(data) {
Felix Meschbergerfb708822010-02-18 15:42:31 +000083 renderData(data);
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000084 }, "json");
85}
86
87function hideDetails( id ) {
88 $("#img" + id).each(function() {
89 $("#pluginInlineDetails").remove();
Felix Meschbergerfb708822010-02-18 15:42:31 +000090 $(this).
91 removeClass('ui-icon-triangle-1-w').//left
92 removeClass('ui-icon-triangle-1-s').//down
93 addClass('ui-icon-triangle-1-e').//right
94 attr("title", "Details").
95 unbind('click').click(function() {showDetails(id)});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000096 });
97}
98
99function renderDetails( data ) {
100 data = data.data[0];
Carsten Ziegeler7cc941e2009-02-16 16:42:07 +0000101 $("#pluginInlineDetails").remove();
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000102 $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>");
103 $("#img" + data.id).each(function() {
104 if ( drawDetails ) {
Felix Meschbergerfb708822010-02-18 15:42:31 +0000105 var ref = window.location.pathname;
106 ref = ref.substring(0, ref.lastIndexOf('/'));
107 $(this).
108 removeClass('ui-icon-triangle-1-e').//right
109 removeClass('ui-icon-triangle-1-s').//down
110 addClass('ui-icon-triangle-1-w').//left
111 attr("title", "Back").
112 unbind('click').click(function() {window.location = ref});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000113 } else {
Felix Meschbergerfb708822010-02-18 15:42:31 +0000114 $(this).
115 removeClass('ui-icon-triangle-1-w').//left
116 removeClass('ui-icon-triangle-1-e').//right
117 addClass('ui-icon-triangle-1-s').//down
118 attr("title", "Hide Details").
119 unbind('click').click(function() {hideDetails(data.id)});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000120 }
121 });
122 $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>");
Felix Meschbergerfb708822010-02-18 15:42:31 +0000123 var details = data.props;
124 for (var idx in details) {
125 var prop = details[idx];
126 var key = i18n[prop.key] ? i18n[prop.key] : prop.key; // i18n
127
128 var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + key + "</td><td class='aligntop' style='border:0px none'>";
129 if (prop.value) {
130 if ( $.isArray(prop.value) ) {
131 var i = 0;
132 for(var pi in prop.value) {
133 var value = prop.value[pi];
134 if (i > 0) { txt = txt + "<br/>"; }
135 var span;
136 if (value.substring(0, 2) == "!!") {
137 txt = txt + "<span style='color: red;'>" + value + "</span>";
138 } else {
139 txt = txt + value;
140 }
141 i++;
142 }
143 } else {
144 txt = txt + prop.value;
145 }
146 } else {
147 txt = txt + "\u00a0";
148 }
149 txt = txt + "</td></tr>";
150 $("#pluginInlineDetails > table > tbody").append(txt);
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000151 }
152}
153
Valentin Valchevf51fe432010-04-15 12:01:33 +0000154var tableBody = false;
155var tableEntryTemplate = false;
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000156
Felix Meschbergerfb708822010-02-18 15:42:31 +0000157$(document).ready(function(){
Valentin Valchevf51fe432010-04-15 12:01:33 +0000158 tableBody = $('#plugin_table tbody');
159 tableEntryTemplate = tableBody.find('tr').clone();
160
161 renderData(scrData);
Felix Meschbergerfb708822010-02-18 15:42:31 +0000162
163 $(".reloadButton").click(loadData);
164
165 var extractMethod = function(node) {
166 var link = node.getElementsByTagName("a");
167 if ( link && link.length == 1 ) {
168 return link[0].innerHTML;
169 }
170 return node.innerHTML;
171 };
172 $("#plugin_table").tablesorter({
173 headers: {
174 0: { sorter:"digit"},
175 3: { sorter: false }
176 },
177 sortList: [[1,0]],
178 textExtraction:extractMethod
179 });
180});
181