/*******************************************************************************
* Copyright (c) 2012-2013 University of Stuttgart.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and the Apache License 2.0 which both accompany this distribution,
* and are available at http://www.eclipse.org/legal/epl-v10.html
* and http://www.apache.org/licenses/LICENSE-2.0
*
* Contributors:
* Oliver Kopp - initial API and implementation and/or initial documentation
*******************************************************************************/
/*
Script for dependent selection boxes.
One object for stating a map from value to content. The value is globally unique.
Verbose example:
*/
/**
*
* @param value the current selected value
* @param targetElement the select to update
* @param dependendSelects the data structure for subsequently dependent select elements
* @param completeData the data structure with the complete data
*/
function updateListContent(value, targetElement, dependendSelects, completeData) {
jQuery(targetElement).empty();
var listData = completeData[value];
if (listData !== undefined) {
for (var i=0; i < listData.options.length; i++) {
var optionName = listData.options[i];
var label = completeData[optionName].label;
var selected;
if (i == 0) {
selected = ' selected="selected"';
} else {
selected = '';
}
var toAppend = '';
jQuery(targetElement).append(toAppend);
}
nextSelect = dependendSelects[targetElement];
if (nextSelect !== undefined) {
// We assume listData is not empty
updateListContent(listData.options[0], nextSelect, dependendSelects, completeData);
}
}
jQuery(targetElement).trigger("change");
}