Project

General

Profile

1
<%@ page language="java"%>
2
<%
3
/**
4
 * 
5
 * '$RCSfile$'
6
 * Copyright: 2008 Regents of the University of California and the
7
 *             National Center for Ecological Analysis and Synthesis
8
 *    '$Author: leinfelder $'
9
 *      '$Date: 2010-12-03 16:24:18 -0800 (Fri, 03 Dec 2010) $'
10
 * '$Revision: 5688 $'
11
 * 
12
 * This program is free software; you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation; either version 2 of the License, or
15
 * (at your option) any later version.
16
 * 
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU General Public License for more details.
21
     
22
 * You should have received a copy of the GNU General Public License
23
 * along with this program; if not, write to the Free Software
24
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
 */  
26
%>
27

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

    
31
<html>
32
<head>
33
<title>Semantic search</title>
34
<link rel="stylesheet" type="text/css" href="<%=STYLE_SKINS_URL%>/semtools/semtools.css">
35
<link rel="stylesheet" type="text/css" href="<%=STYLE_SKINS_URL%>/semtools/jqueryui/css/smoothness/jquery-ui-1.8.6.custom.css">
36
<script type="text/javascript"
37
	src="<%=STYLE_SKINS_URL%>/semtools/search.js"></script>
38

    
39
<script type="text/javascript">
40
                    	    // Set defaults for this installation
41
                    	    //var BP_SEARCH_SERVER = "http://oor-01.cim3.net";
42
                    	    //var BP_SITE = "Sandbox";
43
                    	    //var BP_ORG = "OOR";
44
                    	  </script>
