blob: 0af218229780894622324a789932348828a84b60 [file] [log] [blame]
Felix Meschbergerbb30b0c2008-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 Meschberger5611f012008-06-13 12:19:36 +000024 var select = document.getElementById('configSelection_pid');
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +000025 var pid = select.options[select.selectedIndex].value;
Felix Meschberger0407e252008-06-17 11:43:01 +000026 var parm = pluginRoot + '/' + pid;
27 sendRequest('POST', parm, displayConfigForm);
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +000028}
29
Felix Meschberger5611f012008-06-13 12:19:36 +000030
31function create() {
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +000032 var span = document.getElementById('configField');
33 if (!span) {
34 return;
35 }
Felix Meschberger5611f012008-06-13 12:19:36 +000036 var select = document.getElementById('configSelection_factory');
37 var pid = select.options[select.selectedIndex].value;
Felix Meschberger0407e252008-06-17 11:43:01 +000038 var parm = pluginRoot + '/' + pid + '?create=true';
39 sendRequest('POST', parm, displayConfigForm);
Felix Meschberger5611f012008-06-13 12:19:36 +000040}
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 Meschbergerbb30b0c2008-05-16 11:59:32 +000058 innerHtml += '<tr class="content">';
59 innerHtml += '<th colspan="2" class="content" >' + obj.title + '</th></tr>';
Felix Meschberger5611f012008-06-13 12:19:36 +000060
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +000061 innerHtml += '<tr class="content">';
62 innerHtml += '<td class="content">&nbsp;</td>';
63 innerHtml += '<td class="content">';
Felix Meschberger0407e252008-06-17 11:43:01 +000064 innerHtml += '<form method="post" action="' + pluginRoot + '/' + obj.pid + '">';
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +000065 innerHtml += '<input type="hidden" name="apply" value="true" />';
Felix Meschberger0407e252008-06-17 11:43:01 +000066
67 // add the factory PID as a hidden form field if present
68 if (obj.factoryPid)
69 {
70 innerHtml += '<input type="hidden" name="factoryPid" value="' + obj.factoryPid + '" />';
71 }
72
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +000073 innerHtml += '<input type="hidden" name="action" value="ajaxConfigManager" />';
74 innerHtml += '<table border="0" width="100%">';
75 if (obj.description) {
76 innerHtml += '<tr class="content">';
77 innerHtml += '<td class="content" colspan="2">' + obj.description + '</td></tr>';
78 }
79 if (obj.propertylist == 'properties') {
80 innerHtml += printTextArea(obj.properties);
81 } else {
82 innerHtml += printForm(obj);
83 }
84 innerHtml += '<tr class="content">';
85 innerHtml += '<td class="content">&nbsp;</td>';
86 innerHtml += '<td class="content">';
87 innerHtml += '<input type="submit" class="submit" name="submit" value="Save" />';
88 innerHtml += '&nbsp;&nbsp;&nbsp;';
89 innerHtml += '<input type="reset" class="submit" name="reset" value="Reset" />';
90 innerHtml += '&nbsp;&nbsp;&nbsp;';
91 innerHtml += '<input type="submit" class="submit" name="delete" value="Delete" onClick="return confirmDelete();"/>';
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +000092 innerHtml += '</td></tr>';
93 innerHtml += '</table>';
94 innerHtml += '</form>';
95 innerHtml += '</td></tr>';
Felix Meschberger5611f012008-06-13 12:19:36 +000096
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +000097 innerHtml += printConfigurationInfo(obj);
Felix Meschberger5611f012008-06-13 12:19:36 +000098
99 span1.parentNode.innerHTML = innerHtml;
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000100}
101
102function printTextArea(props) {
103 var innerHtml = '<tr class="content">';
104 innerHtml += '<td class="content" style="vertical-align: top">Properties</td>';
105 innerHtml += '<td class="content" style="width: 99%">';
106 innerHtml += '<textarea name="properties" style="height: 50%; width: 99%">';
107 for (var key in props) {
108 innerHtml += key + ' = ' + props[key] + '\r\n';
109 }
110 innerHtml += '</textarea>';
111 innerHtml += 'Enter Name-Value pairs of configuration properties.</td>';
112 return innerHtml;
113}
114
115function printForm(obj) {
116 var innerHtml = '';
117 var propList;
118 for (var idx in obj.propertylist) {
119 var prop = obj.propertylist[idx];
120 var attr = obj[prop];
121 innerHtml += '<tr class="content">';
122 innerHtml += '<td class="content" style="vertical-align: top">' + attr.name + '</td>';
123 innerHtml += '<td class="content" style="width: 99%">';
124 if (attr.value != undefined) { // check is required to also handle empty strings, 0 and false
125 innerHtml += createInput(prop, attr.value, attr.type, '99%');
126 innerHtml += '<br />';
127 } else if (typeof(attr.type) == 'object') {
128 // assume attr.values and multiselect
129 innerHtml += createMultiSelect(prop, attr.values, attr.type, '99%');
130 innerHtml += '<br />';
Felix Meschberger5611f012008-06-13 12:19:36 +0000131 } else if (attr.values.length == 0) {
132 var spanElement = createSpan(prop, "", attr.type);
133 innerHtml += '<span id="' + spanElement.id + '">';
134 innerHtml += spanElement.innerHTML;
135 innerHtml += '</span>';
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000136 } else {
137 for (var vidx in attr.values) {
138 var spanElement = createSpan(prop, attr.values[vidx], attr.type);
139 innerHtml += '<span id="' + spanElement.id + '">';
140 innerHtml += spanElement.innerHTML;
141 innerHtml += '</span>';
142 }
143 }
144 if (attr.description) {
145 innerHtml += attr.description;
146 }
147 innerHtml += '</td>';
148 if (propList) {
149 propList += ',' + prop;
150 } else {
151 propList = prop;
152 }
153 }
154 innerHtml += '<input type="hidden" name="propertylist" value="' + propList + '"/>';
155 return innerHtml;
156}
157
158function printConfigurationInfo(obj) {
159 var innerHtml = '<tr class="content">';
160 innerHtml += '<th colspan="2" class="content" >Configuration Information</th></tr>';
161 innerHtml += '<tr class="content">';
162 innerHtml += '<td class="content">Persistent Identity (PID)</td>';
163 innerHtml += '<td class="content">' + obj.pid + '</td></tr>';
Felix Meschberger5611f012008-06-13 12:19:36 +0000164
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000165 if (obj.factoryPID) {
166 innerHtml += '<tr class="content">';
167 innerHtml += '<td class="content">Factory Peristent Identifier (Factory PID)</td>';
168 innerHtml += '<td class="content">' + obj.factoryPID + '</td></tr>';
169 }
Felix Meschberger5611f012008-06-13 12:19:36 +0000170
171 var binding = obj.bundleLocation;
172 if (!binding) {
173 binding = "Unbound or new configuration";
174 }
175
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000176 innerHtml += '<tr class="content">';
177 innerHtml += '<td class="content">Configuration Binding</td>';
Felix Meschberger5611f012008-06-13 12:19:36 +0000178 innerHtml += '<td class="content">' + binding + '</td></tr>';
179
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000180 return innerHtml;
181}
182
183function addValue(prop, vidx) {
184 var span = document.getElementById(vidx);
185 if (!span) {
186 return;
187 }
188 var newSpan = createSpan(prop, '');
189 span.parentNode.insertBefore(newSpan, span.nextSibling);
190}
191
192var spanCounter = 0;
193function createSpan(prop, value, type) {
194 spanCounter++;
195 var newId = prop + spanCounter;
196 var innerHtml = createInput(prop, value, type, '89%');
197 innerHtml += '<input class="input" type="button" value="+" onClick="addValue(\'' + prop + '\',\'' + newId + '\');" style="width: 5%" />';
198 innerHtml += '<input class="input" type="button" value="-" onClick="removeValue(\'' + newId + '\');" style="width: 5%" />';
199 innerHtml += '<br />';
200 var newSpan = document.createElement('span');
201 newSpan.id = newId;
202 newSpan.innerHTML = innerHtml;
203 return newSpan;
204}
205
206function createInput(prop, value, type, width) {
207 if (type == 11) { // AttributeDefinition.BOOLEAN
208 if (value && typeof(value) != "boolean") {
209 value = value.toString().toLowerCase() == "true";
210 }
211 var checked = value ? 'checked' : '';
212 return '<input class="input" type="checkbox" name="' + prop + '" value="true" ' + checked + '/>';
213 } else if (typeof(type) == "object") { // predefined values
214 var labels = type.labels;
215 var values = type.values;
216 var innerHtml = '<select class="select" name="' + prop + '" style="width: ' + width + '">';
217 for (var idx in labels) {
218 var selected = (value == values[idx]) ? ' selected' : '';
219 innerHtml += '<option value="' + values[idx] + '"' + selected + '>' + labels[idx] + '</option>';
220 }
221 innerHtml += '</select>';
222 return innerHtml;
223 } else { // Simple
224 return '<input class="input" type="text" name="' + prop + '" value="' + value + '" style="width: ' + width + '"/>';
225 }
226}
227
228function createMultiSelect(prop, values, options, width) {
229 // convert value list into 'set'
230 var valueSet = new Object();
231 for (var idx in values) {
232 valueSet[ values[idx] ] = true;
233 }
234
235 var labels = options.labels;
236 var values = options.values;
237 var innerHtml = '';
238 for (var idx in labels) {
239 var checked = valueSet[ values[idx] ] ? ' checked' : '';
240 innerHtml += '<label><input type="checkbox" name="' + prop + '" value="' + values[idx] + '"' + checked + '>' + labels[idx] + '</label>';
241 }
242 return innerHtml;
243}
244
245function removeValue(vidx) {
246 var span = document.getElementById(vidx);
247 if (!span) {
248 return;
249 }
250 span.parentNode.removeChild(span);
251}
252
253function confirmDelete() {
254 return confirm("Are you sure to delete this configuration ?");
255}