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