source: trunk/www/common/annotations/annotate.jsp @ 5074

Last change on this file since 5074 was 5074, checked in by Nicklas Nordborg, 14 years ago

Fixes #1360: Existing annotatation on an item may not be visible/editable in some cases

This should make sure that all existing annotations can be viewed and edited. The problem with the "Unhandled item: ANNOTATION..." will be fixed as part of #1361.

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