45
<!--  
46
<script language="Javascript" type="text/JavaScript" src="<%=STYLE_SKINS_URL%>/semtools/bioportal/form_complete.js"></script>
47
-->
48
<script language="javascript" type="text/javascript" src="<%=STYLE_SKINS_URL%>/semtools/jsTree/_lib/jquery.js"></script>
49
<script language="javascript" type="text/javascript" src="<%=STYLE_SKINS_URL%>/semtools/jsTree/_lib/jquery.cookie.js"></script>
50
<script language="javascript" type="text/javascript" src="<%=STYLE_SKINS_URL%>/semtools/jsTree/jquery.jstree.js"></script>
51
<!-- jquery ui -->
52
<script language="javascript" type="text/javascript" src="<%=STYLE_SKINS_URL%>/semtools/jqueryui/js/jquery-ui-1.8.6.custom.min.js"></script>
53

    
54
<script language="javascript" type="text/javascript" src="<%=STYLE_SKINS_URL%>/semtools/jquery/jquery.busy.js"></script>
55

    
56
<script language="javascript" type="text/javascript" src="<%=STYLE_SKINS_URL%>/semtools/semtools.js"></script>
57
<script language="javascript" type="text/javascript" src="<%=STYLE_COMMON_URL%>/branding.js"></script>
58

    
59
<script language="Javascript" type="text/JavaScript"><!--
60
function populateActiveDomain(divId, class) {
61
	// collect the filtering values we have so far
62
	// these are hidden input fields in the form for holding the selected values
63
	var entity = $("#activeEntitiesValue").val() ? $("#activeEntitiesValue").val() : "";
64
	var characteristic = $("#activeCharacteristicsValue").val() ? $("#activeCharacteristicsValue").val() : "";
65
	var protocol = $("#activeProtocolsValue").val() ? $("#activeProtocolsValue").val() : "";
66
	var measurement = $("#activeMeasurementsValue").val() ? $("#activeMeasurementsValue").val() : "";
67
	
68
	// TODO: remember the selected value for this when filtering by active domain
69
	var selectedNode = $("#" + divId).jstree("get_selected", $("#" + divId));
70
	var selectedNodeId = $(selectedNode).attr("id");
71
	//alert(divId + " selected node: " + selectedNodeId);
72
	
73
	// load the tree for the given div, passing in the other filtered values
74
	$("#" + divId).load(
75
		"<%=SERVLET_URL%>", 
76
		{
77
			'action': "getactivedomain",
78
			'class': class,
79
			'entity': entity,
80
			'characteristic': characteristic,
81
			'protocol': protocol,
82
			'measurement': measurement
83
		},
84
		// call back function when loading finishes
85
		function(response, status, xhr) {
86
			//alert("callback for: " + divId + " selected node: " + selectedNodeId);
87
			// error
88
			if (status == "error") {
89
				var msg = "Sorry but there was an error: ";
90
				$("#error").html(msg + xhr.status + " " + xhr.statusText);
91
			}
92
 
93
			// make it a js tree
94
			$(function () {
95
				$("#" + divId)
96
					//bind calls here
97
					.jstree({
98
						"ui" : {
99
							"select_limit" : 1,
100
							"select_multiple_modifier" : "alt",
101
							"selected_parent_close" : "select_parent"//,
102
							//"initially_select" : [ selectedNodeId ]
103
						},
104
						"themes" : {
105
							"theme" : "default",
106
							"dots" : true,
107
							"icons" : false
108
						},
109
						//"core" : { "initially_open" : [ selectedNodeId ] },
110
						"search" : { "case_insensitive" : true },
111
						//"cookies" : { 
112
						//		"save_opened" : "jstree_open_" + divId,
113
						//		"save_selected" : "jstree_select_" + divId,
114
						//},
115
						"plugins" : [ 
116
							"themes", 
117
							"html_data", 
118
							"ui", 
119
							//"cookies", 
120
							"search" ]
121
					});
122
			});
123

    
124
			// enable searching on it
125
			$("#" + divId + "Search").keyup(
126
				function () {
127
					var searchTerm = $("#" + divId + "Search").val();
128
					if (searchTerm.length >= 3) {
129
						// search
130
						$("#" + divId).jstree("search", searchTerm);
131
						// now prune
132
						prune(divId, "jstree-search");
133
						// is it an exact match?
134
						checkExactMatch(divId, searchTerm, "jstree-search");
135
					}
136
				});
137
			
138
			// toggle the active domain prune
139
			$("#" + divId + "Only").click(function() {
140
				doActiveDomain(divId);
141
			});	
142

    
143
			// actually prune if we should
144
			doActiveDomain(divId);
145

    
146
			// open first node always
147
			$("#" + divId).jstree("open_node", $("#" + divId).children("ul").first().children("li").first());
148
			
149
			// open to the node to last selected
150
			var nodePath = $("#" + divId).jstree("get_path", $(selectedNode));
151
			if (nodePath) {
152
				for (var index = 0; index < nodePath.length; index++) {
153
					$("#" + divId).jstree("open_node", $("#" + nodePath[index]));
154
				}
155
				// select the original node
156
				$("#" + divId).jstree("select_node", $(selectedNode), false);
157
				$("#" + divId).jstree("refresh", $(selectedNode));
158
				// TODO: scroll to selected node. 
159
				// This is supposed to be part of jsTree 1.0-rc2 but appears to be broken
160
			}
161
			
162
		});
163
}
164
/**
165
* Prunes the given tree to inlcude the given matched class 
166
**/
167
function prune(divId, matchClass) {
168

    
169
	// show all nodes (reset)
170
	$("#" + divId).find("li").show();
171
	
172
	// done if we don't have any thing to prune
173
	if (!matchClass) {
174
		return;
175
	}
176
	
177
	// get all non-matched anchor tags
178
	var nonmatches = $("#" + divId).find("a").not("." + matchClass);
179
	
180
	// get their parent nodes
181
	nonmatches = $(nonmatches).parents("li");
182

    
183
	// are there any matches under each parent node?
184
	$(nonmatches).each(
185
		function(index) {
186
			// do any chidren match?
187
			var childMatches = $(this).find("a." + matchClass);
188
			if (childMatches && childMatches.length > 0) {
189
				return true;
190
			}
191
			// parent matches?
192
			var parentMatches = $(this).parents("li").children("a." + matchClass);
193
			if (parentMatches && parentMatches.length > 0) {
194
				return true;
195
			}
196
			// hide this node if no matches under it
197
			$(this).hide();
198
		});
199
}
200
function checkExactMatch(divId, searchTerm, matchClass) {
201
	// get the current search matches
202
	var matches = $("#" + divId).find("a." + matchClass);
203
	// get their parent nodes
204
	matches = $(matches).parents("li");
205
	// check for exact matches
206
	var exactMatch = $(matches).filter("#" + searchTerm).first();
207
	if (exactMatch && exactMatch.length == 1) {
208
		//alert("exactMatch: " + exactMatch);
209
		select($(exactMatch).children("a"));
210
	}
211
}
212
function doActiveDomain(divId) {
213
	if ($("#" + divId + "Only").is(":checked")) {
214
		// prune to active
215
		prune(divId, "bold");
216
	} else {
217
		// reset
218
		prune(divId, null);
219
	}
220
}
221
function initialize(source) {
222
	// we don't want to reload the source of the filtering request
223
	// but we do want to reload the other trees for active domains
224
	// we reload all of them if no source is given - first time the page loads
225
	if (source) {
226
		source = $(source).attr("id");
227
	}
228
	if (!source) {
229
		source = "";
230
	}
231
	if (source != 'activeEntities') {
232
		populateActiveDomain('activeEntities', 'org.ecoinformatics.sms.annotation.Entity');
233
	}
234
	if (source != 'activeCharacteristics') {
235
		populateActiveDomain('activeCharacteristics', 'org.ecoinformatics.sms.annotation.Characteristic');
236
	}
237
	if (source != 'activeProtocols') {
238
		populateActiveDomain('activeProtocols', 'org.ecoinformatics.sms.annotation.Protocol');
239
	}
240
	if (source != 'activeMeasurements') {
241
		populateActiveDomain('activeMeasurements', 'org.ecoinformatics.sms.annotation.Measurement');
242
	}
243
}
244
function select(item) {
245

    
246
	// get the selected value, stored in the title attribute of the item <a> tag
247
	var value = $(item).attr("title");
248
	//alert("value: " + value);
249
	
250
	// get the parent div so we know what kind of class it is meant to filter
251
	// this is "the first parent of the class 'select'"
252
	var parent = $(item).parents("div.select:first");
253
	//alert("parent: " + parent);
254
	
255
	// set the value for the hidden input value
256
	// the input field of class "value" will hold it, this way we don't need to know the id
257
	var input = $(parent).children("input.value");
258
	$(input).val(value);
259
	//alert("input: " + input);
260
	
261
	// set it in the search field
262
	var treeInstance = $(item).parents("div.jstree:first");
263
	var shortName = $(item).parent().attr("id");
264
	$("#" + $(treeInstance).attr("id") + "Search").val(shortName)
265

    
266
	// refresh the search results
267
	doSearch($("#searchForm").get(0));
268
	
269
	// refresh the other trees for active domain after this filtering action
270
	initialize($(parent).children("div"));
271
}
272
function doSearch(formObj) {
273
	// set the hidden parameters based on the current state of the form
274
	checkSearch(formObj);
275
	
276
	// start the busy indicator
277
	$("#searchResults").busy(
278
			{
279
				position	: 'left', 
280
				offset		: -30, 
281
				hide		: true, 
282
				img			: "<%=STYLE_SKINS_URL%>/semtools/images/busy.gif" 
283
			});
284
	
285
	//load the results
286
	$("#searchResults").load(
287
		"<%=SERVLET_URL%>" + " #content_wrapper",
288
		$(formObj).serialize(),
289
		// call back function when loading finishes
290
		function(response, status, xhr) {
291
			if (status == "error") {
292
				var msg = "Sorry but there was an error performing the search: ";
293
				$("#error").html(msg + xhr.status + " " + xhr.statusText);
294
			}
295
			// collapsible search results?
296
			$(function() {
297
				$('.accordian').click(function() {
298
					$(this).next().slideToggle("slow");
299
					return false;
300
				}).next().hide();
301
			});
302
			
303
			// stop the busy indicator
304
			$("#searchResults").busy("hide");
305
		});
306
		
307
	return false;
308
	
309
}
310
function clearForm() {
311
	// clear the form values
312
	$('#searchForm').get(0).reset();
313
	// clear each of the tree selections
314
	$(".jstree").each(function(index) {
315
		$(this).jstree("deselect_all");
316
	});
317
	$("input.value").each(function(index) {
318
		$(this).val("");
319
	});
320
	// reload the trees
321
	initialize();
322
	// reload the search results
323
	//alert($('#searchForm').get(0));
324
	doSearch($('#searchForm').get(0));
325
}
326
/**
327
 * Perform this when the page first loads
328
 */
