blob: e2c6c570427a308685271ed7277cce47ca6f7b75 [file] [log] [blame]
A. J. David Bosschaert53192892015-07-02 11:09:06 +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 */
17
18
19function renderData( subsystemData ) {
20 tableBody.empty();
21 for (var idx in subsystemData.data) {
22 entry( subsystemData.data[idx] );
23 }
24}
25
26function entry( dataEntry ) {
27 var id = dataEntry.id;
28 var name = dataEntry.name;
29 var _ = tableEntryTemplate.clone().appendTo(tableBody).attr('id', 'entry' + id);
30
31 _.find('td:eq(0)').text(id);
32 _.find('td:eq(1)').text(name);
33 _.find('td:eq(2)').text(dataEntry.version);
34 _.find('td:eq(3)').text(dataEntry.state);
35
36 // setup buttons
37 if (dataEntry.state === "ACTIVE") {
38 _.find('li:eq(1)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(id, 'stop') });
39 } else {
40 _.find('li:eq(0)').removeClass('ui-helper-hidden').click(function() { changeDataEntryState(id, 'start') });
41 }
42 _.find('li:eq(2)').click(function() { changeDataEntryState(id, 'uninstall') });
43}
44
45function changeDataEntryState(id, action) {
46 $.post(pluginRoot + '/' + id, {'action': action}, function(data) {
47 renderData(data);
48
49 // This is a total hack, but it's the only way in which I could get the
50 // table to re-sort itself. TODO remove the next line and find a proper way.
51 window.location.reload();
52 }, 'json');
53}
54
55var tableBody = false;
56var tableEntryTemplate = false;
57var pluginTable = false;
58var uploadDialog = false;
59
60$(document).ready(function(){
61 $('.installButton').click(function() {
62 uploadDialog.dialog('open');
63 return false;
64 });
65
66 pluginTable = $('#plugin_table');
67 tableBody = pluginTable.find('tbody');
68 tableEntryTemplate = tableBody.find('tr').clone();
69
70 // upload dialog
71 var uploadDialogButtons = {};
72 uploadDialogButtons["Install"] = function() {
73 $(this).find('form').submit();
74 }
75 uploadDialog = $('#uploadDialog').dialog({
76 autoOpen: false,
77 modal : true,
78 width : '50%',
79 buttons : uploadDialogButtons
80 });
81
82 renderData(ssData);
83
84 $('.reloadButton').click(document.location.reload);
85
86 pluginTable.tablesorter({
87 headers: {
88 0: { sorter:'digit'},
89 4: { sorter: false }
90 },
91 sortList: [[1,0]],
92 textExtraction:mixedLinksExtraction
93 });
94});
95