Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +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 | */ |
| 17 | |
| 18 | |
| 19 | function configure() { |
| 20 | var span = document.getElementById('configField'); |
| 21 | if (!span) { |
| 22 | return; |
| 23 | } |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 24 | var select = document.getElementById('configSelection_pid'); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 25 | var pid = select.options[select.selectedIndex].value; |
Felix Meschberger | b6c7aec | 2008-06-17 11:43:01 +0000 | [diff] [blame] | 26 | var parm = pluginRoot + '/' + pid; |
| 27 | sendRequest('POST', parm, displayConfigForm); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 30 | |
| 31 | function create() { |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 32 | var span = document.getElementById('configField'); |
| 33 | if (!span) { |
| 34 | return; |
| 35 | } |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 36 | var select = document.getElementById('configSelection_factory'); |
| 37 | var pid = select.options[select.selectedIndex].value; |
Felix Meschberger | b6c7aec | 2008-06-17 11:43:01 +0000 | [diff] [blame] | 38 | var parm = pluginRoot + '/' + pid + '?create=true'; |
| 39 | sendRequest('POST', parm, displayConfigForm); |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | function displayConfigForm(obj) { |
| 43 | var span1 = document.getElementById('configField'); |
| 44 | var span2 = document.getElementById('factoryField'); |
| 45 | if (!span1 && !span2) { |
| 46 | return; |
| 47 | } |
| 48 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 49 | var parent = span1 ? span1.parentNode : span2.parentNode; |
| 50 | |
| 51 | clearChildren( parent ); |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 52 | |
| 53 | if (span1) { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 54 | parent.appendChild( span1 ); |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 55 | } |
| 56 | if (span2) { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 57 | parent.appendChild( span2 ); |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 60 | var trEl = tr( "content" ); |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 61 | var tdEl = createElement( "th", "content", { colSpan: "2" } ); |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 62 | addText( tdEl, obj.title ); |
| 63 | trEl.appendChild( tdEl ); |
| 64 | parent.appendChild( trEl ); |
| 65 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 66 | trEl = tr( "content" ); |
| 67 | parent.appendChild( trEl ); |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 68 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 69 | tdEl = td( "content" ); |
| 70 | addText( tdEl, "\u00a0" ); |
| 71 | trEl.appendChild( tdEl ); |
| 72 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 73 | tdEl = td( "content" ); |
| 74 | trEl.appendChild( tdEl ); |
| 75 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 76 | var formEl = createElement( "form", null, { |
Carsten Ziegeler | 2d009d4 | 2009-03-05 17:55:53 +0000 | [diff] [blame] | 77 | method: "POST", |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 78 | action: pluginRoot + "/" + obj.pid |
| 79 | }); |
| 80 | tdEl.appendChild( formEl ); |
| 81 | |
| 82 | var inputEl = createElement( "input", null, { |
| 83 | type: "hidden", |
| 84 | name: "apply", |
| 85 | value: "true" |
| 86 | }); |
| 87 | formEl.appendChild( inputEl ); |
Felix Meschberger | b6c7aec | 2008-06-17 11:43:01 +0000 | [diff] [blame] | 88 | |
| 89 | // add the factory PID as a hidden form field if present |
| 90 | if (obj.factoryPid) |
| 91 | { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 92 | inputEl = createElement( "input", null, { |
| 93 | type: "hidden", |
| 94 | name: "factoryPid", |
| 95 | value: obj.factoryPid |
| 96 | }); |
| 97 | formEl.appendChild( inputEl ); |
Felix Meschberger | b6c7aec | 2008-06-17 11:43:01 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Felix Meschberger | c76ee7f | 2008-09-29 11:00:33 +0000 | [diff] [blame] | 100 | // add the PID filter as a hidden form field if present |
| 101 | if (obj.pidFilter) |
| 102 | { |
| 103 | inputEl = createElement( "input", null, { |
| 104 | type: "hidden", |
| 105 | name: "pidFilter", |
| 106 | value: obj.pidFilter |
| 107 | }); |
| 108 | formEl.appendChild( inputEl ); |
| 109 | } |
| 110 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 111 | inputEl = createElement( "input", null, { |
| 112 | type: "hidden", |
| 113 | name: "action", |
| 114 | value: "ajaxConfigManager" |
| 115 | }); |
| 116 | formEl.appendChild( inputEl ); |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 117 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 118 | var tableEl = createElement( "table", null, { |
| 119 | border: 0, |
| 120 | width: "100%" |
| 121 | }); |
| 122 | formEl.appendChild( tableEl ); |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 123 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 124 | var bodyEl = createElement( "tbody" ); |
| 125 | tableEl.appendChild( bodyEl ); |
| 126 | |
| 127 | if (obj.description) |
| 128 | { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 129 | trEl = tr( "content" ); |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 130 | tdEl = td( "content", { colSpan: "2" } ); |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 131 | addText( tdEl, obj.description ); |
| 132 | trEl.appendChild( tdEl ); |
| 133 | bodyEl.appendChild( trEl ); |
| 134 | } |
| 135 | |
| 136 | if (obj.propertylist == 'properties') |
| 137 | { |
| 138 | printTextArea(bodyEl, obj.properties); |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | printForm(bodyEl, obj); |
| 143 | } |
| 144 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 145 | trEl = tr( "content" ); |
| 146 | bodyEl.appendChild( trEl ); |
| 147 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 148 | tdEl = td( "content" ); |
| 149 | addText( tdEl, "\u00a0" ); |
| 150 | trEl.appendChild( tdEl ); |
| 151 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 152 | tdEl = td( "content" ); |
| 153 | trEl.appendChild( tdEl ); |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 154 | |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 155 | // define this TD as innerHTML otherwise the onClick event handler |
Felix Meschberger | e7551df | 2009-10-26 13:39:09 +0000 | [diff] [blame] | 156 | // of the Delete button is not accepted by IE6 (!)... |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 157 | var innerHTML = '<input type="submit" class="submit" name="submit" value="Save" />'; |
| 158 | innerHTML += ' '; |
| 159 | innerHTML += '<input type="reset" class="submit" name="reset" value="Reset" />'; |
| 160 | innerHTML += ' '; |
Felix Meschberger | 6a6b9aa | 2009-10-26 13:06:41 +0000 | [diff] [blame] | 161 | innerHTML += '<input type="submit" class="submit" name="delete" value="Delete" onClick="return confirmDelete(\'' + obj.pid + '\', \'' + obj.bundleLocation + '\');"/>'; |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 162 | tdEl.innerHTML = innerHTML; |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 163 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 164 | printConfigurationInfo(parent, obj); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 167 | function printTextArea(/* Element */ parent, props ) |
| 168 | { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 169 | |
| 170 | var propsValue = ""; |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 171 | for (var key in props) |
| 172 | { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 173 | propsValue += key + ' = ' + props[key] + '\r\n'; |
| 174 | } |
| 175 | |
Felix Meschberger | 5224706 | 2009-10-23 22:15:54 +0000 | [diff] [blame] | 176 | parent.appendChild( |
| 177 | tr( "content", null, [ |
| 178 | td( "content aligntop", null, [ |
| 179 | text( "Properties" ) |
| 180 | ]), |
| 181 | td( "content", { style: { width: "99%" } }, [ |
| 182 | createElement( "textarea", null, { |
| 183 | name: "properties", |
Guillaume Nodet | 283faa3 | 2010-03-04 20:54:39 +0000 | [diff] [blame] | 184 | style: { height: "20em", width: "99%" } |
Felix Meschberger | 5224706 | 2009-10-23 22:15:54 +0000 | [diff] [blame] | 185 | }, [ text( propsValue ) ] ), |
Guillaume Nodet | 283faa3 | 2010-03-04 20:54:39 +0000 | [diff] [blame] | 186 | createElement( "br" ), |
Felix Meschberger | 5224706 | 2009-10-23 22:15:54 +0000 | [diff] [blame] | 187 | text( "Enter Name-Value pairs of configuration properties" ) |
| 188 | ]) |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 189 | ]) |
Felix Meschberger | 5224706 | 2009-10-23 22:15:54 +0000 | [diff] [blame] | 190 | ); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 193 | function printForm( /* Element */ parent, obj ) { |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 194 | var propList; |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 195 | for (var idx in obj.propertylist) |
| 196 | { |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 197 | var prop = obj.propertylist[idx]; |
| 198 | var attr = obj[prop]; |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 199 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 200 | var trEl = tr( "content", null, [ |
| 201 | td( "content aligntop", null, [ text( attr.name ) ] ) |
| 202 | ]); |
| 203 | parent.appendChild( trEl ); |
| 204 | |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 205 | var tdEl = td( "content", { style: { width: "99%" } } ); |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 206 | trEl.appendChild( tdEl ); |
| 207 | |
| 208 | if (attr.value != undefined) |
| 209 | { |
| 210 | // check is required to also handle empty strings, 0 and false |
| 211 | tdEl.appendChild( createInput( prop, attr.value, attr.type, '99%' ) ); |
| 212 | tdEl.appendChild( createElement( "br" ) ); |
| 213 | } |
| 214 | else if (typeof(attr.type) == 'object') |
| 215 | { |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 216 | // assume attr.values and multiselect |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 217 | createMultiSelect( tdEl, prop, attr.values, attr.type, '99%' ); |
| 218 | tdEl.appendChild( createElement( "br" ) ); |
| 219 | } |
| 220 | else if (attr.values.length == 0) |
| 221 | { |
| 222 | tdEl.appendChild( createSpan( prop, "", attr.type ) ); |
| 223 | } |
| 224 | else |
| 225 | { |
Carsten Ziegeler | e626d30 | 2009-03-05 18:55:47 +0000 | [diff] [blame] | 226 | for (var i=0;i<attr.values.length;i++) |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 227 | { |
Carsten Ziegeler | e626d30 | 2009-03-05 18:55:47 +0000 | [diff] [blame] | 228 | tdEl.appendChild( createSpan( prop, attr.values[i], attr.type ) ); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 229 | } |
| 230 | } |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 231 | |
| 232 | if (attr.description) |
| 233 | { |
| 234 | addText( tdEl, attr.description ); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 235 | } |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 236 | |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 237 | if (propList) { |
| 238 | propList += ',' + prop; |
| 239 | } else { |
| 240 | propList = prop; |
| 241 | } |
| 242 | } |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 243 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 244 | parent.appendChild( createElement( "input", null, { |
| 245 | type: "hidden", |
| 246 | name: "propertylist", |
| 247 | value: propList |
| 248 | }) |
| 249 | ); |
Carsten Ziegeler | bd5b501 | 2009-03-05 19:47:40 +0000 | [diff] [blame] | 250 | // FIX for IE6 and above: checkbox can only be checked after it is in the DOM |
| 251 | $(".checked_box").attr("checked", true).removeClass("checked_box"); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 254 | function printConfigurationInfo( /* Element */ parent, obj ) |
| 255 | { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 256 | parent.appendChild( tr( "content", null, [ |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 257 | createElement( "th", "content", { colSpan: "2" }, [ |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 258 | text( "Configuration Information" ) |
| 259 | ]) |
| 260 | ]) |
| 261 | ); |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 262 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 263 | parent.appendChild( tr( "content", null, [ |
| 264 | td( "content", null, [ |
| 265 | text( "Persistent Identity (PID)" ) |
| 266 | ]), |
| 267 | td( "content", null, [ |
| 268 | text( obj.pid ) |
| 269 | ]) |
| 270 | ]) |
| 271 | ); |
| 272 | |
Carsten Ziegeler | f7eab26 | 2008-12-21 17:59:09 +0000 | [diff] [blame] | 273 | if (obj.factoryPid) |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 274 | { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 275 | parent.appendChild( tr( "content", null, [ |
| 276 | td( "content", null, [ |
| 277 | text( "Factory Peristent Identifier (Factory PID)" ) |
| 278 | ]), |
| 279 | td( "content", null, [ |
Carsten Ziegeler | f7eab26 | 2008-12-21 17:59:09 +0000 | [diff] [blame] | 280 | text( obj.factoryPid ) |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 281 | ]) |
| 282 | ]) |
| 283 | ); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 284 | } |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 285 | |
| 286 | var binding = obj.bundleLocation; |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 287 | if (!binding) |
| 288 | { |
Felix Meschberger | cd169b2 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 289 | binding = "Unbound or new configuration"; |
| 290 | } |
| 291 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 292 | parent.appendChild( tr( "content", null, [ |
| 293 | td( "content", null, [ |
| 294 | text( "Configuration Binding" ) |
| 295 | ]), |
| 296 | td( "content", null, [ |
| 297 | text( binding ) |
| 298 | ]) |
| 299 | ]) |
| 300 | ); |
Felix Meschberger | 6a6b9aa | 2009-10-26 13:06:41 +0000 | [diff] [blame] | 301 | |
| 302 | if (obj.bundleLocation) |
| 303 | { |
Felix Meschberger | e7551df | 2009-10-26 13:39:09 +0000 | [diff] [blame] | 304 | var form = createElement( "form", null, { |
| 305 | method: "POST", |
| 306 | action: pluginRoot + "/" + obj.pid |
| 307 | }); |
| 308 | |
| 309 | // define this form contents as innerHTML otherwise the onClick |
| 310 | // event handler of the Unbind button is not accepted by IE6 (!)... |
| 311 | var formInner = '<input type="hidden" name="unbind" value="true"/>'; |
| 312 | formInner += '<input type="submit" name="submit" value="Unbind" class="submit" title="Unbind Configuration from Bundle" onClick="return confirmUnbind(\'' + obj.pid + '\', \'' + obj.bundleLocation + '\');"/>'; |
| 313 | form.innerHTML = formInner; |
| 314 | |
Felix Meschberger | 6a6b9aa | 2009-10-26 13:06:41 +0000 | [diff] [blame] | 315 | parent.appendChild( tr( "content", null, [ |
| 316 | td( "content", null, [ |
| 317 | text( " " ) |
| 318 | ]), |
Felix Meschberger | e7551df | 2009-10-26 13:39:09 +0000 | [diff] [blame] | 319 | td( "content", null, [ form ] ) |
Felix Meschberger | 6a6b9aa | 2009-10-26 13:06:41 +0000 | [diff] [blame] | 320 | ]) |
| 321 | ); |
| 322 | } |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 325 | |
| 326 | var spanCounter = 0; |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 327 | /* Element */ function createSpan(prop, value, type) { |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 328 | spanCounter++; |
| 329 | var newId = prop + spanCounter; |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 330 | |
Carsten Ziegeler | e626d30 | 2009-03-05 18:55:47 +0000 | [diff] [blame] | 331 | var addButton = createElement("input", "input", |
| 332 | { type: "button", |
| 333 | style: {width : "5%"}, |
| 334 | value: "+" |
| 335 | } |
| 336 | ); |
| 337 | $(addButton).click(function() {addValue(prop, newId)}); |
| 338 | var remButton = createElement("input", "input", |
| 339 | { type: "button", |
| 340 | style: {width : "5%"}, |
| 341 | value: "-" |
| 342 | } |
| 343 | ); |
| 344 | $(remButton).click(function() {removeValue(newId)}); |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 345 | var spanEl = createElement( "span", null, { id: newId }, [ |
Carsten Ziegeler | e626d30 | 2009-03-05 18:55:47 +0000 | [diff] [blame] | 346 | createInput( prop, value, type, '89%' ), addButton, remButton, |
| 347 | createElement("br") |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 348 | ]); |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 349 | |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 350 | return spanEl; |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 351 | } |
| 352 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 353 | /* Element */ function createInput(prop, value, type, width) { |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 354 | if (type == 11) { // AttributeDefinition.BOOLEAN |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 355 | |
| 356 | var inputEl = createElement( "input", "input", { |
| 357 | type: "checkbox", |
| 358 | name: prop, |
Carsten Ziegeler | bd5b501 | 2009-03-05 19:47:40 +0000 | [diff] [blame] | 359 | value: "true" |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 360 | }); |
| 361 | |
| 362 | if (value && typeof(value) != "boolean") |
| 363 | { |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 364 | value = value.toString().toLowerCase() == "true"; |
| 365 | } |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 366 | if (value) |
| 367 | { |
Carsten Ziegeler | bd5b501 | 2009-03-05 19:47:40 +0000 | [diff] [blame] | 368 | $(inputEl).addClass("checked_box"); |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 369 | } |
Carsten Ziegeler | aad8b88 | 2008-10-15 12:13:54 +0000 | [diff] [blame] | 370 | var hiddenEl = createElement( "input", "input", { |
| 371 | type: "hidden", |
| 372 | name: prop, |
Carsten Ziegeler | bd5b501 | 2009-03-05 19:47:40 +0000 | [diff] [blame] | 373 | value: "false" |
Carsten Ziegeler | aad8b88 | 2008-10-15 12:13:54 +0000 | [diff] [blame] | 374 | }); |
Carsten Ziegeler | bd5b501 | 2009-03-05 19:47:40 +0000 | [diff] [blame] | 375 | var divEl = createElement("div"); |
Carsten Ziegeler | aad8b88 | 2008-10-15 12:13:54 +0000 | [diff] [blame] | 376 | divEl.appendChild(inputEl); |
| 377 | divEl.appendChild(hiddenEl); |
| 378 | return divEl; |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 379 | |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 380 | } else if (typeof(type) == "object") { // predefined values |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 381 | |
| 382 | var selectEl = createElement( "select", "select", { |
| 383 | name: prop, |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 384 | style: { width: width } |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 385 | }); |
| 386 | |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 387 | var labels = type.labels; |
| 388 | var values = type.values; |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 389 | for (var idx in labels) { |
| 390 | var optionEl = createElement( "option", null, { |
| 391 | value: values[idx] |
| 392 | }, [ text( labels[idx] ) ]); |
| 393 | |
| 394 | if (value == values[idx]) |
| 395 | { |
| 396 | optionEl.setAttribute( "selected", true ); |
| 397 | } |
| 398 | selectEl.appendChild( optionEl ); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 399 | } |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 400 | |
| 401 | return selectEl; |
| 402 | |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 403 | } else { // Simple |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 404 | return createElement( "input", "input", { |
| 405 | type: "text", |
| 406 | name: prop, |
| 407 | value: value, |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 408 | style: { width: width } |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 409 | }); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 413 | function createMultiSelect(/* Element */ parent, prop, values, options, width) { |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 414 | // convert value list into 'set' |
| 415 | var valueSet = new Object(); |
| 416 | for (var idx in values) { |
| 417 | valueSet[ values[idx] ] = true; |
| 418 | } |
| 419 | |
| 420 | var labels = options.labels; |
| 421 | var values = options.values; |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 422 | for (var idx in labels) { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 423 | |
| 424 | var inputEl = createElement( "input", null, { |
| 425 | type: "checkbox", |
| 426 | name: prop, |
| 427 | value: values[idx] |
| 428 | }); |
| 429 | |
| 430 | if (valueSet[ values[idx] ]) |
| 431 | { |
| 432 | inputEl.setAttribute( "checked", true ); |
| 433 | } |
| 434 | |
Felix Meschberger | 8f91531 | 2009-09-08 13:58:45 +0000 | [diff] [blame] | 435 | var labelEl = createElement( "label", "multiselect" ); |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 436 | labelEl.appendChild( inputEl ); |
| 437 | addText( labelEl, labels[idx] ); |
| 438 | |
| 439 | parent.appendChild( labelEl ); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 440 | } |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 443 | |
| 444 | function addValue(prop, vidx) |
| 445 | { |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 446 | var span = document.getElementById(vidx); |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 447 | if (!span) |
| 448 | { |
| 449 | return; |
| 450 | } |
| 451 | var newSpan = createSpan(prop, ''); |
| 452 | span.parentNode.insertBefore(newSpan, span.nextSibling); |
Carsten Ziegeler | bd5b501 | 2009-03-05 19:47:40 +0000 | [diff] [blame] | 453 | // FIX for IE6 and above: checkbox can only be checked after it is in the DOM |
| 454 | $(".checked_box").attr("checked", true).removeClass("checked_box"); |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | function removeValue(vidx) |
| 458 | { |
| 459 | var span = document.getElementById(vidx); |
| 460 | if (!span) |
| 461 | { |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 462 | return; |
| 463 | } |
| 464 | span.parentNode.removeChild(span); |
| 465 | } |
| 466 | |
Felix Meschberger | 6a6b9aa | 2009-10-26 13:06:41 +0000 | [diff] [blame] | 467 | function configConfirm(/* String */ message, /* String */ title, /* String */ location) |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 468 | { |
Felix Meschberger | 6a6b9aa | 2009-10-26 13:06:41 +0000 | [diff] [blame] | 469 | var message = "Are you sure to delete this configuration ?"; |
| 470 | |
| 471 | if (title) { |
| 472 | message += "\r\nConfiguration: " + title; |
| 473 | } |
| 474 | if (location) { |
| 475 | message += "\r\nBundle: " + location; |
| 476 | } |
| 477 | |
| 478 | return confirm(message); |
| 479 | } |
| 480 | |
| 481 | function confirmDelete(/* String */ title, /* String */ location) |
| 482 | { |
| 483 | return configConfirm("Are you sure to unbind this configuration ?", title, location); |
| 484 | } |
| 485 | |
| 486 | function confirmUnbind(/* String */ title, /* String */ location) |
| 487 | { |
| 488 | return configConfirm("Are you sure to unbind this configuration ?", title, location); |
Felix Meschberger | ca29a96 | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 489 | } |