blob: 9f98ca45b38940d6e52e88d6d7487ea6768283ed [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 Meschbergerb6c7aec2008-06-17 11:43:01 +000026 var parm = pluginRoot + '/' + pid;
27 sendRequest('POST', parm, displayConfigForm);
Felix Meschbergerca29a962008-05-16 11:59:32 +000028}
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;
Felix Meschbergerb6c7aec2008-06-17 11:43:01 +000038 var parm = pluginRoot + '/' + pid + '?create=true';
39 sendRequest('POST', parm, displayConfigForm);
Felix Meschbergercd169b22008-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 Meschberger5af75272008-06-25 20:26:13 +000049 var parent = span1 ? span1.parentNode : span2.parentNode;
50
51 clearChildren( parent );
Felix Meschbergercd169b22008-06-13 12:19:36 +000052
53 if (span1) {
Felix Meschberger5af75272008-06-25 20:26:13 +000054 parent.appendChild( span1 );
Felix Meschbergercd169b22008-06-13 12:19:36 +000055 }
56 if (span2) {
Felix Meschberger5af75272008-06-25 20:26:13 +000057 parent.appendChild( span2 );
Felix Meschbergercd169b22008-06-13 12:19:36 +000058 }
59
Felix Meschberger5af75272008-06-25 20:26:13 +000060 var trEl = tr( "content" );
Felix Meschberger018b1442008-06-25 23:09:26 +000061 var tdEl = createElement( "th", "content", { colSpan: "2" } );
Felix Meschberger5af75272008-06-25 20:26:13 +000062 addText( tdEl, obj.title );
63 trEl.appendChild( tdEl );
64 parent.appendChild( trEl );
65
Felix Meschberger5af75272008-06-25 20:26:13 +000066 trEl = tr( "content" );
67 parent.appendChild( trEl );
Felix Meschbergercd169b22008-06-13 12:19:36 +000068
Felix Meschberger5af75272008-06-25 20:26:13 +000069 tdEl = td( "content" );
70 addText( tdEl, "\u00a0" );
71 trEl.appendChild( tdEl );
72
Felix Meschberger5af75272008-06-25 20:26:13 +000073 tdEl = td( "content" );
74 trEl.appendChild( tdEl );
75
Felix Meschberger5af75272008-06-25 20:26:13 +000076 var formEl = createElement( "form", null, {
Carsten Ziegeler2d009d42009-03-05 17:55:53 +000077 method: "POST",
Felix Meschberger5af75272008-06-25 20:26:13 +000078 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 Meschbergerb6c7aec2008-06-17 11:43:01 +000088
89 // add the factory PID as a hidden form field if present
90 if (obj.factoryPid)
91 {
Felix Meschberger5af75272008-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 Meschbergerb6c7aec2008-06-17 11:43:01 +000098 }
99
Felix Meschbergerc76ee7f2008-09-29 11:00:33 +0000100 // add the PID filter as a hidden form field if present
101 if (obj.pidFilter)
102 {
103 inputEl = createElement( "input", null, {
104 type: "hidden",
105 name: "pidFilter",
106 value: obj.pidFilter
107 });
108 formEl.appendChild( inputEl );
109 }
110
Felix Meschberger5af75272008-06-25 20:26:13 +0000111 inputEl = createElement( "input", null, {
112 type: "hidden",
113 name: "action",
114 value: "ajaxConfigManager"
115 });
116 formEl.appendChild( inputEl );
Felix Meschbergercd169b22008-06-13 12:19:36 +0000117
Felix Meschberger5af75272008-06-25 20:26:13 +0000118 var tableEl = createElement( "table", null, {
119 border: 0,
120 width: "100%"
121 });
122 formEl.appendChild( tableEl );
Felix Meschbergercd169b22008-06-13 12:19:36 +0000123
Felix Meschberger5af75272008-06-25 20:26:13 +0000124 var bodyEl = createElement( "tbody" );
125 tableEl.appendChild( bodyEl );
126
127 if (obj.description)
128 {
Felix Meschberger5af75272008-06-25 20:26:13 +0000129 trEl = tr( "content" );
Felix Meschberger018b1442008-06-25 23:09:26 +0000130 tdEl = td( "content", { colSpan: "2" } );
Felix Meschberger5af75272008-06-25 20:26:13 +0000131 addText( tdEl, obj.description );
132 trEl.appendChild( tdEl );
133 bodyEl.appendChild( trEl );
134 }
135
136 if (obj.propertylist == 'properties')
137 {
138 printTextArea(bodyEl, obj.properties);
139 }
140 else
141 {
142 printForm(bodyEl, obj);
143 }
144
Felix Meschberger5af75272008-06-25 20:26:13 +0000145 trEl = tr( "content" );
146 bodyEl.appendChild( trEl );
147
Felix Meschberger5af75272008-06-25 20:26:13 +0000148 tdEl = td( "content" );
149 addText( tdEl, "\u00a0" );
150 trEl.appendChild( tdEl );
151
Felix Meschberger5af75272008-06-25 20:26:13 +0000152 tdEl = td( "content" );
153 trEl.appendChild( tdEl );
Felix Meschberger5af75272008-06-25 20:26:13 +0000154
Felix Meschberger018b1442008-06-25 23:09:26 +0000155 // define this TD as innerHTML otherwise the onClick event handler
156 // of the Delete button is not accepted by IE...
157 var innerHTML = '<input type="submit" class="submit" name="submit" value="Save" />';
158 innerHTML += '&nbsp;&nbsp;&nbsp;';
159 innerHTML += '<input type="reset" class="submit" name="reset" value="Reset" />';
160 innerHTML += '&nbsp;&nbsp;&nbsp;';
161 innerHTML += '<input type="submit" class="submit" name="delete" value="Delete" onClick="return confirmDelete();"/>';
162 tdEl.innerHTML = innerHTML;
Felix Meschberger5af75272008-06-25 20:26:13 +0000163
Felix Meschberger5af75272008-06-25 20:26:13 +0000164 printConfigurationInfo(parent, obj);
Felix Meschbergerca29a962008-05-16 11:59:32 +0000165}
166
Felix Meschberger018b1442008-06-25 23:09:26 +0000167function printTextArea(/* Element */ parent, props )
168{
Felix Meschberger5af75272008-06-25 20:26:13 +0000169
170 var propsValue = "";
Felix Meschberger018b1442008-06-25 23:09:26 +0000171 for (var key in props)
172 {
Felix Meschberger5af75272008-06-25 20:26:13 +0000173 propsValue += key + ' = ' + props[key] + '\r\n';
174 }
175
176 return tr( "content", null, [
177 td( "content aligntop", null, [
178 text( "Properties" )
179 ]),
Felix Meschberger018b1442008-06-25 23:09:26 +0000180 td( "content", { style: { width: "99%" } }, [
Felix Meschberger5af75272008-06-25 20:26:13 +0000181 createElement( "textarea", null, {
182 name: "properties",
Felix Meschberger018b1442008-06-25 23:09:26 +0000183 style: { height: "50%", width: "99%" }
Felix Meschberger5af75272008-06-25 20:26:13 +0000184 }, [ text( propsValue ) ] ),
185 text( "Enter Name-Value pairs of configuration properties" )
186 ])
187 ]);
Felix Meschbergerca29a962008-05-16 11:59:32 +0000188}
189
Felix Meschberger5af75272008-06-25 20:26:13 +0000190function printForm( /* Element */ parent, obj ) {
Felix Meschbergerca29a962008-05-16 11:59:32 +0000191 var propList;
Felix Meschberger5af75272008-06-25 20:26:13 +0000192 for (var idx in obj.propertylist)
193 {
Felix Meschbergerca29a962008-05-16 11:59:32 +0000194 var prop = obj.propertylist[idx];
195 var attr = obj[prop];
Felix Meschberger5af75272008-06-25 20:26:13 +0000196
Felix Meschberger5af75272008-06-25 20:26:13 +0000197 var trEl = tr( "content", null, [
198 td( "content aligntop", null, [ text( attr.name ) ] )
199 ]);
200 parent.appendChild( trEl );
201
Felix Meschberger018b1442008-06-25 23:09:26 +0000202 var tdEl = td( "content", { style: { width: "99%" } } );
Felix Meschberger5af75272008-06-25 20:26:13 +0000203 trEl.appendChild( tdEl );
204
205 if (attr.value != undefined)
206 {
207 // check is required to also handle empty strings, 0 and false
208 tdEl.appendChild( createInput( prop, attr.value, attr.type, '99%' ) );
209 tdEl.appendChild( createElement( "br" ) );
210 }
211 else if (typeof(attr.type) == 'object')
212 {
Felix Meschbergerca29a962008-05-16 11:59:32 +0000213 // assume attr.values and multiselect
Felix Meschberger5af75272008-06-25 20:26:13 +0000214 createMultiSelect( tdEl, prop, attr.values, attr.type, '99%' );
215 tdEl.appendChild( createElement( "br" ) );
216 }
217 else if (attr.values.length == 0)
218 {
219 tdEl.appendChild( createSpan( prop, "", attr.type ) );
220 }
221 else
222 {
Carsten Ziegelere626d302009-03-05 18:55:47 +0000223 for (var i=0;i<attr.values.length;i++)
Felix Meschberger5af75272008-06-25 20:26:13 +0000224 {
Carsten Ziegelere626d302009-03-05 18:55:47 +0000225 tdEl.appendChild( createSpan( prop, attr.values[i], attr.type ) );
Felix Meschbergerca29a962008-05-16 11:59:32 +0000226 }
227 }
Felix Meschberger5af75272008-06-25 20:26:13 +0000228
229 if (attr.description)
230 {
231 addText( tdEl, attr.description );
Felix Meschbergerca29a962008-05-16 11:59:32 +0000232 }
Felix Meschberger5af75272008-06-25 20:26:13 +0000233
Felix Meschbergerca29a962008-05-16 11:59:32 +0000234 if (propList) {
235 propList += ',' + prop;
236 } else {
237 propList = prop;
238 }
239 }
Felix Meschberger5af75272008-06-25 20:26:13 +0000240
Felix Meschberger5af75272008-06-25 20:26:13 +0000241 parent.appendChild( createElement( "input", null, {
242 type: "hidden",
243 name: "propertylist",
244 value: propList
245 })
246 );
Carsten Ziegelerbd5b5012009-03-05 19:47:40 +0000247 // FIX for IE6 and above: checkbox can only be checked after it is in the DOM
248 $(".checked_box").attr("checked", true).removeClass("checked_box");
Felix Meschbergerca29a962008-05-16 11:59:32 +0000249}
250
Felix Meschberger5af75272008-06-25 20:26:13 +0000251function printConfigurationInfo( /* Element */ parent, obj )
252{
Felix Meschberger5af75272008-06-25 20:26:13 +0000253 parent.appendChild( tr( "content", null, [
Felix Meschberger018b1442008-06-25 23:09:26 +0000254 createElement( "th", "content", { colSpan: "2" }, [
Felix Meschberger5af75272008-06-25 20:26:13 +0000255 text( "Configuration Information" )
256 ])
257 ])
258 );
Felix Meschbergercd169b22008-06-13 12:19:36 +0000259
Felix Meschberger5af75272008-06-25 20:26:13 +0000260 parent.appendChild( tr( "content", null, [
261 td( "content", null, [
262 text( "Persistent Identity (PID)" )
263 ]),
264 td( "content", null, [
265 text( obj.pid )
266 ])
267 ])
268 );
269
Carsten Ziegelerf7eab262008-12-21 17:59:09 +0000270 if (obj.factoryPid)
Felix Meschberger5af75272008-06-25 20:26:13 +0000271 {
Felix Meschberger5af75272008-06-25 20:26:13 +0000272 parent.appendChild( tr( "content", null, [
273 td( "content", null, [
274 text( "Factory Peristent Identifier (Factory PID)" )
275 ]),
276 td( "content", null, [
Carsten Ziegelerf7eab262008-12-21 17:59:09 +0000277 text( obj.factoryPid )
Felix Meschberger5af75272008-06-25 20:26:13 +0000278 ])
279 ])
280 );
Felix Meschbergerca29a962008-05-16 11:59:32 +0000281 }
Felix Meschbergercd169b22008-06-13 12:19:36 +0000282
283 var binding = obj.bundleLocation;
Felix Meschberger5af75272008-06-25 20:26:13 +0000284 if (!binding)
285 {
Felix Meschbergercd169b22008-06-13 12:19:36 +0000286 binding = "Unbound or new configuration";
287 }
288
Felix Meschberger5af75272008-06-25 20:26:13 +0000289 parent.appendChild( tr( "content", null, [
290 td( "content", null, [
291 text( "Configuration Binding" )
292 ]),
293 td( "content", null, [
294 text( binding )
295 ])
296 ])
297 );
Felix Meschbergerca29a962008-05-16 11:59:32 +0000298}
299
Felix Meschbergerca29a962008-05-16 11:59:32 +0000300
301var spanCounter = 0;
Felix Meschberger5af75272008-06-25 20:26:13 +0000302/* Element */ function createSpan(prop, value, type) {
Felix Meschbergerca29a962008-05-16 11:59:32 +0000303 spanCounter++;
304 var newId = prop + spanCounter;
Felix Meschberger5af75272008-06-25 20:26:13 +0000305
Carsten Ziegelere626d302009-03-05 18:55:47 +0000306 var addButton = createElement("input", "input",
307 { type: "button",
308 style: {width : "5%"},
309 value: "+"
310 }
311 );
312 $(addButton).click(function() {addValue(prop, newId)});
313 var remButton = createElement("input", "input",
314 { type: "button",
315 style: {width : "5%"},
316 value: "-"
317 }
318 );
319 $(remButton).click(function() {removeValue(newId)});
Felix Meschberger018b1442008-06-25 23:09:26 +0000320 var spanEl = createElement( "span", null, { id: newId }, [
Carsten Ziegelere626d302009-03-05 18:55:47 +0000321 createInput( prop, value, type, '89%' ), addButton, remButton,
322 createElement("br")
Felix Meschberger5af75272008-06-25 20:26:13 +0000323 ]);
Felix Meschberger018b1442008-06-25 23:09:26 +0000324
Felix Meschberger018b1442008-06-25 23:09:26 +0000325 return spanEl;
Felix Meschbergerca29a962008-05-16 11:59:32 +0000326}
327
Felix Meschberger5af75272008-06-25 20:26:13 +0000328/* Element */ function createInput(prop, value, type, width) {
Felix Meschbergerca29a962008-05-16 11:59:32 +0000329 if (type == 11) { // AttributeDefinition.BOOLEAN
Felix Meschberger5af75272008-06-25 20:26:13 +0000330
331 var inputEl = createElement( "input", "input", {
332 type: "checkbox",
333 name: prop,
Carsten Ziegelerbd5b5012009-03-05 19:47:40 +0000334 value: "true"
Felix Meschberger5af75272008-06-25 20:26:13 +0000335 });
336
337 if (value && typeof(value) != "boolean")
338 {
Felix Meschbergerca29a962008-05-16 11:59:32 +0000339 value = value.toString().toLowerCase() == "true";
340 }
Felix Meschberger5af75272008-06-25 20:26:13 +0000341 if (value)
342 {
Carsten Ziegelerbd5b5012009-03-05 19:47:40 +0000343 $(inputEl).addClass("checked_box");
Felix Meschberger5af75272008-06-25 20:26:13 +0000344 }
Carsten Ziegeleraad8b882008-10-15 12:13:54 +0000345 var hiddenEl = createElement( "input", "input", {
346 type: "hidden",
347 name: prop,
Carsten Ziegelerbd5b5012009-03-05 19:47:40 +0000348 value: "false"
Carsten Ziegeleraad8b882008-10-15 12:13:54 +0000349 });
Carsten Ziegelerbd5b5012009-03-05 19:47:40 +0000350 var divEl = createElement("div");
Carsten Ziegeleraad8b882008-10-15 12:13:54 +0000351 divEl.appendChild(inputEl);
352 divEl.appendChild(hiddenEl);
353 return divEl;
Felix Meschberger5af75272008-06-25 20:26:13 +0000354
Felix Meschbergerca29a962008-05-16 11:59:32 +0000355 } else if (typeof(type) == "object") { // predefined values
Felix Meschberger5af75272008-06-25 20:26:13 +0000356
357 var selectEl = createElement( "select", "select", {
358 name: prop,
Felix Meschberger018b1442008-06-25 23:09:26 +0000359 style: { width: width }
Felix Meschberger5af75272008-06-25 20:26:13 +0000360 });
361
Felix Meschbergerca29a962008-05-16 11:59:32 +0000362 var labels = type.labels;
363 var values = type.values;
Felix Meschberger5af75272008-06-25 20:26:13 +0000364 for (var idx in labels) {
365 var optionEl = createElement( "option", null, {
366 value: values[idx]
367 }, [ text( labels[idx] ) ]);
368
369 if (value == values[idx])
370 {
371 optionEl.setAttribute( "selected", true );
372 }
373 selectEl.appendChild( optionEl );
Felix Meschbergerca29a962008-05-16 11:59:32 +0000374 }
Felix Meschberger5af75272008-06-25 20:26:13 +0000375
376 return selectEl;
377
Felix Meschbergerca29a962008-05-16 11:59:32 +0000378 } else { // Simple
Felix Meschberger5af75272008-06-25 20:26:13 +0000379 return createElement( "input", "input", {
380 type: "text",
381 name: prop,
382 value: value,
Felix Meschberger018b1442008-06-25 23:09:26 +0000383 style: { width: width }
Felix Meschberger5af75272008-06-25 20:26:13 +0000384 });
Felix Meschbergerca29a962008-05-16 11:59:32 +0000385 }
386}
387
Felix Meschberger5af75272008-06-25 20:26:13 +0000388function createMultiSelect(/* Element */ parent, prop, values, options, width) {
Felix Meschbergerca29a962008-05-16 11:59:32 +0000389 // convert value list into 'set'
390 var valueSet = new Object();
391 for (var idx in values) {
392 valueSet[ values[idx] ] = true;
393 }
394
395 var labels = options.labels;
396 var values = options.values;
Felix Meschbergerca29a962008-05-16 11:59:32 +0000397 for (var idx in labels) {
Felix Meschberger5af75272008-06-25 20:26:13 +0000398
399 var inputEl = createElement( "input", null, {
400 type: "checkbox",
401 name: prop,
402 value: values[idx]
403 });
404
405 if (valueSet[ values[idx] ])
406 {
407 inputEl.setAttribute( "checked", true );
408 }
409
410 var labelEl = createElement( "label" );
411 labelEl.appendChild( inputEl );
412 addText( labelEl, labels[idx] );
413
414 parent.appendChild( labelEl );
Felix Meschbergerca29a962008-05-16 11:59:32 +0000415 }
Felix Meschbergerca29a962008-05-16 11:59:32 +0000416}
417
Felix Meschberger5af75272008-06-25 20:26:13 +0000418
419function addValue(prop, vidx)
420{
Felix Meschbergerca29a962008-05-16 11:59:32 +0000421 var span = document.getElementById(vidx);
Felix Meschberger5af75272008-06-25 20:26:13 +0000422 if (!span)
423 {
424 return;
425 }
426 var newSpan = createSpan(prop, '');
427 span.parentNode.insertBefore(newSpan, span.nextSibling);
Carsten Ziegelerbd5b5012009-03-05 19:47:40 +0000428 // FIX for IE6 and above: checkbox can only be checked after it is in the DOM
429 $(".checked_box").attr("checked", true).removeClass("checked_box");
Felix Meschberger5af75272008-06-25 20:26:13 +0000430}
431
432function removeValue(vidx)
433{
434 var span = document.getElementById(vidx);
435 if (!span)
436 {
Felix Meschbergerca29a962008-05-16 11:59:32 +0000437 return;
438 }
439 span.parentNode.removeChild(span);
440}
441
Felix Meschberger5af75272008-06-25 20:26:13 +0000442function confirmDelete()
443{
Felix Meschbergerca29a962008-05-16 11:59:32 +0000444 return confirm("Are you sure to delete this configuration ?");
445}