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 |
| 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 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 | } |
| 35 | $("#plugin_table").trigger("update"); |
| 36 | if ( drawDetails ) renderDetails(eventData); |
| 37 | initStaticWidgets(); |
| 38 | } |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | function entry( /* Object */ dataEntry ) { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 42 | var id = dataEntry.id; |
| 43 | var name = dataEntry.name; |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 44 | |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 45 | 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 Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 57 | } else { |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 58 | _.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(id, 'disable') }); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 59 | } |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 60 | if ( dataEntry.configurable ) _.find('li:eq(2)').removeClass('ui-helper-hidden').click(function() { // configure |
| 61 | changeDataEntryState(dataEntry.pid, 'configure'); |
| 62 | }); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | function changeDataEntryState(/* long */ id, /* String */ action) { |
Carsten Ziegeler | 86ca51a | 2009-02-10 13:08:50 +0000 | [diff] [blame] | 66 | if ( action == "configure") { |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 67 | window.location = appRoot + "/configMgr/" + id; |
| 68 | return; |
| 69 | } |
| 70 | $.post(pluginRoot + "/" + id, {"action":action}, function(data) { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 71 | renderData(data); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 72 | }, "json"); |
| 73 | } |
| 74 | |
| 75 | function showDetails( id ) { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 76 | $.get(pluginRoot + "/" + id + ".json", null, function(data) { |
| 77 | renderDetails(data); |
| 78 | }, "json"); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | function loadData() { |
| 82 | $.get(pluginRoot + "/.json", null, function(data) { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 83 | renderData(data); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 84 | }, "json"); |
| 85 | } |
| 86 | |
| 87 | function hideDetails( id ) { |
| 88 | $("#img" + id).each(function() { |
| 89 | $("#pluginInlineDetails").remove(); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 90 | $(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 Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 96 | }); |
| 97 | } |
| 98 | |
| 99 | function renderDetails( data ) { |
| 100 | data = data.data[0]; |
Carsten Ziegeler | 7cc941e | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 101 | $("#pluginInlineDetails").remove(); |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 102 | $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>"); |
| 103 | $("#img" + data.id).each(function() { |
| 104 | if ( drawDetails ) { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 105 | 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 Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 113 | } else { |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 114 | $(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 Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 120 | } |
| 121 | }); |
| 122 | $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>"); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 123 | 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 Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 154 | var tableBody = false; |
| 155 | var tableEntryTemplate = false; |
Carsten Ziegeler | 7ecffce | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 156 | |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 157 | $(document).ready(function(){ |
Valentin Valchev | f51fe43 | 2010-04-15 12:01:33 +0000 | [diff] [blame] | 158 | tableBody = $('#plugin_table tbody'); |
| 159 | tableEntryTemplate = tableBody.find('tr').clone(); |
| 160 | |
| 161 | renderData(scrData); |
Felix Meschberger | fb70882 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 162 | |
| 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 | |