blob: 30cc9e0ac8ac33e4ef0d4e65886ef58a1b54c679 [file] [log] [blame]
Clement Escoffier530a19e2010-07-12 17:36:50 +00001/*
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 */
17function 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
26function getInstancesStatLine(instances) {
27 return instances.count + " instances in total, "
28 + instances.valid_count + " valid instances, "
29 + instances.invalid_count + " invalid instances.";
30}
31
32function 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 Escoffiercbf19c42010-07-12 17:43:48 +000039 _.find('td.name').html('<a href="' + instances_url + '/' + name + '">' + name + '</a>');
40 _.find('td.factory').html('<a href="' + factories_url + '/' + factory + '">' + factory + '</a>');;
Clement Escoffier530a19e2010-07-12 17:36:50 +000041 _.find('td.state').text(state);
42}
43
44
45function loadInstancesData() {
46 $.get(pluginRoot + "/instances.json", null, function(data) {
47 renderInstancesData(data);
48 }, "json");
49}
50
51function loadFactoriesData() {
Clement Escoffierd430a1d2010-07-12 17:42:03 +000052 window.location = factories_url;
Clement Escoffier530a19e2010-07-12 17:36:50 +000053}
54
55function loadHandlersData() {
Clement Escoffierd430a1d2010-07-12 17:42:03 +000056 window.location = handlers_url;
Clement Escoffier530a19e2010-07-12 17:36:50 +000057}
58
59var tableBody = false;
60var 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