blob: d1fa35773ff8b69f62363c04c6fd2ccd788be051 [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
Valentin Valchev32cf3b12011-09-12 14:45:53 +000020 $('.statline').html(i18n.stat_no_service);
21 $('#scr').addClass('ui-helper-hidden');
Felix Meschbergerfb708822010-02-18 15:42:31 +000022 break;
23 case 0: // no components
Valentin Valchev32cf3b12011-09-12 14:45:53 +000024 $('.statline').html(i18n.stat_no_components);
Felix Meschbergerfb708822010-02-18 15:42:31 +000025 $('#scr').addClass('ui-helper-hidden');
26 break;
27 default:
Valentin Valchev32cf3b12011-09-12 14:45:53 +000028 $('.statline').html(i18n.stat_ok.msgFormat(eventData.status));
Felix Meschbergerfb708822010-02-18 15:42:31 +000029 $('#scr').removeClass('ui-helper-hidden');
Valentin Valchev32cf3b12011-09-12 14:45:53 +000030
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 }
Felix Meschbergerfb708822010-02-18 15:42:31 +000035 if ( drawDetails ) renderDetails(eventData);
36 initStaticWidgets();
37 }
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000038}
39
Felix Meschberger96f11462010-08-03 09:47:04 +000040function getEntryId(/* Object */ dataEntry) {
41 var id = dataEntry.id;
42 if (id < 0) {
43 id = dataEntry.name;
44 if (dataEntry.pid) {
Valentin Valchev32cf3b12011-09-12 14:45:53 +000045 id += '/' + dataEntry.pid;
Felix Meschberger96f11462010-08-03 09:47:04 +000046 }
47 }
48 return id;
49}
Felix Meschbergerfb708822010-02-18 15:42:31 +000050
Felix Meschberger96f11462010-08-03 09:47:04 +000051function entry( /* Object */ dataEntry ) {
52 var idPath = getEntryId(dataEntry);
Valentin Valchev32cf3b12011-09-12 14:45:53 +000053 var id = idPath.replace(/[./-]/g, '_');
Felix Meschberger96f11462010-08-03 09:47:04 +000054 var name = dataEntry.name;
55 var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'entry' + id);
Valentin Valchevf51fe432010-04-15 12:01:33 +000056
57 _.find('.bIcon').attr('id', 'img' + id).click(function() {
Felix Meschberger96f11462010-08-03 09:47:04 +000058 showDetails(idPath);
59 }).after(drawDetails ? name : ('<a href="' + pluginRoot + '/' + idPath + '">' + name + '</a>'));
Valentin Valchevf51fe432010-04-15 12:01:33 +000060
Felix Meschberger96f11462010-08-03 09:47:04 +000061 _.find('td:eq(0)').text( dataEntry.id );
Valentin Valchevf51fe432010-04-15 12:01:33 +000062 _.find('td:eq(2)').text( dataEntry.state );
63
64 // setup buttons
65 if ( dataEntry.stateRaw == 1 || dataEntry.stateRaw == 1024 ) { // disabled or disabling
Felix Meschberger96f11462010-08-03 09:47:04 +000066 _.find('li:eq(0)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'enable') });
Felix Meschbergerfb708822010-02-18 15:42:31 +000067 } else {
Felix Meschberger96f11462010-08-03 09:47:04 +000068 _.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'disable') });
Felix Meschbergerfb708822010-02-18 15:42:31 +000069 }
Valentin Valchevf51fe432010-04-15 12:01:33 +000070 if ( dataEntry.configurable ) _.find('li:eq(2)').removeClass('ui-helper-hidden').click(function() { // configure
71 changeDataEntryState(dataEntry.pid, 'configure');
72 });
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000073}
74
75function changeDataEntryState(/* long */ id, /* String */ action) {
Valentin Valchev32cf3b12011-09-12 14:45:53 +000076 if ( action == 'configure') {
77 window.location = appRoot + '/configMgr/' + id;
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000078 return;
79 }
Valentin Valchev32cf3b12011-09-12 14:45:53 +000080 $.post(pluginRoot + '/' + id, {'action':action}, function(data) {
Felix Meschbergerfb708822010-02-18 15:42:31 +000081 renderData(data);
Valentin Valchev32cf3b12011-09-12 14:45:53 +000082 }, 'json');
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000083}
84
85function showDetails( id ) {
Valentin Valchev32cf3b12011-09-12 14:45:53 +000086 $.get(pluginRoot + '/' + id + '.json', null, function(data) {
Felix Meschbergerfb708822010-02-18 15:42:31 +000087 renderDetails(data);
Valentin Valchev32cf3b12011-09-12 14:45:53 +000088 }, 'json');
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +000089}
90
91function hideDetails( id ) {
Valentin Valchev32cf3b12011-09-12 14:45:53 +000092 var __test__ = $('#img' + id);
93 $('#img' + id).each(function() {
94 $('#pluginInlineDetails').remove();
Felix Meschbergerfb708822010-02-18 15:42:31 +000095 $(this).
96 removeClass('ui-icon-triangle-1-w').//left
97 removeClass('ui-icon-triangle-1-s').//down
98 addClass('ui-icon-triangle-1-e').//right
Valentin Valchev32cf3b12011-09-12 14:45:53 +000099 attr('title', 'Details').
Felix Meschbergerfb708822010-02-18 15:42:31 +0000100 unbind('click').click(function() {showDetails(id)});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000101 });
102}
103
104function renderDetails( data ) {
105 data = data.data[0];
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000106 var id = getEntryId(data).replace(/[./-]/g, '_');
107 $('#pluginInlineDetails').remove();
108 var __test__ = $('#entry' + id);
109 $('#entry' + id + ' > td').eq(1).append('<div id="pluginInlineDetails"/>');
110 $('#img' + id).each(function() {
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000111 if ( drawDetails ) {
Felix Meschbergerfb708822010-02-18 15:42:31 +0000112 var ref = window.location.pathname;
113 ref = ref.substring(0, ref.lastIndexOf('/'));
114 $(this).
115 removeClass('ui-icon-triangle-1-e').//right
116 removeClass('ui-icon-triangle-1-s').//down
117 addClass('ui-icon-triangle-1-w').//left
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000118 attr('title', 'Back').
Felix Meschbergerfb708822010-02-18 15:42:31 +0000119 unbind('click').click(function() {window.location = ref});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000120 } else {
Felix Meschbergerfb708822010-02-18 15:42:31 +0000121 $(this).
122 removeClass('ui-icon-triangle-1-w').//left
123 removeClass('ui-icon-triangle-1-e').//right
124 addClass('ui-icon-triangle-1-s').//down
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000125 attr('title', 'Hide Details').
Felix Meschberger96f11462010-08-03 09:47:04 +0000126 unbind('click').click(function() {hideDetails(id)});
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000127 }
128 });
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000129 $('#pluginInlineDetails').append('<table border="0"><tbody></tbody></table>');
Felix Meschbergerfb708822010-02-18 15:42:31 +0000130 var details = data.props;
131 for (var idx in details) {
132 var prop = details[idx];
133 var key = i18n[prop.key] ? i18n[prop.key] : prop.key; // i18n
134
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000135 var txt = '<tr><td class="aligntop" noWrap="true" style="border:0px none">' + key + '</td><td class="aligntop" style="border:0px none">';
Felix Meschbergerfb708822010-02-18 15:42:31 +0000136 if (prop.value) {
137 if ( $.isArray(prop.value) ) {
138 var i = 0;
139 for(var pi in prop.value) {
140 var value = prop.value[pi];
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000141 if (i > 0) { txt = txt + '<br/>'; }
Felix Meschbergerfb708822010-02-18 15:42:31 +0000142 var span;
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000143 if (value.substring(0, 2) == '!!') {
144 txt = txt + '<span style="color: red;'> + value + '</span>';
Felix Meschbergerfb708822010-02-18 15:42:31 +0000145 } else {
146 txt = txt + value;
147 }
148 i++;
149 }
150 } else {
151 txt = txt + prop.value;
152 }
153 } else {
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000154 txt = txt + '\u00a0';
Felix Meschbergerfb708822010-02-18 15:42:31 +0000155 }
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000156 txt = txt + '</td></tr>';
157 $('#pluginInlineDetails > table > tbody').append(txt);
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000158 }
159}
160
Valentin Valchevf51fe432010-04-15 12:01:33 +0000161var tableBody = false;
162var tableEntryTemplate = false;
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000163var pluginTable = false;
Carsten Ziegeler7ecffce2009-02-09 20:48:31 +0000164
Felix Meschbergerfb708822010-02-18 15:42:31 +0000165$(document).ready(function(){
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000166 pluginTable = $('#plugin_table');
167 tableBody = pluginTable.find('tbody');
Valentin Valchevf51fe432010-04-15 12:01:33 +0000168 tableEntryTemplate = tableBody.find('tr').clone();
169
170 renderData(scrData);
Felix Meschbergerfb708822010-02-18 15:42:31 +0000171
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000172 $('.reloadButton').click(document.location.reload);
Felix Meschbergerfb708822010-02-18 15:42:31 +0000173
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000174 pluginTable.tablesorter({
Felix Meschbergerfb708822010-02-18 15:42:31 +0000175 headers: {
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000176 0: { sorter:'digit'},
Felix Meschbergerfb708822010-02-18 15:42:31 +0000177 3: { sorter: false }
178 },
179 sortList: [[1,0]],
Valentin Valchev32cf3b12011-09-12 14:45:53 +0000180 textExtraction:mixedLinksExtraction
Felix Meschbergerfb708822010-02-18 15:42:31 +0000181 });
182});
183