blob: 149590e91e804a1e5f318ca44c58ae91ea3a14c3 [file] [log] [blame]
Valentin Valchev32cf3b12011-09-12 14:45:53 +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
18function fixId(id) { return id.replace('.', '_'); }
19
20function data( /* Array of Object */ dataArray ) { // render components
21 plugin_table.find('tbody').empty();
22 if (dataArray.length == 1) {
23 entry( dataArray[0], true );
24 } else {
25 for ( var idx in dataArray ) {
26 entry( dataArray[idx] );
27 }
28 }
29}
30
31function entry( /* Object */ dataEntry, /* boolean */ singleEntry ) {
32 var id = fixId(dataEntry.id);
33 var trElement = tr( 'ui-state-active', { 'id': 'entry' + id });
34
35 // entry brief
36 entryInternal( trElement, dataEntry, singleEntry );
37 plugin_table.append(trElement);
38
39 // dataEntry detailed properties
40 trElement = tr( 'ui-helper-hidden', {
41 'id' : 'entry' + id + '_details'
42 });
43 if (dataEntry.props) {
44 getDataEntryDetails( trElement, dataEntry.props );
45 }
46 plugin_table.append(trElement);
47}
48
49function entryInternal( /* Element */ parent, /* Object */ dataEntry, /* boolean */ singleEntry ) {
50 var id = dataEntry.id;
51 var _id = fixId(id);
52
53 parent.appendChild( td( null, null, [ text( id ) ] ) );
54 parent.appendChild( td( null,
55 {
56 'onclick': 'toggleDetails("#entry' + _id + '")',
57 'class': 'pkgname'
58 },
59 [
60 createElement( 'span', 'ui-icon ui-icon-triangle-1-e', { id: 'entry' + _id + '_icon'} ),
61 text(dataEntry.name)
62 ]
63 )
64 );
65 parent.appendChild( td( null, null, [ text( dataEntry.state ) ] ) );
66
67 for ( var aidx in dataEntry.actions ) {
68 var action = dataEntry.actions[aidx];
69 parent.appendChild( actionButton( action.enabled, id, action.link, action.name ) );
70 }
71}
72
73
74/* Element */ function actionButton( /* boolean */ enabled, /* long */ id, /* String */ op, /* String */ opLabel ) {
75 var buttonTd = td( "content", { align: "right" } );
76 if ( op ) {
77 switch (opLabel) {
78 case "Uninstall" : opLabel = i18n.uninstall; break;
79 }
80 var input = createElement( "input", null, {
81 type: 'button',
82 value: opLabel,
83 onclick: 'changeDataEntryState("' + id + '", "' + op + '");'
84 });
85 if (!enabled) {
86 input.setAttribute( "disabled", true );
87 $(input).addClass('ui-state-disabled');
88 }
89 buttonTd.appendChild( input );
90 } else {
91 addText( buttonTd, "\u00a0" );
92 }
93 return buttonTd;
94}
95
96
97function getDataEntryDetails( /* Element */ parent, /* Array of Object */ details )
98{
99 parent.appendChild( addText( td( "content"), "\u00a0" ) );
100
101 var tdEl = td( null, { colspan: 4 } );
102 parent.appendChild( tdEl );
103
104 var tableEl = createElement( "table", null, { border: 0 } );
105 tdEl.appendChild( tableEl );
106
107 var tbody = createElement( "tbody" );
108 tableEl.appendChild( tbody );
109 for (var idx in details) {
110 var prop = details[idx];
111 var trEl = tr();
112 var key = prop.key;
113 switch (key) {
114 case 'Package Name': key = i18n.package_name; break;
115 case 'Version' : key = i18n.version; break;
116 case 'Bundles' : key = i18n.bundles; break;
117 }
118 trEl.appendChild( addText( td( null, { noWrap: true } ), key ) );
119
120 var proptd = td();
121 trEl.appendChild( proptd );
122 $(proptd).html( prop.value ? prop.value : "\u00a0");
123
124 tbody.appendChild( trEl );
125 }
126 }
127
128
129function changeDataEntryState(/* long */ id, /* String */ action) {
130 var parm = pluginRoot + "/" + id + "?action=" + action;
131 $.post(parm, null, function() { // always reload
132 document.location.reload();
133 }, "text");
134}
135
136
137function toggleDetails(name) {
138 var icon = $(name + '_icon');
139 var details = $(name + '_details');
140 var show = icon.attr('show');
141 if (typeof show == 'undefined') show = '';
142 icon.attr('show', show ? '' : 'true');
143
144 if (show == 'true') {
145 icon.removeClass('ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e');
146 details.addClass('ui-helper-hidden');
147 } else {
148 icon.removeClass('ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s');
149 details.removeClass('ui-helper-hidden');
150 }
151}
152
153var plugin_table = false;
154$(document).ready(function() {
155 plugin_table = $('#plugin_table');
156 var /* Array of Data Objects */ bundleData = packageListData;
157 if (bundleData.error) {
158 $('.statline').text(i18n.status_no_serv);
159 $('#dps1').addClass('ui-helper-hidden');
160 } else if (!bundleData.data || bundleData.data.length == 0) {
161 $('.statline').text(i18n.status_no_data);
162 $('#dps1').removeClass('ui-helper-hidden');
163 $('#dps2').addClass('ui-helper-hidden');
164 } else {
165 data( bundleData.data );
166 $('.statline').text(i18n.status_ok);
167 $('#dps1').removeClass('ui-helper-hidden');
168 $('#dps2').removeClass('ui-helper-hidden');
169 initStaticWidgets(plugin_table);
170 }
171});
172