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

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

References #1290: Change source files to UTF-8

Changed 'Hakkinen' to 'Häkkinen'.

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