summaryrefslogtreecommitdiffstats
path: root/winery/org.eclipse.winery.repository/src/main/webapp/js/nextselect.js
blob: 050fcb16e8973e4579fd1ebe013c89e4e3078ac7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*******************************************************************************
 * 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:
<script>

var WSDLoperationsData = {
	"ns1" : {
		"options" : ["ns1:pt11", "ns1:pt12"],
	},

	"ns2" : {
		"options" : ["ns2:pt21"],
	},

	"ns3" : {
		"options" : ["ns3:pt31"],
	},

	"ns1:pt11" : {
		"label" : "PortType 1.1",
		"options" : ["ns1:pt11:op111", "ns1:pt11:op112"]
	},

	"ns1:pt12" : {
		"label" : "PortType 1.2",
		"options" : ["ns1:pt12:op113", "ns1:pt11:op114"]
	},


	"ns2:pt21" : {
		"label" : "PortType 2.1",
		"options" : ["ns2:pt21:op211", "ns2:pt21:op212"]
	},


	"ns3:pt31" : {
		"label" : "PortType 3.1",
		"options" : ["ns3:pt31:op311", "ns3:pt31:op312"]
	},


	"ns1:pt11:op111" : {
		"label" : "operation 1.1.1",
	},

	"ns1:pt11:op112" : {
		"label" : "operation 1.1.2",
	},

	"ns1:pt12:op113" : {
		"label" : "operation 1.1.3",
	},

	"ns1:pt12:op114" : {
		"label" : "operation 1.1.4",
	},

	"ns2:pt21:op211" : {
		"label" : "operation 2.1.1",
	},

	"ns2:pt21:op212" : {
		"label" : "operation 2.1.2",
	},

	"ns3:pt31:op311" : {
		"label" : "operation 3.1.1",
	},

	"ns3:pt31:op312" : {
		"label" : "operation 3.1.2",
	}
}

var WSDLdependendSelects = {
		"#portTypes" : "#operations"
}
</script>

<select size="15" onchange="updateListContent(this.value, '#portTypes', WSDLdependendSelects, WSDLoperationsData);" >
	<option value="ns1" selected="true" >Namespace1</option>
	<option value="ns2" >Namespace2</option>
	<option value="ns3" >Namespace3</option>
</select>

<select id="portTypes" size="15" onchange="updateListContent(this.value, '#operations', WSDLdependendSelects, WSDLoperationsData);">
	<option value="ns1:pt11" selected="true">PortType1.1</option>
	<option value="ns1:pt11">PortType1.2</option>
</select>

<select id="operations" size="15">
	<option value="ns1:pt11:op111" selected="true">op1.1.2</option>
	<option value="ns1:pt12:op112">op1.1.2</option>
	<option value="ns1:pt13:op113">op1.1.2</option>
</select>

 */

/**
 *
 * @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 = '<option value="' + optionName + '"' + selected + '>' + label + '</option>';
			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");
}