Project

General

Profile

« Previous | Next » 

Revision 5633

use jQuery to build active domain selections

View differences:

index.jsp
1 1
<%@ page language="java"%>
2
<%@page import="java.util.List"%>
3
<%@page import="java.util.ArrayList"%>
4
<%@page import="org.ecoinformatics.sms.SMS"%>
5
<%@page import="org.ecoinformatics.sms.ontology.OntologyClass"%>
6

  
7 2
<%
8 3
/**
9 4
 * 
......
29 24
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30 25
 */  
31 26
%>
32
<%
33 27

  
34
	//harvest parameters
35
	String[] entityParam = request.getParameterValues("entity");
36
	String[] characteristicParam = request.getParameterValues("characteristic");
37
	String[] standardParam = request.getParameterValues("standard");
38
	String[] protocolParam = request.getParameterValues("protocol");
39
	String[] measurementParam = request.getParameterValues("measurement");
40
	
41
	List<OntologyClass> activeEntities = new ArrayList<OntologyClass>();
42
	List<OntologyClass> activeCharacteristics = new ArrayList<OntologyClass>();
43
	List<OntologyClass> activeStandards = new ArrayList<OntologyClass>();
44
	List<OntologyClass> activeProtocols = new ArrayList<OntologyClass>();
45
	List<OntologyClass> activeMeasurements = new ArrayList<OntologyClass>();
46
	
47
	// Entity
48
	if (entityParam != null) {
49
		for (String entityString: entityParam) {
50
			OntologyClass e = new OntologyClass(entityString);
51
			activeEntities.add(e);
52
		}
53
	}
54
	// Characteristic
55
	if (characteristicParam != null) {
56
		for (String classString: characteristicParam) {
57
			OntologyClass c = new OntologyClass(classString);
58
			activeCharacteristics.add(c);
59
		}
60
	}
61
	// Standard
62
	if (standardParam != null) {
63
		for (String classString: standardParam) {
64
			OntologyClass c = new OntologyClass(classString);
65
			activeStandards.add(c);
66
		}
67
	}
68
	// Protocol
69
	if (protocolParam != null) {
70
		for (String classString: protocolParam) {
71
			OntologyClass c = new OntologyClass(classString);
72
			activeProtocols.add(c);
73
		}
74
	}
75
	// Measurement
76
	// TODO: implement measurement expansion
77
	
78
	// construct the selection fields for existing annotations
79
	// Entity
80
	StringBuffer entityOptions = new StringBuffer();
81
	List<OntologyClass> entities = SMS.getInstance().getAnnotationManager().getActiveEntities(activeCharacteristics, activeStandards);
82
	for (OntologyClass oc: entities) {
83
		entityOptions.append("<option ");
84
		entityOptions.append("title='");
85
		entityOptions.append(oc.getURI());
86
		entityOptions.append("' ");
87
		entityOptions.append("value='");
88
		entityOptions.append(oc.getURI());
89
		entityOptions.append("'");
90
		entityOptions.append(">");
91
		entityOptions.append(oc.getName());
92
		entityOptions.append("</option>");
93
	}
94
	// Characteristic
95
	StringBuffer characteristicOptions = new StringBuffer();
96
	List<OntologyClass> characteristics = SMS.getInstance().getAnnotationManager().getActiveCharacteristics(activeEntities, activeStandards);
97
	for (OntologyClass oc: characteristics) {
98
		characteristicOptions.append("<option ");
99
		characteristicOptions.append("title='");
100
		characteristicOptions.append(oc.getURI());
101
		characteristicOptions.append("' ");
102
		characteristicOptions.append("value='");
103
		characteristicOptions.append(oc.getURI());
104
		characteristicOptions.append("'");
105
		characteristicOptions.append(">");
106
		characteristicOptions.append(oc.getName());
107
		characteristicOptions.append("</option>");
108
	}
109
	// Standard
110
	StringBuffer standardOptions = new StringBuffer();
111
	List<OntologyClass> standards = SMS.getInstance().getAnnotationManager().getActiveStandards(activeEntities, activeCharacteristics);
112
	for (OntologyClass oc: standards) {
113
		standardOptions.append("<option ");
114
		standardOptions.append("title='");
115
		standardOptions.append(oc.getURI());
116
		standardOptions.append("' ");
117
		standardOptions.append("value='");
118
		standardOptions.append(oc.getURI());
119
		standardOptions.append("'");
120
		standardOptions.append(">");
121
		standardOptions.append(oc.getName());
122
		standardOptions.append("</option>");
123
	}
