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 | 4317f09 | 2014-11-26 10:04:11 +0000 | [diff] [blame] | 496 | $.post(pluginRoot + '/' + configId, param.apply + '=1&' + param.dele + '=1', function() { |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 497 | document.location.href = pluginRoot; |
| 498 | }, 'json'); |
| 499 | return true; |
| 500 | } |
| 501 | return false; |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 504 | function unbindConfig(/* String */ configId, /* String */ bundleLocation) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 505 | { |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 506 | if ( configConfirm(i18n.unbind_ask, configId, bundleLocation) ) { |
Valentin Valchev | 4317f09 | 2014-11-26 10:04:11 +0000 | [diff] [blame] | 507 | $.post(pluginRoot + '/' + configId, param.unbind + '=1', function() { |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 508 | document.location.href = pluginRoot + '/' + configId; |
| 509 | }, 'json'); |
| 510 | return true; |
| 511 | } |
| 512 | return false; |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 515 | function addConfig(conf) { |
| 516 | var tr = configRow.clone().appendTo(configBody); |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 517 | |
| 518 | if (!conf.has_config) { |
| 519 | tr.find('td:eq(0)').empty(); |
| 520 | } |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 521 | |
| 522 | // rendering name - indented if factory pid is set |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 523 | var nms = tr.find('td:eq(1) div'); |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 524 | if (conf.fpid) { |
Carsten Ziegeler | e1f29c4 | 2014-12-29 13:21:01 +0000 | [diff] [blame] | 525 | if (conf.nameHint) { |
| 526 | nms.after("<span title='" + conf.id + "'>" + conf.nameHint + "</span>"); |
| 527 | } else { |
| 528 | nms.after(conf.id); |
| 529 | } |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 530 | tr.attr('fpid', conf.name); |
| 531 | } else { |
| 532 | nms.addClass('ui-helper-hidden').parent().text(conf.name); |
| 533 | } |
| 534 | |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 535 | tr.find('td:eq(1)').click(function() { // name & edit |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 536 | configure(conf.id); |
| 537 | }); |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 538 | 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] | 539 | |
| 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 Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 545 | deleteConfig(conf.id, conf.bundle_name); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 546 | }); |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 547 | 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 Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 552 | } |
| 553 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 554 | function addFactoryConfig(conf) { |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 555 | var tr = factoryRow.clone().appendTo(configTable).attr('fpid', conf.name); |
| 556 | //tr.find('td:eq(1)').text(conf.id); // fpid |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 557 | tr.find('td:eq(1)').text(conf.name).click(function() { // name & edit |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 558 | configure(conf.id, true); |
| 559 | }); |
| 560 | // buttons |
Valentin Valchev | 605354e | 2014-12-19 08:22:00 +0000 | [diff] [blame] | 561 | tr.find('li:eq(0)').click(function() { // edit |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 562 | configure(conf.id, true); |
| 563 | }); |
| 564 | } |
| 565 | |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 566 | function 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 Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 578 | if ( row.hasClass('fpid') && fpid) return fpid + (desc==1?1:0) + text; |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 579 | |
| 580 | // bundle or name row |
| 581 | if ( fpid ) return fpid + desc + text; |
| 582 | |
| 583 | return mixedLinksExtraction(node); |
| 584 | }; |
| 585 | |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 586 | $(document).ready(function() { |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 587 | configContent = $('#configContent'); |
| 588 | // config table list |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 589 | configTable = $('#configTable'); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 590 | configBody = configTable.find('tbody'); |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 591 | configRow = configBody.find('tr:eq(0)').clone(); |
| 592 | factoryRow = configBody.find('tr:eq(1)').clone(); |
Carsten Ziegeler | 434525a | 2015-01-02 15:55:51 +0000 | [diff] [blame] | 593 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 594 | // setup button - cannot inline in dialog option because of i18n |
| 595 | var _buttons = {}; |
| 596 | _buttons[i18n.abort] = function() { |
| 597 | $(this).dialog('close'); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 598 | } |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 599 | _buttons[i18n.reset] = function() { |
| 600 | var form = document.getElementById('editorForm'); |
| 601 | if (form) form.reset(); |
| 602 | } |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 603 | _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 Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 611 | _buttons[i18n.save] = function() { |
Carsten Ziegeler | 434525a | 2015-01-02 15:55:51 +0000 | [diff] [blame] | 612 | if ( $("#locinput").val() === i18n.unbound ) { |
| 613 | $("#lochidden").val(""); |
| 614 | } else { |
| 615 | $("#lochidden").val($("#locinput").val()); |
| 616 | } |
| 617 | |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 618 | // 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 Meschberger | c89425a | 2013-11-04 16:08:19 +0000 | [diff] [blame] | 632 | $.post(pluginRoot + '/' + $(this).attr('__pid'), $(this).find('form').serialize(), function() { |
Valentin Valchev | 4b25d4f | 2011-09-15 07:06:36 +0000 | [diff] [blame] | 633 | // reload on success - prevents AJAX errors - see FELIX-3116 |
| 634 | document.location.href = pluginRoot; |
| 635 | }); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 636 | $(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 Valchev | de16088 | 2010-03-22 09:30:38 +0000 | [diff] [blame] | 646 | editorMessage = editor.find('p'); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 647 | |
| 648 | // display the configuration data |
| 649 | $(".statline").html(configData.status ? i18n.stat_ok : i18n.stat_missing); |
| 650 | if (configData.status) { |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 651 | configBody.empty(); |
| 652 | var factories = {}; |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 653 | |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 654 | 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 Meschberger | 1e671e1 | 2010-03-13 15:09:51 +0000 | [diff] [blame] | 665 | |
Felix Meschberger | b58af94 | 2011-12-19 12:54:03 +0000 | [diff] [blame] | 666 | 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 Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 673 | } |
| 674 | } |
Felix Meschberger | b58af94 | 2011-12-19 12:54:03 +0000 | [diff] [blame] | 675 | 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 Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 682 | initStaticWidgets(configTable); |
| 683 | |
| 684 | // init tablesorte |
| 685 | configTable.tablesorter({ |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 686 | headers: { |
| 687 | 0: { sorter: false }, |
| 688 | 3: { sorter: false } |
| 689 | }, |
| 690 | sortList: [[1,1]], |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 691 | textExtraction: treetableExtraction |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 692 | }).bind('sortStart', function() { // clear cache, otherwise extraction will not work |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 693 | var table = $(this).trigger('update'); |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 694 | }).find('th:eq(1)').click(); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 695 | } else { |
| 696 | configContent.addClass('ui-helper-hidden'); |
| 697 | } |
| 698 | if (selectedPid) configure(selectedPid); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 699 | }); |