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