blob: d4dad3bc3cb482b3cd165cf489b09049edf24945 [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 Valchev0d0723d2015-09-16 12:45:21 +0000496 $.ajax({
497 type : 'POST',
498 url : pluginRoot + '/' + configId,
499 data : param.apply + '=1&' + param.dele + '=1',
500 success : function () {
501 if(!navigateAfterConfigurationClose()) document.location.href = pluginRoot;
502 },
503 dataType : 'json',
504 async : false
505 });
Felix Meschberger07741202011-07-07 11:55:53 +0000506 return true;
507 }
508 return false;
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000509}
510
Felix Meschberger07741202011-07-07 11:55:53 +0000511function unbindConfig(/* String */ configId, /* String */ bundleLocation)
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000512{
Felix Meschberger07741202011-07-07 11:55:53 +0000513 if ( configConfirm(i18n.unbind_ask, configId, bundleLocation) ) {
Valentin Valchev4317f092014-11-26 10:04:11 +0000514 $.post(pluginRoot + '/' + configId, param.unbind + '=1', function() {
Felix Meschberger07741202011-07-07 11:55:53 +0000515 document.location.href = pluginRoot + '/' + configId;
516 }, 'json');
517 return true;
518 }
519 return false;
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000520}
521
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000522function addConfig(conf) {
523 var tr = configRow.clone().appendTo(configBody);
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000524
525 if (!conf.has_config) {
526 tr.find('td:eq(0)').empty();
527 }
Felix Meschberger67726fe2010-03-17 06:55:00 +0000528
529 // rendering name - indented if factory pid is set
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000530 var nms = tr.find('td:eq(1) div');
Felix Meschberger67726fe2010-03-17 06:55:00 +0000531 if (conf.fpid) {
Carsten Ziegelere1f29c42014-12-29 13:21:01 +0000532 if (conf.nameHint) {
533 nms.after("<span title='" + conf.id + "'>" + conf.nameHint + "</span>");
534 } else {
535 nms.after(conf.id);
536 }
Felix Meschberger67726fe2010-03-17 06:55:00 +0000537 tr.attr('fpid', conf.name);
538 } else {
539 nms.addClass('ui-helper-hidden').parent().text(conf.name);
540 }
541
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000542 tr.find('td:eq(1)').click(function() { // name & edit
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000543 configure(conf.id);
544 });
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000545 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 +0000546
547 // buttons
548 tr.find('li:eq(0)').click(function() { // edit
549 configure(conf.id);
550 });
551 tr.find('li:eq(2)').click(function() { // delete
Felix Meschberger07741202011-07-07 11:55:53 +0000552 deleteConfig(conf.id, conf.bundle_name);
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000553 });
Felix Meschberger07741202011-07-07 11:55:53 +0000554 if (conf.bundle) {
555 tr.find('li:eq(1)').click(function() { // unbind
556 unbindConfig(conf.id, conf.bundle_name);
557 }).removeClass('ui-state-disabled');
558 }
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000559}
560
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000561function addFactoryConfig(conf) {
Felix Meschberger67726fe2010-03-17 06:55:00 +0000562 var tr = factoryRow.clone().appendTo(configTable).attr('fpid', conf.name);
563 //tr.find('td:eq(1)').text(conf.id); // fpid
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000564 tr.find('td:eq(1)').text(conf.name).click(function() { // name & edit
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000565 configure(conf.id, true);
566 });
567 // buttons
Valentin Valchev605354e2014-12-19 08:22:00 +0000568 tr.find('li:eq(0)').click(function() { // edit
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000569 configure(conf.id, true);
570 });
571}
572
Felix Meschberger67726fe2010-03-17 06:55:00 +0000573function treetableExtraction(node) {
574 var td = $(node);
575 var text = td.text();
576 if (!text) return text;
577
578 // current sort order
579 var desc = $(this)[0].sortList[0][1];
580
581 var row = td.parent();
582 var fpid = row.attr('fpid');
583
584 // factory row
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000585 if ( row.hasClass('fpid') && fpid) return fpid + (desc==1?1:0) + text;
Felix Meschberger67726fe2010-03-17 06:55:00 +0000586
587 // bundle or name row
588 if ( fpid ) return fpid + desc + text;
589
590 return mixedLinksExtraction(node);
591};
Valentin Valchev0d0723d2015-09-16 12:45:21 +0000592function navigateAfterConfigurationClose() {
593 if(configurationReferer) {
594 window.location = configurationReferer;
595 return true;
596 }
597 return false;
598}
Felix Meschberger67726fe2010-03-17 06:55:00 +0000599
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000600$(document).ready(function() {
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000601 configContent = $('#configContent');
602 // config table list
Felix Meschberger67726fe2010-03-17 06:55:00 +0000603 configTable = $('#configTable');
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000604 configBody = configTable.find('tbody');
Felix Meschberger67726fe2010-03-17 06:55:00 +0000605 configRow = configBody.find('tr:eq(0)').clone();
606 factoryRow = configBody.find('tr:eq(1)').clone();
Carsten Ziegeler434525a2015-01-02 15:55:51 +0000607
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000608 // setup button - cannot inline in dialog option because of i18n
609 var _buttons = {};
610 _buttons[i18n.abort] = function() {
611 $(this).dialog('close');
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000612 }
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000613 _buttons[i18n.reset] = function() {
614 var form = document.getElementById('editorForm');
615 if (form) form.reset();
616 }
Felix Meschberger07741202011-07-07 11:55:53 +0000617 _buttons[i18n.del] = function() {
618 if (deleteConfig($(this).attr('__pid'), $(this).attr('__location'))) {
619 $(this).dialog('close');
620 }
621 }
622 _buttons[i18n.unbind_btn] = function() {
623 unbindConfig($(this).attr('__pid'), $(this).attr('__location'));
624 }
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000625 _buttons[i18n.save] = function() {
Carsten Ziegeler434525a2015-01-02 15:55:51 +0000626 if ( $("#locinput").val() === i18n.unbound ) {
627 $("#lochidden").val("");
628 } else {
629 $("#lochidden").val($("#locinput").val());
630 }
631
Valentin Valchevf7fe52e2014-11-17 13:07:24 +0000632 // get all the configuration properties names
633 var propListElement = $(this).find('form').find('[name=propertylist]');
634 var propListArray = propListElement.val().split(',');
635
636 // removes the properties, that are unchecked
637 $(this).find('form').find('input.optionality:not(:checked)').each( function(idx, el) {
638 var name = $(el).attr('name').substring(3); // name - 'opt'
639 var index = propListArray.indexOf(name);
640 if (index >= 0) {
641 propListArray.splice(index, 1);
642 }
643 });
644 propListElement.val(propListArray.join(','));
645
Valentin Valchev0d0723d2015-09-16 12:45:21 +0000646 $.ajax({
647 type : 'POST',
648 url : pluginRoot + '/' + $(this).attr('__pid'),
649 data : $(this).find('form').serialize(),
650 success : function () {
651 // reload on success - prevents AJAX errors - see FELIX-3116
652 if(!navigateAfterConfigurationClose()) document.location.href = pluginRoot;
653 },
654 async : false
655 })
656 .fail(function () {
657 $(this).dialog('close');
Valentin Valchev4b25d4f2011-09-15 07:06:36 +0000658 });
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000659 }
660 // prepare editor, but don't open yet!
661 editor = $('#editor').dialog({
662 autoOpen : false,
663 modal : true,
664 width : '90%',
665 closeText: i18n.abort,
Valentin Valchev0d0723d2015-09-16 12:45:21 +0000666 buttons : _buttons,
667 close : function( event, ui ) { navigateAfterConfigurationClose(); }
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000668 });
Valentin Valchevde160882010-03-22 09:30:38 +0000669 editorMessage = editor.find('p');
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000670
671 // display the configuration data
672 $(".statline").html(configData.status ? i18n.stat_ok : i18n.stat_missing);
673 if (configData.status) {
Felix Meschberger67726fe2010-03-17 06:55:00 +0000674 configBody.empty();
675 var factories = {};
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000676
Felix Meschberger67726fe2010-03-17 06:55:00 +0000677 for(var i in configData.pids) {
678 var c = configData.pids[i];
679 if (c.fpid) {
680 if (!factories[c.fpid]) factories[c.fpid] = new Array();
681 factories[c.fpid].push(c);
682 } else {
683 addConfig(c);
684 }
685 }
686 for(var i in configData.fpids) {
687 addFactoryConfig(configData.fpids[i]);
Felix Meschberger1e671e12010-03-13 15:09:51 +0000688
Felix Meschbergerb58af942011-12-19 12:54:03 +0000689 var fpid = configData.fpids[i].id;
690 var confs = factories[ fpid ];
691 if (confs) {
692 for (var j in confs) {
693 addConfig(confs[j]);
694 }
695 delete factories[ fpid ];
Felix Meschberger67726fe2010-03-17 06:55:00 +0000696 }
697 }
Felix Meschbergerb58af942011-12-19 12:54:03 +0000698 for(var fpid in factories) {
699 var flist = factories[fpid];
700 for(var i in flist) {
701 delete flist[i].fpid; // render as regular config
702 addConfig(flist[i]);
703 }
704 }
Felix Meschberger67726fe2010-03-17 06:55:00 +0000705 initStaticWidgets(configTable);
706
707 // init tablesorte
708 configTable.tablesorter({
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000709 headers: {
710 0: { sorter: false },
711 3: { sorter: false }
712 },
713 sortList: [[1,1]],
Felix Meschberger67726fe2010-03-17 06:55:00 +0000714 textExtraction: treetableExtraction
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000715 }).bind('sortStart', function() { // clear cache, otherwise extraction will not work
Felix Meschberger67726fe2010-03-17 06:55:00 +0000716 var table = $(this).trigger('update');
Valentin Valchev7c4a80f2014-12-03 12:51:09 +0000717 }).find('th:eq(1)').click();
Carsten Ziegeler149faaa2010-03-10 16:41:53 +0000718 } else {
719 configContent.addClass('ui-helper-hidden');
720 }
Valentin Valchev6cc663f2015-09-11 12:26:00 +0000721 if(selectedPid) {
722 if(factoryCreate) configure(selectedPid, true);
723 else configure(selectedPid);
724 }
Felix Meschbergerb812b2e2010-02-18 15:36:53 +0000725});