124
	// Protocol TODO: filtering
125
	StringBuffer protocolOptions = new StringBuffer();
126
	List<OntologyClass> protocols = SMS.getInstance().getAnnotationManager().getActiveProtocols();
127
	for (OntologyClass oc: protocols) {
128
		protocolOptions.append("<option ");
129
		protocolOptions.append("title='");
130
		protocolOptions.append(oc.getURI());
131
		protocolOptions.append("' ");
132
		protocolOptions.append("value='");
133
		protocolOptions.append(oc.getURI());
134
		protocolOptions.append("'");
135
		protocolOptions.append(">");
136
		protocolOptions.append(oc.getName());
137
		protocolOptions.append("</option>");
138
	}
139
	// Measurement TODO: filtering
140
	StringBuffer measurementOptions = new StringBuffer();
141
	List<OntologyClass> measurements = SMS.getInstance().getAnnotationManager().getActiveMeasurements();
142
	for (OntologyClass oc: measurements) {
143
		measurementOptions.append("<option ");
144
		measurementOptions.append("title='");
145
		measurementOptions.append(oc.getURI());
146
		measurementOptions.append("' ");
147
		measurementOptions.append("value='");
148
		measurementOptions.append(oc.getURI());
149
		measurementOptions.append("'");
150
		measurementOptions.append(">");
151
		measurementOptions.append(oc.getName());
152
		measurementOptions.append("</option>");
153
	}
154
%>
155

  
156 28
<%@ include file="../../common/common-settings.jsp"%>
157 29
<%@ include file="../../common/configure-check.jsp"%>
158 30

  
......
176 48
<script language="javascript" type="text/javascript" src="<%=STYLE_SKINS_URL%>/semtools/semtools.js"></script>
177 49
<script language="javascript" type="text/javascript" src="<%=STYLE_COMMON_URL%>/branding.js"></script>
178 50

  
51
<script language="Javascript" type="text/JavaScript">
52
function populateActiveDomain(divId, class) {
53
	var entity = $("#activeEntities").val() ? $("#activeEntities").val() : "";
54
	var characteristic = $("#activeCharacteristics").val() ? $("#activeCharacteristics").val() : "";
55
	var protocol = $("#activeProtocols").val() ? $("#activeProtocols").val() : "";
56
	var measurement = $("#activeMeasurements").val() ? $("#activeMeasurements").val() : "";
57
	
58
	var originalValue = $("#" + divId).val();
59
	$("#" + divId).load(
60
	"http://fred.msi.ucsb.edu:8080/knb/metacat", 
61
	{
62
		'action': "getactivedomain",
63
		'class': class,
64
		'entity': entity,
65
		'characteristic': characteristic,
66
		'protocol': protocol,
67
		'measurement': measurement
68
	}, 
69
	function(response, status, xhr) {
70
	  if (status == "error") {
71
	    var msg = "Sorry but there was an error: ";
72
	    $("#error").html(msg + xhr.status + " " + xhr.statusText);
73
	  }
74
	  // set the original selected value
75
	  $("#" + divId).val(originalValue);
76
	});
77
}
78
function initialize(source) {
79
	if (source) {
80
		source = source.id;
81
	}
82
	if (!source) {
83
		source = "";
84
	}
85
	if (source != 'activeEntities') {
86
		populateActiveDomain('activeEntities', 'org.ecoinformatics.sms.annotation.Entity');
87
	}
88
	if (source != 'activeCharacteristics') {
89
		var v = $('#activeCharacteristics').val();
90
		populateActiveDomain('activeCharacteristics', 'org.ecoinformatics.sms.annotation.Characteristic');
91
		$('#activeCharacteristics').val(v);
92
	}
93
	if (source != 'activeProtocols') {
94
		var v = $('#activeProtocols').val();
95
		populateActiveDomain('activeProtocols', 'org.ecoinformatics.sms.annotation.Protocol');
96
		$('#activeProtocols').val(v);
97
	}
98
	if (source != 'activeMeasurements') {
99
		var v = $('#activeMeasurements').val();
100
		populateActiveDomain('activeMeasurements', 'org.ecoinformatics.sms.annotation.Measurement');
101
		$('#activeMeasurements').val(v);
102
	}
103
}
104
</script>
105

  
179 106
</head>
180
<body>
107
<body onload="initialize()">
181 108
<script language="javascript">
182 109
	insertTemplateOpening("<%=CONTEXT_URL%>");
