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