blob: 7c4ce5a5d349b130b7009e47f67e3c8d14de9ddd [file] [log] [blame]
Felix Meschbergerca29a962008-05-16 11:59: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
18
19function configure() {
20 var span = document.getElementById('configField');
21 if (!span) {
22 return;
23 }
Felix Meschbergercd169b22008-06-13 12:19:36 +000024 var select = document.getElementById('configSelection_pid');
Felix Meschbergerca29a962008-05-16 11:59:32 +000025 var pid = select.options[select.selectedIndex].value;
Felix Meschbergercd169b22008-06-13 12:19:36 +000026 var parm = '?action=ajaxConfigManager&pid=' + pid;
Felix Meschbergerca29a962008-05-16 11:59:32 +000027 sendRequest('GET', parm, displayConfigForm);
28}
29
Felix Meschbergercd169b22008-06-13 12:19:36 +000030
31function create() {
Felix Meschbergerca29a962008-05-16 11:59:32 +000032 var span = document.getElementById('configField');
33 if (!span) {
34 return;
35 }
Felix Meschbergercd169b22008-06-13 12:19:36 +000036 var select = document.getElementById('configSelection_factory');
37 var pid = select.options[select.selectedIndex].value;
38 var parm = '?action=ajaxConfigManager&create=true&pid=' + pid;
39 sendRequest('GET', parm, displayConfigForm);
40}
41
42function displayConfigForm(obj) {
43 var span1 = document.getElementById('configField');
44 var span2 = document.getElementById('factoryField');
45 if (!span1 && !span2) {
46 return;
47 }
48
49 var innerHtml = "";
50
51 if (span1) {
52 innerHtml += '<tr class="content" id="configField">' + span1.innerHTML + '</tr>';
53 }
54 if (span2) {
55 innerHtml += '<tr class="content" id="factoryField">' + span2.innerHTML + '</tr>';
56 }
57
Felix Meschbergerca29a962008-05-16 11:59:32 +000058 innerHtml += '<tr class="content">';
59 innerHtml += '<th colspan="2" class="content" >' + obj.title + '</th></tr>';
Felix Meschbergercd169b22008-06-13 12:19:36 +000060
Felix Meschbergerca29a962008-05-16 11:59:32 +000061 innerHtml += '<tr class="content">';
62 innerHtml += '<td class="content">&nbsp;</td>';
63 innerHtml += '<td class="content">';
64 innerHtml += '<form method="post">';
65 innerHtml += '<input type="hidden" name="apply" value="true" />';
66 innerHtml += '<input type="hidden" name="pid" value="' + obj.pid + '" />';
67 innerHtml += '<input type="hidden" name="action" value="ajaxConfigManager" />';
68 innerHtml += '<table border="0" width="100%">';
69 if (obj.description) {
70 innerHtml += '<tr class="content">';
71 innerHtml += '<td class="content" colspan="2">' + obj.description + '</td></tr>';
72 }
73 if (obj.propertylist == 'properties') {
74 innerHtml += printTextArea(obj.properties);
75 } else {
76 innerHtml += printForm(obj);
77 }
78 innerHtml += '<tr class="content">';
79 innerHtml += '<td class="content">&nbsp;</td>';
80 innerHtml += '<td class="content">';
81 innerHtml += '<input type="submit" class="submit" name="submit" value="Save" />';
82 innerHtml += '&nbsp;&nbsp;&nbsp;';
83 innerHtml += '<input type="reset" class="submit" name="reset" value="Reset" />';
84 innerHtml += '&nbsp;&nbsp;&nbsp;';
85 innerHtml += '<input type="submit" class="submit" name="delete" value="Delete" onClick="return confirmDelete();"/>';
Felix Meschbergerca29a962008-05-16 11:59:32 +000086 innerHtml += '</td></tr>';
87 innerHtml += '</table>';
88 innerHtml += '</form>';
89 innerHtml += '</td></tr>';
Felix Meschbergercd169b22008-06-13 12:19:36 +000090
Felix Meschbergerca29a962008-05-16 11:59:32 +000091 innerHtml += printConfigurationInfo(obj);
Felix Meschbergercd169b22008-06-13 12:19:36 +000092
93 span1.parentNode.innerHTML = innerHtml;
Felix Meschbergerca29a962008-05-16 11:59:32 +000094}
95
96function printTextArea(props) {
97 var innerHtml = '<tr class="content">';
98 innerHtml += '<td class="content" style="vertical-align: top">Properties</td>';
99 innerHtml += '<td class="content" style="width: 99%">';
100 innerHtml += '<textarea name="properties" style="height: 50%; width: 99%">';
101 for (var key in props) {
102 innerHtml += key + ' = ' + props[key] + '\r\n';
103 }
104 innerHtml += '</textarea>';
105 innerHtml += 'Enter Name-Value pairs of configuration properties.</td>';
106 return innerHtml;
107}
108
109function printForm(obj) {
110 var innerHtml = '';
111 var propList;
112 for (var idx in obj.propertylist) {
113 var prop = obj.propertylist[idx];
114 var attr = obj[prop];
115 innerHtml += '<tr class="content">';
116 innerHtml += '<td class="content" style="vertical-align: top">' + attr.name + '</td>';
117 innerHtml += '<td class="content" style="width: 99%">';
118 if (attr.value != undefined) { // check is required to also handle empty strings, 0 and false
119 innerHtml += createInput(prop, attr.value, attr.type, '99%');
120 innerHtml += '<br />';
121 } else if (typeof(attr.type) == 'object') {
122 // assume attr.values and multiselect
123 innerHtml += createMultiSelect(prop, attr.values, attr.type, '99%');
124 innerHtml += '<br />';
Felix Meschbergercd169b22008-06-13 12:19:36 +0000125 } else if (attr.values.length == 0) {
126 var spanElement = createSpan(prop, "", attr.type);
127 innerHtml += '<span id="' + spanElement.id + '">';
128 innerHtml += spanElement.innerHTML;
129 innerHtml += '</span>';
Felix Meschbergerca29a962008-05-16 11:59:32 +0000130 } else {
131 for (var vidx in attr.values) {
132 var spanElement = createSpan(prop, attr.values[vidx], attr.type);
133 innerHtml += '<span id="' + spanElement.id + '">';
134 innerHtml += spanElement.innerHTML;
135 innerHtml += '</span>';
136 }
137 }
138 if (attr.description) {
139 innerHtml += attr.description;
140 }
141 innerHtml += '</td>';
142 if (propList) {
143 propList += ',' + prop;
144 } else {
145 propList = prop;
146 }
147 }
148 innerHtml += '<input type="hidden" name="propertylist" value="' + propList + '"/>';
149 return innerHtml;
150}
151
152function printConfigurationInfo(obj) {
153 var innerHtml = '<tr class="content">';
154 innerHtml += '<th colspan="2" class="content" >Configuration Information</th></tr>';
155 innerHtml += '<tr class="content">';
156 innerHtml += '<td class="content">Persistent Identity (PID)</td>';
157 innerHtml += '<td class="content">' + obj.pid + '</td></tr>';
Felix Meschbergercd169b22008-06-13 12:19:36 +0000158
Felix Meschbergerca29a962008-05-16 11:59:32 +0000159 if (obj.factoryPID) {
160 innerHtml += '<tr class="content">';
161 innerHtml += '<td class="content">Factory Peristent Identifier (Factory PID)</td>';
162 innerHtml += '<td class="content">' + obj.factoryPID + '</td></tr>';
163 }
Felix Meschbergercd169b22008-06-13 12:19:36 +0000164
165 var binding = obj.bundleLocation;
166 if (!binding) {
167 binding = "Unbound or new configuration";
168 }
169
Felix Meschbergerca29a962008-05-16 11:59:32 +0000170 innerHtml += '<tr class="content">';
171 innerHtml += '<td class="content">Configuration Binding</td>';
Felix Meschbergercd169b22008-06-13 12:19:36 +0000172 innerHtml += '<td class="content">' + binding + '</td></tr>';
173
Felix Meschbergerca29a962008-05-16 11:59:32 +0000174 return innerHtml;
175}
176
177function addValue(prop, vidx) {
178 var span = document.getElementById(vidx);
179 if (!span) {
180 return;
181 }
182 var newSpan = createSpan(prop, '');
183 span.parentNode.insertBefore(newSpan, span.nextSibling);
184}
185
186var spanCounter = 0;
187function createSpan(prop, value, type) {
188 spanCounter++;
189 var newId = prop + spanCounter;
190 var innerHtml = createInput(prop, value, type, '89%');
191 innerHtml += '<input class="input" type="button" value="+" onClick="addValue(\'' + prop + '\',\'' + newId + '\');" style="width: 5%" />';
192 innerHtml += '<input class="input" type="button" value="-" onClick="removeValue(\'' + newId + '\');" style="width: 5%" />';
193 innerHtml += '<br />';
194 var newSpan = document.createElement('span');
195 newSpan.id = newId;
196 newSpan.innerHTML = innerHtml;
197 return newSpan;
198}
199
200function createInput(prop, value, type, width) {
201 if (type == 11) { // AttributeDefinition.BOOLEAN
202 if (value && typeof(value) != "boolean") {
203 value = value.toString().toLowerCase() == "true";
204 }
205 var checked = value ? 'checked' : '';
206 return '<input class="input" type="checkbox" name="' + prop + '" value="true" ' + checked + '/>';
207 } else if (typeof(type) == "object") { // predefined values
208 var labels = type.labels;
209 var values = type.values;
210 var innerHtml = '<select class="select" name="' + prop + '" style="width: ' + width + '">';
211 for (var idx in labels) {
212 var selected = (value == values[idx]) ? ' selected' : '';
213 innerHtml += '<option value="' + values[idx] + '"' + selected + '>' + labels[idx] + '</option>';
214 }
215 innerHtml += '</select>';
216 return innerHtml;
217 } else { // Simple
218 return '<input class="input" type="text" name="' + prop + '" value="' + value + '" style="width: ' + width + '"/>';
219 }
220}
221
222function createMultiSelect(prop, values, options, width) {
223 // convert value list into 'set'
224 var valueSet = new Object();
225 for (var idx in values) {
226 valueSet[ values[idx] ] = true;
227 }
228
229 var labels = options.labels;
230 var values = options.values;
231 var innerHtml = '';
232 for (var idx in labels) {
233 var checked = valueSet[ values[idx] ] ? ' checked' : '';
234 innerHtml += '<label><input type="checkbox" name="' + prop + '" value="' + values[idx] + '"' + checked + '>' + labels[idx] + '</label>';
235 }
236 return innerHtml;
237}
238
239function removeValue(vidx) {
240 var span = document.getElementById(vidx);
241 if (!span) {
242 return;
243 }
244 span.parentNode.removeChild(span);
245}
246
247function confirmDelete() {
248 return confirm("Are you sure to delete this configuration ?");
249}