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

Last change on this file since 5425 was 5425, checked in by Nicklas Nordborg, 13 years ago

References #1514: Fix character encoding of jsp files

I hope this fixes most of the issues, including the reporter list filtering in many places. Let's keep an eye open for more issues until it is time to release 2.16

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