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