183 110
</script>
......
186 113

  
187 114
<h2>Annotation-based search</h2>
188 115

  
116
<div id="error">
117
	<!-- error messages here -->
118
</div>
119

  
189 120
<form method="POST" action="<%=SERVLET_URL%>" target="_top" id="searchForm" name="searchForm" onSubmit="return checkSearch(this)">
190 121
	<input name="query" type="hidden" />
191 122
	<input name="qformat" value="semtools" type="hidden" />
......
218 149
					</tr>
219 150
					<tr>
220 151
						<td>
221
							<select name="dynamicValue" id="dynamicValue" multiple="multiple" size="5" style="width: 100%">
222
								<%=measurementOptions %>
152
							<select name="activeMeasurements" id="activeMeasurements" multiple="multiple" size="5" style="width: 100%" onchange="initialize(this)">
153
								<option>loading...</option>
223 154
							</select>
224
							<input type="hidden" name="dynamicClass" id="dynamicClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Measurement"/>
155
							<input type="hidden" name="activeMeasurementsClass" id="activeMeasurementsClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Measurement"/>
225 156
						</td>
226 157
					</tr>
227 158
					<tr>
......
247 178
					<tr>
248 179
						<td>
249 180
							(a)
250
							<select name="dynamicValue" id="dynamicValue" multiple="multiple" size="5" style="width: 216px">
251
								<%=entityOptions %>
181
							<select name="activeEntities" id="activeEntities" multiple="multiple" size="5" style="width: 216px" onchange="initialize(this)">
182
								<option>loading...</option>
252 183
							</select>
253
							<input type="hidden" name="dynamicClass" id="dynamicClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Entity"/>
184
							<input type="hidden" name="activeEntitiesClass" id="activeEntitiesClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Entity"/>
254 185
						</td>
255 186
					</tr>
256 187
					<tr>
......
274 205
					</tr>
275 206
					<tr>
276 207
						<td>
277
							<select name="dynamicValue" id="dynamicValue" multiple="multiple" size="5" style="width: 216px">
278
								<%=characteristicOptions %>
208
							<select name="activeCharacteristics" id="activeCharacteristics" multiple="multiple" size="5" style="width: 216px" onchange="initialize(this)">
209
								<option>loading...</option>
279 210
							</select>
280
							<input type="hidden" name="dynamicClass" id="dynamicClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Characteristic"/>
211
							<input type="hidden" name="activeCharacteristicsClass" id="activeCharacteristicsClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Characteristic"/>
281 212
						</td>
282 213
					</tr>
283 214
					<tr>
......
301 232
					</tr>
302 233
					<tr>
303 234
						<td>
304
							<select name="dynamicValue" id="dynamicValue" multiple="multiple" size="5" style="width: 216px">
305
								<%=standardOptions %>
235
							<select name="activeStandards" id="activeStandards" multiple="multiple" size="5" style="width: 216px" onchange="initialize(this)">
236
								<option>loading...</option>
306 237
							</select>
307
							<input type="hidden" name="dynamicClass" id="dynamicClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Standard"/>
238
							<input type="hidden" name="activeStandardsClass" id="activeStandardsClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Standard"/>
308 239
						</td>
309 240
					</tr>
310 241
					<tr>
......
328 259
					</tr>
329 260
					<tr>
330 261
						<td>
331
							<select name="dynamicValue" id="dynamicValue" multiple="multiple" size="5" style="width: 216px">
332
								<%=protocolOptions %>
262
							<select name="activeProtocols" id="activeProtocols" multiple="multiple" size="5" style="width: 216px" onchange="initialize(this)">
263
								<option>loading...</option>
333 264
							</select>
334
							<input type="hidden" name="dynamicClass" id="dynamicClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Protocol"/>
265
							<input type="hidden" name="activeProtocolsClass" id="activeProtocolsClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Protocol"/>
335 266
						</td>
336 267
					</tr>
337 268
					<tr>
......
350 281
			<td colspan="3">From same Observation? <input type="checkbox" name="strict"/></td>
351 282
		</tr>
352 283
		<tr>
353
			<td colspan="3"><input type="submit" value="Search"/></td>
284
			<td colspan="3">
285
				<input type="submit" value="Search"/>
286
				<input type="reset" value="Clear" onclick="$('#searchForm').get(0).reset(); initialize()"/>
287
			</td>
354 288
		</tr>
355 289
	</table>
356 290
		<!-- 

Also available in: Unified diff