/*
 Copyright (c) 2000-2005 University of Washington.  All rights reserved.

 Redistribution and use of this distribution in source and binary forms,
 with or without modification, are permitted provided that:

   The above copyright notice and this permission notice appear in
   all copies and supporting documentation;

   The name, identifiers, and trademarks of the University of Washington
   are not used in advertising or publicity without the express prior
   written permission of the University of Washington;

   Recipients acknowledge that this distribution is made available as a
   research courtesy, "as is", potentially with defects, without
   any obligation on the part of the University of Washington to
   provide support, services, or repair;

   THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR
   IMPLIED, WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION
   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
   PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF
   WASHINGTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
   DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
   PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING
   NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
   THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
/* **********************************************************************
    Copyright 2005 Rensselaer Polytechnic Institute. All worldwide rights reserved.

    Redistribution and use of this distribution in source and binary forms,
    with or without modification, are permitted provided that:
       The above copyright notice and this permission notice appear in all
        copies and supporting documentation;

        The name, identifiers, and trademarks of Rensselaer Polytechnic
        Institute are not used in advertising or publicity without the
        express prior written permission of Rensselaer Polytechnic Institute;

    DISCLAIMER: The software is distributed" AS IS" without any express or
    implied warranty, including but not limited to, any implied warranties
    of merchantability or fitness for a particular purpose or any warrant)'
    of non-infringement of any current or pending patent rights. The authors
    of the software make no representations about the suitability of this
    software for any particular purpose. The entire risk as to the quality
    and performance of the software is with the user. Should the software
    prove defective, the user assumes the cost of all necessary servicing,
    repair or correction. In particular, neither Rensselaer Polytechnic
    Institute, nor the authors of the software are liable for any indirect,
    special, consequential, or incidental damages related to the software,
    to the maximum extent the law permits.
*/

package org.bedework.webclient;

import org.bedework.calfacade.CalFacadeUtil;

import javax.servlet.http.HttpServletRequest;

/** Set up for addition of new event.
 *
 * <p>Parameters are:<ul>
 *      <li>"startdate"              Optional start date for the event
                                     as yymmdd or yymmddTHHmmss</li>
        <li>"enddate"                Optional end date for the event
                                     as yymmdd or yymmddTHHmmss</li>
 * </ul>
 *
 */
public class BwInitEventAction extends BwCalAbstractAction {
  /* (non-Javadoc)
   * @see org.bedework.webclient.BwCalAbstractAction#doAction(javax.servlet.http.HttpServletRequest, org.bedework.webclient.BwActionForm)
   */
  public String doAction(HttpServletRequest request,
                         BwActionForm form) throws Throwable {
    form.refreshIsNeeded();

    String date = getReqPar(request, "startdate");

    if (date != null) {
      if (CalFacadeUtil.isISODateTime(date)) {
        form.assignEventDates(CalFacadeUtil.fromISODateTime(date));
      } else if (CalFacadeUtil.isISODate(date)) {
        form.assignEventDates(CalFacadeUtil.fromISODate(date));
      } else {
        form.getErr().emit("org.bedework.client.error.baddate", date);
        return "badDate";
      }
    }

    date = getReqPar(request, "enddate");

    if (date != null) {
      if (CalFacadeUtil.isISODateTime(date)) {
        form.getEventDates().getEndDate().setDateTime(CalFacadeUtil.fromISODateTime(date));
      } else if (CalFacadeUtil.isISODate(date)) {
        form.getEventDates().getEndDate().setDateTime(CalFacadeUtil.fromISODate(date));
      } else {
        form.getErr().emit("org.bedework.client.error.baddate", date);
        return "badDate";
      }
    }

    return "success";
  }
}


@@ -2859,17 +2859,16 @@
 its.%0A*/%0A
-%0A
 package 
@@ -2892,16 +2892,55 @@
 lient;%0A%0A
+import org.bedework.calfacade.BwEvent;%0A
 import o
@@ -2975,16 +2975,102 @@
 adeUtil;
+%0Aimport org.bedework.webcommon.DurationBean;%0Aimport org.bedework.webcommon.EventDates;
 %0A%0Aimport
@@ -3455,16 +3455,87 @@
 ss%3C/li%3E%0A
+        %3Cli%3E%22minutes%22                Optional duration in minutes%3C/li%3E%0A
  * %3C/ul%3E
@@ -3955,32 +3955,80 @@
  %22startdate%22);%0A%0A
+    EventDates evdates = form.getEventDates();%0A%0A
     if (date != 
@@ -4090,37 +4090,35 @@
         
-form.assignEvent
+evdates.setFrom
 Date
-s
 (CalFaca
@@ -4210,29 +4210,27 @@
     
-form.assignEvent
+evdates.setFrom
 Date
-s
 (Cal
@@ -4509,36 +4509,23 @@
         
-form.getEventD
+evd
 ates
-()
 .getEndD
@@ -4638,36 +4638,23 @@
         
-form.getEventD
+evd
 ates
-()
 .getEndD
@@ -4828,24 +4828,333 @@
    %7D%0A    %7D%0A%0A
+    int minutes = getIntReqPar(request, %22minutes%22, -1);%0A%0A    if (minutes %3E 0) %7B%0A      // Set the duration%0A      evdates.setEndType(String.valueOf(BwEvent.endTypeDuration));%0A      DurationBean dur = evdates.getDuration();%0A%0A      dur.setType(DurationBean.dayTimeDuration);%0A      dur.setMinutes(minutes);%0A    %7D%0A%0A
     return %22
@@ -5169,9 +5169,8 @@
 ;%0A  %7D%0A%7D%0A
-%0A

Allow specification of event duration on init event