Changeset 5423


Ignore:
Timestamp:
Sep 23, 2010, 11:09:55 AM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1512: Add support for datetime annotation types

Makes it possible to crete TIMESTAMP annotation types and to enter values for them.

This is basically 3) in the ticket description.

Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/formatter/FormatterFactory.java

    r5136 r5423  
    262262      return getDateFormatter(sc);
    263263    }
     264    else if (type == Type.TIMESTAMP)
     265    {
     266      return getDateTimeFormatter(sc);
     267    }
    264268    else if (type == Type.BOOLEAN)
    265269    {
  • trunk/www/admin/annotationtypes/edit_annotationtype.jsp

    r5156 r5423  
    22  ------------------------------------------------------------------
    33  Copyright (C) 2005 Nicklas Nordborg
    4   Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
     4  Copyright (C) 2006 Jari Hkkinen, Nicklas Nordborg
    55
    66  This file is part of BASE - BioArray Software Environment.
     
    132132  String jsDateFormat = HTML.javaScriptEncode(dateFormat);
    133133  String htmlDateFormat = HTML.encodeTags(dateFormat);
     134 
     135  Formatter<Date> dateTimeFormatter = FormatterFactory.getDateTimeFormatter(sc);
     136  String dateTimeFormat = FormatterSettings.getDateTimeFormat(sc);
     137  String jsDateTimeFormat = HTML.javaScriptEncode(dateTimeFormat);
     138  String htmlDateTimeFormat = HTML.encodeTags(dateTimeFormat);
    134139  %>
    135140  <base:page type="popup" title="<%=title%>">
     
    483488            <%
    484489          }
     490          else if (valueType == Type.TIMESTAMP)
     491          {
     492            %>
     493            <table border="0" cellspacing="0" cellpadding="0">
     494            <tr>
     495            <td>
     496              <input <%=clazz%> type="text" name="defaultValue"
     497                value="<%=HTML.encodeTags(defaultValue)%>"
     498                size="30" maxlength="30 "title="Enter date in format: <%=htmlDateTimeFormat%>">&nbsp;
     499            </td>
     500            <td>
     501              <base:button
     502                onclick="<%="Dates.selectDateTime('Default value', 'annotationType', 'defaultValue', null, '"+jsDateTimeFormat+"')"%>"
     503                image="calendar.png"
     504                title="Calendar&hellip;"
     505                tooltip="Select a date and time from a calendar"
     506              />
     507            </td>
     508            </tr>
     509            </table>
     510            <%
     511          }
    485512          else if (valueType == Type.STRING)
    486513          {
     
    711738            <a href="javascript:Main.zoom('Values', 'annotationtype', 'values')" title="Edit in larger window"><base:icon image="zoom.gif" /></a><br>
    712739            One date value (<%=htmlDateFormat%>) per line
     740          </td>
     741        </tr>
     742        <%
     743      }
     744      else if (valueType == Type.TIMESTAMP)
     745      {
     746        %>
     747        <tr>
     748          <td class="prompt">Input box width</td>
     749          <td>
     750            <input <%=clazz%> type="text" name="width"
     751              value="<%=annotationType == null ? "" : annotationType.getWidth()%>"
     752              size="12" maxlength="10" onkeypress="return Numbers.integerOnly(event)">
    713753          </td>
    714754        </tr>
  • trunk/www/admin/annotationtypes/list_annotationtypes.jsp

    r5165 r5423  
    11<%-- $Id$
    22  ------------------------------------------------------------------
    3   Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
     3  Copyright (C) 2006 Jari Hkkinen, Nicklas Nordborg, Martin Svensson
    44  Copyright (C) 2007 Johan Enell, Nicklas Nordborg, Martin Svensson
    55
     
    612612                  /></tbl:cell>
    613613                <tbl:cell column="isEnumeration"><%=item.isEnumeration() ?
    614                   HTML.encodeTags(Values.getString(item.getValues(), ", ", true)) :
     614                  HTML.encodeTags(Values.getString((List)item.getValues(), ", ", true, (Formatter)FormatterFactory.getTypeFormatter(sc, item.getValueType()) )) :
    615615                  "<i>- no -</i>"%></tbl:cell>
    616616                <tbl:cell column="requiredForMiame"><%=item.isRequiredForMiame() ? "yes" : "no"%></tbl:cell>
  • trunk/www/admin/annotationtypes/view_annotationtype.jsp

    r5070 r5423  
    11<%-- $Id$
    22  ------------------------------------------------------------------
    3   Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
     3  Copyright (C) 2006 Jari Hkkinen, Nicklas Nordborg, Martin Svensson
    44  Copyright (C) 2007 Martin Svensson
    55
     
    6363  import="java.util.Date"
    6464  import="java.util.Set"
     65  import="java.util.List"
    6566%>
    6667<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
     
    283284        <td class="prompt">Enumeration</td>
    284285        <td><%=annotationType.isEnumeration() ?
    285           HTML.encodeTags(Values.getString(annotationType.getValues(), ", ", true,
    286             annotationType.getValueType() == Type.DATE ? dateFormatter : null)) : "no"%></td>
     286          HTML.encodeTags(Values.getString((List)annotationType.getValues(), ", ", true,
     287            (Formatter)FormatterFactory.getTypeFormatter(sc, annotationType.getValueType()))) : "no"%></td>
    287288      </tr>
    288289      <tr>
  • trunk/www/common/annotations/annotate.jsp

    r5075 r5423  
    22  ------------------------------------------------------------------
    33  Copyright (C) 2005 Nicklas Nordborg
    4   Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
     4  Copyright (C) 2006 Jari Hkkinen, Nicklas Nordborg
    55  Copyright (C) 2007 Nicklas Nordborg
    66
     
    8888  String htmlDateFormat = HTML.encodeTags(dateFormat);
    8989
     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 
    9095  final Annotatable item = itemId == 0 ? null : (Annotatable)itemType.getById(dc, itemId);
    9196  final boolean writePermission = item == null ? true : item.hasPermission(Permission.WRITE);
     
    190195      List values = null;
    191196      Unit unit = at.getDefaultUnit();
     197      Type valueType = at.getValueType();
    192198      if (existing != null && existing.containsKey(at))
    193199      {
     
    206212        for (Object value : values)
    207213        {
    208           if (value instanceof Date) value = dateFormatter.format((Date)value);
     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          }
    209225          %>
    210226          values[values.length] = '<%=HTML.javaScriptEncode(value.toString())%>';
     
    807823            <%
    808824          }
     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          }
    809849          if (at.supportUnits() && !at.isEnumeration())
    810850          {
  • trunk/www/common/calendar.jsp

    r4889 r5423  
    22  ------------------------------------------------------------------
    33  Copyright (C) 2005 Nicklas Nordborg
    4   Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
     4  Copyright (C) 2006 Jari Hkkinen, Nicklas Nordborg
    55
    66  This file is part of BASE - BioArray Software Environment.
     
    3333--%>
    3434<%@ page session="false"
     35  import="net.sf.basedb.core.SessionControl"
    3536  import="net.sf.basedb.util.Values"
     37  import="net.sf.basedb.clients.web.Base"
    3638  import="net.sf.basedb.clients.web.util.HTML"
    3739  import="java.util.Date"
     
    3941<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    4042<%
     43  final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
    4144  String title = request.getParameter("title");
    4245  String form = request.getParameter("form");
    4346  String input = request.getParameter("input");
    4447  String callback = request.getParameter("callback");
    45   String format = Values.getString(request.getParameter("format"), "yyyy-MM-dd");
     48  boolean datetime = Values.getBoolean(request.getParameter("datetime"));
     49  String format = Values.getString(request.getParameter("format"), datetime ? "yyyy-MM-dd HH:mm:ss" : "yyyy-MM-dd");
     50  final float scale = Base.getScale(sc);
    4651%>
    4752<base:page type="popup" title="<%=title%>">
    48 <base:head styles="calendar.css">
     53<base:head styles="calendar.css?x">
    4954  <script language="JavaScript">
     55
     56  var datetime = <%=datetime ? "1" : "0"%>;
     57  var dateFormat = '<%=HTML.javaScriptEncode(format)%>';
     58  var currentDate;
    5059  function init()
    5160  {
    52     var date = getDate();
    53     var frm = document.forms['calendar'];
    54     Forms.selectListOption(frm.month, date.getMonth());
    55     frm.year.value = Dates.getFourDigitYear(date.getFullYear());
    56     displayMonth(date.getFullYear(), date.getMonth(), date);
    57   }
    58  
    59   function getDate()
     61    currentDate = getInitialDate();
     62    showFullDate(currentDate);
     63  }
     64
     65  function getInitialDate()
    6066  {
    6167    var frm = window.opener.document.forms['<%=form%>'];
     
    6571    return date;
    6672  }
    67  
    68   function setDate(theDate)
    69   {
    70     var formattedDate = Dates.formatDate(theDate, '<%=HTML.javaScriptEncode(format)%>');
     73
     74  function saveCurrentDate()
     75  {
     76    var frm = document.forms['calendar'];
     77    if (!validate())
     78    {
     79      alert(document.getElementById('error').innerHTML);
     80      return;
     81    }
     82    var formattedDate = Dates.formatDate(currentDate, dateFormat);
    7183    <%
    7284    if (callback == null)
     
    8799  }
    88100 
     101  function showFullDate(date)
     102  {
     103    var frm = document.forms['calendar'];
     104    // Year is a regular input field
     105    frm.year.value = Dates.getFourDigitYear(date.getFullYear());
     106    // Month is a selection list
     107    Forms.selectListOption(frm.month, date.getMonth());
     108    // Days in the month are displayed as a table
     109    displayMonth(date.getFullYear(), date.getMonth(), date);
     110    // Time (if present) are regular input fields
     111    if (datetime)
     112    {
     113      frm.hours.value = zeroPad(date.getHours());
     114      frm.minutes.value = zeroPad(date.getMinutes());
     115      frm.seconds.value = zeroPad(date.getSeconds());
     116    }
     117    // Finally, a complete formatted date is created
     118    document.getElementById('current').innerHTML = Dates.formatDate(date, dateFormat);
     119  }
     120 
     121  function zeroPad(value)
     122  {
     123    return value <= 9 ? '0' + value : value;
     124  }
     125
     126  function setDate(date)
     127  {
     128    if (!validate()) return;
     129    currentDate.setFullYear(date.getFullYear());
     130    currentDate.setMonth(date.getMonth());
     131    currentDate.setDate(date.getDate());
     132    if (datetime)
     133    {
     134      showFullDate(currentDate);
     135    }
     136    else
     137    {
     138      saveCurrentDate();
     139    }
     140  }
     141
     142  function setTime()
     143  {
     144    if (!validate()) return;
     145    var frm = document.forms['calendar'];
     146    currentDate.setHours(frm.hours.value);
     147    currentDate.setMinutes(frm.minutes.value);
     148    currentDate.setSeconds(frm.seconds.value);
     149    document.getElementById('current').innerHTML = Dates.formatDate(currentDate, dateFormat);
     150  }
     151 
    89152  function setToday()
    90153  {
    91     setDate(new Date());
     154    currentDate = new Date();
     155    saveCurrentDate();
    92156  }
    93157 
     
    107171        if (dayOfMonth < 1 || dayOfMonth > daysInMonth)
    108172        {
    109           cell.firstChild.nodeValue = ' ';
     173          cell.firstChild.nodeValue = '';
    110174          cell.theDate = '';
     175          if (day == 0 && week > 4) Main.hide('w' + week);
    111176        }
    112177        else
     
    114179          cell.firstChild.nodeValue = dayOfMonth;
    115180          cell.theDate = Dates.newDate(year, month, dayOfMonth);
     181          if (day == 0) Main.show('w' + week);
    116182        }
    117183        if (year == today.getFullYear() && month == today.getMonth() && dayOfMonth == today.getDate())
     
    138204  function changeMonth()
    139205  {
    140     var frm = document.forms['calendar'];
    141     if (frm.year.value.length != 4)
    142     {
    143       Main.showInline('invalidyear');
    144       return;
    145     }
    146     else
    147     {
    148       Main.hide('invalidyear');
    149     }
     206    if (!validate()) return;
     207    var frm = document.forms['calendar'];
    150208    var month = Number(frm.month[frm.month.selectedIndex].value);
    151209    var year = Number(frm.year.value);
    152     displayMonth(year, month, getDate());
    153   }
    154  
     210    displayMonth(year, month, currentDate);
     211  }
     212
     213  function addToYear(delta)
     214  {
     215    var frm = document.forms['calendar'];
     216    var nextYear = parseInt(frm.year.value, 10) + delta;
     217    frm.year.value = nextYear;
     218    changeMonth();
     219  }
     220 
     221  function addToHour(delta)
     222  {
     223    var frm = document.forms['calendar'];
     224    var nextHour = parseInt(frm.hours.value, 10) + delta;
     225    if (nextHour < 0) nextHour = 0;
     226    if (nextHour > 23) nextHour = 23;
     227    frm.hours.value = zeroPad(nextHour);
     228    setTime();
     229  }
     230
     231  function addToMinute(delta)
     232  {
     233    var frm = document.forms['calendar'];
     234    var nextMinute = parseInt(frm.minutes.value, 10) + delta;
     235    if (nextMinute < 0) nextMinute = 0;
     236    if (nextMinute > 59) nextMinute = 59;
     237    frm.minutes.value = zeroPad(nextMinute);
     238    setTime();
     239  }
     240
     241  function addToSecond(delta)
     242  {
     243    var frm = document.forms['calendar'];
     244    var nextSecond = parseInt(frm.seconds.value, 10) + delta;
     245    if (nextSecond < 0) nextSecond = 0;
     246    if (nextSecond > 59) nextSecond = 59;
     247    frm.seconds.value = zeroPad(nextSecond);
     248    setTime();
     249  }
     250
     251  function showError(message)
     252  {
     253    document.getElementById('error').innerHTML = message;
     254    Main.show('error');
     255    Main.hide('current');
     256  }
     257
     258  function validate()
     259  {
     260    var frm = document.forms['calendar'];
     261    if (frm.year.value.length != 4)
     262    {
     263      showError('Year must have four digits');
     264      return false;
     265    }
     266    if (datetime)
     267    {
     268      var hours = parseInt(frm.hours.value, 10);
     269      if (hours < 0 || hours > 23)
     270      {
     271        showError('Hours must be a value between 0 and 23');
     272        return false;
     273      }
     274      var minutes = parseInt(frm.minutes.value, 10);
     275      if (minutes < 0 || minutes > 59)
     276      {
     277        showError('Minutes must be a value between 0 and 59');
     278        return false;
     279      }
     280      var seconds = parseInt(frm.seconds.value, 10);
     281      if (seconds < 0 || seconds > 59)
     282      {
     283        showError('Seconds must be a value between 0 and 59');
     284        return false;
     285      }
     286    }
     287    Main.hide('error');
     288    Main.show('current');
     289    return true;
     290  }
    155291  </script>
    156292</base:head>
    157293<base:body onload="init()">
    158   <form name="calendar" onsubmit="changeMonth(); return false;">
     294  <form name="calendar" onsubmit="return false;">
    159295  <h3 class="docked"><%=title%><base:help helpid="calendar.selectday" /></h3>
    160296  <div class="boxed">
     
    179315    </td>
    180316    <td style="text-align: right;">
    181       <span id="invalidyear" class="error" style="display: none;">Year must have 4 digits!</span>
    182317      <input type="text" class="text" name="year" size="4" maxlength="4"
    183318        onkeypress="return Numbers.integerOnly(event);"
    184319        onkeyup="changeMonth()">
    185320    </td>
     321    <td width="12px">
     322      <table border="0" cellspacing="2" cellpadding="0">
     323      <tr><td><base:icon image="mini_scroll_up.png" onclick="addToYear(1)" tooltip="Next year"/></td></tr>
     324      <tr><td><base:icon image="mini_scroll_down.png" onclick="addToYear(-1)" tooltip="Previous year"/></td></tr>
     325      </table>
     326    </td>
    186327    </tr>
    187328    </table>
    188 
     329    <div style="min-height: <%=(int)(scale*130)%>px;">
    189330    <table width="100%" border=0 cellspacing=0 cellpadding=0 class="calendar">
    190331    <tr>
     
    220361    %>
    221362    </table>
     363    </div>
     364    <%
     365    if (datetime)
     366    {
     367      %>
     368      <table border="0" cellspacing=2 cellpadding=0 align="center" style="padding-top: 4px;">
     369      <tr>
     370        <td class="time">Time</td>
     371        <td><input class="text" type="text" name="hours" title="Hours" size="2" maxlength="2"
     372          onkeypress="return Numbers.integerOnly(event)" onblur="setTime()"></td>
     373        <td width="12px">
     374          <table border="0" cellspacing="1" cellpadding="0">
     375          <tr><td><base:icon image="mini_scroll_up.png" onclick="addToHour(1)" tooltip="Add one hour"/></td></tr>
     376          <tr><td><base:icon image="mini_scroll_down.png" onclick="addToHour(-1)" tooltip="Subtract one hour"/></td></tr>
     377          </table>
     378        </td>
     379        <td><input class="text" type="text" name="minutes" title="Minutes" size="2" maxlength="2"
     380          onkeypress="return Numbers.integerOnly(event)" onblur="setTime()"></td>
     381        <td width="12px">
     382          <table border="0" cellspacing="1" cellpadding="0">
     383          <tr><td><base:icon image="mini_scroll_up.png" onclick="addToMinute(1)" tooltip="Add one minute"/></td></tr>
     384          <tr><td><base:icon image="mini_scroll_down.png" onclick="addToMinute(-1)" tooltip="Subtract one minute"/></td></tr>
     385          </table>
     386        </td>
     387        <td><input class="text" type="text" name="seconds" title="Seconds" size="2" maxlength="2"
     388          onkeypress="return Numbers.integerOnly(event)" onblur="setTime()"></td>
     389        <td width="12px">
     390          <table border="0" cellspacing="1" cellpadding="0">
     391          <tr><td><base:icon image="mini_scroll_up.png" onclick="addToSecond(1)" tooltip="Add one second"/></td></tr>
     392          <tr><td><base:icon image="mini_scroll_down.png" onclick="addToSecond(-1)" tooltip="Subtract one second"/></td></tr>
     393          </table>
     394        </td>
     395      </tr>
     396      </table>
     397      <%
     398    }
     399    %>
    222400  </div>
    223401  </form>
    224   <table align="center">
    225   <tr>
    226     <td><base:button image="today.png" onclick="setToday()" title="Today" /></td>
    227     <td><base:button onclick="window.close()" title="Cancel" /></td>
    228   </tr>
    229   </table>
     402  <p></p>
     403  <div id="error" class="error" style="display: none;"></div>
     404  <div id="current" style="text-align: center; font-weight: bold;"></div>
     405  <base:buttongroup align="center">
     406    <base:button image="today.png" onclick="setToday()" title="<%=datetime ? "Now" : "Today"%>" />
     407    <base:button onclick="saveCurrentDate()" title="Ok" visible="<%=datetime%>"/>
     408    <base:button onclick="window.close()" title="Cancel" />
     409  </base:buttongroup>
    230410</base:body>
    231411</base:page>
  • trunk/www/include/scripts/main.js

    r5411 r5423  
    13661366    url += '&ID='+getSessionId();
    13671367    if (callback) url += '&callback='+callback;
    1368     Main.openPopup(url, title.replace(/[^\w]/, ''), 350, 240);
    1369   }
     1368    Main.openPopup(url, title.replace(/[^\w]/, ''), 440, 340);
     1369  }
     1370
     1371  /*
     1372    Opens a popup window allowing a user to select a date and time graphically. The
     1373    current value is taken from the specified input field of the specified form and
     1374    is saved back to it when the window is closed.
     1375 
     1376    @param title The title of the window
     1377    @param form The name of the form where the input field is located
     1378    @param input The name of the input field that holds the date value
     1379    @param callback If specified, the date is returned by using this javascript call instead
     1380      of by setting the form field
     1381  */
     1382  this.selectDateTime = function(title, form, input, callback, format)
     1383  {
     1384    var url = getRoot()+'common/calendar.jsp?datetime=1&title='+escape(title)+'&form='+form+'&input='+input+'&format='+escape(format);
     1385    url += '&ID='+getSessionId();
     1386    if (callback) url += '&callback='+callback;
     1387    Main.openPopup(url, title.replace(/[^\w]/, ''), 440, 340);
     1388  }
     1389
     1390
    13701391}
    13711392
  • trunk/www/include/styles/calendar.css

    r4889 r5423  
    22  ------------------------------------------------------------------
    33  Copyright (C) 2005 Nicklas Nordborg
    4   Copyright (C) 2006 Jari Häkkinen
     4  Copyright (C) 2006 Jari Hkkinen
    55
    66  This file is part of BASE - BioArray Software Environment.
     
    5151}
    5252
     53.time {
     54  padding-left: 2px;
     55  font-weight: bold;
     56}
     57
    5358.today, .current {
    5459  font-weight: bold;
Note: See TracChangeset for help on using the changeset viewer.