blob: 9c66195bf39169e3e2cd90cc8661d0e4aa48bdf5 [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
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000026var factoryBody = false;
27var factoryRow = false;
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000028
29
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000030// editor dialog
31var editor = false;
Valentin Valchevde160882010-03-22 09:30:38 +000032var editorMessage = 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;
Carsten Ziegelerd2637c32012-12-11 17:46:47 +000036 // we have to add a cache killer for IE8
Carsten Ziegeler0d98fa912013-10-21 11:11:43 +000037 var postUri = uri + '?post=true&';
Carsten Ziegelerd2637c32012-12-11 17:46:47 +000038 if ( create ) {
Felix Meschberger27870e82012-12-28 15:19:38 +000039 postUri += param.create + '=1&';
Carsten Ziegelerd2637c32012-12-11 17:46:47 +000040 }
41 postUri = postUri + 'ts='+new Date().getMilliseconds();
Carsten Ziegeler0d98fa912013-10-21 11:11:43 +000042 $.get(postUri, null, displayConfigForm, 'json');
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000043}
44
45function displayConfigForm(obj) {
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000046 var parent = document.getElementById('editorTable');
47 clearChildren( parent )
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000048
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000049 var trEl = tr( );
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000050 parent.appendChild( trEl );
51
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000052 var tdEl = td( null, { colSpan: "2" } );
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000053 trEl.appendChild( tdEl );
54
55 var formEl = createElement( "form", null, {
Carsten Ziegeler149faaa2010-03-10 16:41:53 +000056 id : "editorForm",
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000057 method: "POST",
58 action: pluginRoot + "/" + obj.pid
59 });
60 tdEl.appendChild( formEl );
61
62 var inputEl = createElement( "input", null, {
63 type: "hidden",
Felix Meschberger27870e82012-12-28 15:19:38 +000064 name: param.apply,
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000065 value: "true"
66 });
67 formEl.appendChild( inputEl );
68
69 // add the factory PID as a hidden form field if present
70 if (obj.factoryPid)
71 {
72 inputEl = createElement( "input", null, {
73 type: "hidden",
74 name: "factoryPid",
75 value: obj.factoryPid
76 });
77 formEl.appendChild( inputEl );
78 }
79
80 // add the PID filter as a hidden form field if present
Felix Meschberger27870e82012-12-28 15:19:38 +000081 if (obj[ param.pidFilter ])
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000082 {
83 inputEl = createElement( "input", null, {
84 type: "hidden",
Felix Meschberger27870e82012-12-28 15:19:38 +000085 name: param.pidFilter,
Felix Meschbergerb812b2e2010-02-18 15:36:53 +000086 value: obj.pidFilter
87 });
88 formEl.appendChild( inputEl );
89 }
90
91 inputEl = createElement( "input", null, {
92 type: "hidden",
93 name: "action",
94 value: "ajaxConfigManager"
95 });
96 formEl.appendChild( inputEl );
97
Carsten Ziegeler434525a2015-01-02 15:55:51 +000098 inputEl = createElement( "input", null, {
99 type: "hidden",
100 name: "$location",
101 id: "lochidden"
102 });
103 formEl.appendChild( inputEl );
104
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000105 var tableEl = createElement( "table", null, {
106 border: 0,
107 width: "100%"
108 });
109 formEl.appendChild( tableEl );
110
111 var bodyEl = createElement( "tbody" );
112 tableEl.appendChild( bodyEl );
113
114 if (obj.description)
115 {
116 trEl = tr( );
Valentin Valchevf7fe52e2014-11-17 13:07:24 +0000117 tdEl = td( null, { colSpan: "3" } );
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000118 addText( tdEl, obj.description );
119 trEl.appendChild( tdEl );
120 bodyEl.appendChild( trEl );
121 }
122
Felix Meschbergera87e8592011-12-17 16:19:41 +0000123 if (obj.properties)
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000124 {
Felix Meschbergera87e8592011-12-17 16:19:41 +0000125 printForm(bodyEl, obj.properties);
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000126 }
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000127
128 printConfigurationInfo(parent, obj);
Valentin Valchevde160882010-03-22 09:30:38 +0000129 if ( obj.service_location && obj.bundle_location && obj.service_location != obj.bundle_location) {
130 editorMessage.removeClass('ui-helper-hidden').text(i18n.err_bind.msgFormat(obj.pid, obj.bundle_location, obj.service_location));
131 } else editorMessage.addClass('ui-helper-hidden');
Valentin Valchev0fc8b7b2010-04-15 12:33:58 +0000132
133 // ugly workaround for IE6 and IE7 - these browsers don't show correctly the dialog
134 var ua = navigator.userAgent;
135 if (ua.indexOf('MSIE 6') != -1 || ua.indexOf('MSIE 7') != -1) $(parent).html(parent.innerHTML);
136
Felix Meschberger07741202011-07-07 11:55:53 +0000137 initStaticWidgets(editor
138 .attr('__pid', obj.pid)
139 .attr('__location', obj.bundleLocation?obj.bundleLocation:'')
140 .dialog('option', 'title', obj.title)
141 .dialog('open'));
Carsten Ziegelerb0efb6d2014-12-29 14:24:03 +0000142
143 // autosize
144 $('textarea').trigger('autosize.resize');
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000145}
146
Valentin Valchevf7fe52e2014-11-17 13:07:24 +0000147/* Element */ function addDefaultValue( /* Element */ element ) {
148 if (element) {
149 element.appendChild(
150 createElement('span', 'default_value ui-state-highlight1 ui-icon ui-icon-alert', {
151 title : i18n.dflt_value
152 })
153 );
154 }
155 return element;
156}
157
Felix Meschbergera87e8592011-12-17 16:19:41 +0000158function printForm( /* Element */ parent, /* Object */ properties ) {
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000159 var propList;
Felix Meschbergera87e8592011-12-17 16:19:41 +0000160 for (var prop in properties)
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000161 {
Felix Meschbergera87e8592011-12-17 16:19:41 +0000162 var attr = properties[prop];
Valentin Valchevf7fe52e2014-11-17 13:07:24 +0000163
164 // create optionality element
165 var optElement = false;
166 if (attr.optional) {
167 var elAttributes = {
168 type: "checkbox",
169 name: "opt" + prop,
170 title: i18n.opt_value
171 };
172 if (attr.is_set) {
173 elAttributes['checked'] = 'checked';
174 }
175 optElement = createElement( "input", "optionality", elAttributes);
176 } else {
177 optElement = text( "" );
178 }
179 // create the raw
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000180 var trEl = tr( null, null, [
Valentin Valchevf7fe52e2014-11-17 13:07:24 +0000181 td( null, null, [ optElement ] ),
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000182 td( null, null, [ text( attr.name ) ] )
183 ]);
184 parent.appendChild( trEl );
185
186 var tdEl = td( null, { style: { width: "99%" } } );
187 trEl.appendChild( tdEl );
188
189 if (attr.value != undefined)
190 {
191 // check is required to also handle empty strings, 0 and false
Valentin Valchevcb68caa2014-10-20 07:48:07 +0000192 var inputName = (prop == "action" || prop == "propertylist" || prop == "apply" || prop == "delete") ? '$' + prop : prop;
Valentin Valchevf7fe52e2014-11-17 13:07:24 +0000193 var inputEl = createInput( inputName, attr.value, attr.type, '99%' );
194 tdEl.appendChild( inputEl );
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000195 tdEl.appendChild( createElement( "br" ) );
196 }
197 else if (typeof(attr.type) == 'object')
198 {
199 // assume attr.values and multiselect
200 createMultiSelect( tdEl, prop, attr.values, attr.type, '99%' );
201 tdEl.appendChild( createElement( "br" ) );
202 }
203 else if (attr.values.length == 0)
204 {
205 tdEl.appendChild( createSpan( prop, "", attr.type ) );
206 }
207 else
208 {
209 for (var i=0;i<attr.values.length;i++)
210 {
211 tdEl.appendChild( createSpan( prop, attr.values[i], attr.type ) );
212 }
213 }
214
Valentin Valchevf7fe52e2014-11-17 13:07:24 +0000215 if (!attr.is_set) {
216 addDefaultValue( tdEl );
217 }
218
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000219 if (attr.description)
220 {
221 addText( tdEl, attr.description );
222 }
223
224 if (propList) {
225 propList += ',' + prop;
226 } else {
227 propList = prop;
228 }
229 }
230
231 parent.appendChild( createElement( "input", null, {
232 type: "hidden",
Felix Meschberger27870e82012-12-28 15:19:38 +0000233 name: param.propertylist,
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000234 value: propList
235 })
236 );
Felix Meschbergera87e8592011-12-17 16:19:41 +0000237
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000238 // FIX for IE6 and above: checkbox can only be checked after it is in the DOM
239 $(".checked_box").attr("checked", true).removeClass("checked_box");
240}
241
242function printConfigurationInfo( /* Element */ parent, obj )
243{
244 parent.appendChild( tr( null, null, [
245 createElement( "th", null, { colSpan: "2" }, [
246 text( i18n.cfg_title )
247 ])
248 ])
249 );
250
251 parent.appendChild( tr( null, null, [
252 td( null, null, [
253 text( i18n.pid )
254 ]),
255 td( null, null, [
256 text( obj.pid )
257 ])
258 ])
259 );
260
261 if (obj.factoryPid)
262 {
263 parent.appendChild( tr( null, null, [
264 td( null, null, [
265 text( i18n.fpid )
266 ]),
267 td( null, null, [
268 text( obj.factoryPid )
269 ])
270 ])
271 );
272 }
273
Carsten Ziegeler434525a2015-01-02 15:55:51 +0000274 var binding = obj.bundle_location;
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000275 if (!binding)
276 {
277 binding = i18n.unbound;
Carsten Ziegeler434525a2015-01-02 15:55:51 +0000278 } else {
279 $("#lochidden").val(binding);
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000280 }
281
282 parent.appendChild( tr( null, null, [
283 td( null, null, [
284 text( i18n.binding )
285 ]),
286 td( null, null, [
Carsten Ziegeler434525a2015-01-02 15:55:51 +0000287 createElement( "input", null, {
288 type: "text",
289 name: "$location",
290 style: { width: '99%' },
291 value: binding,
292 id: "locinput"
293 })
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000294 ])
295 ])
296 );
Carsten Ziegeler434525a2015-01-02 15:55:51 +0000297 if ( binding === i18n.unbound ) {
298 $("#locinput").addClass("placeholder-active");
299 }
300 $("#locinput").on("focus", function() {
301 if ($("#locinput").val() === i18n.unbound) {
302 $("#locinput").removeClass("placeholder-active");
303 $("#locinput").val("");
304 }
305 });
306 $("#locinput").on("blur", function() {
307 if($("#locinput").val() === "") {
308 $("#locinput").val(i18n.unbound);
309 $("#locinput").addClass("placeholder-active");
310 }
311 });
312 $("#locinput").on("keydown", function(event) {
313 if (event.keyCode == 27){
314 $("#locinput").val("");
315 }
316 });
317 if ( obj.bundleLocation && obj.bundleLocation != "" ) {
318 parent.appendChild( tr( null, null, [
319 td( null, null, [
320 text( "" )
321 ]),
322 td( null, null, [
323 text( obj.bundleLocation )
324 ])
325 ])
326 );
327 }
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000328}
329
330
331var spanCounter = 0;
332/* Element */ function createSpan(prop, value, type) {
333 spanCounter++;
334 var newId = prop + spanCounter;
335
336 var addButton = createElement("input", null,
337 { type: "button",
338 style: {width : "5%"},
339 value: "+"
340 }
341 );
342 $(addButton).click(function() {addValue(prop, newId)});
343 var remButton = createElement("input", null,
344 { type: "button",
345 style: {width : "5%"},
346 value: "-"
347 }
348 );
349 $(remButton).click(function() {removeValue(newId)});
350 var spanEl = createElement( "span", null, { id: newId }, [
351 createInput( prop, value, type, '89%' ), addButton, remButton,
352 createElement("br")
353 ]);
354
355 return spanEl;
356}
357
358/* Element */ function createInput(prop, value, type, width) {
359 if (type == 11) { // AttributeDefinition.BOOLEAN
360
361 var inputEl = createElement( "input", null, {
362 type: "checkbox",
363 name: prop,
364 value: "true"
365 });
366
367 if (value && typeof(value) != "boolean")
368 {
369 value = value.toString().toLowerCase() == "true";
370 }
371 if (value)
372 {
373 $(inputEl).addClass("checked_box");
374 }
375 var hiddenEl = createElement( "input", null, {
376 type: "hidden",
377 name: prop,
378 value: "false"
379 });
380 var divEl = createElement("div");
381 divEl.appendChild(inputEl);
382 divEl.appendChild(hiddenEl);
383 return divEl;
384
385 } else if (typeof(type) == "object") { // predefined values
386
387 var selectEl = createElement( "select", null, {
388 name: prop,
389 style: { width: width }
390 });
391
392 var labels = type.labels;
393 var values = type.values;
394 for (var idx in labels) {
395 var optionEl = createElement( "option", null, {
396 value: values[idx]
397 }, [ text( labels[idx] ) ]);
398
399 if (value == values[idx])
400 {
401 optionEl.setAttribute( "selected", true );
402 }
403 selectEl.appendChild( optionEl );
404 }
405
406 return selectEl;
407
Carsten Ziegelerb0efb6d2014-12-29 14:24:03 +0000408 } else if (type == 12) { // Metatype 1.2: Attr type 12 is PASSWORD
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000409 return createElement( "input", null, {
Carsten Ziegelerb0efb6d2014-12-29 14:24:03 +0000410 type: "password",
411 name: prop,
412 value: value,
413 style: { width: width }
414 });
415 } else { // Simple
416 var textareaEl = createElement( "textarea", null, {
417 name: prop,
418 style: { width: width }
419 });
420 addText(textareaEl, value.toString());
421 $(textareaEl).autosize();
422 return textareaEl;
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000423 }
424}
425
426function createMultiSelect(/* Element */ parent, prop, values, options, width) {
427 // convert value list into 'set'
428 var valueSet = new Object();
429 for (var idx in values) {
430 valueSet[ values[idx] ] = true;
431 }
432
433 var labels = options.labels;
434 var values = options.values;
435 for (var idx in labels) {
436
437 var inputEl = createElement( "input", null, {
438 type: "checkbox",
439 name: prop,
440 value: values[idx]
441 });
442
443 if (valueSet[ values[idx] ])
444 {
445 inputEl.setAttribute( "checked", true );
446 }
447
448 var labelEl = createElement( "label", "multiselect" );
449 labelEl.appendChild( inputEl );
450 addText( labelEl, labels[idx] );
451
452 parent.appendChild( labelEl );
453 }
454}
455
456
457function addValue(prop, vidx)
458{
459 var span = document.getElementById(vidx);
460 if (!span)
461 {
462 return;
463 }
464 var newSpan = createSpan(prop, '');
465 span.parentNode.insertBefore(newSpan, span.nextSibling);
466 // FIX for IE6 and above: checkbox can only be checked after it is in the DOM
467 $(".checked_box").attr("checked", true).removeClass("checked_box");
468 //$(span).ready(initStaticWidgets);
469}
470
471function removeValue(vidx)
472{
473 var span = document.getElementById(vidx);
474 if (!span)
475 {
476 return;
477 }
478 span.parentNode.removeChild(span);
479}
480
481function configConfirm(/* String */ message, /* String */ title, /* String */ location)
482{
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000483 if (title) {
484 message += "\r\n" + i18n.del_config + title;
485 }
486 if (location) {
487 message += "\r\n" + i18n.del_bundle + location;
488 }
489
490 return confirm(message);
491}
492
Felix Meschberger07741202011-07-07 11:55:53 +0000493function deleteConfig(/* String */ configId, /* String */ bundleLocation)
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000494{
Felix Meschberger07741202011-07-07 11:55:53 +0000495 if ( configConfirm(i18n.del_ask, configId, bundleLocation) ) {
Valentin Valchev4317f092014-11-26 10:04:11 +0000496 $.post(pluginRoot + '/' + configId, param.apply + '=1&' + param.dele + '=1', function() {
Felix Meschberger07741202011-07-07 11:55:53 +0000497 document.location.href = pluginRoot;
498 }, 'json');
499 return true;
500 }
501 return false;
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000502}
503
Felix Meschberger07741202011-07-07 11:55:53 +0000504function unbindConfig(/* String */ configId, /* String */ bundleLocation)
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000505{
Felix Meschberger07741202011-07-07 11:55:53 +0000506 if ( configConfirm(i18n.unbind_ask, configId, bundleLocation) ) {
Valentin Valchev4317f092014-11-26 10:04:11 +0000507 $.post(pluginRoot + '/' + configId, param.unbind + '=1', function() {
Felix Meschberger07741202011-07-07 11:55:53 +0000508 document.location.href = pluginRoot + '/' + configId;
509 }, 'json');
510 return true;
511 }
512 return false;
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000513}
514
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000515function addConfig(conf) {
516 var tr = configRow.clone().appendTo(configBody);
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000517
518 if (!conf.has_config) {
519 tr.find('td:eq(0)').empty();
520 }
Felix Meschberger67726fe2010-03-17 06:55:00 +0000521
522 // rendering name - indented if factory pid is set
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000523 var nms = tr.find('td:eq(1) div');
Felix Meschberger67726fe2010-03-17 06:55:00 +0000524 if (conf.fpid) {
Carsten Ziegelere1f29c42014-12-29 13:21:01 +0000525 if (conf.nameHint) {
526 nms.after("<span title='" + conf.id + "'>" + conf.nameHint + "</span>");
527 } else {
528 nms.after(conf.id);
529 }
Felix Meschberger67726fe2010-03-17 06:55:00 +0000530 tr.attr('fpid', conf.name);
531 } else {
532 nms.addClass('ui-helper-hidden').parent().text(conf.name);
533 }
534
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000535 tr.find('td:eq(1)').click(function() { // name & edit
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000536 configure(conf.id);
537 });
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000538 tr.find('td:eq(2)').html(conf.bundle ? '<a href="' + pluginRoot + '/../bundles/' + conf.bundle + '">' + conf.bundle_name + '</a>' : '-'); // binding
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000539
540 // buttons
541 tr.find('li:eq(0)').click(function() { // edit
542 configure(conf.id);
543 });
544 tr.find('li:eq(2)').click(function() { // delete
Felix Meschberger07741202011-07-07 11:55:53 +0000545 deleteConfig(conf.id, conf.bundle_name);
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000546 });
Felix Meschberger07741202011-07-07 11:55:53 +0000547 if (conf.bundle) {
548 tr.find('li:eq(1)').click(function() { // unbind
549 unbindConfig(conf.id, conf.bundle_name);
550 }).removeClass('ui-state-disabled');
551 }
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000552}
553
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000554function addFactoryConfig(conf) {
Felix Meschberger67726fe2010-03-17 06:55:00 +0000555 var tr = factoryRow.clone().appendTo(configTable).attr('fpid', conf.name);
556 //tr.find('td:eq(1)').text(conf.id); // fpid
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000557 tr.find('td:eq(1)').text(conf.name).click(function() { // name & edit
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000558 configure(conf.id, true);
559 });
560 // buttons
Valentin Valchev605354e2014-12-19 08:22:00 +0000561 tr.find('li:eq(0)').click(function() { // edit
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000562 configure(conf.id, true);
563 });
564}
565
Felix Meschberger67726fe2010-03-17 06:55:00 +0000566function treetableExtraction(node) {
567 var td = $(node);
568 var text = td.text();
569 if (!text) return text;
570
571 // current sort order
572 var desc = $(this)[0].sortList[0][1];
573
574 var row = td.parent();
575 var fpid = row.attr('fpid');
576
577 // factory row
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000578 if ( row.hasClass('fpid') && fpid) return fpid + (desc==1?1:0) + text;
Felix Meschberger67726fe2010-03-17 06:55:00 +0000579
580 // bundle or name row
581 if ( fpid ) return fpid + desc + text;
582
583 return mixedLinksExtraction(node);
584};
585
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000586$(document).ready(function() {
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000587 configContent = $('#configContent');
588 // config table list
Felix Meschberger67726fe2010-03-17 06:55:00 +0000589 configTable = $('#configTable');
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000590 configBody = configTable.find('tbody');
Felix Meschberger67726fe2010-03-17 06:55:00 +0000591 configRow = configBody.find('tr:eq(0)').clone();
592 factoryRow = configBody.find('tr:eq(1)').clone();
Carsten Ziegeler434525a2015-01-02 15:55:51 +0000593
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000594 // setup button - cannot inline in dialog option because of i18n
595 var _buttons = {};
596 _buttons[i18n.abort] = function() {
597 $(this).dialog('close');
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000598 }
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000599 _buttons[i18n.reset] = function() {
600 var form = document.getElementById('editorForm');
601 if (form) form.reset();
602 }
Felix Meschberger07741202011-07-07 11:55:53 +0000603 _buttons[i18n.del] = function() {
604 if (deleteConfig($(this).attr('__pid'), $(this).attr('__location'))) {
605 $(this).dialog('close');
606 }
607 }
608 _buttons[i18n.unbind_btn] = function() {
609 unbindConfig($(this).attr('__pid'), $(this).attr('__location'));
610 }
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000611 _buttons[i18n.save] = function() {
Carsten Ziegeler434525a2015-01-02 15:55:51 +0000612 if ( $("#locinput").val() === i18n.unbound ) {
613 $("#lochidden").val("");
614 } else {
615 $("#lochidden").val($("#locinput").val());
616 }
617
Valentin Valchevf7fe52e2014-11-17 13:07:24 +0000618 // get all the configuration properties names
619 var propListElement = $(this).find('form').find('[name=propertylist]');
620 var propListArray = propListElement.val().split(',');
621
622 // removes the properties, that are unchecked
623 $(this).find('form').find('input.optionality:not(:checked)').each( function(idx, el) {
624 var name = $(el).attr('name').substring(3); // name - 'opt'
625 var index = propListArray.indexOf(name);
626 if (index >= 0) {
627 propListArray.splice(index, 1);
628 }
629 });
630 propListElement.val(propListArray.join(','));
631
Felix Meschbergerc89425a2013-11-04 16:08:19 +0000632 $.post(pluginRoot + '/' + $(this).attr('__pid'), $(this).find('form').serialize(), function() {
Valentin Valchev4b25d4f2011-09-15 07:06:36 +0000633 // reload on success - prevents AJAX errors - see FELIX-3116
634 document.location.href = pluginRoot;
635 });
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000636 $(this).dialog('close');
637 }
638 // prepare editor, but don't open yet!
639 editor = $('#editor').dialog({
640 autoOpen : false,
641 modal : true,
642 width : '90%',
643 closeText: i18n.abort,
644 buttons : _buttons
645 });
Valentin Valchevde160882010-03-22 09:30:38 +0000646 editorMessage = editor.find('p');
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000647
648 // display the configuration data
649 $(".statline").html(configData.status ? i18n.stat_ok : i18n.stat_missing);
650 if (configData.status) {
Felix Meschberger67726fe2010-03-17 06:55:00 +0000651 configBody.empty();
652 var factories = {};
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000653
Felix Meschberger67726fe2010-03-17 06:55:00 +0000654 for(var i in configData.pids) {
655 var c = configData.pids[i];
656 if (c.fpid) {
657 if (!factories[c.fpid]) factories[c.fpid] = new Array();
658 factories[c.fpid].push(c);
659 } else {
660 addConfig(c);
661 }
662 }
663 for(var i in configData.fpids) {
664 addFactoryConfig(configData.fpids[i]);
Felix Meschberger1e671e12010-03-13 15:09:51 +0000665
Felix Meschbergerb58af942011-12-19 12:54:03 +0000666 var fpid = configData.fpids[i].id;
667 var confs = factories[ fpid ];
668 if (confs) {
669 for (var j in confs) {
670 addConfig(confs[j]);
671 }
672 delete factories[ fpid ];
Felix Meschberger67726fe2010-03-17 06:55:00 +0000673 }
674 }
Felix Meschbergerb58af942011-12-19 12:54:03 +0000675 for(var fpid in factories) {
676 var flist = factories[fpid];
677 for(var i in flist) {
678 delete flist[i].fpid; // render as regular config
679 addConfig(flist[i]);
680 }
681 }
Felix Meschberger67726fe2010-03-17 06:55:00 +0000682 initStaticWidgets(configTable);
683
684 // init tablesorte
685 configTable.tablesorter({
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000686 headers: {
687 0: { sorter: false },
688 3: { sorter: false }
689 },
690 sortList: [[1,1]],
Felix Meschberger67726fe2010-03-17 06:55:00 +0000691 textExtraction: treetableExtraction
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000692 }).bind('sortStart', function() { // clear cache, otherwise extraction will not work
Felix Meschberger67726fe2010-03-17 06:55:00 +0000693 var table = $(this).trigger('update');
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000694 }).find('th:eq(1)').click();
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000695 } else {
696 configContent.addClass('ui-helper-hidden');
697 }
698 if (selectedPid) configure(selectedPid);
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000699});