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