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 | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 100 | inputEl = createElement( "input", null, { |
| 101 | type: "hidden", |
| 102 | name: "action", |
| 103 | value: "ajaxConfigManager" |
| 104 | }); |
| 105 | formEl.appendChild( inputEl ); |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 106 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 107 | var tableEl = createElement( "table", null, { |
| 108 | border: 0, |
| 109 | width: "100%" |
| 110 | }); |
| 111 | formEl.appendChild( tableEl ); |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 112 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 113 | var bodyEl = createElement( "tbody" ); |
| 114 | tableEl.appendChild( bodyEl ); |
| 115 | |
| 116 | if (obj.description) |
| 117 | { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 118 | trEl = tr( "content" ); |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 119 | tdEl = td( "content", { colSpan: "2" } ); |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 120 | addText( tdEl, obj.description ); |
| 121 | trEl.appendChild( tdEl ); |
| 122 | bodyEl.appendChild( trEl ); |
| 123 | } |
| 124 | |
| 125 | if (obj.propertylist == 'properties') |
| 126 | { |
| 127 | printTextArea(bodyEl, obj.properties); |
| 128 | } |
| 129 | else |
| 130 | { |
| 131 | printForm(bodyEl, obj); |
| 132 | } |
| 133 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 134 | trEl = tr( "content" ); |
| 135 | bodyEl.appendChild( trEl ); |
| 136 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 137 | tdEl = td( "content" ); |
| 138 | addText( tdEl, "\u00a0" ); |
| 139 | trEl.appendChild( tdEl ); |
| 140 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 141 | tdEl = td( "content" ); |
| 142 | trEl.appendChild( tdEl ); |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 143 | |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 144 | // define this TD as innerHTML otherwise the onClick event handler |
| 145 | // of the Delete button is not accepted by IE... |
| 146 | var innerHTML = '<input type="submit" class="submit" name="submit" value="Save" />'; |
| 147 | innerHTML += ' '; |
| 148 | innerHTML += '<input type="reset" class="submit" name="reset" value="Reset" />'; |
| 149 | innerHTML += ' '; |
| 150 | innerHTML += '<input type="submit" class="submit" name="delete" value="Delete" onClick="return confirmDelete();"/>'; |
| 151 | tdEl.innerHTML = innerHTML; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 152 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 153 | printConfigurationInfo(parent, obj); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 156 | function printTextArea(/* Element */ parent, props ) |
| 157 | { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 158 | |
| 159 | var propsValue = ""; |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 160 | for (var key in props) |
| 161 | { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 162 | propsValue += key + ' = ' + props[key] + '\r\n'; |
| 163 | } |
| 164 | |
| 165 | return tr( "content", null, [ |
| 166 | td( "content aligntop", null, [ |
| 167 | text( "Properties" ) |
| 168 | ]), |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 169 | td( "content", { style: { width: "99%" } }, [ |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 170 | createElement( "textarea", null, { |
| 171 | name: "properties", |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 172 | style: { height: "50%", width: "99%" } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 173 | }, [ text( propsValue ) ] ), |
| 174 | text( "Enter Name-Value pairs of configuration properties" ) |
| 175 | ]) |
| 176 | ]); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 179 | function printForm( /* Element */ parent, obj ) { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 180 | var propList; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 181 | for (var idx in obj.propertylist) |
| 182 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 183 | var prop = obj.propertylist[idx]; |
| 184 | var attr = obj[prop]; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 185 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 186 | var trEl = tr( "content", null, [ |
| 187 | td( "content aligntop", null, [ text( attr.name ) ] ) |
| 188 | ]); |
| 189 | parent.appendChild( trEl ); |
| 190 | |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 191 | var tdEl = td( "content", { style: { width: "99%" } } ); |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 192 | trEl.appendChild( tdEl ); |
| 193 | |
| 194 | if (attr.value != undefined) |
| 195 | { |
| 196 | // check is required to also handle empty strings, 0 and false |
| 197 | tdEl.appendChild( createInput( prop, attr.value, attr.type, '99%' ) ); |
| 198 | tdEl.appendChild( createElement( "br" ) ); |
| 199 | } |
| 200 | else if (typeof(attr.type) == 'object') |
| 201 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 202 | // assume attr.values and multiselect |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 203 | createMultiSelect( tdEl, prop, attr.values, attr.type, '99%' ); |
| 204 | tdEl.appendChild( createElement( "br" ) ); |
| 205 | } |
| 206 | else if (attr.values.length == 0) |
| 207 | { |
| 208 | tdEl.appendChild( createSpan( prop, "", attr.type ) ); |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | for (var vidx in attr.values) |
| 213 | { |
| 214 | tdEl.appendChild( createSpan( prop, attr.values[vidx], attr.type ) ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 217 | |
| 218 | if (attr.description) |
| 219 | { |
| 220 | addText( tdEl, attr.description ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 221 | } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 222 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 223 | if (propList) { |
| 224 | propList += ',' + prop; |
| 225 | } else { |
| 226 | propList = prop; |
| 227 | } |
| 228 | } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 229 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 230 | parent.appendChild( createElement( "input", null, { |
| 231 | type: "hidden", |
| 232 | name: "propertylist", |
| 233 | value: propList |
| 234 | }) |
| 235 | ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 238 | function printConfigurationInfo( /* Element */ parent, obj ) |
| 239 | { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 240 | parent.appendChild( tr( "content", null, [ |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 241 | createElement( "th", "content", { colSpan: "2" }, [ |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 242 | text( "Configuration Information" ) |
| 243 | ]) |
| 244 | ]) |
| 245 | ); |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 246 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 247 | parent.appendChild( tr( "content", null, [ |
| 248 | td( "content", null, [ |
| 249 | text( "Persistent Identity (PID)" ) |
| 250 | ]), |
| 251 | td( "content", null, [ |
| 252 | text( obj.pid ) |
| 253 | ]) |
| 254 | ]) |
| 255 | ); |
| 256 | |
| 257 | if (obj.factoryPID) |
| 258 | { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 259 | parent.appendChild( tr( "content", null, [ |
| 260 | td( "content", null, [ |
| 261 | text( "Factory Peristent Identifier (Factory PID)" ) |
| 262 | ]), |
| 263 | td( "content", null, [ |
| 264 | text( obj.factoryPID ) |
| 265 | ]) |
| 266 | ]) |
| 267 | ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 268 | } |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 269 | |
| 270 | var binding = obj.bundleLocation; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 271 | if (!binding) |
| 272 | { |
Felix Meschberger | 5611f01 | 2008-06-13 12:19:36 +0000 | [diff] [blame] | 273 | binding = "Unbound or new configuration"; |
| 274 | } |
| 275 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 276 | parent.appendChild( tr( "content", null, [ |
| 277 | td( "content", null, [ |
| 278 | text( "Configuration Binding" ) |
| 279 | ]), |
| 280 | td( "content", null, [ |
| 281 | text( binding ) |
| 282 | ]) |
| 283 | ]) |
| 284 | ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 287 | |
| 288 | var spanCounter = 0; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 289 | /* Element */ function createSpan(prop, value, type) { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 290 | spanCounter++; |
| 291 | var newId = prop + spanCounter; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 292 | |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 293 | var spanEl = createElement( "span", null, { id: newId }, [ |
| 294 | createInput( prop, value, type, '89%' ) |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 295 | ]); |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 296 | |
| 297 | // define this SPAN as innerHTML otherwise the onClick event handler |
| 298 | // of the buttons is not accepted by IE... |
| 299 | var innerHTML = "<input type='button' class='input' style='width:\"5%\"' value='+' onClick='addValue(\"" + prop + "\", \"" + newId + "\")' />"; |
| 300 | innerHTML += "<input type='button' class='input' style='width:\"5%\"' value='-' onClick='removeValue(\"" + newId + "\")' />"; |
| 301 | innerHTML += "<br />"; |
| 302 | spanEl.innerHTML += innerHTML; |
| 303 | |
| 304 | return spanEl; |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 307 | /* Element */ function createInput(prop, value, type, width) { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 308 | if (type == 11) { // AttributeDefinition.BOOLEAN |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 309 | |
| 310 | var inputEl = createElement( "input", "input", { |
| 311 | type: "checkbox", |
| 312 | name: prop, |
| 313 | value: true |
| 314 | }); |
| 315 | |
| 316 | if (value && typeof(value) != "boolean") |
| 317 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 318 | value = value.toString().toLowerCase() == "true"; |
| 319 | } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 320 | if (value) |
| 321 | { |
| 322 | inputEl.setAttribute( "checked", true ); |
| 323 | } |
| 324 | |
| 325 | return inputEl; |
| 326 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 327 | } else if (typeof(type) == "object") { // predefined values |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 328 | |
| 329 | var selectEl = createElement( "select", "select", { |
| 330 | name: prop, |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 331 | style: { width: width } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 332 | }); |
| 333 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 334 | var labels = type.labels; |
| 335 | var values = type.values; |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 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 ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 346 | } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 347 | |
| 348 | return selectEl; |
| 349 | |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 350 | } else { // Simple |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 351 | |
| 352 | return createElement( "input", "input", { |
| 353 | type: "text", |
| 354 | name: prop, |
| 355 | value: value, |
Felix Meschberger | fb550db | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 356 | style: { width: width } |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 357 | }); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 361 | function createMultiSelect(/* Element */ parent, prop, values, options, width) { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 362 | // convert value list into 'set' |
| 363 | var valueSet = new Object(); |
| 364 | for (var idx in values) { |
| 365 | valueSet[ values[idx] ] = true; |
| 366 | } |
| 367 | |
| 368 | var labels = options.labels; |
| 369 | var values = options.values; |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 370 | for (var idx in labels) { |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 371 | |
| 372 | var inputEl = createElement( "input", null, { |
| 373 | type: "checkbox", |
| 374 | name: prop, |
| 375 | value: values[idx] |
| 376 | }); |
| 377 | |
| 378 | if (valueSet[ values[idx] ]) |
| 379 | { |
| 380 | inputEl.setAttribute( "checked", true ); |
| 381 | } |
| 382 | |
| 383 | var labelEl = createElement( "label" ); |
| 384 | labelEl.appendChild( inputEl ); |
| 385 | addText( labelEl, labels[idx] ); |
| 386 | |
| 387 | parent.appendChild( labelEl ); |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 388 | } |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 391 | |
| 392 | function addValue(prop, vidx) |
| 393 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 394 | var span = document.getElementById(vidx); |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 395 | if (!span) |
| 396 | { |
| 397 | return; |
| 398 | } |
| 399 | var newSpan = createSpan(prop, ''); |
| 400 | span.parentNode.insertBefore(newSpan, span.nextSibling); |
| 401 | } |
| 402 | |
| 403 | function removeValue(vidx) |
| 404 | { |
| 405 | var span = document.getElementById(vidx); |
| 406 | if (!span) |
| 407 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 408 | return; |
| 409 | } |
| 410 | span.parentNode.removeChild(span); |
| 411 | } |
| 412 | |
Felix Meschberger | c07350a | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 413 | function confirmDelete() |
| 414 | { |
Felix Meschberger | bb30b0c | 2008-05-16 11:59:32 +0000 | [diff] [blame] | 415 | return confirm("Are you sure to delete this configuration ?"); |
| 416 | } |