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 | |
| 31 | $("#plugin_table > tbody > tr").remove(); |
| 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 | |
| 41 | function entry( /* Object */ dataEntry ) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 42 | var trElement = tr( null, { id: "entry" + dataEntry.id } ); |
| 43 | entryInternal( trElement, dataEntry ); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 44 | $("#plugin_table > tbody").append(trElement); |
| 45 | } |
| 46 | |
| 47 | function actionButton( /* Element */ parent, /* string */ id, /* Obj */ action, /* string */ pid ) { |
| 48 | var enabled = action.enabled; |
| 49 | var op = action.link; |
| 50 | var opLabel = action.name; |
| 51 | var img = action.image; |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 52 | // fixup JQuery UI icons |
| 53 | if (img == 'configure') { img = 'wrench' |
| 54 | } else if (img == 'disable') { img = 'stop' //locked |
| 55 | } else if (img == 'enable') { img = 'play' //unlocked |
| 56 | } |
| 57 | |
| 58 | // apply i18n |
| 59 | opLabel = i18n[opLabel] ? i18n[opLabel] : opLabel; |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 60 | |
| 61 | var arg = id; |
Carsten Ziegeler | 83ff044 | 2009-02-10 13:08:50 +0000 | [diff] [blame] | 62 | if ( op == "configure" ) { |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 63 | arg = pid |
| 64 | } |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 65 | var input = createElement('li', 'dynhover', { |
| 66 | title: opLabel |
| 67 | }); |
| 68 | $(input) |
| 69 | .html('<span class="ui-icon ui-icon-'+img+'"></span>') |
| 70 | .click(function() {changeDataEntryState(arg, op)}); |
| 71 | |
| 72 | if (!enabled) { |
| 73 | $(input).attr('disabled', true).addClass('ui-state-disabled'); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 74 | |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 75 | } |
| 76 | parent.appendChild( input ); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | function entryInternal( /* Element */ parent, /* Object */ dataEntry ) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 80 | var id = dataEntry.id; |
| 81 | var name = dataEntry.name; |
| 82 | var state = dataEntry.state; |
| 83 | |
| 84 | var inputElement = createElement('span', 'ui-icon ui-icon-triangle-1-e', { |
| 85 | title: "Details", |
| 86 | id: 'img' + id, |
| 87 | style: {display: "inline-block"} |
| 88 | }); |
Carsten Ziegeler | 0b83c01 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 89 | $(inputElement).click(function() {showDetails(id)}); |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 90 | var titleElement; |
| 91 | if ( drawDetails ) { |
| 92 | titleElement = text(name); |
| 93 | } else { |
| 94 | titleElement = createElement ("a", null, { |
| 95 | href: window.location.pathname + "/" + id |
| 96 | }); |
| 97 | titleElement.appendChild(text(name)); |
| 98 | } |
| 99 | |
| 100 | parent.appendChild( td( null, null, [ text( id ) ] ) ); |
| 101 | parent.appendChild( td( null, null, [ inputElement, text(" "), titleElement ] ) ); |
| 102 | parent.appendChild( td( null, null, [ text( state ) ] ) ); |
| 103 | var actionsTd = td( null, null ); |
| 104 | var div = createElement('ul', 'icons ui-widget'); |
| 105 | actionsTd.appendChild(div); |
| 106 | |
| 107 | for ( var a in dataEntry.actions ) { |
| 108 | actionButton( div, id, dataEntry.actions[a], dataEntry.pid ); |
| 109 | } |
| 110 | parent.appendChild( actionsTd ); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | function changeDataEntryState(/* long */ id, /* String */ action) { |
Carsten Ziegeler | 83ff044 | 2009-02-10 13:08:50 +0000 | [diff] [blame] | 114 | if ( action == "configure") { |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 115 | window.location = appRoot + "/configMgr/" + id; |
| 116 | return; |
| 117 | } |
| 118 | $.post(pluginRoot + "/" + id, {"action":action}, function(data) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 119 | renderData(data); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 120 | }, "json"); |
| 121 | } |
| 122 | |
| 123 | function showDetails( id ) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 124 | $.get(pluginRoot + "/" + id + ".json", null, function(data) { |
| 125 | renderDetails(data); |
| 126 | }, "json"); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | function loadData() { |
| 130 | $.get(pluginRoot + "/.json", null, function(data) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 131 | renderData(data); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 132 | }, "json"); |
| 133 | } |
| 134 | |
| 135 | function hideDetails( id ) { |
| 136 | $("#img" + id).each(function() { |
| 137 | $("#pluginInlineDetails").remove(); |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 138 | $(this). |
| 139 | removeClass('ui-icon-triangle-1-w').//left |
| 140 | removeClass('ui-icon-triangle-1-s').//down |
| 141 | addClass('ui-icon-triangle-1-e').//right |
| 142 | attr("title", "Details"). |
| 143 | unbind('click').click(function() {showDetails(id)}); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 144 | }); |
| 145 | } |
| 146 | |
| 147 | function renderDetails( data ) { |
| 148 | data = data.data[0]; |
Carsten Ziegeler | d721c96 | 2009-02-16 16:42:07 +0000 | [diff] [blame] | 149 | $("#pluginInlineDetails").remove(); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 150 | $("#entry" + data.id + " > td").eq(1).append("<div id='pluginInlineDetails'/>"); |
| 151 | $("#img" + data.id).each(function() { |
| 152 | if ( drawDetails ) { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 153 | var ref = window.location.pathname; |
| 154 | ref = ref.substring(0, ref.lastIndexOf('/')); |
| 155 | $(this). |
| 156 | removeClass('ui-icon-triangle-1-e').//right |
| 157 | removeClass('ui-icon-triangle-1-s').//down |
| 158 | addClass('ui-icon-triangle-1-w').//left |
| 159 | attr("title", "Back"). |
| 160 | unbind('click').click(function() {window.location = ref}); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 161 | } else { |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 162 | $(this). |
| 163 | removeClass('ui-icon-triangle-1-w').//left |
| 164 | removeClass('ui-icon-triangle-1-e').//right |
| 165 | addClass('ui-icon-triangle-1-s').//down |
| 166 | attr("title", "Hide Details"). |
| 167 | unbind('click').click(function() {hideDetails(data.id)}); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 168 | } |
| 169 | }); |
| 170 | $("#pluginInlineDetails").append("<table border='0'><tbody></tbody></table>"); |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 171 | var details = data.props; |
| 172 | for (var idx in details) { |
| 173 | var prop = details[idx]; |
| 174 | var key = i18n[prop.key] ? i18n[prop.key] : prop.key; // i18n |
| 175 | |
| 176 | var txt = "<tr><td class='aligntop' noWrap='true' style='border:0px none'>" + key + "</td><td class='aligntop' style='border:0px none'>"; |
| 177 | if (prop.value) { |
| 178 | if ( $.isArray(prop.value) ) { |
| 179 | var i = 0; |
| 180 | for(var pi in prop.value) { |
| 181 | var value = prop.value[pi]; |
| 182 | if (i > 0) { txt = txt + "<br/>"; } |
| 183 | var span; |
| 184 | if (value.substring(0, 2) == "!!") { |
| 185 | txt = txt + "<span style='color: red;'>" + value + "</span>"; |
| 186 | } else { |
| 187 | txt = txt + value; |
| 188 | } |
| 189 | i++; |
| 190 | } |
| 191 | } else { |
| 192 | txt = txt + prop.value; |
| 193 | } |
| 194 | } else { |
| 195 | txt = txt + "\u00a0"; |
| 196 | } |
| 197 | txt = txt + "</td></tr>"; |
| 198 | $("#pluginInlineDetails > table > tbody").append(txt); |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
Carsten Ziegeler | 83fbe44 | 2009-02-09 20:48:31 +0000 | [diff] [blame] | 202 | |
Felix Meschberger | b722be5 | 2010-02-18 15:42:31 +0000 | [diff] [blame] | 203 | $(document).ready(function(){ |
| 204 | renderData (scrData); |
| 205 | |
| 206 | $(".reloadButton").click(loadData); |
| 207 | |
| 208 | var extractMethod = function(node) { |
| 209 | var link = node.getElementsByTagName("a"); |
| 210 | if ( link && link.length == 1 ) { |
| 211 | return link[0].innerHTML; |
| 212 | } |
| 213 | return node.innerHTML; |
| 214 | }; |
| 215 | $("#plugin_table").tablesorter({ |
| 216 | headers: { |
| 217 | 0: { sorter:"digit"}, |
| 218 | 3: { sorter: false } |
| 219 | }, |
| 220 | sortList: [[1,0]], |
| 221 | textExtraction:extractMethod |
| 222 | }); |
| 223 | }); |
| 224 | |