1 | <%-- $Id: annotate.jsp 5075 2009-08-24 11:05:40Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
---|
5 | Copyright (C) 2007 Nicklas Nordborg |
---|
6 | |
---|
7 | This file is part of BASE - BioArray Software Environment. |
---|
8 | Available at http://base.thep.lu.se/ |
---|
9 | |
---|
10 | BASE is free software; you can redistribute it and/or |
---|
11 | modify it under the terms of the GNU General Public License |
---|
12 | as published by the Free Software Foundation; either version 3 |
---|
13 | of the License, or (at your option) any later version. |
---|
14 | |
---|
15 | BASE is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | ------------------------------------------------------------------ |
---|
23 | |
---|
24 | @author Nicklas |
---|
25 | @version 2.0 |
---|
26 | --%> |
---|
27 | <%@ page session="false" |
---|
28 | import="net.sf.basedb.core.SessionControl" |
---|
29 | import="net.sf.basedb.core.DbControl" |
---|
30 | import="net.sf.basedb.core.Item" |
---|
31 | import="net.sf.basedb.core.Type" |
---|
32 | import="net.sf.basedb.core.BasicItem" |
---|
33 | import="net.sf.basedb.core.Permission" |
---|
34 | import="net.sf.basedb.core.Annotatable" |
---|
35 | import="net.sf.basedb.core.Nameable" |
---|
36 | import="net.sf.basedb.core.Protocol" |
---|
37 | import="net.sf.basedb.core.AnnotationSet" |
---|
38 | import="net.sf.basedb.core.Annotation" |
---|
39 | import="net.sf.basedb.core.Unit" |
---|
40 | import="net.sf.basedb.core.Quantity" |
---|
41 | import="net.sf.basedb.core.AnnotatableProxy" |
---|
42 | import="net.sf.basedb.core.ItemQuery" |
---|
43 | import="net.sf.basedb.core.Include" |
---|
44 | import="net.sf.basedb.core.ItemResultList" |
---|
45 | import="net.sf.basedb.core.AnnotationType" |
---|
46 | import="net.sf.basedb.core.AnnotationTypeCategory" |
---|
47 | import="net.sf.basedb.core.PermissionDeniedException" |
---|
48 | import="net.sf.basedb.core.query.Expressions" |
---|
49 | import="net.sf.basedb.core.query.Restrictions" |
---|
50 | import="net.sf.basedb.core.query.Hql" |
---|
51 | import="net.sf.basedb.core.query.Orders" |
---|
52 | import="net.sf.basedb.util.NameableComparator" |
---|
53 | import="net.sf.basedb.clients.web.Base" |
---|
54 | import="net.sf.basedb.clients.web.util.HTML" |
---|
55 | import="net.sf.basedb.util.formatter.Formatter" |
---|
56 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
57 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
58 | import="net.sf.basedb.util.Values" |
---|
59 | import="java.util.ArrayList" |
---|
60 | import="java.util.List" |
---|
61 | import="java.util.Date" |
---|
62 | import="java.util.Set" |
---|
63 | import="java.util.HashSet" |
---|
64 | import="java.util.TreeSet" |
---|
65 | import="java.util.Map" |
---|
66 | import="java.util.HashMap" |
---|
67 | %> |
---|
68 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
69 | <% |
---|
70 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
71 | final String ID = sc.getId(); |
---|
72 | final float scale = Base.getScale(sc); |
---|
73 | final Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
74 | final int itemId = Values.getInt(request.getParameter("item_id")); |
---|
75 | final int protocolId = Values.getInt(request.getParameter("protocol_id"), -1); |
---|
76 | final int annotationTypeId = Values.getInt(request.getParameter("annotationtype_id")); |
---|
77 | final boolean standalone = Values.getBoolean(request.getParameter("standalone")); |
---|
78 | |
---|
79 | final DbControl dc = sc.newDbControl(); |
---|
80 | Set<AnnotationType> annotationTypes = null; |
---|
81 | Set<AnnotationType> protocolParameters = null; |
---|
82 | Map<AnnotationType, Annotation> existing = null; |
---|
83 | try |
---|
84 | { |
---|
85 | Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc); |
---|
86 | String dateFormat = FormatterSettings.getDateFormat(sc); |
---|
87 | String jsDateFormat = HTML.javaScriptEncode(dateFormat); |
---|
88 | String htmlDateFormat = HTML.encodeTags(dateFormat); |
---|
89 | |
---|
90 | final Annotatable item = itemId == 0 ? null : (Annotatable)itemType.getById(dc, itemId); |
---|
91 | final boolean writePermission = item == null ? true : item.hasPermission(Permission.WRITE); |
---|
92 | Protocol protocol = null; |
---|
93 | boolean readProtocol = true; |
---|
94 | try |
---|
95 | { |
---|
96 | if (protocolId == - 1 && item != null) |
---|
97 | { |
---|
98 | protocol = item.getProtocol(); |
---|
99 | } |
---|
100 | else if (protocolId > 0) |
---|
101 | { |
---|
102 | protocol = Protocol.getById(dc, protocolId); |
---|
103 | } |
---|
104 | } |
---|
105 | catch (PermissionDeniedException ex) |
---|
106 | { |
---|
107 | readProtocol = false; |
---|
108 | } |
---|
109 | if (standalone) |
---|
110 | { |
---|
111 | sc.getCurrentContext(itemType).setObject("item", item); |
---|
112 | } |
---|
113 | final String clazz = "class=\"text\"" ; |
---|
114 | |
---|
115 | String title = "Annotate " + |
---|
116 | HTML.encodeTags((item instanceof Nameable ? ((Nameable)item).getName() : |
---|
117 | (item == null ? " new item" : item.toString()))); |
---|
118 | |
---|
119 | // Queries to retrieve annotation types and protocol parameters |
---|
120 | boolean isProxy = item instanceof AnnotatableProxy; |
---|
121 | ItemQuery<AnnotationType> annotationTypeQuery = null; |
---|
122 | String message = null; |
---|
123 | |
---|
124 | if (isProxy) |
---|
125 | { |
---|
126 | AnnotatableProxy proxy = (AnnotatableProxy)item; |
---|
127 | annotationTypeQuery = Base.getAnnotationTypesQuery(proxy); |
---|
128 | message = proxy.getAnnotationMessage(); |
---|
129 | } |
---|
130 | else |
---|
131 | { |
---|
132 | annotationTypeQuery = Base.getAnnotationTypesQuery(itemType, false); |
---|
133 | } |
---|
134 | final ItemQuery<AnnotationType> parameterQuery = Base.getProtocolParametersQuery(protocol); |
---|
135 | |
---|
136 | // Query to retrieve the categories of an annotation type |
---|
137 | final ItemQuery<AnnotationTypeCategory> categoryQuery = AnnotationTypeCategory.getQuery(); |
---|
138 | categoryQuery.include(Include.MINE, Include.OTHERS, Include.SHARED, Include.IN_PROJECT); |
---|
139 | categoryQuery.join(Hql.innerJoin("annotationTypes", "atp")); |
---|
140 | categoryQuery.restrict(Restrictions.eq(Hql.alias("atp"), Expressions.parameter("annotationType"))); |
---|
141 | |
---|
142 | // Holds all categories that we have found |
---|
143 | final Set<AnnotationTypeCategory> allCategories = |
---|
144 | new TreeSet<AnnotationTypeCategory>(new NameableComparator(false)); |
---|
145 | |
---|
146 | final StringBuilder sb = new StringBuilder(); |
---|
147 | final AnnotationSet as = item == null || !item.isAnnotated() ? null : item.getAnnotationSet(); |
---|
148 | if (as != null) |
---|
149 | { |
---|
150 | // Load the existing annotations |
---|
151 | existing = new HashMap<AnnotationType, Annotation>(); |
---|
152 | List<Annotation> annotations = as.getAnnotations().list(dc); |
---|
153 | for (Annotation a : annotations) |
---|
154 | { |
---|
155 | try |
---|
156 | { |
---|
157 | existing.put(a.getAnnotationType(), a); |
---|
158 | } |
---|
159 | catch (PermissionDeniedException ex) |
---|
160 | {} |
---|
161 | } |
---|
162 | } |
---|
163 | %> |
---|
164 | |
---|
165 | <base:page type="popup" title="<%=title%>"> |
---|
166 | <base:head scripts="annotations.js,parameters.js" styles="parameters.css"> |
---|
167 | |
---|
168 | <script language="JavaScript"> |
---|
169 | function init() |
---|
170 | { |
---|
171 | <% |
---|
172 | annotationTypes = new TreeSet<AnnotationType>(new NameableComparator(false)); |
---|
173 | annotationTypes.addAll(annotationTypeQuery.list(dc)); |
---|
174 | if (existing != null) annotationTypes.addAll(existing.keySet()); |
---|
175 | if (annotationTypeId != 0) |
---|
176 | { |
---|
177 | annotationTypes.add(AnnotationType.getById(dc, annotationTypeId)); |
---|
178 | } |
---|
179 | if (parameterQuery != null) |
---|
180 | { |
---|
181 | protocolParameters = new HashSet<AnnotationType>(parameterQuery.list(dc)); |
---|
182 | annotationTypes.addAll(protocolParameters); |
---|
183 | } |
---|
184 | for (AnnotationType at : annotationTypes) |
---|
185 | { |
---|
186 | boolean isParameter = protocolParameters != null && protocolParameters.contains(at); |
---|
187 | String label = (isParameter ? "<img src=\"../../images/parameter.gif\">" : "") + |
---|
188 | HTML.encodeTags(Values.trimString(at.getName(), 25)); |
---|
189 | String fullLabel = HTML.encodeTags(at.getName()); |
---|
190 | List values = null; |
---|
191 | Unit unit = at.getDefaultUnit(); |
---|
192 | if (existing != null && existing.containsKey(at)) |
---|
193 | { |
---|
194 | Annotation a = existing.get(at); |
---|
195 | unit = a.getUnit(); |
---|
196 | values = a.getValues(null); |
---|
197 | } |
---|
198 | if (at.isRemoved() && values == null) continue; |
---|
199 | categoryQuery.setParameter("annotationType", at.getId(), Type.INT); |
---|
200 | %> |
---|
201 | var values = new Array(); |
---|
202 | var categories = new Array(); |
---|
203 | <% |
---|
204 | if (values != null) |
---|
205 | { |
---|
206 | for (Object value : values) |
---|
207 | { |
---|
208 | if (value instanceof Date) value = dateFormatter.format((Date)value); |
---|
209 | %> |
---|
210 | values[values.length] = '<%=HTML.javaScriptEncode(value.toString())%>'; |
---|
211 | <% |
---|
212 | } |
---|
213 | } |
---|
214 | for (AnnotationTypeCategory category : categoryQuery.list(dc)) |
---|
215 | { |
---|
216 | allCategories.add(category); |
---|
217 | %> |
---|
218 | categories[categories.length] = <%=category.getId()%>; |
---|
219 | <% |
---|
220 | } |
---|
221 | |
---|
222 | String icon = ""; |
---|
223 | if (values != null && values.size() > 0) |
---|
224 | { |
---|
225 | icon = "notrequired_values.gif"; |
---|
226 | } |
---|
227 | else |
---|
228 | { |
---|
229 | icon = "notrequired_novalues.gif"; |
---|
230 | } |
---|
231 | String deleted = at.isRemoved() ? "<img src=\"../../images/deleted.gif\">" : ""; |
---|
232 | icon = "<span class=\"icon\"><img id=\"icon_"+at.getId()+"\" src=\"../../images/"+icon+"\"></span>"; |
---|
233 | sb.append("<div class=\"param\" id=\"prompt_"+at.getId()+"\" onclick=\"parametersOnClick('"+at.getId()+"')\""); |
---|
234 | sb.append(" onmouseover=\"Main.addClass(this, 'hover')\" onmouseout=\"Main.removeClass(this, 'hover')\" title=\""+fullLabel+"\">"); |
---|
235 | sb.append(icon+"<span class=\"label\">"+deleted+label+"</span></div>\n"); |
---|
236 | %> |
---|
237 | var at = new Parameter('<%=at.getId()%>', '<%=HTML.javaScriptEncode(at.getName())%>', <%=at.getMultiplicity()%>, <%=at.isEnumeration()%>, false, values, <%=unit != null ? unit.getId() : 0%>); |
---|
238 | at.categories = categories; |
---|
239 | at.isParameter = <%=isParameter ? "true" : "false" %>; |
---|
240 | <% |
---|
241 | } |
---|
242 | %> |
---|
243 | <% |
---|
244 | if (annotationTypeId != 0) |
---|
245 | { |
---|
246 | %> |
---|
247 | parametersOnClick(<%=annotationTypeId%>); |
---|
248 | <% |
---|
249 | } |
---|
250 | %> |
---|
251 | } |
---|
252 | |
---|
253 | function categoryOnChange() |
---|
254 | { |
---|
255 | var frm = document.forms['annotations']; |
---|
256 | var categoryId = frm.categories[frm.categories.selectedIndex].value; |
---|
257 | for (var i = 0; i < Parameters.allParameters.length; i++) |
---|
258 | { |
---|
259 | var pp = Parameters.allParameters[i]; |
---|
260 | var show = false; |
---|
261 | if (categoryId == -1) |
---|
262 | { |
---|
263 | // show all |
---|
264 | show = true; |
---|
265 | } |
---|
266 | else if (categoryId == -2 && pp.isParameter) |
---|
267 | { |
---|
268 | show = true; |
---|
269 | } |
---|
270 | else if (categoryId == 0 && pp.categories.length == 0 && !pp.isParameter) |
---|
271 | { |
---|
272 | // show uncategorized |
---|
273 | show = true; |
---|
274 | } |
---|
275 | else |
---|
276 | { |
---|
277 | for (var j = 0; j < pp.categories.length; j++) |
---|
278 | { |
---|
279 | if (pp.categories[j] == categoryId) show = true; |
---|
280 | } |
---|
281 | } |
---|
282 | var div = 'prompt_'+pp.name; |
---|
283 | if (show) |
---|
284 | { |
---|
285 | Main.show(div); |
---|
286 | } |
---|
287 | else |
---|
288 | { |
---|
289 | Main.hide(div); |
---|
290 | } |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | var oldValueDiv; |
---|
295 | function parametersOnClick(parameterId) |
---|
296 | { |
---|
297 | var frm = document.forms['annotations']; |
---|
298 | if (oldValueDiv) Main.hide(oldValueDiv); |
---|
299 | |
---|
300 | var pp = Parameters.allParameters['ID'+parameterId]; |
---|
301 | setSelectedParameter(pp, parameterId); |
---|
302 | oldValueDiv = 'value_'+pp.name+'_div' |
---|
303 | Main.show(oldValueDiv); |
---|
304 | |
---|
305 | var valueElement = frm['value_'+pp.name]; |
---|
306 | if (valueElement.focus) valueElement.focus(); |
---|
307 | if (pp.enumeration) |
---|
308 | { |
---|
309 | Main.hide('valuecontainer'); |
---|
310 | if (valueElement.type && valueElement.type.search('select') != -1) |
---|
311 | { |
---|
312 | // selection list |
---|
313 | Forms.selectListOptions(valueElement, pp.values); |
---|
314 | } |
---|
315 | else if (pp.multiplicity == 1) |
---|
316 | { |
---|
317 | // radio buttons |
---|
318 | Forms.checkRadio(valueElement, pp.values[0]); |
---|
319 | } |
---|
320 | else |
---|
321 | { |
---|
322 | // check boxes |
---|
323 | Forms.checkCheckBoxes(valueElement, pp.values); |
---|
324 | } |
---|
325 | } |
---|
326 | else if (pp.multiplicity == 1) |
---|
327 | { |
---|
328 | Main.hide('valuecontainer'); |
---|
329 | if (pp.values.length > 0) |
---|
330 | { |
---|
331 | if (valueElement.length) // ie. radio buttons for boolean parameter |
---|
332 | { |
---|
333 | Forms.checkRadio(valueElement, pp.values[0]); |
---|
334 | } |
---|
335 | else |
---|
336 | { |
---|
337 | valueElement.value = pp.values[0]; |
---|
338 | } |
---|
339 | |
---|
340 | } |
---|
341 | } |
---|
342 | else |
---|
343 | { |
---|
344 | var values = frm.values; |
---|
345 | values.length = 0; |
---|
346 | for (var i = 0; i < pp.values.length; i++) // > |
---|
347 | { |
---|
348 | var value = Main.cutString(pp.values[i].replace(/\n/g, ' '), 40); |
---|
349 | values[values.length] = new Option(value); |
---|
350 | } |
---|
351 | var mult = document.getElementById('multiplicity'); |
---|
352 | mult.innerHTML = pp.multiplicity == 0 ? '' : '(Max '+pp.multiplicity+' values)'; |
---|
353 | Main.show('valuecontainer'); |
---|
354 | } |
---|
355 | } |
---|
356 | |
---|
357 | var selectedParameter = null; |
---|
358 | var selectedParameterId = null; |
---|
359 | function getSelectedParameter() |
---|
360 | { |
---|
361 | return selectedParameter; |
---|
362 | } |
---|
363 | |
---|
364 | function setSelectedParameter(parameter, parameterId) |
---|
365 | { |
---|
366 | if (selectedParameter != null) |
---|
367 | { |
---|
368 | Main.removeClass(document.getElementById('prompt_'+selectedParameter.name), 'selected'); |
---|
369 | } |
---|
370 | selectedParameter = parameter; |
---|
371 | selectedParameterId = parameterId; |
---|
372 | if (selectedParameter != null) |
---|
373 | { |
---|
374 | Main.addClass(document.getElementById('prompt_'+selectedParameter.name), 'selected'); |
---|
375 | } |
---|
376 | } |
---|
377 | |
---|
378 | function updateSelectedStyle() |
---|
379 | { |
---|
380 | var pp = getSelectedParameter(); |
---|
381 | var icon = document.getElementById('icon_'+pp.name); |
---|
382 | var gif = getRoot()+'images/'; |
---|
383 | if (pp.values.length == 0) |
---|
384 | { |
---|
385 | gif += pp.required ? 'required_novalues.gif' : 'notrequired_novalues.gif'; |
---|
386 | } |
---|
387 | else |
---|
388 | { |
---|
389 | gif += pp.required ? 'required_values.gif' : 'notrequired_values.gif'; |
---|
390 | } |
---|
391 | icon.src = gif; |
---|
392 | } |
---|
393 | |
---|
394 | function setCurrentValue(value) |
---|
395 | { |
---|
396 | var pp = getSelectedParameter(); |
---|
397 | if (value == null || value == '') |
---|
398 | { |
---|
399 | pp.removeValue(0); |
---|
400 | } |
---|
401 | else |
---|
402 | { |
---|
403 | pp.updateValue(0, value); |
---|
404 | } |
---|
405 | updateSelectedStyle(); |
---|
406 | } |
---|
407 | |
---|
408 | function setEnumValues(name) |
---|
409 | { |
---|
410 | var pp = getSelectedParameter(); |
---|
411 | if (!pp) return; |
---|
412 | |
---|
413 | var frm = document.forms['annotations']; |
---|
414 | var valueElement = frm[name]; |
---|
415 | var values = new Array(); |
---|
416 | for (var i = 0; i < valueElement.length; i++) // > |
---|
417 | { |
---|
418 | if (valueElement[i].checked || valueElement[i].selected) |
---|
419 | { |
---|
420 | values[values.length] = valueElement[i].value; |
---|
421 | } |
---|
422 | } |
---|
423 | pp.setValues(values); |
---|
424 | updateSelectedStyle(); |
---|
425 | } |
---|
426 | |
---|
427 | var lastValueIndex = -1; |
---|
428 | function valuesOnClick() |
---|
429 | { |
---|
430 | var frm = document.forms['annotations']; |
---|
431 | var pp = getSelectedParameter(); |
---|
432 | lastValueIndex = frm.values.selectedIndex; |
---|
433 | if (lastValueIndex >= 0) |
---|
434 | { |
---|
435 | frm['value_'+pp.name].value = pp.values[lastValueIndex]; |
---|
436 | } |
---|
437 | } |
---|
438 | |
---|
439 | function valueOnBlur(value) |
---|
440 | { |
---|
441 | var pp = getSelectedParameter(); |
---|
442 | if (!pp) return; |
---|
443 | var frm = document.forms['annotations']; |
---|
444 | var unitList = frm['unit:'+pp.name]; |
---|
445 | if (unitList) pp.setUnit(unitList[unitList.selectedIndex].value); |
---|
446 | if (pp.multiplicity == 1) |
---|
447 | { |
---|
448 | setCurrentValue(value); |
---|
449 | } |
---|
450 | else |
---|
451 | { |
---|
452 | if (lastValueIndex < 0) return; // > |
---|
453 | if (value == '' || value == null) |
---|
454 | { |
---|
455 | pp.removeValue(lastValueIndex); |
---|
456 | frm.values[lastValueIndex] = null; |
---|
457 | } |
---|
458 | else |
---|
459 | { |
---|
460 | pp.updateValue(lastValueIndex, value); |
---|
461 | frm.values[lastValueIndex].text = value; |
---|
462 | } |
---|
463 | } |
---|
464 | } |
---|
465 | |
---|
466 | function addOnClick() |
---|
467 | { |
---|
468 | var pp = getSelectedParameter(); |
---|
469 | if (!pp) return; |
---|
470 | var frm = document.forms['annotations']; |
---|
471 | var valueElement = frm['value_'+pp.name]; |
---|
472 | if (frm.values.selectedIndex < 0 && valueElement.value != '') // > |
---|
473 | { |
---|
474 | if (pp.addValue(valueElement.value)) |
---|
475 | { |
---|
476 | lastValueIndex = frm.values.length; |
---|
477 | frm.values[lastValueIndex] = new Option(valueElement.value, '', false, false); |
---|
478 | valueElement.value = ''; |
---|
479 | lastValueIndex = -1; |
---|
480 | } |
---|
481 | } |
---|
482 | else |
---|
483 | { |
---|
484 | if (pp.addValue('')) |
---|
485 | { |
---|
486 | lastValueIndex = frm.values.length; |
---|
487 | frm.values[lastValueIndex] = new Option('<new>', '', false, true); |
---|
488 | valueElement.value = ''; |
---|
489 | } |
---|
490 | } |
---|
491 | valueElement.focus(); |
---|
492 | updateSelectedStyle(); |
---|
493 | } |
---|
494 | function removeOnClick() |
---|
495 | { |
---|
496 | var pp = getSelectedParameter(); |
---|
497 | if (!pp) return; |
---|
498 | |
---|
499 | var frm = document.forms['annotations']; |
---|
500 | var values = frm.values; |
---|
501 | for (var i = 0; i < values.length; i++) // > |
---|
502 | { |
---|
503 | if (values[i].selected) |
---|
504 | { |
---|
505 | pp.removeValue(i); |
---|
506 | values[i] = null; |
---|
507 | i--; |
---|
508 | } |
---|
509 | } |
---|
510 | updateSelectedStyle(); |
---|
511 | } |
---|
512 | |
---|
513 | function setDateCallback(frmName, inputName, theDate) |
---|
514 | { |
---|
515 | var frm = document.forms[frmName]; |
---|
516 | frm[inputName].value = theDate; |
---|
517 | valueOnBlur(theDate); |
---|
518 | } |
---|
519 | |
---|
520 | function unitOnChange(unitList) |
---|
521 | { |
---|
522 | var pp = getSelectedParameter(); |
---|
523 | if (!pp) return; |
---|
524 | pp.setUnit(unitList[unitList.selectedIndex].value); |
---|
525 | } |
---|
526 | |
---|
527 | function hideErrorList() |
---|
528 | { |
---|
529 | Main.hide('errorlist'); |
---|
530 | Main.show('showerrorlist'); |
---|
531 | } |
---|
532 | function showErrorList() |
---|
533 | { |
---|
534 | Main.show('errorlist'); |
---|
535 | Main.hide('showerrorlist'); |
---|
536 | } |
---|
537 | |
---|
538 | function saveAnnotations() |
---|
539 | { |
---|
540 | var frm = document.forms['modified']; |
---|
541 | Annotations.addModifiedAnnotationsToForm(window, frm); |
---|
542 | frm.submit(); |
---|
543 | } |
---|
544 | </script> |
---|
545 | </base:head> |
---|
546 | |
---|
547 | <base:body onload="init()" style="<%=standalone ? "" : "background: #E0E0E0;"%>"> |
---|
548 | <% |
---|
549 | if (standalone) |
---|
550 | { |
---|
551 | %> |
---|
552 | <h3 class="docked"><%=title%> <base:help helpid="annotations.edit" /></h3> |
---|
553 | <div class="boxed" style="background: #E0E0E0"> |
---|
554 | <% |
---|
555 | } |
---|
556 | %> |
---|
557 | |
---|
558 | <form name="annotations"> |
---|
559 | <table class="form" cellspacing="2" border="0" cellpadding="0" width="100%"> |
---|
560 | <tr valign="top"> |
---|
561 | <td width="50%"> |
---|
562 | <b>Categories</b> <select name="categories" onchange="categoryOnChange()"> |
---|
563 | <option value="-1">- all - |
---|
564 | <% |
---|
565 | if (protocol != null) |
---|
566 | { |
---|
567 | %> |
---|
568 | <option value="-2">- protocol parameters - |
---|
569 | <% |
---|
570 | } |
---|
571 | %> |
---|
572 | <option value="0">- uncategorized - |
---|
573 | <% |
---|
574 | for (AnnotationTypeCategory category : allCategories) |
---|
575 | { |
---|
576 | %> |
---|
577 | <option value="<%=category.getId()%>" |
---|
578 | title="<%=HTML.encodeTags(category.getDescription())%>" |
---|
579 | ><%=HTML.encodeTags(category.getName())%> |
---|
580 | <% |
---|
581 | } |
---|
582 | %> |
---|
583 | </select> |
---|
584 | |
---|
585 | <div class="parameterlist" style="height: <%=(int)(scale*300)%>px; margin-top: 4px;"> |
---|
586 | <%=sb.toString()%> |
---|
587 | </div> |
---|
588 | <base:icon image="hasvalues.gif" /> = Has value(s) |
---|
589 | <base:icon image="parameter.gif" /> = Protocol parameter |
---|
590 | </td> |
---|
591 | <td width="50%"> |
---|
592 | <%=message == null ? "" : message + "<br>"%> |
---|
593 | <br> |
---|
594 | <div id="valuecontainer" style="display: none;"> |
---|
595 | <b>Values</b> <span id="multiplicity"></span><br> |
---|
596 | <select name="values" size="5" style="width: 20em;" |
---|
597 | onchange="valuesOnClick()" multiple> |
---|
598 | </select> |
---|
599 | |
---|
600 | <table cellspacing="2" border="0" cellpadding="0" cellspacing="0" align="center"> |
---|
601 | <tr> |
---|
602 | <td width="50%"><base:button onclick="addOnClick()" title="Add" tooltip="Add a new value" /></td> |
---|
603 | <td width="50%"><base:button onclick="removeOnClick()" title="Remove" tooltip="Remove the selected values"/></td> |
---|
604 | </tr> |
---|
605 | </table> |
---|
606 | <br> |
---|
607 | </div> |
---|
608 | <% |
---|
609 | for (AnnotationType at : annotationTypes) |
---|
610 | { |
---|
611 | Annotation a = as != null && as.hasAnnotation(at) ? as.getAnnotation(at) : null; |
---|
612 | int multiplicity = at.getMultiplicity(); |
---|
613 | String inputName = "value_"+at.getId(); |
---|
614 | Type valueType = at.getValueType(); |
---|
615 | int width = at.getWidth() <= 0 ? 40 : at.getWidth(); |
---|
616 | if (width > 80) width = 80; |
---|
617 | int height = at.getHeight() <= 0 ? 6 : at.getHeight(); |
---|
618 | if (height > 20) height = 20; |
---|
619 | String select = null; |
---|
620 | if (multiplicity == 0) |
---|
621 | { |
---|
622 | select = "Select one or more"; |
---|
623 | } |
---|
624 | else if (multiplicity == 1) |
---|
625 | { |
---|
626 | select = "Select one"; |
---|
627 | } |
---|
628 | else |
---|
629 | { |
---|
630 | select = "Select 1 -- "+multiplicity; |
---|
631 | } |
---|
632 | |
---|
633 | %> |
---|
634 | <div id="<%=inputName%>_div" style="display: none;"> |
---|
635 | <% |
---|
636 | if (at.isEnumeration()) |
---|
637 | { |
---|
638 | List<?> values = at.getValues(); |
---|
639 | Formatter f = FormatterFactory.getTypeFormatter(sc, at.getValueType()); |
---|
640 | String unitSymbol = ""; |
---|
641 | if (at.supportUnits()) unitSymbol = " " + at.getDefaultUnit().getDisplaySymbol(); |
---|
642 | %> |
---|
643 | <b><%=HTML.encodeTags(at.getName())%></b> (<%=select%>)<br> |
---|
644 | <% |
---|
645 | if (at.getDisplayAsList()) |
---|
646 | { |
---|
647 | if (multiplicity == 1) |
---|
648 | { |
---|
649 | %> |
---|
650 | <select name="<%=inputName%>" |
---|
651 | onchange="setCurrentValue(this[this.selectedIndex].value)"> |
---|
652 | <option value="" style="font-style: italic;">- not specified - |
---|
653 | <% |
---|
654 | } |
---|
655 | else |
---|
656 | { |
---|
657 | %> |
---|
658 | <select name="<%=inputName%>" multiple size="10" |
---|
659 | onchange="setEnumValues('<%=inputName%>')"> |
---|
660 | <% |
---|
661 | } |
---|
662 | for (Object value : values) |
---|
663 | { |
---|
664 | String encoded = f.format(value); |
---|
665 | %> |
---|
666 | <option value="<%=encoded%>"><%=encoded%><%=unitSymbol%> |
---|
667 | <% |
---|
668 | } |
---|
669 | %> |
---|
670 | </select> |
---|
671 | <% |
---|
672 | } |
---|
673 | else |
---|
674 | { |
---|
675 | String checkType = multiplicity == 1 ? "radio" : "checkbox"; |
---|
676 | String onclick = multiplicity == 1 ? "setCurrentValue(this.value)" : "setEnumValues('"+inputName+"')"; |
---|
677 | int i = 0; |
---|
678 | if (multiplicity == 1) |
---|
679 | { |
---|
680 | %> |
---|
681 | <input name="<%=inputName%>" type="<%=checkType%>" |
---|
682 | checked value="" onclick="setCurrentValue(null)"><a |
---|
683 | href="javascript:document.forms['annotations'].<%=inputName%>[<%=i%>].click()"><i>- not specified -</i></a><br> |
---|
684 | <% |
---|
685 | i++; |
---|
686 | } |
---|
687 | for (Object value : values) |
---|
688 | { |
---|
689 | String encoded = f.format(value); |
---|
690 | %> |
---|
691 | <input name="<%=inputName%>" type="<%=checkType%>" |
---|
692 | value="<%=encoded%>" onclick="<%=onclick%>"><a |
---|
693 | href="javascript:document.forms['annotations'].<%=inputName%>[<%=i%>].click()"><%=encoded%><%=unitSymbol%></a><br> |
---|
694 | <% |
---|
695 | i++; |
---|
696 | } |
---|
697 | } |
---|
698 | } |
---|
699 | else if (valueType == Type.INT || valueType == Type.LONG) |
---|
700 | { |
---|
701 | Long minValue = at.getMinValueLong(); |
---|
702 | Long maxValue = at.getMaxValueLong(); |
---|
703 | String minMax = ""; |
---|
704 | if (minValue != null && maxValue != null) |
---|
705 | { |
---|
706 | minMax = ": " + minValue + " -- " +maxValue; |
---|
707 | } |
---|
708 | else if (minValue != null) |
---|
709 | { |
---|
710 | minMax = " >= "+minValue; |
---|
711 | } |
---|
712 | else if (maxValue != null) |
---|
713 | { |
---|
714 | minMax = " <= "+maxValue; |
---|
715 | } |
---|
716 | %> |
---|
717 | <b><%=HTML.encodeTags(at.getName())%></b> |
---|
718 | (<%=valueType == Type.INT ? "Integer" : "Long"%><%=minMax%>)<br> |
---|
719 | <input <%=clazz%> type="text" name="<%=inputName%>" value="" |
---|
720 | size="20" maxlength="20" onkeypress="return Numbers.integerOnly(event)" |
---|
721 | onblur="valueOnBlur(this.value)"> |
---|
722 | <% |
---|
723 | } |
---|
724 | else if (valueType == Type.FLOAT || valueType == Type.DOUBLE) |
---|
725 | { |
---|
726 | Double minValue = at.getMinValueDouble(); |
---|
727 | Double maxValue = at.getMaxValueDouble(); |
---|
728 | String minMax = ""; |
---|
729 | if (minValue != null && maxValue != null) |
---|
730 | { |
---|
731 | minMax = ": " + minValue + " -- " +maxValue; |
---|
732 | } |
---|
733 | else if (minValue != null) |
---|
734 | { |
---|
735 | minMax = " >= "+minValue; |
---|
736 | } |
---|
737 | else if (maxValue != null) |
---|
738 | { |
---|
739 | minMax = " <= "+maxValue; |
---|
740 | } |
---|
741 | %> |
---|
742 | <b><%=HTML.encodeTags(at.getName())%></b> |
---|
743 | (<%=valueType == Type.FLOAT ? "Float" : "Double"%><%=minMax%>)<br> |
---|
744 | <input <%=clazz%> type="text" name="<%=inputName%>" value="" |
---|
745 | size="20" maxlength="20" onkeypress="return Numbers.numberOnly(event)" |
---|
746 | onblur="valueOnBlur(this.value)"> |
---|
747 | <% |
---|
748 | } |
---|
749 | else if (valueType == Type.STRING) |
---|
750 | { |
---|
751 | Integer maxLength = at.getMaxLength(); |
---|
752 | if (maxLength == null) maxLength = 255; |
---|
753 | %> |
---|
754 | <b><%=HTML.encodeTags(at.getName())%></b> (String)<br> |
---|
755 | <input <%=clazz%> type="text" name="<%=inputName%>" value="" |
---|
756 | size="<%=width%>" maxlength="<%=maxLength%>" |
---|
757 | onblur="valueOnBlur(this.value)"> |
---|
758 | <% |
---|
759 | } |
---|
760 | else if (valueType == Type.TEXT) |
---|
761 | { |
---|
762 | %> |
---|
763 | <b><%=HTML.encodeTags(at.getName())%></b> (Text)<br> |
---|
764 | <textarea <%=clazz%> name="<%=inputName%>" rows="<%=height%>" cols="<%=width%>" |
---|
765 | onblur="valueOnBlur(this.value)"></textarea> |
---|
766 | <a href="javascript:Main.zoom('<%=HTML.javaScriptEncode(at.getName())%>', 'annotations', '<%=inputName%>')" |
---|
767 | title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
768 | <% |
---|
769 | } |
---|
770 | else if (valueType == Type.BOOLEAN) |
---|
771 | { |
---|
772 | %> |
---|
773 | <b><%=HTML.encodeTags(at.getName())%></b><br> |
---|
774 | <input type="radio" name="<%=inputName%>" value="" checked |
---|
775 | onclick="setCurrentValue(null)"><a |
---|
776 | href="javascript:document.forms['annotations'].<%=inputName%>[0].click()"><i>- not specified -</i></a><br> |
---|
777 | <input type="radio" name="<%=inputName%>" value="true" |
---|
778 | onclick="setCurrentValue('true')"><a |
---|
779 | href="javascript:document.forms['annotations'].<%=inputName%>[1].click()">true</a><br> |
---|
780 | <input type="radio" name="<%=inputName%>" value="false" |
---|
781 | onclick="setCurrentValue('false')"><a |
---|
782 | href="javascript:document.forms['annotations'].<%=inputName%>[2].click()">false</a> |
---|
783 | <% |
---|
784 | } |
---|
785 | else if (valueType == Type.DATE) |
---|
786 | { |
---|
787 | %> |
---|
788 | <table> |
---|
789 | <tr> |
---|
790 | <td> |
---|
791 | <b><%=HTML.encodeTags(at.getName())%></b> (Date)<br> |
---|
792 | <input <%=clazz%> type="text" name="<%=inputName%>" value="" |
---|
793 | size="20" maxlength="20" title="Enter date in format: <%=htmlDateFormat%>" |
---|
794 | onblur="valueOnBlur(this.value)"> |
---|
795 | </td> |
---|
796 | <td> |
---|
797 | <br> |
---|
798 | <base:button |
---|
799 | onclick="<%="Dates.selectDate('Value', 'annotations', '"+inputName+"', 'setDateCallback', '"+jsDateFormat+"')"%>" |
---|
800 | image="calendar.png" |
---|
801 | title="Calendar…" |
---|
802 | tooltip="Select a date from a calendar" |
---|
803 | /> |
---|
804 | </td> |
---|
805 | </tr> |
---|
806 | </table> |
---|
807 | <% |
---|
808 | } |
---|
809 | if (at.supportUnits() && !at.isEnumeration()) |
---|
810 | { |
---|
811 | ItemQuery<Unit> unitQuery = at.getUsableUnits(); |
---|
812 | if (unitQuery.count(dc) == 0) |
---|
813 | { |
---|
814 | unitQuery = at.getQuantity().getUnits(); |
---|
815 | } |
---|
816 | else |
---|
817 | { |
---|
818 | unitQuery.reset(); |
---|
819 | } |
---|
820 | unitQuery.order(Orders.desc(Hql.property("referenceFactor"))); |
---|
821 | unitQuery.order(Orders.asc(Hql.property("displaySymbol"))); |
---|
822 | List<Unit> units = unitQuery.list(dc); |
---|
823 | Unit current = a != null ? a.getUnit() : null; |
---|
824 | if (current == null) current = at.getDefaultUnit(); |
---|
825 | %> |
---|
826 | <select name="unit:<%=at.getId()%>" onchange="unitOnChange(this)"> |
---|
827 | <% |
---|
828 | boolean hasSelected = false; |
---|
829 | for (Unit unit : units) |
---|
830 | { |
---|
831 | String selected = ""; |
---|
832 | if (unit.equals(current)) |
---|
833 | { |
---|
834 | selected = " selected"; |
---|
835 | hasSelected = true; |
---|
836 | } |
---|
837 | %> |
---|
838 | <option value="<%=unit.getId()%>" <%=selected%> |
---|
839 | title="<%=HTML.encodeTags(unit.getName() + " - " + unit.getDescription()) %>" |
---|
840 | ><%=HTML.encodeTags(unit.getDisplaySymbol())%> |
---|
841 | <% |
---|
842 | } |
---|
843 | if (!hasSelected && current != null) |
---|
844 | { |
---|
845 | %> |
---|
846 | <option value="<%=current.getId()%>" selected |
---|
847 | title="<%=HTML.encodeTags(current.getName() + " - " + current.getDescription()) %>" |
---|
848 | ><%=HTML.encodeTags(current.getDisplaySymbol())%> |
---|
849 | <% |
---|
850 | } |
---|
851 | %> |
---|
852 | </select> |
---|
853 | <% |
---|
854 | } |
---|
855 | %> |
---|
856 | <p> |
---|
857 | <%=HTML.encodeTags(at.getDescription())%> |
---|
858 | </div> |
---|
859 | <% |
---|
860 | } |
---|
861 | %> |
---|
862 | </td> |
---|
863 | |
---|
864 | </tr> |
---|
865 | </table> |
---|
866 | |
---|
867 | </form> |
---|
868 | |
---|
869 | <% |
---|
870 | if (standalone) |
---|
871 | { |
---|
872 | %> |
---|
873 | </div> |
---|
874 | <% |
---|
875 | if (writePermission) |
---|
876 | { |
---|
877 | %> |
---|
878 | <table align="center"> |
---|
879 | <tr> |
---|
880 | <td width="50%"><base:button onclick="saveAnnotations()" title="Save" /></td> |
---|
881 | <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td> |
---|
882 | </tr> |
---|
883 | </table> |
---|
884 | <% |
---|
885 | } |
---|
886 | else |
---|
887 | { |
---|
888 | %> |
---|
889 | <div class="error">You do not have permission to change this information</div> |
---|
890 | <table align="center"> |
---|
891 | <tr> |
---|
892 | <td><base:button onclick="window.close()" title="Close" /></td> |
---|
893 | </tr> |
---|
894 | </table> |
---|
895 | <% |
---|
896 | } |
---|
897 | %> |
---|
898 | <form name="modified" method="post" action="index.jsp?ID=<%=ID%>"> |
---|
899 | <input type="hidden" name="cmd" value="SaveAnnotations"> |
---|
900 | <input type="hidden" name="item_type" value="<%=itemType.name()%>"> |
---|
901 | <input type="hidden" name="item_id" value="<%=itemId%>"> |
---|
902 | </form> |
---|
903 | <% |
---|
904 | } |
---|
905 | %> |
---|
906 | |
---|
907 | </base:body> |
---|
908 | </base:page> |
---|
909 | <% |
---|
910 | } |
---|
911 | finally |
---|
912 | { |
---|
913 | if (dc != null) dc.close(); |
---|
914 | } |
---|
915 | %> |
---|