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