Clement Escoffier | 64bcab8 | 2010-07-12 17:40:19 +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 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 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 | */ |
| 17 | function renderHandlersData(handlers) { |
| 18 | $(".statline").html(getHandlersStatLine(handlers)); |
| 19 | tableBody.empty(); |
| 20 | for ( var idx in handlers.data ) { |
| 21 | handlersEntry( handlers.data[idx] ); |
| 22 | } |
| 23 | $("#plugin_table").trigger("update"); |
| 24 | } |
| 25 | |
| 26 | function getHandlersStatLine(handlers) { |
| 27 | return handlers.count + " handlers in total, " |
| 28 | + handlers.valid_count + " valid handlers, " |
| 29 | + handlers.invalid_count + " invalid handlers."; |
| 30 | } |
| 31 | |
| 32 | function handlersEntry(handler) { |
| 33 | var name = handler.name; |
| 34 | var state = handler.state; |
| 35 | var bundle = handler.bundle; |
| 36 | var type = handler.type; |
| 37 | |
| 38 | console.log("Create entry : " + handler); |
| 39 | |
| 40 | var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'handler-' + handler.name); |
| 41 | |
| 42 | _.find('td.name').text(name); |
| 43 | _.find('td.type').text(type); |
| 44 | _.find('td.bundle').text(bundle); |
| 45 | _.find('td.state').text(state); |
| 46 | if (handler.missing) { |
| 47 | _.find('td.missing').html(handler.missing); |
| 48 | } else { |
| 49 | _.find('td.missing').html('<i>No missing handlers</i>'); |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | |
| 54 | |
| 55 | function loadHandlersData() { |
| 56 | console.log("Load handlers data"); |
| 57 | $.get(pluginRoot + "/handlers.json", null, function(data) { |
| 58 | renderHandlersData(data); |
| 59 | }, "json"); |
| 60 | } |
| 61 | |
| 62 | function loadInstancesData() { |
| 63 | window.location=window.location.pathname + "?view=instances" |
| 64 | } |
| 65 | |
| 66 | function loadFactoriesData() { |
| 67 | window.location=window.location.pathname + "?view=factories" |
| 68 | } |
| 69 | |
| 70 | var tableBody = false; |
| 71 | var tableEntryTemplate = false; |
| 72 | |
| 73 | $(document).ready(function(){ |
| 74 | tableBody = $('#plugin_table tbody'); |
| 75 | tableEntryTemplate = tableBody.find('tr').clone(); |
| 76 | |
| 77 | loadHandlersData(); |
| 78 | |
| 79 | $(".instancesButton").click(loadInstancesData); |
| 80 | $(".factoriesButton").click(loadFactoriesData); |
| 81 | $(".handlersButton").click(loadHandlersData); |
| 82 | |
| 83 | var extractMethod = function(node) { |
| 84 | var link = node.getElementsByTagName("a"); |
| 85 | if ( link && link.length == 1 ) { |
| 86 | return link[0].innerHTML; |
| 87 | } |
| 88 | return node.innerHTML; |
| 89 | }; |
| 90 | $("#plugin_table").tablesorter({ |
| 91 | sortList: [[1,0]], |
| 92 | textExtraction:extractMethod |
| 93 | }); |
| 94 | }); |
| 95 | |