Clement Escoffier | 34c7663 | 2010-07-12 17:36:50 +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 renderInstancesData(instances) { |
| 18 | $(".statline").html(getInstancesStatLine(instances)); |
| 19 | tableBody.empty(); |
| 20 | for ( var idx in instances.data ) { |
| 21 | instancesEntry( instances.data[idx] ); |
| 22 | } |
| 23 | $("#plugin_table").trigger("update"); |
| 24 | } |
| 25 | |
| 26 | function getInstancesStatLine(instances) { |
| 27 | return instances.count + " instances in total, " |
| 28 | + instances.valid_count + " valid instances, " |
| 29 | + instances.invalid_count + " invalid instances."; |
| 30 | } |
| 31 | |
| 32 | function instancesEntry(instance) { |
| 33 | var name = instance.name; |
| 34 | var state = instance.state; |
| 35 | var factory = instance.factory; |
| 36 | |
| 37 | var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'instance-' + instance.name); |
| 38 | |
Clement Escoffier | 2d0b189 | 2010-07-12 17:43:48 +0000 | [diff] [blame] | 39 | _.find('td.name').html('<a href="' + instances_url + '/' + name + '">' + name + '</a>'); |
| 40 | _.find('td.factory').html('<a href="' + factories_url + '/' + factory + '">' + factory + '</a>');; |
Clement Escoffier | 34c7663 | 2010-07-12 17:36:50 +0000 | [diff] [blame] | 41 | _.find('td.state').text(state); |
| 42 | } |
| 43 | |
| 44 | |
| 45 | function loadInstancesData() { |
| 46 | $.get(pluginRoot + "/instances.json", null, function(data) { |
| 47 | renderInstancesData(data); |
| 48 | }, "json"); |
| 49 | } |
| 50 | |
| 51 | function loadFactoriesData() { |
Clement Escoffier | 5f2d0e4 | 2010-07-12 17:42:03 +0000 | [diff] [blame] | 52 | window.location = factories_url; |
Clement Escoffier | 34c7663 | 2010-07-12 17:36:50 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | function loadHandlersData() { |
Clement Escoffier | 5f2d0e4 | 2010-07-12 17:42:03 +0000 | [diff] [blame] | 56 | window.location = handlers_url; |
Clement Escoffier | 34c7663 | 2010-07-12 17:36:50 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | var tableBody = false; |
| 60 | var tableEntryTemplate = false; |
| 61 | |
| 62 | $(document).ready(function(){ |
| 63 | tableBody = $('#plugin_table tbody'); |
| 64 | tableEntryTemplate = tableBody.find('tr').clone(); |
| 65 | |
| 66 | loadInstancesData(); |
| 67 | |
| 68 | $(".instancesButton").click(loadInstancesData); |
| 69 | $(".factoriesButton").click(loadFactoriesData); |
| 70 | $(".handlersButton").click(loadHandlersData); |
| 71 | |
| 72 | var extractMethod = function(node) { |
| 73 | var link = node.getElementsByTagName("a"); |
| 74 | if ( link && link.length == 1 ) { |
| 75 | return link[0].innerHTML; |
| 76 | } |
| 77 | return node.innerHTML; |
| 78 | }; |
| 79 | $("#plugin_table").tablesorter({ |
| 80 | sortList: [[1,0]], |
| 81 | textExtraction:extractMethod |
| 82 | }); |
| 83 | }); |
| 84 | |