329
function pageLoad() {
330
	initialize();
331
	doSearch($('#searchForm').get(0));
332
}
333
function donothing() {}
334
--></script>
335

    
336
</head>
337
<body onload="pageLoad()">
338
<script language="javascript">
339
	insertTemplateOpening("<%=CONTEXT_URL%>");
340
</script>
341

    
342
<div id="content_wrapper">
343
 
344
<h2>Annotation-based search</h2>
345

    
346
<div id="error">
347
	<!-- error messages here -->
348
</div>
349

    
350
<!-- set up the tabs -->
351
<script>
352
	$(function() {
353
		$("#searchTabs").tabs();
354
		$("#searchTabs").tabs("add", "#ecpTab", "Entity, Characteristic, Protocol");
355
		$("#searchTabs").tabs("add", "#measurementTab", "Measurement");
356
		$("#searchTabs").tabs("add", "#optionsTab", "Options");
357
	});
358
</script>
359

    
360
<form method="POST" 
361
		action="<%=SERVLET_URL%>" 
362
		target="_top" 
363
		id="searchForm" 
364
		name="searchForm" 
365
		onSubmit="return doSearch(this)">
366
	<input name="query" type="hidden" />
367
	<input name="qformat" value="semtools" type="hidden" />
368
	<input name="includeHeader" value="false" type="hidden" />
