blob: c282eb8f4293f622d6ac75aa8c0fbe2ac0815ac5 [file] [log] [blame]
Felix Meschbergerb812b2e2010-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 */
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000017// tables container - will get hidden, when no config service available
18var configContent = false;
19
20// config table list
21var configTable = false;
22var configBody = false;
23var configRow = false;
24
25// factories table list
26var factoryTable = false;
27var factoryBody = false;
28var factoryRow = false;
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000029
30
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000031// editor dialog
32var editor = false;
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000033
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000034function configure(pid, create) {
35 var uri = pluginRoot + '/' + pid;
36 $.post(create ? uri + '?create=1' : uri, null, displayConfigForm, 'json');
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000037}
38
39function displayConfigForm(obj) {
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000040 var parent = document.getElementById('editorTable');
41 clearChildren( parent )
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000042
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000043 var trEl = tr( );
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000044 parent.appendChild( trEl );
45
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000046 var tdEl = td( null, { colSpan: "2" } );
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000047 trEl.appendChild( tdEl );
48
49 var formEl = createElement( "form", null, {
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000050 id : "editorForm",
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000051 method: "POST",
52 action: pluginRoot + "/" + obj.pid
53 });
54 tdEl.appendChild( formEl );
55
56 var inputEl = createElement( "input", null, {
57 type: "hidden",
58 name: "apply",
59 value: "true"
60 });
61 formEl.appendChild( inputEl );
62
63 // add the factory PID as a hidden form field if present
64 if (obj.factoryPid)
65 {
66 inputEl = createElement( "input", null, {
67 type: "hidden",
68 name: "factoryPid",
69 value: obj.factoryPid
70 });
71 formEl.appendChild( inputEl );
72 }
73
74 // add the PID filter as a hidden form field if present
75 if (obj.pidFilter)
76 {
77 inputEl = createElement( "input", null, {
78 type: "hidden",
79 name: "pidFilter",
80 value: obj.pidFilter
81 });
82 formEl.appendChild( inputEl );
83 }
84
85 inputEl = createElement( "input", null, {
86 type: "hidden",
87 name: "action",
88 value: "ajaxConfigManager"
89 });
90 formEl.appendChild( inputEl );
91
92 var tableEl = createElement( "table", null, {
93 border: 0,
94 width: "100%"
95 });
96 formEl.appendChild( tableEl );
97
98 var bodyEl = createElement( "tbody" );
99 tableEl.appendChild( bodyEl );
100
101 if (obj.description)
102 {
103 trEl = tr( );
104 tdEl = td( null, { colSpan: "2" } );
105 addText( tdEl, obj.description );
106 trEl.appendChild( tdEl );
107 bodyEl.appendChild( trEl );
108 }
109
110 if (obj.propertylist == 'properties')
111 {
112 printTextArea(bodyEl, obj.properties);
113 }
114 else
115 {
116 printForm(bodyEl, obj);
117 }
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000118
119 printConfigurationInfo(parent, obj);
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000120 initStaticWidgets(editor.attr('__pid', obj.pid).dialog('option', 'title', obj.title).dialog('open'));
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000121}
122
123function printTextArea(/* Element */ parent, props )
124{
125
126 var propsValue = "";
127 for (var key in props)
128 {
129 propsValue += key + ' = ' + props[key] + '\r\n';
130 }
131
132 parent.appendChild(
133 tr( null, null, [
134 td( null, null, [
135 text( i18n.props_title )
136 ]),
137 td( null, { style: { width: "99%" } }, [
138 createElement( "textarea", null, {
139 name: "properties",
Guillaume Nodet283faa32010-03-04 20:54:39 +0000140 style: { height: "20em", width: "99%" }
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000141 }, [ text( propsValue ) ] ),
Guillaume Nodet283faa32010-03-04 20:54:39 +0000142 createElement( "br" ),
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000143 text( i18n.props_enter )
144 ])
145 ])
146 );
147}
148
149function printForm( /* Element */ parent, obj ) {
150 var propList;
151 for (var idx in obj.propertylist)
152 {
153 var prop = obj.propertylist[idx];
154 var attr = obj[prop];
155
156 var trEl = tr( null, null, [
157 td( null, null, [ text( attr.name ) ] )
158 ]);
159 parent.appendChild( trEl );
160
161 var tdEl = td( null, { style: { width: "99%" } } );
162 trEl.appendChild( tdEl );
163
164 if (attr.value != undefined)
165 {
166 // check is required to also handle empty strings, 0 and false
167 tdEl.appendChild( createInput( prop, attr.value, attr.type, '99%' ) );
168 tdEl.appendChild( createElement( "br" ) );
169 }
170 else if (typeof(attr.type) == 'object')
171 {
172 // assume attr.values and multiselect
173 createMultiSelect( tdEl, prop, attr.values, attr.type, '99%' );
174 tdEl.appendChild( createElement( "br" ) );
175 }
176 else if (attr.values.length == 0)
177 {
178 tdEl.appendChild( createSpan( prop, "", attr.type ) );
179 }
180 else
181 {
182 for (var i=0;i<attr.values.length;i++)
183 {
184 tdEl.appendChild( createSpan( prop, attr.values[i], attr.type ) );
185 }
186 }
187
188 if (attr.description)
189 {
190 addText( tdEl, attr.description );
191 }
192
193 if (propList) {
194 propList += ',' + prop;
195 } else {
196 propList = prop;
197 }
198 }
199
200 parent.appendChild( createElement( "input", null, {
201 type: "hidden",
202 name: "propertylist",
203 value: propList
204 })
205 );
206 // FIX for IE6 and above: checkbox can only be checked after it is in the DOM
207 $(".checked_box").attr("checked", true).removeClass("checked_box");
208}
209
210function printConfigurationInfo( /* Element */ parent, obj )
211{
212 parent.appendChild( tr( null, null, [
213 createElement( "th", null, { colSpan: "2" }, [
214 text( i18n.cfg_title )
215 ])
216 ])
217 );
218
219 parent.appendChild( tr( null, null, [
220 td( null, null, [
221 text( i18n.pid )
222 ]),
223 td( null, null, [
224 text( obj.pid )
225 ])
226 ])
227 );
228
229 if (obj.factoryPid)
230 {
231 parent.appendChild( tr( null, null, [
232 td( null, null, [
233 text( i18n.fpid )
234 ]),
235 td( null, null, [
236 text( obj.factoryPid )
237 ])
238 ])
239 );
240 }
241
242 var binding = obj.bundleLocation;
243 if (!binding)
244 {
245 binding = i18n.unbound;
246 }
247
248 parent.appendChild( tr( null, null, [
249 td( null, null, [
250 text( i18n.binding )
251 ]),
252 td( null, null, [
253 text( binding )
254 ])
255 ])
256 );
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000257
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000258}
259
260
261var spanCounter = 0;
262/* Element */ function createSpan(prop, value, type) {
263 spanCounter++;
264 var newId = prop + spanCounter;
265
266 var addButton = createElement("input", null,
267 { type: "button",
268 style: {width : "5%"},
269 value: "+"
270 }
271 );
272 $(addButton).click(function() {addValue(prop, newId)});
273 var remButton = createElement("input", null,
274 { type: "button",
275 style: {width : "5%"},
276 value: "-"
277 }
278 );
279 $(remButton).click(function() {removeValue(newId)});
280 var spanEl = createElement( "span", null, { id: newId }, [
281 createInput( prop, value, type, '89%' ), addButton, remButton,
282 createElement("br")
283 ]);
284
285 return spanEl;
286}
287
288/* Element */ function createInput(prop, value, type, width) {
289 if (type == 11) { // AttributeDefinition.BOOLEAN
290
291 var inputEl = createElement( "input", null, {
292 type: "checkbox",
293 name: prop,
294 value: "true"
295 });
296
297 if (value && typeof(value) != "boolean")
298 {
299 value = value.toString().toLowerCase() == "true";
300 }
301 if (value)
302 {
303 $(inputEl).addClass("checked_box");
304 }
305 var hiddenEl = createElement( "input", null, {
306 type: "hidden",
307 name: prop,
308 value: "false"
309 });
310 var divEl = createElement("div");
311 divEl.appendChild(inputEl);
312 divEl.appendChild(hiddenEl);
313 return divEl;
314
315 } else if (typeof(type) == "object") { // predefined values
316
317 var selectEl = createElement( "select", null, {
318 name: prop,
319 style: { width: width }
320 });
321
322 var labels = type.labels;
323 var values = type.values;
324 for (var idx in labels) {
325 var optionEl = createElement( "option", null, {
326 value: values[idx]
327 }, [ text( labels[idx] ) ]);
328
329 if (value == values[idx])
330 {
331 optionEl.setAttribute( "selected", true );
332 }
333 selectEl.appendChild( optionEl );
334 }
335
336 return selectEl;
337
338 } else { // Simple
339 return createElement( "input", null, {
340 type: "text",
341 name: prop,
342 value: value,
343 style: { width: width }
344 });
345 }
346}
347
348function createMultiSelect(/* Element */ parent, prop, values, options, width) {
349 // convert value list into 'set'
350 var valueSet = new Object();
351 for (var idx in values) {
352 valueSet[ values[idx] ] = true;
353 }
354
355 var labels = options.labels;
356 var values = options.values;
357 for (var idx in labels) {
358
359 var inputEl = createElement( "input", null, {
360 type: "checkbox",
361 name: prop,
362 value: values[idx]
363 });
364
365 if (valueSet[ values[idx] ])
366 {
367 inputEl.setAttribute( "checked", true );
368 }
369
370 var labelEl = createElement( "label", "multiselect" );
371 labelEl.appendChild( inputEl );
372 addText( labelEl, labels[idx] );
373
374 parent.appendChild( labelEl );
375 }
376}
377
378
379function addValue(prop, vidx)
380{
381 var span = document.getElementById(vidx);
382 if (!span)
383 {
384 return;
385 }
386 var newSpan = createSpan(prop, '');
387 span.parentNode.insertBefore(newSpan, span.nextSibling);
388 // FIX for IE6 and above: checkbox can only be checked after it is in the DOM
389 $(".checked_box").attr("checked", true).removeClass("checked_box");
390 //$(span).ready(initStaticWidgets);
391}
392
393function removeValue(vidx)
394{
395 var span = document.getElementById(vidx);
396 if (!span)
397 {
398 return;
399 }
400 span.parentNode.removeChild(span);
401}
402
403function configConfirm(/* String */ message, /* String */ title, /* String */ location)
404{
405 var message = i18n.del_ask;
406
407 if (title) {
408 message += "\r\n" + i18n.del_config + title;
409 }
410 if (location) {
411 message += "\r\n" + i18n.del_bundle + location;
412 }
413
414 return confirm(message);
415}
416
417function confirmDelete(/* String */ title, /* String */ location)
418{
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000419 return configConfirm(i18n.del_ask, title, location);
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000420}
421
422function confirmUnbind(/* String */ title, /* String */ location)
423{
424 return configConfirm(i18n.unbind_ask, title, location);
425}
426
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000427function addConfig(conf) {
428 var tr = configRow.clone().appendTo(configBody);
Felix Meschberger1e671e12010-03-13 15:09:51 +0000429 tr.find('td:eq(1)').text(conf.fpid ? conf.fpid : '-'); // fpid
430 tr.find('td:eq(0)').text(conf.name).click(function() { // name & edit
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000431 configure(conf.id);
432 });
433 tr.find('td:eq(2)').html(conf.bundle ? '<a href="' + pluginRoot + '/../bundles/' + conf.bundle + '">' + conf.bundle_name + '</a>' : '-'); // binding
434
435 // buttons
436 tr.find('li:eq(0)').click(function() { // edit
437 configure(conf.id);
438 });
439 tr.find('li:eq(2)').click(function() { // delete
440 if ( confirmDelete(conf.id, conf.bundle_name) ) {
441 $.post(pluginRoot + '/' + conf.id + '?apply=1&delete=1', null, function() {
442 document.location.href = pluginRoot;
443 }, 'json');
444 }
445 });
446 if (conf.bundle) tr.find('li:eq(1)').click(function() { // unbind
447 if ( confirmUnbind(conf.id, conf.bundle_name) ) {
448 $.post(pluginRoot + '/' + conf.id + '?apply=1&delete=1', null, function() {
449 document.location.href = pluginRoot + '/' + conf.id;
450 }, 'json');
451 }
452 }).removeClass('ui-state-disabled');
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000453}
454
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000455function addFactoryConfig(conf) {
456 var tr = factoryRow.clone().appendTo(factoryBody);
Felix Meschberger1e671e12010-03-13 15:09:51 +0000457 tr.find('td:eq(1)').text(conf.id); // fpid
458 tr.find('td:eq(0)').text(conf.name).click(function() { // name & edit
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000459 configure(conf.id, true);
460 });
461 // buttons
462 tr.find('li:eq(0)').click(function() { // edit
463 configure(conf.id, true);
464 });
465}
466
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000467$(document).ready(function() {
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000468 configContent = $('#configContent');
469 // config table list
470 configTable = configContent.find('table:eq(0)').tablesorter({
471 headers: { 3: { sorter: false } },
472 textExtraction:mixedLinksExtraction
473 });
474 configBody = configTable.find('tbody');
475 configRow = configBody.find('tr').clone();
476
477 // factories table list
478 factoryTable = configContent.find('table:eq(1)').tablesorter({
479 headers: { 2: { sorter: false } }
480 });
481 factoryBody = factoryTable.find('tbody');
482 factoryRow = factoryBody.find('tr').clone();
Felix Meschberger1e671e12010-03-13 15:09:51 +0000483
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000484 // setup button - cannot inline in dialog option because of i18n
485 var _buttons = {};
486 _buttons[i18n.abort] = function() {
487 $(this).dialog('close');
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000488 }
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000489 _buttons[i18n.reset] = function() {
490 var form = document.getElementById('editorForm');
491 if (form) form.reset();
492 }
493 _buttons[i18n.save] = function() {
494 $.post(pluginRoot + '/' + $(this).attr('__pid') + '?' + $(this).find('form').serialize());
495 $(this).dialog('close');
496 }
497 // prepare editor, but don't open yet!
498 editor = $('#editor').dialog({
499 autoOpen : false,
500 modal : true,
501 width : '90%',
502 closeText: i18n.abort,
503 buttons : _buttons
504 });
505
506 // display the configuration data
507 $(".statline").html(configData.status ? i18n.stat_ok : i18n.stat_missing);
508 if (configData.status) {
509 configBody.empty(); factoryBody.empty();
510
511 for(var i in configData.pids) addConfig(configData.pids[i]);
512 for(var i in configData.fpids) addFactoryConfig(configData.fpids[i]);
513 initStaticWidgets(configContent);
Felix Meschberger1e671e12010-03-13 15:09:51 +0000514
515 // initial sorting orger by name
516 var sorting = [[0,0]];
517 configTable.trigger('sorton', [sorting]);
518 factoryTable.trigger('sorton', [sorting]);
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000519 } else {
520 configContent.addClass('ui-helper-hidden');
521 }
522 if (selectedPid) configure(selectedPid);
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000523});