Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 1 | /* |
| 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 Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 17 | // tables container - will get hidden, when no config service available |
| 18 | var configContent = false; |
| 19 | |
| 20 | // config table list |
| 21 | var configTable = false; |
| 22 | var configBody = false; |
| 23 | var configRow = false; |
| 24 | |
| 25 | // factories table list |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 26 | var factoryBody = false; |
| 27 | var factoryRow = false; |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 28 | |
| 29 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 30 | // editor dialog |
| 31 | var editor = false; |
Valentin Valchev | de16088 | 2010-03-22 09:30:38 +0000 | [diff] [blame] | 32 | var editorMessage = false; |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 33 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 34 | function configure(pid, create) { |
| 35 | var uri = pluginRoot + '/' + pid; |
Carsten Ziegeler | d2637c3 | 2012-12-11 17:46:47 +0000 | [diff] [blame] | 36 | // we have to add a cache killer for IE8 |
Carsten Ziegeler | 0d98fa91 | 2013-10-21 11:11:43 +0000 | [diff] [blame] | 37 | var postUri = uri + '?post=true&'; |
Carsten Ziegeler | d2637c3 | 2012-12-11 17:46:47 +0000 | [diff] [blame] | 38 | if ( create ) { |
Felix Meschberger | 27870e8 | 2012-12-28 15:19:38 +0000 | [diff] [blame] | 39 | postUri += param.create + '=1&'; |
Carsten Ziegeler | d2637c3 | 2012-12-11 17:46:47 +0000 | [diff] [blame] | 40 | } |
| 41 | postUri = postUri + 'ts='+new Date().getMilliseconds(); |
Carsten Ziegeler | 0d98fa91 | 2013-10-21 11:11:43 +0000 | [diff] [blame] | 42 | $.get(postUri, null, displayConfigForm, 'json'); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | function displayConfigForm(obj) { |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 46 | var parent = document.getElementById('editorTable'); |
| 47 | clearChildren( parent ) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 48 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 49 | var trEl = tr( ); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 50 | parent.appendChild( trEl ); |
| 51 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 52 | var tdEl = td( null, { colSpan: "2" } ); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 53 | trEl.appendChild( tdEl ); |
| 54 | |
| 55 | var formEl = createElement( "form", null, { |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 56 | id : "editorForm", |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 57 | method: "POST", |
| 58 | action: pluginRoot + "/" + obj.pid |
| 59 | }); |
| 60 | tdEl.appendChild( formEl ); |
| 61 | |
| 62 | var inputEl = createElement( "input", null, { |
| 63 | type: "hidden", |
Felix Meschberger | 27870e8 | 2012-12-28 15:19:38 +0000 | [diff] [blame] | 64 | name: param.apply, |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 65 | 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 Meschberger | 27870e8 | 2012-12-28 15:19:38 +0000 | [diff] [blame] | 81 | if (obj[ param.pidFilter ]) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 82 | { |
| 83 | inputEl = createElement( "input", null, { |
| 84 | type: "hidden", |
Felix Meschberger | 27870e8 | 2012-12-28 15:19:38 +0000 | [diff] [blame] | 85 | name: param.pidFilter, |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 86 | 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 Ziegeler | 434525a | 2015-01-02 15:55:51 +0000 | [diff] [blame] | 98 | inputEl = createElement( "input", null, { |
| 99 | type: "hidden", |
| 100 | name: "$location", |
| 101 | id: "lochidden" |
| 102 | }); |
| 103 | formEl.appendChild( inputEl ); |
| 104 | |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 105 | 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 Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 117 | tdEl = td( null, { colSpan: "3" } ); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 118 | addText( tdEl, obj.description ); |
| 119 | trEl.appendChild( tdEl ); |
| 120 | bodyEl.appendChild( trEl ); |
| 121 | } |
| 122 | |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 123 | if (obj.properties) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 124 | { |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 125 | printForm(bodyEl, obj.properties); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 126 | } |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 127 | |
| 128 | printConfigurationInfo(parent, obj); |
Valentin Valchev | de16088 | 2010-03-22 09:30:38 +0000 | [diff] [blame] | 129 | 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 Valchev | 0fc8b7b | 2010-04-15 12:33:58 +0000 | [diff] [blame] | 132 | |
| 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 Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 137 | initStaticWidgets(editor |
| 138 | .attr('__pid', obj.pid) |
| 139 | .attr('__location', obj.bundleLocation?obj.bundleLocation:'') |
| 140 | .dialog('option', 'title', obj.title) |
| 141 | .dialog('open')); |
Carsten Ziegeler | b0efb6d | 2014-12-29 14:24:03 +0000 | [diff] [blame] | 142 | |
| 143 | // autosize |
| 144 | $('textarea').trigger('autosize.resize'); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 147 | /* 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 Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 158 | function printForm( /* Element */ parent, /* Object */ properties ) { |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 159 | var propList; |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 160 | for (var prop in properties) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 161 | { |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 162 | var attr = properties[prop]; |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 163 | |
| 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 Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 180 | var trEl = tr( null, null, [ |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 181 | td( null, null, [ optElement ] ), |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 182 | 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 Valchev | cb68caa | 2014-10-20 07:48:07 +0000 | [diff] [blame] | 192 | var inputName = (prop == "action" || prop == "propertylist" || prop == "apply" || prop == "delete") ? '$' + prop : prop; |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 193 | var inputEl = createInput( inputName, attr.value, attr.type, '99%' ); |
| 194 | tdEl.appendChild( inputEl ); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 195 | 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 Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 215 | if (!attr.is_set) { |
| 216 | addDefaultValue( tdEl ); |
| 217 | } |
| 218 | |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 219 | 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 Meschberger | 27870e8 | 2012-12-28 15:19:38 +0000 | [diff] [blame] | 233 | name: param.propertylist, |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 234 | value: propList |
| 235 | }) |
| 236 | ); |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 237 | |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 238 | // 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 | |
| 242 | function 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 Ziegeler | 434525a | 2015-01-02 15:55:51 +0000 | [diff] [blame] | 274 | var binding = obj.bundle_location; |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 275 | if (!binding) |
| 276 | { |
| 277 | binding = i18n.unbound; |
Carsten Ziegeler | 434525a | 2015-01-02 15:55:51 +0000 | [diff] [blame] | 278 | } else { |
| 279 | $("#lochidden").val(binding); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | parent.appendChild( tr( null, null, [ |
| 283 | td( null, null, [ |
| 284 | text( i18n.binding ) |
| 285 | ]), |
| 286 | td( null, null, [ |
Carsten Ziegeler | 434525a | 2015-01-02 15:55:51 +0000 | [diff] [blame] | 287 | createElement( "input", null, { |
| 288 | type: "text", |
| 289 | name: "$location", |
| 290 | style: { width: '99%' }, |
| 291 | value: binding, |
| 292 | id: "locinput" |
| 293 | }) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 294 | ]) |
| 295 | ]) |
| 296 | ); |
Carsten Ziegeler | 434525a | 2015-01-02 15:55:51 +0000 | [diff] [blame] | 297 | 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 Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | |
| 331 | var 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 Ziegeler | b0efb6d | 2014-12-29 14:24:03 +0000 | [diff] [blame] | 408 | } else if (type == 12) { // Metatype 1.2: Attr type 12 is PASSWORD |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 409 | return createElement( "input", null, { |
Carsten Ziegeler | b0efb6d | 2014-12-29 14:24:03 +0000 | [diff] [blame] | 410 | 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 Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | function 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 | |
| 457 | function 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 | |
| 471 | function removeValue(vidx) |
| 472 | { |
| 473 | var span = document.getElementById(vidx); |
| 474 | if (!span) |
| 475 | { |
| 476 | return; |
| 477 | } |
| 478 | span.parentNode.removeChild(span); |
| 479 | } |
| 480 | |
| 481 | function configConfirm(/* String */ message, /* String */ title, /* String */ location) |
| 482 | { |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 483 | 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 Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 493 | function deleteConfig(/* String */ configId, /* String */ bundleLocation) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 494 | { |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 495 | if ( configConfirm(i18n.del_ask, configId, bundleLocation) ) { |
Valentin Valchev | 0d0723d | 2015-09-16 12:45:21 +0000 | [diff] [blame] | 496 | $.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 Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 506 | return true; |
| 507 | } |
| 508 | return false; |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 511 | function unbindConfig(/* String */ configId, /* String */ bundleLocation) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 512 | { |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 513 | if ( configConfirm(i18n.unbind_ask, configId, bundleLocation) ) { |
Valentin Valchev | 4317f09 | 2014-11-26 10:04:11 +0000 | [diff] [blame] | 514 | $.post(pluginRoot + '/' + configId, param.unbind + '=1', function() { |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 515 | document.location.href = pluginRoot + '/' + configId; |
| 516 | }, 'json'); |
| 517 | return true; |
| 518 | } |
| 519 | return false; |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 522 | function addConfig(conf) { |
| 523 | var tr = configRow.clone().appendTo(configBody); |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 524 | |
| 525 | if (!conf.has_config) { |
| 526 | tr.find('td:eq(0)').empty(); |
| 527 | } |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 528 | |
| 529 | // rendering name - indented if factory pid is set |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 530 | var nms = tr.find('td:eq(1) div'); |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 531 | if (conf.fpid) { |
Carsten Ziegeler | e1f29c4 | 2014-12-29 13:21:01 +0000 | [diff] [blame] | 532 | if (conf.nameHint) { |
| 533 | nms.after("<span title='" + conf.id + "'>" + conf.nameHint + "</span>"); |
| 534 | } else { |
| 535 | nms.after(conf.id); |
| 536 | } |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 537 | tr.attr('fpid', conf.name); |
| 538 | } else { |
| 539 | nms.addClass('ui-helper-hidden').parent().text(conf.name); |
| 540 | } |
| 541 | |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 542 | tr.find('td:eq(1)').click(function() { // name & edit |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 543 | configure(conf.id); |
| 544 | }); |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 545 | tr.find('td:eq(2)').html(conf.bundle ? '<a href="' + pluginRoot + '/../bundles/' + conf.bundle + '">' + conf.bundle_name + '</a>' : '-'); // binding |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 546 | |
| 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 Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 552 | deleteConfig(conf.id, conf.bundle_name); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 553 | }); |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 554 | 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 Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 561 | function addFactoryConfig(conf) { |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 562 | var tr = factoryRow.clone().appendTo(configTable).attr('fpid', conf.name); |
| 563 | //tr.find('td:eq(1)').text(conf.id); // fpid |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 564 | tr.find('td:eq(1)').text(conf.name).click(function() { // name & edit |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 565 | configure(conf.id, true); |
| 566 | }); |
| 567 | // buttons |
Valentin Valchev | 605354e | 2014-12-19 08:22:00 +0000 | [diff] [blame] | 568 | tr.find('li:eq(0)').click(function() { // edit |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 569 | configure(conf.id, true); |
| 570 | }); |
| 571 | } |
| 572 | |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 573 | function 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 Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 585 | if ( row.hasClass('fpid') && fpid) return fpid + (desc==1?1:0) + text; |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 586 | |
| 587 | // bundle or name row |
| 588 | if ( fpid ) return fpid + desc + text; |
| 589 | |
| 590 | return mixedLinksExtraction(node); |
| 591 | }; |
Valentin Valchev | 0d0723d | 2015-09-16 12:45:21 +0000 | [diff] [blame] | 592 | function navigateAfterConfigurationClose() { |
| 593 | if(configurationReferer) { |
| 594 | window.location = configurationReferer; |
| 595 | return true; |
| 596 | } |
| 597 | return false; |
| 598 | } |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 599 | |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 600 | $(document).ready(function() { |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 601 | configContent = $('#configContent'); |
| 602 | // config table list |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 603 | configTable = $('#configTable'); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 604 | configBody = configTable.find('tbody'); |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 605 | configRow = configBody.find('tr:eq(0)').clone(); |
| 606 | factoryRow = configBody.find('tr:eq(1)').clone(); |
Carsten Ziegeler | 434525a | 2015-01-02 15:55:51 +0000 | [diff] [blame] | 607 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 608 | // setup button - cannot inline in dialog option because of i18n |
| 609 | var _buttons = {}; |
| 610 | _buttons[i18n.abort] = function() { |
| 611 | $(this).dialog('close'); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 612 | } |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 613 | _buttons[i18n.reset] = function() { |
| 614 | var form = document.getElementById('editorForm'); |
| 615 | if (form) form.reset(); |
| 616 | } |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 617 | _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 Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 625 | _buttons[i18n.save] = function() { |
Carsten Ziegeler | 434525a | 2015-01-02 15:55:51 +0000 | [diff] [blame] | 626 | if ( $("#locinput").val() === i18n.unbound ) { |
| 627 | $("#lochidden").val(""); |
| 628 | } else { |
| 629 | $("#lochidden").val($("#locinput").val()); |
| 630 | } |
| 631 | |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 632 | // 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 Valchev | 0d0723d | 2015-09-16 12:45:21 +0000 | [diff] [blame] | 646 | $.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 Valchev | 4b25d4f | 2011-09-15 07:06:36 +0000 | [diff] [blame] | 658 | }); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 659 | } |
| 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 Valchev | 0d0723d | 2015-09-16 12:45:21 +0000 | [diff] [blame] | 666 | buttons : _buttons, |
| 667 | close : function( event, ui ) { navigateAfterConfigurationClose(); } |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 668 | }); |
Valentin Valchev | de16088 | 2010-03-22 09:30:38 +0000 | [diff] [blame] | 669 | editorMessage = editor.find('p'); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 670 | |
| 671 | // display the configuration data |
| 672 | $(".statline").html(configData.status ? i18n.stat_ok : i18n.stat_missing); |
| 673 | if (configData.status) { |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 674 | configBody.empty(); |
| 675 | var factories = {}; |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 676 | |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 677 | 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 Meschberger | 1e671e1 | 2010-03-13 15:09:51 +0000 | [diff] [blame] | 688 | |
Felix Meschberger | b58af94 | 2011-12-19 12:54:03 +0000 | [diff] [blame] | 689 | 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 Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
Felix Meschberger | b58af94 | 2011-12-19 12:54:03 +0000 | [diff] [blame] | 698 | 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 Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 705 | initStaticWidgets(configTable); |
| 706 | |
| 707 | // init tablesorte |
| 708 | configTable.tablesorter({ |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 709 | headers: { |
| 710 | 0: { sorter: false }, |
| 711 | 3: { sorter: false } |
| 712 | }, |
| 713 | sortList: [[1,1]], |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 714 | textExtraction: treetableExtraction |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 715 | }).bind('sortStart', function() { // clear cache, otherwise extraction will not work |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 716 | var table = $(this).trigger('update'); |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 717 | }).find('th:eq(1)').click(); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 718 | } else { |
| 719 | configContent.addClass('ui-helper-hidden'); |
| 720 | } |
Valentin Valchev | 6cc663f | 2015-09-11 12:26:00 +0000 | [diff] [blame] | 721 | if(selectedPid) { |
| 722 | if(factoryCreate) configure(selectedPid, true); |
| 723 | else configure(selectedPid); |
| 724 | } |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 725 | }); |