Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 1 | /* |
| 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 Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 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 | */ |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 17 | function renderData( eventData ) { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 18 | switch(eventData.status) { |
| 19 | case -1: // no event admin |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 20 | $('.statline').html(i18n.stat_no_service); |
| 21 | $('#scr').addClass('ui-helper-hidden'); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 22 | break; |
| 23 | case 0: // no components |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 24 | $('.statline').html(i18n.stat_no_components); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 25 | $('#scr').addClass('ui-helper-hidden'); |
| 26 | break; |
| 27 | default: |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 28 | $('.statline').html(i18n.stat_ok.msgFormat(eventData.status)); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 29 | $('#scr').removeClass('ui-helper-hidden'); |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 30 | |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 31 | tableBody.empty(); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 32 | for ( var idx in eventData.data ) { |
| 33 | entry( eventData.data[idx] ); |
| 34 | } |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 35 | if ( drawDetails ) renderDetails(eventData); |
| 36 | initStaticWidgets(); |
| 37 | } |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Felix Meschberger | 96f1146 | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 40 | function getEntryId(/* Object */ dataEntry) { |
| 41 | var id = dataEntry.id; |
| 42 | if (id < 0) { |
| 43 | id = dataEntry.name; |
| 44 | if (dataEntry.pid) { |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 45 | id += '/' + dataEntry.pid; |
Felix Meschberger | 96f1146 | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | return id; |
| 49 | } |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 50 | |
Felix Meschberger | 96f1146 | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 51 | function entry( /* Object */ dataEntry ) { |
| 52 | var idPath = getEntryId(dataEntry); |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 53 | var id = idPath.replace(/[./-]/g, '_'); |
Felix Meschberger | 96f1146 | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 54 | var name = dataEntry.name; |
| 55 | var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'entry' + id); |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 56 | |
| 57 | _.find('.bIcon').attr('id', 'img' + id).click(function() { |
Felix Meschberger | 96f1146 | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 58 | showDetails(idPath); |
| 59 | }).after(drawDetails ? name : ('<a href="' + pluginRoot + '/' + idPath + '">' + name + '</a>')); |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 60 | |
Felix Meschberger | 96f1146 | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 61 | _.find('td:eq(0)').text( dataEntry.id ); |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 62 | _.find('td:eq(2)').text( dataEntry.state ); |
| 63 | |
| 64 | // setup buttons |
| 65 | if ( dataEntry.stateRaw == 1 || dataEntry.stateRaw == 1024 ) { // disabled or disabling |
Felix Meschberger | 96f1146 | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 66 | _.find('li:eq(0)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'enable') }); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 67 | } else { |
Felix Meschberger | 96f1146 | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 68 | _.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'disable') }); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 69 | } |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 70 | if ( dataEntry.configurable ) _.find('li:eq(2)').removeClass('ui-helper-hidden').click(function() { // configure |
| 71 | changeDataEntryState(dataEntry.pid, 'configure'); |
| 72 | }); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | function changeDataEntryState(/* long */ id, /* String */ action) { |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 76 | if ( action == 'configure') { |
| 77 | window.location = appRoot + '/configMgr/' + id; |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 78 | return; |
| 79 | } |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 80 | $.post(pluginRoot + '/' + id, {'action':action}, function(data) { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 81 | renderData(data); |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 82 | }, 'json'); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | function showDetails( id ) { |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 86 | $.get(pluginRoot + '/' + id + '.json', null, function(data) { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 87 | renderDetails(data); |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 88 | }, 'json'); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | function hideDetails( id ) { |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 92 | var __test__ = $('#img' + id); |
| 93 | $('#img' + id).each(function() { |
| 94 | $('#pluginInlineDetails').remove(); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 95 | $(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 Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 99 | attr('title', 'Details'). |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 100 | unbind('click').click(function() {showDetails(id)}); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 101 | }); |
| 102 | } |
| 103 | |
| 104 | function renderDetails( data ) { |
| 105 | data = data.data[0]; |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 106 | 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 Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 111 | if ( drawDetails ) { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 112 | 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 Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 118 | attr('title', 'Back'). |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 119 | unbind('click').click(function() {window.location = ref}); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 120 | } else { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 121 | $(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 Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 125 | attr('title', 'Hide Details'). |
Felix Meschberger | 96f1146 | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 126 | unbind('click').click(function() {hideDetails(id)}); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 127 | } |
| 128 | }); |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 129 | $('#pluginInlineDetails').append('<table border="0"><tbody></tbody></table>'); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 130 | 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 Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 135 | var txt = '<tr><td class="aligntop" noWrap="true" style="border:0px none">' + key + '</td><td class="aligntop" style="border:0px none">'; |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 136 | 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 Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 141 | if (i > 0) { txt = txt + '<br/>'; } |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 142 | var span; |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 143 | if (value.substring(0, 2) == '!!') { |
| 144 | txt = txt + '<span style="color: red;'> + value + '</span>'; |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 145 | } else { |
| 146 | txt = txt + value; |
| 147 | } |
| 148 | i++; |
| 149 | } |
| 150 | } else { |
| 151 | txt = txt + prop.value; |
| 152 | } |
| 153 | } else { |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 154 | txt = txt + '\u00a0'; |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 155 | } |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 156 | txt = txt + '</td></tr>'; |
| 157 | $('#pluginInlineDetails > table > tbody').append(txt); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 161 | var tableBody = false; |
| 162 | var tableEntryTemplate = false; |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 163 | var pluginTable = false; |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 164 | |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 165 | $(document).ready(function(){ |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 166 | pluginTable = $('#plugin_table'); |
| 167 | tableBody = pluginTable.find('tbody'); |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 168 | tableEntryTemplate = tableBody.find('tr').clone(); |
| 169 | |
| 170 | renderData(scrData); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 171 | |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 172 | $('.reloadButton').click(document.location.reload); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 173 | |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 174 | pluginTable.tablesorter({ |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 175 | headers: { |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 176 | 0: { sorter:'digit'}, |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 177 | 3: { sorter: false } |
| 178 | }, |
| 179 | sortList: [[1,0]], |
Valentin Valchev | 32cf3b1 | 2011-09-12 14:45:53 +0000 | [diff] [blame] | 180 | textExtraction:mixedLinksExtraction |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 181 | }); |
| 182 | }); |
| 183 | |