blob: 96f19f1bd0feb42d4941162ab38e6bd94173466b [file] [log] [blame]
Felix Meschberger62e1a4f2010-02-18 15:36:53 +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 select = document.getElementById('configSelection_pid');
21 var pid = select.options[select.selectedIndex].value;
22 var parm = pluginRoot + '/' + pid;
23 $.post(parm, null, displayConfigForm, "json");
24}
25
26
27function create() {
28 var select = document.getElementById('configSelection_factory');
29 var pid = select.options[select.selectedIndex].value;
30 var parm = pluginRoot + '/' + pid + '?create=true';
31 $.post(parm, null, displayConfigForm, "json");
32}
33
34function displayConfigForm(obj) {
35 var span1 = document.getElementById('configField');
36 var span2 = document.getElementById('factoryField');
37 if (!span1 && !span2) {
38 return;
39 }
40
41 var parent = span1 ? span1.parentNode : span2.parentNode;
42
43 clearChildren( parent );
44
45 if (span1) {
46 parent.appendChild( span1 );
47 }
48 if (span2) {
49 parent.appendChild( span2 );
50 }
51
52 var trEl = tr( null );
53 var tdEl = createElement( "th", null, { colSpan: "2" } );
54 addText( tdEl, obj.title );
55 trEl.appendChild( tdEl );
56 parent.appendChild( trEl );
57
58 trEl = tr( );
59 parent.appendChild( trEl );
60
61 tdEl = td( );
62 addText( tdEl, "\u00a0" );
63 trEl.appendChild( tdEl );
64
65 tdEl = td( );
66 trEl.appendChild( tdEl );
67
68 var formEl = createElement( "form", null, {
69 method: "POST",
70 action: pluginRoot + "/" + obj.pid
71 });
72 tdEl.appendChild( formEl );
73
74 var inputEl = createElement( "input", null, {
75 type: "hidden",
76 name: "apply",
77 value: "true"
78 });
79 formEl.appendChild( inputEl );
80
81 // add the factory PID as a hidden form field if present
82 if (obj.factoryPid)
83 {
84 inputEl = createElement( "input", null, {
85 type: "hidden",
86 name: "factoryPid",
87 value: obj.factoryPid
88 });
89 formEl.appendChild( inputEl );
90 }
91
92 // add the PID filter as a hidden form field if present
93 if (obj.pidFilter)
94 {
95 inputEl = createElement( "input", null, {
96 type: "hidden",
97 name: "pidFilter",
98 value: obj.pidFilter
99 });
100 formEl.appendChild( inputEl );
101 }
102
103 inputEl = createElement( "input", null, {
104 type: "hidden",
105 name: "action",
106 value: "ajaxConfigManager"
107 });
108 formEl.appendChild( inputEl );
109
110 var tableEl = createElement( "table", null, {
111 border: 0,
112 width: "100%"
113 });
114 formEl.appendChild( tableEl );
115
116 var bodyEl = createElement( "tbody" );
117 tableEl.appendChild( bodyEl );
118
119 if (obj.description)
120 {
121 trEl = tr( );
122 tdEl = td( null, { colSpan: "2" } );
123 addText( tdEl, obj.description );
124 trEl.appendChild( tdEl );
125 bodyEl.appendChild( trEl );
126 }
127
128 if (obj.propertylist == 'properties')
129 {
130 printTextArea(bodyEl, obj.properties);
131 }
132 else
133 {
134 printForm(bodyEl, obj);
135 }
136
137 trEl = tr( );
138 bodyEl.appendChild( trEl );
139
140 tdEl = td( );
141 addText( tdEl, "\u00a0" );
142 trEl.appendChild( tdEl );
143
144 tdEl = td( );
145 trEl.appendChild( tdEl );
146
147 // define this TD as innerHTML otherwise the onClick event handler
148 // of the Delete button is not accepted by IE6 (!)...
149 var innerHTML = '<input type="submit" name="submit" value="'+i18n.save+'" />';
150 innerHTML += '&nbsp;&nbsp;&nbsp;';
151 innerHTML += '<input type="reset" name="reset" value="'+i18n.reset+'" />';
152 innerHTML += '&nbsp;&nbsp;&nbsp;';
153 innerHTML += '<input type="submit" name="delete" value="'+i18n.del+'" onClick="return confirmDelete(\'' + obj.pid + '\', \'' + obj.bundleLocation + '\');"/>';
154 tdEl.innerHTML = innerHTML;
155
156 printConfigurationInfo(parent, obj);
157 initStaticWidgets($(parent));
158}
159
160function printTextArea(/* Element */ parent, props )
161{
162
163 var propsValue = "";
164 for (var key in props)
165 {
166 propsValue += key + ' = ' + props[key] + '\r\n';
167 }
168
169 parent.appendChild(
170 tr( null, null, [
171 td( null, null, [
172 text( i18n.props_title )
173 ]),
174 td( null, { style: { width: "99%" } }, [
175 createElement( "textarea", null, {
176 name: "properties",
177 style: { height: "50%", width: "99%" }
178 }, [ text( propsValue ) ] ),
179 text( i18n.props_enter )
180 ])
181 ])
182 );
183}
184
185function printForm( /* Element */ parent, obj ) {
186 var propList;
187 for (var idx in obj.propertylist)
188 {
189 var prop = obj.propertylist[idx];
190 var attr = obj[prop];
191
192 var trEl = tr( null, null, [
193 td( null, null, [ text( attr.name ) ] )
194 ]);
195 parent.appendChild( trEl );
196
197 var tdEl = td( null, { style: { width: "99%" } } );
198 trEl.appendChild( tdEl );
199
200 if (attr.value != undefined)
201 {
202 // check is required to also handle empty strings, 0 and false
203 tdEl.appendChild( createInput( prop, attr.value, attr.type, '99%' ) );
204 tdEl.appendChild( createElement( "br" ) );
205 }
206 else if (typeof(attr.type) == 'object')
207 {
208 // assume attr.values and multiselect
209 createMultiSelect( tdEl, prop, attr.values, attr.type, '99%' );
210 tdEl.appendChild( createElement( "br" ) );
211 }
212 else if (attr.values.length == 0)
213 {
214 tdEl.appendChild( createSpan( prop, "", attr.type ) );
215 }
216 else
217 {
218 for (var i=0;i<attr.values.length;i++)
219 {
220 tdEl.appendChild( createSpan( prop, attr.values[i], attr.type ) );
221 }
222 }
223
224 if (attr.description)
225 {
226 addText( tdEl, attr.description );
227 }
228
229 if (propList) {
230 propList += ',' + prop;
231 } else {
232 propList = prop;
233 }
234 }
235
236 parent.appendChild( createElement( "input", null, {
237 type: "hidden",
238 name: "propertylist",
239 value: propList
240 })
241 );
242 // FIX for IE6 and above: checkbox can only be checked after it is in the DOM
243 $(".checked_box").attr("checked", true).removeClass("checked_box");
244}
245
246function printConfigurationInfo( /* Element */ parent, obj )
247{
248 parent.appendChild( tr( null, null, [
249 createElement( "th", null, { colSpan: "2" }, [
250 text( i18n.cfg_title )
251 ])
252 ])
253 );
254
255 parent.appendChild( tr( null, null, [
256 td( null, null, [
257 text( i18n.pid )
258 ]),
259 td( null, null, [
260 text( obj.pid )
261 ])
262 ])
263 );
264
265 if (obj.factoryPid)
266 {
267 parent.appendChild( tr( null, null, [
268 td( null, null, [
269 text( i18n.fpid )
270 ]),
271 td( null, null, [
272 text( obj.factoryPid )
273 ])
274 ])
275 );
276 }
277
278 var binding = obj.bundleLocation;
279 if (!binding)
280 {
281 binding = i18n.unbound;
282 }
283
284 parent.appendChild( tr( null, null, [
285 td( null, null, [
286 text( i18n.binding )
287 ]),
288 td( null, null, [
289 text( binding )
290 ])
291 ])
292 );
293
294 if (obj.bundleLocation)
295 {
296 var form = createElement( "form", null, {
297 method: "POST",
298 action: pluginRoot + "/" + obj.pid
299 });
300
301 // define this form contents as innerHTML otherwise the onClick
302 // event handler of the Unbind button is not accepted by IE6 (!)...
303 var formInner = '<input type="hidden" name="unbind" value="true"/>';
304 formInner += '<input type="submit" name="submit" value="'+i18n.unbind_btn+'" class="ui-state-default ui-corner-all" title="'+i18n.unbind_tip+'" onClick="return confirmUnbind(\'' + obj.pid + '\', \'' + obj.bundleLocation + '\');"/>';
305 form.innerHTML = formInner;
306
307 parent.appendChild( tr( null, null, [
308 td( null, null, [
309 text( " " )
310 ]),
311 td( null, null, [ form ] )
312 ])
313 );
314 }
315 //$(form).ready(initStaticWidgets);
316}
317
318
319var spanCounter = 0;
320/* Element */ function createSpan(prop, value, type) {
321 spanCounter++;
322 var newId = prop + spanCounter;
323
324 var addButton = createElement("input", null,
325 { type: "button",
326 style: {width : "5%"},
327 value: "+"
328 }
329 );
330 $(addButton).click(function() {addValue(prop, newId)});
331 var remButton = createElement("input", null,
332 { type: "button",
333 style: {width : "5%"},
334 value: "-"
335 }
336 );
337 $(remButton).click(function() {removeValue(newId)});
338 var spanEl = createElement( "span", null, { id: newId }, [
339 createInput( prop, value, type, '89%' ), addButton, remButton,
340 createElement("br")
341 ]);
342
343 return spanEl;
344}
345
346/* Element */ function createInput(prop, value, type, width) {
347 if (type == 11) { // AttributeDefinition.BOOLEAN
348
349 var inputEl = createElement( "input", null, {
350 type: "checkbox",
351 name: prop,
352 value: "true"
353 });
354
355 if (value && typeof(value) != "boolean")
356 {
357 value = value.toString().toLowerCase() == "true";
358 }
359 if (value)
360 {
361 $(inputEl).addClass("checked_box");
362 }
363 var hiddenEl = createElement( "input", null, {
364 type: "hidden",
365 name: prop,
366 value: "false"
367 });
368 var divEl = createElement("div");
369 divEl.appendChild(inputEl);
370 divEl.appendChild(hiddenEl);
371 return divEl;
372
373 } else if (typeof(type) == "object") { // predefined values
374
375 var selectEl = createElement( "select", null, {
376 name: prop,
377 style: { width: width }
378 });
379
380 var labels = type.labels;
381 var values = type.values;
382 for (var idx in labels) {
383 var optionEl = createElement( "option", null, {
384 value: values[idx]
385 }, [ text( labels[idx] ) ]);
386
387 if (value == values[idx])
388 {
389 optionEl.setAttribute( "selected", true );
390 }
391 selectEl.appendChild( optionEl );
392 }
393
394 return selectEl;
395
396 } else { // Simple
397 return createElement( "input", null, {
398 type: "text",
399 name: prop,
400 value: value,
401 style: { width: width }
402 });
403 }
404}
405
406function createMultiSelect(/* Element */ parent, prop, values, options, width) {
407 // convert value list into 'set'
408 var valueSet = new Object();
409 for (var idx in values) {
410 valueSet[ values[idx] ] = true;
411 }
412
413 var labels = options.labels;
414 var values = options.values;
415 for (var idx in labels) {
416
417 var inputEl = createElement( "input", null, {
418 type: "checkbox",
419 name: prop,
420 value: values[idx]
421 });
422
423 if (valueSet[ values[idx] ])
424 {
425 inputEl.setAttribute( "checked", true );
426 }
427
428 var labelEl = createElement( "label", "multiselect" );
429 labelEl.appendChild( inputEl );
430 addText( labelEl, labels[idx] );
431
432 parent.appendChild( labelEl );
433 }
434}
435
436
437function addValue(prop, vidx)
438{
439 var span = document.getElementById(vidx);
440 if (!span)
441 {
442 return;
443 }
444 var newSpan = createSpan(prop, '');
445 span.parentNode.insertBefore(newSpan, span.nextSibling);
446 // FIX for IE6 and above: checkbox can only be checked after it is in the DOM
447 $(".checked_box").attr("checked", true).removeClass("checked_box");
448 //$(span).ready(initStaticWidgets);
449}
450
451function removeValue(vidx)
452{
453 var span = document.getElementById(vidx);
454 if (!span)
455 {
456 return;
457 }
458 span.parentNode.removeChild(span);
459}
460
461function configConfirm(/* String */ message, /* String */ title, /* String */ location)
462{
463 var message = i18n.del_ask;
464
465 if (title) {
466 message += "\r\n" + i18n.del_config + title;
467 }
468 if (location) {
469 message += "\r\n" + i18n.del_bundle + location;
470 }
471
472 return confirm(message);
473}
474
475function confirmDelete(/* String */ title, /* String */ location)
476{
477 return configConfirm(i18n.unbind_ask, title, location);
478}
479
480function confirmUnbind(/* String */ title, /* String */ location)
481{
482 return configConfirm(i18n.unbind_ask, title, location);
483}
484
485function addOption(list, target)
486{
487 var html = "";
488 for (i in list) {
489 var sel = list[i].id == selectedPid ? '" selected="selected' : '';
490 html += '<option value="' + list[i].id + sel + '">' + list[i].name + '</option>';
491 }
492 if (html) target.html(html);
493}
494
495var configSelection_pid = false;
496var configSelection_factory = false;
497$(document).ready(function() {
498 configSelection_pid = $('#configSelection_pid');
499 configSelection_factory = $('#configSelection_factory');
500 $(".statline").html(configData.status ? i18n.stat_ok : i18n.stat_missing);
501 $("#config_content").css("display", configData.status ? "block" : "none");
502 if (configData.status) {
503 addOption(configData.pids, $("#configSelection_pid"));
504 addOption(configData.fpids, $("#configSelection_factory"));
505 }
506 if (selectedPid) configure();
507});