blob: 81fc78254d74dceed64f57452d986c9d41637bb4 [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 renderFactoriesData(factories) {
18 $(".statline").html(getFactoriesStatLine(factories));
19 tableBody.empty();
20 for ( var idx in factories.data ) {
21 factoriesEntry( factories.data[idx] );
22 }
23 $("#plugin_table").trigger("update");
24}
25
26function getFactoriesStatLine(factories) {
27 return factories.count + " factories in total, "
28 + factories.valid_count + " valid factories, "
29 + factories.invalid_count + " invalid factories.";
30}
31
32function factoriesEntry(factory) {
33 var name = factory.name;
34 var state = factory.state;
35 var bundle = factory.bundle;
36
37 console.log("Create entry : " + factory);
38
39 var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'factory-' + factory.name);
40
Clement Escoffierd430a1d2010-07-12 17:42:03 +000041 _.find('td.name').html('<a href="' + factories_url + '/' + name + '">' + name + '</a>');
Clement Escoffier530a19e2010-07-12 17:36:50 +000042 _.find('td.bundle').text(bundle);
43 _.find('td.state').text(state);
44}
45
46
47function loadFactoriesData() {
48 console.log("Load factories data");
49 $.get(pluginRoot + "/factories.json", null, function(data) {
50 renderFactoriesData(data);
51 }, "json");
52}
53
54function loadInstancesData() {
Clement Escoffierd430a1d2010-07-12 17:42:03 +000055 window.location = instances_url;
Clement Escoffier530a19e2010-07-12 17:36:50 +000056}
57
58function loadHandlersData() {
Clement Escoffierd430a1d2010-07-12 17:42:03 +000059 window.location = handlers_url;
Clement Escoffier530a19e2010-07-12 17:36:50 +000060}
61
62var tableBody = false;
63var tableEntryTemplate = false;
64
65$(document).ready(function(){
66 tableBody = $('#plugin_table tbody');
67 tableEntryTemplate = tableBody.find('tr').clone();
68
69 loadFactoriesData();
70
71 $(".instancesButton").click(loadInstancesData);
72 $(".factoriesButton").click(loadFactoriesData);
73 $(".handlersButton").click(loadHandlersData);
74
75 var extractMethod = function(node) {
76 var link = node.getElementsByTagName("a");
77 if ( link && link.length == 1 ) {
78 return link[0].innerHTML;
79 }
80 return node.innerHTML;
81 };
82 $("#plugin_table").tablesorter({
83 sortList: [[1,0]],
84 textExtraction:extractMethod
85 });
86});
87