Carsten Ziegeler | 83fbe44 | 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 | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Carsten Ziegeler | 83fbe44 | 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 | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 17 | function renderData( eventData ) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 18 | 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 Valchev | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 31 | tableBody.empty(); |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 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 Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Felix Meschberger | 2ad2a1f | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 41 | function 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 Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 51 | |
Felix Meschberger | 2ad2a1f | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 52 | function 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 Valchev | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 57 | |
| 58 | _.find('.bIcon').attr('id', 'img' + id).click(function() { |
Felix Meschberger | 2ad2a1f | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 59 | showDetails(idPath); |
| 60 | }).after(drawDetails ? name : ('<a href="' + pluginRoot + '/' + idPath + '">' + name + '</a>')); |
Valentin Pavlov Valchev | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 61 | |
Felix Meschberger | 2ad2a1f | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 62 | _.find('td:eq(0)').text( dataEntry.id ); |
Valentin Pavlov Valchev | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 63 | _.find('td:eq(2)').text( dataEntry.state ); |
| 64 | |
| 65 | // setup buttons |
| 66 | if ( dataEntry.stateRaw == 1 || dataEntry.stateRaw == 1024 ) { // disabled or disabling |
Felix Meschberger | 2ad2a1f | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 67 | _.find('li:eq(0)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'enable') }); |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 68 | } else { |
Felix Meschberger | 2ad2a1f | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 69 | _.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(idPath, 'disable') }); |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 70 | } |
Valentin Pavlov Valchev | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 71 | if ( dataEntry.configurable ) _.find('li:eq(2)').removeClass('ui-helper-hidden').click(function() { // configure |
| 72 | changeDataEntryState(dataEntry.pid, 'configure'); |
| 73 | }); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | function changeDataEntryState(/* long */ id, /* String */ action) { |
Carsten Ziegeler | 83ff044 | 2009-02-10 13:08:50 +0000 | [diff] [blame] | 77 | if ( action == "configure") { |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 78 | window.location = appRoot + "/configMgr/" + id; |
| 79 | return; |
| 80 | } |
| 81 | $.post(pluginRoot + "/" + id, {"action":action}, function(data) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 82 | renderData(data); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 83 | }, "json"); |
| 84 | } |
| 85 | |
| 86 | function showDetails( id ) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 87 | $.get(pluginRoot + "/" + id + ".json", null, function(data) { |
| 88 | renderDetails(data); |
| 89 | }, "json"); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | function loadData() { |
| 93 | $.get(pluginRoot + "/.json", null, function(data) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 94 | renderData(data); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 95 | }, "json"); |
| 96 | } |
| 97 | |
| 98 | function hideDetails( id ) { |
Felix Meschberger | 2ad2a1f | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 99 | var __test__ = $("#img" + id); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 100 | $("#img" + id).each(function() { |
| 101 | $("#pluginInlineDetails").remove(); |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 102 | $(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 Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 108 | }); |
| 109 | } |
| 110 | |
| 111 | function renderDetails( data ) { |
| 112 | data = data.data[0]; |
Felix Meschberger | 2ad2a1f | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 113 | var id = getEntryId(data).replace(/[./-]/g, "_"); |
Carsten Ziegeler | d721c96 | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 114 | $("#pluginInlineDetails").remove(); |
Felix Meschberger | 2ad2a1f | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 115 | var __test__ = $("#entry" + id); |
| 116 | $("#entry" + id + " > td").eq(1).append("<div id='pluginInlineDetails'/>"); |
| 117 | $("#img" + id).each(function() { |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 118 | if ( drawDetails ) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 119 | 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 Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 127 | } else { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 128 | $(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 Meschberger | 2ad2a1f | 2010-08-03 09:47:04 +0000 | [diff] [blame] | 133 | unbind('click').click(function() {hideDetails(id)}); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 134 | } |
| 135 | }); |
| 136 | $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>"); |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 137 | 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 Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
Valentin Pavlov Valchev | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 168 | var tableBody = false; |
| 169 | var tableEntryTemplate = false; |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 170 | |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 171 | $(document).ready(function(){ |
Valentin Pavlov Valchev | 90d662b | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 172 | tableBody = $('#plugin_table tbody'); |
| 173 | tableEntryTemplate = tableBody.find('tr').clone(); |
| 174 | |
| 175 | renderData(scrData); |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 176 | |
| 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 | |