blob: 9f95ce66e1674ebc4d7e0d16e50c920a856f7c58 [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
Felix Meschbergerc07350a2008-06-25 20:26:13 +000049 var parent = span1 ? span1.parentNode : span2.parentNode;
50
51 clearChildren( parent );
Felix Meschberger5611f012008-06-13 12:19:36 +000052
53 if (span1) {
Felix Meschbergerc07350a2008-06-25 20:26:13 +000054 parent.appendChild( span1 );
Felix Meschberger5611f012008-06-13 12:19:36 +000055 }
56 if (span2) {
Felix Meschbergerc07350a2008-06-25 20:26:13 +000057 parent.appendChild( span2 );
Felix Meschberger5611f012008-06-13 12:19:36 +000058 }
59
Felix Meschbergerc07350a2008-06-25 20:26:13 +000060 var trEl = tr( "content" );
Felix Meschbergerfb550db2008-06-25 23:09:26 +000061 var tdEl = createElement( "th", "content", { colSpan: "2" } );
Felix Meschbergerc07350a2008-06-25 20:26:13 +000062 addText( tdEl, obj.title );
63 trEl.appendChild( tdEl );
64 parent.appendChild( trEl );
65
Felix Meschbergerc07350a2008-06-25 20:26:13 +000066 trEl = tr( "content" );
67 parent.appendChild( trEl );
Felix Meschberger5611f012008-06-13 12:19:36 +000068
Felix Meschbergerc07350a2008-06-25 20:26:13 +000069 tdEl = td( "content" );
70 addText( tdEl, "\u00a0" );
71 trEl.appendChild( tdEl );
72
Felix Meschbergerc07350a2008-06-25 20:26:13 +000073 tdEl = td( "content" );
74 trEl.appendChild( tdEl );
75
Felix Meschbergerc07350a2008-06-25 20:26:13 +000076 var formEl = createElement( "form", null, {
77 method: "post",
78 action: pluginRoot + "/" + obj.pid
79 });
80 tdEl.appendChild( formEl );
81
82 var inputEl = createElement( "input", null, {
83 type: "hidden",
84 name: "apply",
85 value: "true"
86 });
87 formEl.appendChild( inputEl );
Felix Meschberger0407e252008-06-17 11:43:01 +000088
89 // add the factory PID as a hidden form field if present
90 if (obj.factoryPid)
91 {
Felix Meschbergerc07350a2008-06-25 20:26:13 +000092 inputEl = createElement( "input", null, {
93 type: "hidden",
94 name: "factoryPid",
95 value: obj.factoryPid
96 });
97 formEl.appendChild( inputEl );
Felix Meschberger0407e252008-06-17 11:43:01 +000098 }
99
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000100 inputEl = createElement( "input", null, {
101 type: "hidden",
102 name: "action",
103 value: "ajaxConfigManager"
104 });
105 formEl.appendChild( inputEl );
Felix Meschberger5611f012008-06-13 12:19:36 +0000106
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000107 var tableEl = createElement( "table", null, {
108 border: 0,
109 width: "100%"
110 });
111 formEl.appendChild( tableEl );
Felix Meschberger5611f012008-06-13 12:19:36 +0000112
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000113 var bodyEl = createElement( "tbody" );
114 tableEl.appendChild( bodyEl );
115
116 if (obj.description)
117 {
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000118 trEl = tr( "content" );
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000119 tdEl = td( "content", { colSpan: "2" } );
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000120 addText( tdEl, obj.description );
121 trEl.appendChild( tdEl );
122 bodyEl.appendChild( trEl );
123 }
124
125 if (obj.propertylist == 'properties')
126 {
127 printTextArea(bodyEl, obj.properties);
128 }
129 else
130 {
131 printForm(bodyEl, obj);
132 }
133
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000134 trEl = tr( "content" );
135 bodyEl.appendChild( trEl );
136
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000137 tdEl = td( "content" );
138 addText( tdEl, "\u00a0" );
139 trEl.appendChild( tdEl );
140
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000141 tdEl = td( "content" );
142 trEl.appendChild( tdEl );
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000143
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000144 // define this TD as innerHTML otherwise the onClick event handler
145 // of the Delete button is not accepted by IE...
146 var innerHTML = '<input type="submit" class="submit" name="submit" value="Save" />';
147 innerHTML += '&nbsp;&nbsp;&nbsp;';
148 innerHTML += '<input type="reset" class="submit" name="reset" value="Reset" />';
149 innerHTML += '&nbsp;&nbsp;&nbsp;';
150 innerHTML += '<input type="submit" class="submit" name="delete" value="Delete" onClick="return confirmDelete();"/>';
151 tdEl.innerHTML = innerHTML;
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000152
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000153 printConfigurationInfo(parent, obj);
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000154}
155
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000156function printTextArea(/* Element */ parent, props )
157{
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000158
159 var propsValue = "";
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000160 for (var key in props)
161 {
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000162 propsValue += key + ' = ' + props[key] + '\r\n';
163 }
164
165 return tr( "content", null, [
166 td( "content aligntop", null, [
167 text( "Properties" )
168 ]),
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000169 td( "content", { style: { width: "99%" } }, [
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000170 createElement( "textarea", null, {
171 name: "properties",
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000172 style: { height: "50%", width: "99%" }
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000173 }, [ text( propsValue ) ] ),
174 text( "Enter Name-Value pairs of configuration properties" )
175 ])
176 ]);
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000177}
178
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000179function printForm( /* Element */ parent, obj ) {
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000180 var propList;
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000181 for (var idx in obj.propertylist)
182 {
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000183 var prop = obj.propertylist[idx];
184 var attr = obj[prop];
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000185
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000186 var trEl = tr( "content", null, [
187 td( "content aligntop", null, [ text( attr.name ) ] )
188 ]);
189 parent.appendChild( trEl );
190
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000191 var tdEl = td( "content", { style: { width: "99%" } } );
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000192 trEl.appendChild( tdEl );
193
194 if (attr.value != undefined)
195 {
196 // check is required to also handle empty strings, 0 and false
197 tdEl.appendChild( createInput( prop, attr.value, attr.type, '99%' ) );
198 tdEl.appendChild( createElement( "br" ) );
199 }
200 else if (typeof(attr.type) == 'object')
201 {
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000202 // assume attr.values and multiselect
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000203 createMultiSelect( tdEl, prop, attr.values, attr.type, '99%' );
204 tdEl.appendChild( createElement( "br" ) );
205 }
206 else if (attr.values.length == 0)
207 {
208 tdEl.appendChild( createSpan( prop, "", attr.type ) );
209 }
210 else
211 {
212 for (var vidx in attr.values)
213 {
214 tdEl.appendChild( createSpan( prop, attr.values[vidx], attr.type ) );
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000215 }
216 }
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000217
218 if (attr.description)
219 {
220 addText( tdEl, attr.description );
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000221 }
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000222
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000223 if (propList) {
224 propList += ',' + prop;
225 } else {
226 propList = prop;
227 }
228 }
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000229
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000230 parent.appendChild( createElement( "input", null, {
231 type: "hidden",
232 name: "propertylist",
233 value: propList
234 })
235 );
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000236}
237
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000238function printConfigurationInfo( /* Element */ parent, obj )
239{
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000240 parent.appendChild( tr( "content", null, [
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000241 createElement( "th", "content", { colSpan: "2" }, [
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000242 text( "Configuration Information" )
243 ])
244 ])
245 );
Felix Meschberger5611f012008-06-13 12:19:36 +0000246
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000247 parent.appendChild( tr( "content", null, [
248 td( "content", null, [
249 text( "Persistent Identity (PID)" )
250 ]),
251 td( "content", null, [
252 text( obj.pid )
253 ])
254 ])
255 );
256
257 if (obj.factoryPID)
258 {
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000259 parent.appendChild( tr( "content", null, [
260 td( "content", null, [
261 text( "Factory Peristent Identifier (Factory PID)" )
262 ]),
263 td( "content", null, [
264 text( obj.factoryPID )
265 ])
266 ])
267 );
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000268 }
Felix Meschberger5611f012008-06-13 12:19:36 +0000269
270 var binding = obj.bundleLocation;
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000271 if (!binding)
272 {
Felix Meschberger5611f012008-06-13 12:19:36 +0000273 binding = "Unbound or new configuration";
274 }
275
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000276 parent.appendChild( tr( "content", null, [
277 td( "content", null, [
278 text( "Configuration Binding" )
279 ]),
280 td( "content", null, [
281 text( binding )
282 ])
283 ])
284 );
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000285}
286
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000287
288var spanCounter = 0;
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000289/* Element */ function createSpan(prop, value, type) {
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000290 spanCounter++;
291 var newId = prop + spanCounter;
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000292
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000293 var spanEl = createElement( "span", null, { id: newId }, [
294 createInput( prop, value, type, '89%' )
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000295 ]);
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000296
297 // define this SPAN as innerHTML otherwise the onClick event handler
298 // of the buttons is not accepted by IE...
299 var innerHTML = "<input type='button' class='input' style='width:\"5%\"' value='+' onClick='addValue(\"" + prop + "\", \"" + newId + "\")' />";
300 innerHTML += "<input type='button' class='input' style='width:\"5%\"' value='-' onClick='removeValue(\"" + newId + "\")' />";
301 innerHTML += "<br />";
302 spanEl.innerHTML += innerHTML;
303
304 return spanEl;
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000305}
306
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000307/* Element */ function createInput(prop, value, type, width) {
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000308 if (type == 11) { // AttributeDefinition.BOOLEAN
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000309
310 var inputEl = createElement( "input", "input", {
311 type: "checkbox",
312 name: prop,
313 value: true
314 });
315
316 if (value && typeof(value) != "boolean")
317 {
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000318 value = value.toString().toLowerCase() == "true";
319 }
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000320 if (value)
321 {
322 inputEl.setAttribute( "checked", true );
323 }
324
325 return inputEl;
326
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000327 } else if (typeof(type) == "object") { // predefined values
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000328
329 var selectEl = createElement( "select", "select", {
330 name: prop,
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000331 style: { width: width }
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000332 });
333
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000334 var labels = type.labels;
335 var values = type.values;
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000336 for (var idx in labels) {
337 var optionEl = createElement( "option", null, {
338 value: values[idx]
339 }, [ text( labels[idx] ) ]);
340
341 if (value == values[idx])
342 {
343 optionEl.setAttribute( "selected", true );
344 }
345 selectEl.appendChild( optionEl );
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000346 }
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000347
348 return selectEl;
349
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000350 } else { // Simple
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000351
352 return createElement( "input", "input", {
353 type: "text",
354 name: prop,
355 value: value,
Felix Meschbergerfb550db2008-06-25 23:09:26 +0000356 style: { width: width }
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000357 });
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000358 }
359}
360
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000361function createMultiSelect(/* Element */ parent, prop, values, options, width) {
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000362 // convert value list into 'set'
363 var valueSet = new Object();
364 for (var idx in values) {
365 valueSet[ values[idx] ] = true;
366 }
367
368 var labels = options.labels;
369 var values = options.values;
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000370 for (var idx in labels) {
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000371
372 var inputEl = createElement( "input", null, {
373 type: "checkbox",
374 name: prop,
375 value: values[idx]
376 });
377
378 if (valueSet[ values[idx] ])
379 {
380 inputEl.setAttribute( "checked", true );
381 }
382
383 var labelEl = createElement( "label" );
384 labelEl.appendChild( inputEl );
385 addText( labelEl, labels[idx] );
386
387 parent.appendChild( labelEl );
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000388 }
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000389}
390
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000391
392function addValue(prop, vidx)
393{
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000394 var span = document.getElementById(vidx);
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000395 if (!span)
396 {
397 return;
398 }
399 var newSpan = createSpan(prop, '');
400 span.parentNode.insertBefore(newSpan, span.nextSibling);
401}
402
403function removeValue(vidx)
404{
405 var span = document.getElementById(vidx);
406 if (!span)
407 {
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000408 return;
409 }
410 span.parentNode.removeChild(span);
411}
412
Felix Meschbergerc07350a2008-06-25 20:26:13 +0000413function confirmDelete()
414{
Felix Meschbergerbb30b0c2008-05-16 11:59:32 +0000415 return confirm("Are you sure to delete this configuration ?");
416}