369
	<input name="action" value="semquery" type="hidden" />
370

    
371
	<!-- tabs for the search interface -->		
372
	<div id="searchTabs">
373
		<!-- place holder for ui tabs -->
374
		<ul></ul>
375
	
376
		<!-- other criteria tabs -->
377
		<div id="ecpTab">
378
			<table>
379
				<tr>
380
					<td>
381
						<table class="subGroup subGroup_border">
382
							
383
							<tr>
384
								<th><p>Find observations of</p></th>
385
							</tr>
386
							<tr>
387
								<td>
388
									<input type="text" id="activeEntitiesSearch" />
389
									<input type="checkbox" id="activeEntitiesOnly" title="Show only active concepts" />
390
									<div class="select">
391
										<div id="activeEntities" class="activeTree">
392
											<p>loading...</p>
393
										</div>
394
										<input type="hidden" class="value" name="activeEntitiesValue" id="activeEntitiesValue"/>
395
										<input type="hidden" name="activeEntitiesClass" id="activeEntitiesClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Entity"/>
396
									</div>
397
								</td>
398
							</tr>
399
						</table>
400
					</td>
401
					<td>
402
						<table class="subGroup subGroup_border">
403
							<tr>
404
								<th><p>with measurements of</p></th>
405
							</tr>
406
							<tr>
407
								<td>
408
									<input type="text" id="activeCharacteristicsSearch" />
409
									<input type="checkbox" id="activeCharacteristicsOnly" title="Show only active concepts" />
410
									<div class="select">
411
										<div id="activeCharacteristics" class="activeTree">
412
											<p>loading...</p>
413
										</div>
414
										<input type="hidden" class="value" name="activeCharacteristicsValue" id="activeCharacteristicsValue"/>
415
										<input type="hidden" name="activeCharacteristicsClass" id="activeCharacteristicsClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Characteristic"/>
