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 | |
| 98 | var tableEl = createElement( "table", null, { |
| 99 | border: 0, |
| 100 | width: "100%" |
| 101 | }); |
| 102 | formEl.appendChild( tableEl ); |
| 103 | |
| 104 | var bodyEl = createElement( "tbody" ); |
| 105 | tableEl.appendChild( bodyEl ); |
| 106 | |
| 107 | if (obj.description) |
| 108 | { |
| 109 | trEl = tr( ); |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 110 | tdEl = td( null, { colSpan: "3" } ); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 111 | addText( tdEl, obj.description ); |
| 112 | trEl.appendChild( tdEl ); |
| 113 | bodyEl.appendChild( trEl ); |
| 114 | } |
| 115 | |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 116 | if (obj.properties) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 117 | { |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 118 | printForm(bodyEl, obj.properties); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 119 | } |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 120 | |
| 121 | printConfigurationInfo(parent, obj); |
Valentin Valchev | de16088 | 2010-03-22 09:30:38 +0000 | [diff] [blame] | 122 | if ( obj.service_location && obj.bundle_location && obj.service_location != obj.bundle_location) { |
| 123 | editorMessage.removeClass('ui-helper-hidden').text(i18n.err_bind.msgFormat(obj.pid, obj.bundle_location, obj.service_location)); |
| 124 | } else editorMessage.addClass('ui-helper-hidden'); |
Valentin Valchev | 0fc8b7b | 2010-04-15 12:33:58 +0000 | [diff] [blame] | 125 | |
| 126 | // ugly workaround for IE6 and IE7 - these browsers don't show correctly the dialog |
| 127 | var ua = navigator.userAgent; |
| 128 | if (ua.indexOf('MSIE 6') != -1 || ua.indexOf('MSIE 7') != -1) $(parent).html(parent.innerHTML); |
| 129 | |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 130 | initStaticWidgets(editor |
| 131 | .attr('__pid', obj.pid) |
| 132 | .attr('__location', obj.bundleLocation?obj.bundleLocation:'') |
| 133 | .dialog('option', 'title', obj.title) |
| 134 | .dialog('open')); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 137 | /* Element */ function addDefaultValue( /* Element */ element ) { |
| 138 | if (element) { |
| 139 | element.appendChild( |
| 140 | createElement('span', 'default_value ui-state-highlight1 ui-icon ui-icon-alert', { |
| 141 | title : i18n.dflt_value |
| 142 | }) |
| 143 | ); |
| 144 | } |
| 145 | return element; |
| 146 | } |
| 147 | |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 148 | function printForm( /* Element */ parent, /* Object */ properties ) { |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 149 | var propList; |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 150 | for (var prop in properties) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 151 | { |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 152 | var attr = properties[prop]; |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 153 | |
| 154 | // create optionality element |
| 155 | var optElement = false; |
| 156 | if (attr.optional) { |
| 157 | var elAttributes = { |
| 158 | type: "checkbox", |
| 159 | name: "opt" + prop, |
| 160 | title: i18n.opt_value |
| 161 | }; |
| 162 | if (attr.is_set) { |
| 163 | elAttributes['checked'] = 'checked'; |
| 164 | } |
| 165 | optElement = createElement( "input", "optionality", elAttributes); |
| 166 | } else { |
| 167 | optElement = text( "" ); |
| 168 | } |
| 169 | // create the raw |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 170 | var trEl = tr( null, null, [ |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 171 | td( null, null, [ optElement ] ), |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 172 | td( null, null, [ text( attr.name ) ] ) |
| 173 | ]); |
| 174 | parent.appendChild( trEl ); |
| 175 | |
| 176 | var tdEl = td( null, { style: { width: "99%" } } ); |
| 177 | trEl.appendChild( tdEl ); |
| 178 | |
| 179 | if (attr.value != undefined) |
| 180 | { |
| 181 | // check is required to also handle empty strings, 0 and false |
Valentin Valchev | cb68caa | 2014-10-20 07:48:07 +0000 | [diff] [blame] | 182 | var inputName = (prop == "action" || prop == "propertylist" || prop == "apply" || prop == "delete") ? '$' + prop : prop; |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 183 | var inputEl = createInput( inputName, attr.value, attr.type, '99%' ); |
| 184 | tdEl.appendChild( inputEl ); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 185 | tdEl.appendChild( createElement( "br" ) ); |
| 186 | } |
| 187 | else if (typeof(attr.type) == 'object') |
| 188 | { |
| 189 | // assume attr.values and multiselect |
| 190 | createMultiSelect( tdEl, prop, attr.values, attr.type, '99%' ); |
| 191 | tdEl.appendChild( createElement( "br" ) ); |
| 192 | } |
| 193 | else if (attr.values.length == 0) |
| 194 | { |
| 195 | tdEl.appendChild( createSpan( prop, "", attr.type ) ); |
| 196 | } |
| 197 | else |
| 198 | { |
| 199 | for (var i=0;i<attr.values.length;i++) |
| 200 | { |
| 201 | tdEl.appendChild( createSpan( prop, attr.values[i], attr.type ) ); |
| 202 | } |
| 203 | } |
| 204 | |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 205 | if (!attr.is_set) { |
| 206 | addDefaultValue( tdEl ); |
| 207 | } |
| 208 | |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 209 | if (attr.description) |
| 210 | { |
| 211 | addText( tdEl, attr.description ); |
| 212 | } |
| 213 | |
| 214 | if (propList) { |
| 215 | propList += ',' + prop; |
| 216 | } else { |
| 217 | propList = prop; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | parent.appendChild( createElement( "input", null, { |
| 222 | type: "hidden", |
Felix Meschberger | 27870e8 | 2012-12-28 15:19:38 +0000 | [diff] [blame] | 223 | name: param.propertylist, |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 224 | value: propList |
| 225 | }) |
| 226 | ); |
Felix Meschberger | a87e859 | 2011-12-17 16:19:41 +0000 | [diff] [blame] | 227 | |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 228 | // FIX for IE6 and above: checkbox can only be checked after it is in the DOM |
| 229 | $(".checked_box").attr("checked", true).removeClass("checked_box"); |
| 230 | } |
| 231 | |
| 232 | function printConfigurationInfo( /* Element */ parent, obj ) |
| 233 | { |
| 234 | parent.appendChild( tr( null, null, [ |
| 235 | createElement( "th", null, { colSpan: "2" }, [ |
| 236 | text( i18n.cfg_title ) |
| 237 | ]) |
| 238 | ]) |
| 239 | ); |
| 240 | |
| 241 | parent.appendChild( tr( null, null, [ |
| 242 | td( null, null, [ |
| 243 | text( i18n.pid ) |
| 244 | ]), |
| 245 | td( null, null, [ |
| 246 | text( obj.pid ) |
| 247 | ]) |
| 248 | ]) |
| 249 | ); |
| 250 | |
| 251 | if (obj.factoryPid) |
| 252 | { |
| 253 | parent.appendChild( tr( null, null, [ |
| 254 | td( null, null, [ |
| 255 | text( i18n.fpid ) |
| 256 | ]), |
| 257 | td( null, null, [ |
| 258 | text( obj.factoryPid ) |
| 259 | ]) |
| 260 | ]) |
| 261 | ); |
| 262 | } |
| 263 | |
| 264 | var binding = obj.bundleLocation; |
| 265 | if (!binding) |
| 266 | { |
| 267 | binding = i18n.unbound; |
| 268 | } |
| 269 | |
| 270 | parent.appendChild( tr( null, null, [ |
| 271 | td( null, null, [ |
| 272 | text( i18n.binding ) |
| 273 | ]), |
| 274 | td( null, null, [ |
| 275 | text( binding ) |
| 276 | ]) |
| 277 | ]) |
| 278 | ); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 279 | |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | |
| 283 | var spanCounter = 0; |
| 284 | /* Element */ function createSpan(prop, value, type) { |
| 285 | spanCounter++; |
| 286 | var newId = prop + spanCounter; |
| 287 | |
| 288 | var addButton = createElement("input", null, |
| 289 | { type: "button", |
| 290 | style: {width : "5%"}, |
| 291 | value: "+" |
| 292 | } |
| 293 | ); |
| 294 | $(addButton).click(function() {addValue(prop, newId)}); |
| 295 | var remButton = createElement("input", null, |
| 296 | { type: "button", |
| 297 | style: {width : "5%"}, |
| 298 | value: "-" |
| 299 | } |
| 300 | ); |
| 301 | $(remButton).click(function() {removeValue(newId)}); |
| 302 | var spanEl = createElement( "span", null, { id: newId }, [ |
| 303 | createInput( prop, value, type, '89%' ), addButton, remButton, |
| 304 | createElement("br") |
| 305 | ]); |
| 306 | |
| 307 | return spanEl; |
| 308 | } |
| 309 | |
| 310 | /* Element */ function createInput(prop, value, type, width) { |
| 311 | if (type == 11) { // AttributeDefinition.BOOLEAN |
| 312 | |
| 313 | var inputEl = createElement( "input", null, { |
| 314 | type: "checkbox", |
| 315 | name: prop, |
| 316 | value: "true" |
| 317 | }); |
| 318 | |
| 319 | if (value && typeof(value) != "boolean") |
| 320 | { |
| 321 | value = value.toString().toLowerCase() == "true"; |
| 322 | } |
| 323 | if (value) |
| 324 | { |
| 325 | $(inputEl).addClass("checked_box"); |
| 326 | } |
| 327 | var hiddenEl = createElement( "input", null, { |
| 328 | type: "hidden", |
| 329 | name: prop, |
| 330 | value: "false" |
| 331 | }); |
| 332 | var divEl = createElement("div"); |
| 333 | divEl.appendChild(inputEl); |
| 334 | divEl.appendChild(hiddenEl); |
| 335 | return divEl; |
| 336 | |
| 337 | } else if (typeof(type) == "object") { // predefined values |
| 338 | |
| 339 | var selectEl = createElement( "select", null, { |
| 340 | name: prop, |
| 341 | style: { width: width } |
| 342 | }); |
| 343 | |
| 344 | var labels = type.labels; |
| 345 | var values = type.values; |
| 346 | for (var idx in labels) { |
| 347 | var optionEl = createElement( "option", null, { |
| 348 | value: values[idx] |
| 349 | }, [ text( labels[idx] ) ]); |
| 350 | |
| 351 | if (value == values[idx]) |
| 352 | { |
| 353 | optionEl.setAttribute( "selected", true ); |
| 354 | } |
| 355 | selectEl.appendChild( optionEl ); |
| 356 | } |
| 357 | |
| 358 | return selectEl; |
| 359 | |
| 360 | } else { // Simple |
Felix Meschberger | d5fe6b6 | 2011-12-17 15:26:02 +0000 | [diff] [blame] | 361 | // Metatype 1.2: Attr type 12 is PASSWORD |
| 362 | var elType = (type == 12) ? "password" : "text"; |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 363 | return createElement( "input", null, { |
Felix Meschberger | d5fe6b6 | 2011-12-17 15:26:02 +0000 | [diff] [blame] | 364 | type: elType, |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 365 | name: prop, |
| 366 | value: value, |
| 367 | style: { width: width } |
| 368 | }); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | function createMultiSelect(/* Element */ parent, prop, values, options, width) { |
| 373 | // convert value list into 'set' |
| 374 | var valueSet = new Object(); |
| 375 | for (var idx in values) { |
| 376 | valueSet[ values[idx] ] = true; |
| 377 | } |
| 378 | |
| 379 | var labels = options.labels; |
| 380 | var values = options.values; |
| 381 | for (var idx in labels) { |
| 382 | |
| 383 | var inputEl = createElement( "input", null, { |
| 384 | type: "checkbox", |
| 385 | name: prop, |
| 386 | value: values[idx] |
| 387 | }); |
| 388 | |
| 389 | if (valueSet[ values[idx] ]) |
| 390 | { |
| 391 | inputEl.setAttribute( "checked", true ); |
| 392 | } |
| 393 | |
| 394 | var labelEl = createElement( "label", "multiselect" ); |
| 395 | labelEl.appendChild( inputEl ); |
| 396 | addText( labelEl, labels[idx] ); |
| 397 | |
| 398 | parent.appendChild( labelEl ); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | |
| 403 | function addValue(prop, vidx) |
| 404 | { |
| 405 | var span = document.getElementById(vidx); |
| 406 | if (!span) |
| 407 | { |
| 408 | return; |
| 409 | } |
| 410 | var newSpan = createSpan(prop, ''); |
| 411 | span.parentNode.insertBefore(newSpan, span.nextSibling); |
| 412 | // FIX for IE6 and above: checkbox can only be checked after it is in the DOM |
| 413 | $(".checked_box").attr("checked", true).removeClass("checked_box"); |
| 414 | //$(span).ready(initStaticWidgets); |
| 415 | } |
| 416 | |
| 417 | function removeValue(vidx) |
| 418 | { |
| 419 | var span = document.getElementById(vidx); |
| 420 | if (!span) |
| 421 | { |
| 422 | return; |
| 423 | } |
| 424 | span.parentNode.removeChild(span); |
| 425 | } |
| 426 | |
| 427 | function configConfirm(/* String */ message, /* String */ title, /* String */ location) |
| 428 | { |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 429 | if (title) { |
| 430 | message += "\r\n" + i18n.del_config + title; |
| 431 | } |
| 432 | if (location) { |
| 433 | message += "\r\n" + i18n.del_bundle + location; |
| 434 | } |
| 435 | |
| 436 | return confirm(message); |
| 437 | } |
| 438 | |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 439 | function deleteConfig(/* String */ configId, /* String */ bundleLocation) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 440 | { |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 441 | if ( configConfirm(i18n.del_ask, configId, bundleLocation) ) { |
Valentin Valchev | 4317f09 | 2014-11-26 10:04:11 +0000 | [diff] [blame] | 442 | $.post(pluginRoot + '/' + configId, param.apply + '=1&' + param.dele + '=1', function() { |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 443 | document.location.href = pluginRoot; |
| 444 | }, 'json'); |
| 445 | return true; |
| 446 | } |
| 447 | return false; |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 450 | function unbindConfig(/* String */ configId, /* String */ bundleLocation) |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 451 | { |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 452 | if ( configConfirm(i18n.unbind_ask, configId, bundleLocation) ) { |
Valentin Valchev | 4317f09 | 2014-11-26 10:04:11 +0000 | [diff] [blame] | 453 | $.post(pluginRoot + '/' + configId, param.unbind + '=1', function() { |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 454 | document.location.href = pluginRoot + '/' + configId; |
| 455 | }, 'json'); |
| 456 | return true; |
| 457 | } |
| 458 | return false; |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 461 | function addConfig(conf) { |
| 462 | var tr = configRow.clone().appendTo(configBody); |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 463 | |
| 464 | if (!conf.has_config) { |
| 465 | tr.find('td:eq(0)').empty(); |
| 466 | } |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 467 | |
| 468 | // rendering name - indented if factory pid is set |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 469 | var nms = tr.find('td:eq(1) div'); |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 470 | if (conf.fpid) { |
| 471 | nms.after(conf.id); |
| 472 | tr.attr('fpid', conf.name); |
| 473 | } else { |
| 474 | nms.addClass('ui-helper-hidden').parent().text(conf.name); |
| 475 | } |
| 476 | |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 477 | tr.find('td:eq(1)').click(function() { // name & edit |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 478 | configure(conf.id); |
| 479 | }); |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 480 | 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] | 481 | |
| 482 | // buttons |
| 483 | tr.find('li:eq(0)').click(function() { // edit |
| 484 | configure(conf.id); |
| 485 | }); |
| 486 | tr.find('li:eq(2)').click(function() { // delete |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 487 | deleteConfig(conf.id, conf.bundle_name); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 488 | }); |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 489 | if (conf.bundle) { |
| 490 | tr.find('li:eq(1)').click(function() { // unbind |
| 491 | unbindConfig(conf.id, conf.bundle_name); |
| 492 | }).removeClass('ui-state-disabled'); |
| 493 | } |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 496 | function addFactoryConfig(conf) { |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 497 | var tr = factoryRow.clone().appendTo(configTable).attr('fpid', conf.name); |
| 498 | //tr.find('td:eq(1)').text(conf.id); // fpid |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 499 | tr.find('td:eq(1)').text(conf.name).click(function() { // name & edit |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 500 | configure(conf.id, true); |
| 501 | }); |
| 502 | // buttons |
Valentin Valchev | 605354e | 2014-12-19 08:22:00 +0000 | [diff] [blame^] | 503 | tr.find('li:eq(0)').click(function() { // edit |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 504 | configure(conf.id, true); |
| 505 | }); |
| 506 | } |
| 507 | |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 508 | function treetableExtraction(node) { |
| 509 | var td = $(node); |
| 510 | var text = td.text(); |
| 511 | if (!text) return text; |
| 512 | |
| 513 | // current sort order |
| 514 | var desc = $(this)[0].sortList[0][1]; |
| 515 | |
| 516 | var row = td.parent(); |
| 517 | var fpid = row.attr('fpid'); |
| 518 | |
| 519 | // factory row |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 520 | if ( row.hasClass('fpid') && fpid) return fpid + (desc==1?1:0) + text; |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 521 | |
| 522 | // bundle or name row |
| 523 | if ( fpid ) return fpid + desc + text; |
| 524 | |
| 525 | return mixedLinksExtraction(node); |
| 526 | }; |
| 527 | |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 528 | $(document).ready(function() { |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 529 | configContent = $('#configContent'); |
| 530 | // config table list |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 531 | configTable = $('#configTable'); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 532 | configBody = configTable.find('tbody'); |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 533 | configRow = configBody.find('tr:eq(0)').clone(); |
| 534 | factoryRow = configBody.find('tr:eq(1)').clone(); |
Felix Meschberger | 1e671e1 | 2010-03-13 15:09:51 +0000 | [diff] [blame] | 535 | |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 536 | // setup button - cannot inline in dialog option because of i18n |
| 537 | var _buttons = {}; |
| 538 | _buttons[i18n.abort] = function() { |
| 539 | $(this).dialog('close'); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 540 | } |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 541 | _buttons[i18n.reset] = function() { |
| 542 | var form = document.getElementById('editorForm'); |
| 543 | if (form) form.reset(); |
| 544 | } |
Felix Meschberger | 0774120 | 2011-07-07 11:55:53 +0000 | [diff] [blame] | 545 | _buttons[i18n.del] = function() { |
| 546 | if (deleteConfig($(this).attr('__pid'), $(this).attr('__location'))) { |
| 547 | $(this).dialog('close'); |
| 548 | } |
| 549 | } |
| 550 | _buttons[i18n.unbind_btn] = function() { |
| 551 | unbindConfig($(this).attr('__pid'), $(this).attr('__location')); |
| 552 | } |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 553 | _buttons[i18n.save] = function() { |
Valentin Valchev | f7fe52e | 2014-11-17 13:07:24 +0000 | [diff] [blame] | 554 | // get all the configuration properties names |
| 555 | var propListElement = $(this).find('form').find('[name=propertylist]'); |
| 556 | var propListArray = propListElement.val().split(','); |
| 557 | |
| 558 | // removes the properties, that are unchecked |
| 559 | $(this).find('form').find('input.optionality:not(:checked)').each( function(idx, el) { |
| 560 | var name = $(el).attr('name').substring(3); // name - 'opt' |
| 561 | var index = propListArray.indexOf(name); |
| 562 | if (index >= 0) { |
| 563 | propListArray.splice(index, 1); |
| 564 | } |
| 565 | }); |
| 566 | propListElement.val(propListArray.join(',')); |
| 567 | |
Felix Meschberger | c89425a | 2013-11-04 16:08:19 +0000 | [diff] [blame] | 568 | $.post(pluginRoot + '/' + $(this).attr('__pid'), $(this).find('form').serialize(), function() { |
Valentin Valchev | 4b25d4f | 2011-09-15 07:06:36 +0000 | [diff] [blame] | 569 | // reload on success - prevents AJAX errors - see FELIX-3116 |
| 570 | document.location.href = pluginRoot; |
| 571 | }); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 572 | $(this).dialog('close'); |
| 573 | } |
| 574 | // prepare editor, but don't open yet! |
| 575 | editor = $('#editor').dialog({ |
| 576 | autoOpen : false, |
| 577 | modal : true, |
| 578 | width : '90%', |
| 579 | closeText: i18n.abort, |
| 580 | buttons : _buttons |
| 581 | }); |
Valentin Valchev | de16088 | 2010-03-22 09:30:38 +0000 | [diff] [blame] | 582 | editorMessage = editor.find('p'); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 583 | |
| 584 | // display the configuration data |
| 585 | $(".statline").html(configData.status ? i18n.stat_ok : i18n.stat_missing); |
| 586 | if (configData.status) { |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 587 | configBody.empty(); |
| 588 | var factories = {}; |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 589 | |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 590 | for(var i in configData.pids) { |
| 591 | var c = configData.pids[i]; |
| 592 | if (c.fpid) { |
| 593 | if (!factories[c.fpid]) factories[c.fpid] = new Array(); |
| 594 | factories[c.fpid].push(c); |
| 595 | } else { |
| 596 | addConfig(c); |
| 597 | } |
| 598 | } |
| 599 | for(var i in configData.fpids) { |
| 600 | addFactoryConfig(configData.fpids[i]); |
Felix Meschberger | 1e671e1 | 2010-03-13 15:09:51 +0000 | [diff] [blame] | 601 | |
Felix Meschberger | b58af94 | 2011-12-19 12:54:03 +0000 | [diff] [blame] | 602 | var fpid = configData.fpids[i].id; |
| 603 | var confs = factories[ fpid ]; |
| 604 | if (confs) { |
| 605 | for (var j in confs) { |
| 606 | addConfig(confs[j]); |
| 607 | } |
| 608 | delete factories[ fpid ]; |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 609 | } |
| 610 | } |
Felix Meschberger | b58af94 | 2011-12-19 12:54:03 +0000 | [diff] [blame] | 611 | for(var fpid in factories) { |
| 612 | var flist = factories[fpid]; |
| 613 | for(var i in flist) { |
| 614 | delete flist[i].fpid; // render as regular config |
| 615 | addConfig(flist[i]); |
| 616 | } |
| 617 | } |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 618 | initStaticWidgets(configTable); |
| 619 | |
| 620 | // init tablesorte |
| 621 | configTable.tablesorter({ |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 622 | headers: { |
| 623 | 0: { sorter: false }, |
| 624 | 3: { sorter: false } |
| 625 | }, |
| 626 | sortList: [[1,1]], |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 627 | textExtraction: treetableExtraction |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 628 | }).bind('sortStart', function() { // clear cache, otherwise extraction will not work |
Felix Meschberger | 67726fe | 2010-03-17 06:55:00 +0000 | [diff] [blame] | 629 | var table = $(this).trigger('update'); |
Valentin Valchev | 7c4a80f | 2014-12-03 12:51:09 +0000 | [diff] [blame] | 630 | }).find('th:eq(1)').click(); |
Carsten Ziegeler | 149faaa | 2010-03-10 16:41:53 +0000 | [diff] [blame] | 631 | } else { |
| 632 | configContent.addClass('ui-helper-hidden'); |
| 633 | } |
| 634 | if (selectedPid) configure(selectedPid); |
Felix Meschberger | b812b2e | 2010-02-18 15:36:53 +0000 | [diff] [blame] | 635 | }); |