Felix Meschberger | bb30b0c | 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 | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 24 | var select = document.getElementById('configSelection_pid'); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 25 | var pid = select.options[select.selectedIndex].value; |
Felix Meschberger | 0407e25 | 2008-06-17 11:43:01 +0000 | [diff] [blame] | 26 | var parm = pluginRoot + '/' + pid; |
| 27 | sendRequest('POST', parm, displayConfigForm); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 30 | |
| 31 | function create() { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 32 | var span = document.getElementById('configField'); |
| 33 | if (!span) { |
| 34 | return; |
| 35 | } |
Felix Meschberger | 5611f01 | 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 | 0407e25 | 2008-06-17 11:43:01 +0000 | [diff] [blame] | 38 | var parm = pluginRoot + '/' + pid + '?create=true'; |
| 39 | sendRequest('POST', parm, displayConfigForm); |
Felix Meschberger | 5611f01 | 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 | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 49 | var parent = span1 ? span1.parentNode : span2.parentNode; |
| 50 | |
| 51 | clearChildren( parent ); |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 52 | |
| 53 | if (span1) { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 54 | parent.appendChild( span1 ); |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 55 | } |
| 56 | if (span2) { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 57 | parent.appendChild( span2 ); |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 60 | var trEl = tr( "content" ); |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 61 | var tdEl = createElement( "th", "content", { colSpan: "2" } ); |
Felix Meschberger | c07350a | 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 | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 66 | trEl = tr( "content" ); |
| 67 | parent.appendChild( trEl ); |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 68 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 69 | tdEl = td( "content" ); |
| 70 | addText( tdEl, "\u00a0" ); |
| 71 | trEl.appendChild( tdEl ); |
| 72 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 73 | tdEl = td( "content" ); |
| 74 | trEl.appendChild( tdEl ); |
| 75 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 76 | var formEl = createElement( "form", null, { |
| 77 | method: "post", |
| 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 | 0407e25 | 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 | c07350a | 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 | 0407e25 | 2008-06-17 11:43:01 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Felix Meschberger | 05d2e9b | 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 | c07350a | 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 | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 117 | |
Felix Meschberger | c07350a | 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 | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 123 | |
Felix Meschberger | c07350a | 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 | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 129 | trEl = tr( "content" ); |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 130 | tdEl = td( "content", { colSpan: "2" } ); |
Felix Meschberger | c07350a | 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 | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 145 | trEl = tr( "content" ); |
| 146 | bodyEl.appendChild( trEl ); |
| 147 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 148 | tdEl = td( "content" ); |
| 149 | addText( tdEl, "\u00a0" ); |
| 150 | trEl.appendChild( tdEl ); |
| 151 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 152 | tdEl = td( "content" ); |
| 153 | trEl.appendChild( tdEl ); |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 154 | |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 155 | // define this TD as innerHTML otherwise the onClick event handler |
| 156 | // of the Delete button is not accepted by IE... |
| 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 += ' '; |
| 161 | innerHTML += '<input type="submit" class="submit" name="delete" value="Delete" onClick="return confirmDelete();"/>'; |
| 162 | tdEl.innerHTML = innerHTML; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 163 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 164 | printConfigurationInfo(parent, obj); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 167 | function printTextArea(/* Element */ parent, props ) |
| 168 | { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 169 | |
| 170 | var propsValue = ""; |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 171 | for (var key in props) |
| 172 | { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 173 | propsValue += key + ' = ' + props[key] + '\r\n'; |
| 174 | } |
| 175 | |
| 176 | return tr( "content", null, [ |
| 177 | td( "content aligntop", null, [ |
| 178 | text( "Properties" ) |
| 179 | ]), |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 180 | td( "content", { style: { width: "99%" } }, [ |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 181 | createElement( "textarea", null, { |
| 182 | name: "properties", |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 183 | style: { height: "50%", width: "99%" } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 184 | }, [ text( propsValue ) ] ), |
| 185 | text( "Enter Name-Value pairs of configuration properties" ) |
| 186 | ]) |
| 187 | ]); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 190 | function printForm( /* Element */ parent, obj ) { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 191 | var propList; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 192 | for (var idx in obj.propertylist) |
| 193 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 194 | var prop = obj.propertylist[idx]; |
| 195 | var attr = obj[prop]; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 196 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 197 | var trEl = tr( "content", null, [ |
| 198 | td( "content aligntop", null, [ text( attr.name ) ] ) |
| 199 | ]); |
| 200 | parent.appendChild( trEl ); |
| 201 | |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 202 | var tdEl = td( "content", { style: { width: "99%" } } ); |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 203 | trEl.appendChild( tdEl ); |
| 204 | |
| 205 | if (attr.value != undefined) |
| 206 | { |
| 207 | // check is required to also handle empty strings, 0 and false |
| 208 | tdEl.appendChild( createInput( prop, attr.value, attr.type, '99%' ) ); |
| 209 | tdEl.appendChild( createElement( "br" ) ); |
| 210 | } |
| 211 | else if (typeof(attr.type) == 'object') |
| 212 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 213 | // assume attr.values and multiselect |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 214 | createMultiSelect( tdEl, prop, attr.values, attr.type, '99%' ); |
| 215 | tdEl.appendChild( createElement( "br" ) ); |
| 216 | } |
| 217 | else if (attr.values.length == 0) |
| 218 | { |
| 219 | tdEl.appendChild( createSpan( prop, "", attr.type ) ); |
| 220 | } |
| 221 | else |
| 222 | { |
| 223 | for (var vidx in attr.values) |
| 224 | { |
| 225 | tdEl.appendChild( createSpan( prop, attr.values[vidx], attr.type ) ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 226 | } |
| 227 | } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 228 | |
| 229 | if (attr.description) |
| 230 | { |
| 231 | addText( tdEl, attr.description ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 232 | } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 233 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 234 | if (propList) { |
| 235 | propList += ',' + prop; |
| 236 | } else { |
| 237 | propList = prop; |
| 238 | } |
| 239 | } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 240 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 241 | parent.appendChild( createElement( "input", null, { |
| 242 | type: "hidden", |
| 243 | name: "propertylist", |
| 244 | value: propList |
| 245 | }) |
| 246 | ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 249 | function printConfigurationInfo( /* Element */ parent, obj ) |
| 250 | { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 251 | parent.appendChild( tr( "content", null, [ |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 252 | createElement( "th", "content", { colSpan: "2" }, [ |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 253 | text( "Configuration Information" ) |
| 254 | ]) |
| 255 | ]) |
| 256 | ); |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 257 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 258 | parent.appendChild( tr( "content", null, [ |
| 259 | td( "content", null, [ |
| 260 | text( "Persistent Identity (PID)" ) |
| 261 | ]), |
| 262 | td( "content", null, [ |
| 263 | text( obj.pid ) |
| 264 | ]) |
| 265 | ]) |
| 266 | ); |
| 267 | |
| 268 | if (obj.factoryPID) |
| 269 | { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 270 | parent.appendChild( tr( "content", null, [ |
| 271 | td( "content", null, [ |
| 272 | text( "Factory Peristent Identifier (Factory PID)" ) |
| 273 | ]), |
| 274 | td( "content", null, [ |
| 275 | text( obj.factoryPID ) |
| 276 | ]) |
| 277 | ]) |
| 278 | ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 279 | } |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 280 | |
| 281 | var binding = obj.bundleLocation; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 282 | if (!binding) |
| 283 | { |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 284 | binding = "Unbound or new configuration"; |
| 285 | } |
| 286 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 287 | parent.appendChild( tr( "content", null, [ |
| 288 | td( "content", null, [ |
| 289 | text( "Configuration Binding" ) |
| 290 | ]), |
| 291 | td( "content", null, [ |
| 292 | text( binding ) |
| 293 | ]) |
| 294 | ]) |
| 295 | ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 298 | |
| 299 | var spanCounter = 0; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 300 | /* Element */ function createSpan(prop, value, type) { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 301 | spanCounter++; |
| 302 | var newId = prop + spanCounter; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 303 | |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 304 | var spanEl = createElement( "span", null, { id: newId }, [ |
| 305 | createInput( prop, value, type, '89%' ) |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 306 | ]); |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 307 | |
| 308 | // define this SPAN as innerHTML otherwise the onClick event handler |
| 309 | // of the buttons is not accepted by IE... |
| 310 | var innerHTML = "<input type='button' class='input' style='width:\"5%\"' value='+' onClick='addValue(\"" + prop + "\", \"" + newId + "\")' />"; |
| 311 | innerHTML += "<input type='button' class='input' style='width:\"5%\"' value='-' onClick='removeValue(\"" + newId + "\")' />"; |
| 312 | innerHTML += "<br />"; |
| 313 | spanEl.innerHTML += innerHTML; |
| 314 | |
| 315 | return spanEl; |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 316 | } |
| 317 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 318 | /* Element */ function createInput(prop, value, type, width) { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 319 | if (type == 11) { // AttributeDefinition.BOOLEAN |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 320 | |
| 321 | var inputEl = createElement( "input", "input", { |
| 322 | type: "checkbox", |
| 323 | name: prop, |
| 324 | value: true |
| 325 | }); |
| 326 | |
| 327 | if (value && typeof(value) != "boolean") |
| 328 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 329 | value = value.toString().toLowerCase() == "true"; |
| 330 | } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 331 | if (value) |
| 332 | { |
| 333 | inputEl.setAttribute( "checked", true ); |
| 334 | } |
Carsten Ziegeler | 5f193ed | 2008-10-15 12:13:54 +0000 | [diff] [blame^] | 335 | |
| 336 | var hiddenEl = createElement( "input", "input", { |
| 337 | type: "hidden", |
| 338 | name: prop, |
| 339 | value: false |
| 340 | }); |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 341 | |
Carsten Ziegeler | 5f193ed | 2008-10-15 12:13:54 +0000 | [diff] [blame^] | 342 | var divEl = createElement("div", "div"); |
| 343 | divEl.appendChild(inputEl); |
| 344 | divEl.appendChild(hiddenEl); |
| 345 | return divEl; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 346 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 347 | } else if (typeof(type) == "object") { // predefined values |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 348 | |
| 349 | var selectEl = createElement( "select", "select", { |
| 350 | name: prop, |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 351 | style: { width: width } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 352 | }); |
| 353 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 354 | var labels = type.labels; |
| 355 | var values = type.values; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 356 | for (var idx in labels) { |
| 357 | var optionEl = createElement( "option", null, { |
| 358 | value: values[idx] |
| 359 | }, [ text( labels[idx] ) ]); |
| 360 | |
| 361 | if (value == values[idx]) |
| 362 | { |
| 363 | optionEl.setAttribute( "selected", true ); |
| 364 | } |
| 365 | selectEl.appendChild( optionEl ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 366 | } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 367 | |
| 368 | return selectEl; |
| 369 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 370 | } else { // Simple |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 371 | |
| 372 | return createElement( "input", "input", { |
| 373 | type: "text", |
| 374 | name: prop, |
| 375 | value: value, |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 376 | style: { width: width } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 377 | }); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 381 | function createMultiSelect(/* Element */ parent, prop, values, options, width) { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 382 | // convert value list into 'set' |
| 383 | var valueSet = new Object(); |
| 384 | for (var idx in values) { |
| 385 | valueSet[ values[idx] ] = true; |
| 386 | } |
| 387 | |
| 388 | var labels = options.labels; |
| 389 | var values = options.values; |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 390 | for (var idx in labels) { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 391 | |
| 392 | var inputEl = createElement( "input", null, { |
| 393 | type: "checkbox", |
| 394 | name: prop, |
| 395 | value: values[idx] |
| 396 | }); |
| 397 | |
| 398 | if (valueSet[ values[idx] ]) |
| 399 | { |
| 400 | inputEl.setAttribute( "checked", true ); |
| 401 | } |
| 402 | |
| 403 | var labelEl = createElement( "label" ); |
| 404 | labelEl.appendChild( inputEl ); |
| 405 | addText( labelEl, labels[idx] ); |
| 406 | |
| 407 | parent.appendChild( labelEl ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 408 | } |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 411 | |
| 412 | function addValue(prop, vidx) |
| 413 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 414 | var span = document.getElementById(vidx); |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 415 | if (!span) |
| 416 | { |
| 417 | return; |
| 418 | } |
| 419 | var newSpan = createSpan(prop, ''); |
| 420 | span.parentNode.insertBefore(newSpan, span.nextSibling); |
| 421 | } |
| 422 | |
| 423 | function removeValue(vidx) |
| 424 | { |
| 425 | var span = document.getElementById(vidx); |
| 426 | if (!span) |
| 427 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 428 | return; |
| 429 | } |
| 430 | span.parentNode.removeChild(span); |
| 431 | } |
| 432 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 433 | function confirmDelete() |
| 434 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 435 | return confirm("Are you sure to delete this configuration ?"); |
| 436 | } |