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