416
									</div>
417
								</td>
418
							</tr>
419
						</table>
420
					</td>
421
					<td>
422
						<table class="subGroup subGroup_border">
423
							<tr>
424
								<th><p>using procedures outlined by</p></th>
425
							</tr>
426
							<tr>
427
								<td>
428
									<input type="text" id="activeProtocolsSearch" />
429
									<input type="checkbox" id="activeProtocolsOnly" title="Show only active concepts" />
430
									<div class="select">
431
										<div id="activeProtocols" class="activeTree">
432
											<p>loading...</p>
433
										</div>
434
										<input type="hidden" class="value" name="activeProtocolsValue" id="activeProtocolsValue" />
435
										<input type="hidden" name="activeProtocolsClass" id="activeProtocolsClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Protocol"/>
436
									</div>
437
								</td>
438
							</tr>
439
						</table>
440
					</td>
441
				</tr>
442
			</table>
443
		</div>
444
		
445
		<!-- measurement -->
446
		<div id="measurementTab">
447
			<table class="subGroup subGroup_border onehundred_percent">
448
				
449
				<tr>
450
					<th><p>a template that defines Entity, Characteristic, Standard, and/or Protocol</p></th>
451
				</tr>
452
				
453
				<tr>
454
					<td>
455
						<input type="text" id="activeMeasurementsSearch" />
456
						Only active? <input type="checkbox" id="activeMeasurementsOnly" title="Show only active concepts"/>
457
						<div class="select">
458
							<div id="activeMeasurements" class="activeTree" style="width: 100%">
459
								<p>loading...</p>
460
							</div>
461
							<input type="hidden" class="value" name="activeMeasurementsValue" id="activeMeasurementsValue"/>
462
							<input type="hidden" name="activeMeasurementsClass" id="activeMeasurementsClass" value="http://ecoinformatics.org/oboe/oboe.1.0/oboe-core.owl#Measurement"/>
463
						</div>
464
					</td>
465
				</tr>
466
			</table>
467
		</div>
468
		
469
		<!-- query options -->
470
		<div id="optionsTab">
471
			<table class="group group_border">
472
				<tr>
473
					<th colspan="2">
474
						<p>
475
							Locate <b>data packages</b> that have been semantically annotated within the observation model by
476
							selecting concepts from OBOE extension ontologies
477
						</p>
478
					</th>
479
				</tr>
480
				
481
				<tr>
482
					
483
					<td colspan="1">Match All? <input type="checkbox" name="matchAll" checked="checked"/></td>
484
				
485
					<td colspan="1">From same Observation? <input type="checkbox" name="strict"/></td>
486
				</tr>
487
				
488
			</table>
489
		</div>	
490
					
491
	</div>
492
	
493
	<br/>
494
	
495
	<!-- search results here -->	
496
	<table class="subGroup subGroup_border onehundred_percent">
497
		<tr>
498
			<th>
499
				Search Results
500
				<input type="reset" value="Clear" onclick="clearForm()"/>
501
			</th>
502
		</tr>
503
		<tr>
504
			<td>
505
				<div id="searchResults">
506
				No query has been specified	
507
				</div>
508
			</td>
509
		</tr>
510
	</table>	
511

    
512
</form>
513

    
514

    
515

    
516
<!-- Included default search/login -->
517
<% if ( PropertyService.getProperty("spatial.runSpatialOption").equals("true") ) { %>
518
<script language="javascript">
519
	insertMap("<%=CONTEXT_URL%>");
520
</script>
521
<br/>
522
<% } %>
523
  
524
<script language="javascript">
525
	insertSearchBox("<%=CONTEXT_URL%>");
526
	insertLoginBox("<%=CONTEXT_URL%>");	
527
</script>
528

    
529
</div>
530

    
531
<script language="javascript">
532
	insertTemplateClosing("<%=CONTEXT_URL%>");
533
</script>
534

    
535
</body>
536
</html>
(5-5/14)