click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r776472 - in /incubator/click/trunk/click/extras: src/META-INF/web/click/calendar/ src/org/apache/click/extras/control/ test/org/apache/click/extras/control/
Date Tue, 19 May 2009 21:28:02 GMT
Author: sabob
Date: Tue May 19 21:28:00 2009
New Revision: 776472

URL: http://svn.apache.org/viewvc?rev=776472&view=rev
Log:
refacted CalendarField functionality into DateField

Added:
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/blue.css   (props changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/blue.css
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/calendar.gif   (props
changed)
      - copied unchanged from r775772, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/calendar.gif
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/calendar_date_select.js
  (props changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/calendar_date_select.js
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/da.js   (props changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/da.js
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/de.js   (props changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/de.js
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/default.css   (props
changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/default.css
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/fi.js   (props changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/fi.js
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/fr.js   (props changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/fr.js
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/pl.js   (props changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/pl.js
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/plain.css   (props
changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/plain.css
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/pt.js   (props changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/pt.js
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/red.css   (props changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/red.css
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/ru.js   (props changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/ru.js
    incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/silver.css   (props
changed)
      - copied unchanged from r773995, incubator/click/trunk/click/extras/src/META-INF/web/click/prototype/calendar/silver.css
Modified:
    incubator/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.java
    incubator/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.properties
    incubator/click/trunk/click/extras/test/org/apache/click/extras/control/DateFieldTest.java

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/blue.css
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/calendar.gif
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/calendar.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/calendar_date_select.js
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/da.js
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/de.js
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/default.css
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/fi.js
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/fr.js
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/pl.js
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/plain.css
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/pt.js
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/red.css
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/ru.js
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: incubator/click/trunk/click/extras/src/META-INF/web/click/calendar/silver.css
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.java?rev=776472&r1=776471&r2=776472&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.java
(original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.java
Tue May 19 21:28:00 2009
@@ -21,24 +21,33 @@
 import java.sql.Timestamp;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Calendar;
 import java.util.Date;
+import java.util.List;
 import java.util.Locale;
 
+import org.apache.click.Context;
 import org.apache.click.control.TextField;
+import org.apache.click.element.CssImport;
+import org.apache.click.element.JsImport;
+import org.apache.click.element.JsScript;
+import org.apache.click.util.ClickUtils;
 import org.apache.click.util.HtmlStringBuffer;
 
 /**
- * Provides a Date Field control:   <input type='text'>.
+ * Provides a Date Field control:   <input type='text'><img>.
  *
  * <table class='htmlHeader' cellspacing='6'>
  * <tr>
  * <td style="vertical-align:baseline">Date Field</td>
- * <td style="vertical-align:baseline"><input type='text' size='20' title='DateField
Control' value='15 Mar 2006'/></td>
+ * <td style="vertical-align:baseline"><input type='text' size='20' title='DateField
Control' value='12 May 2009'/><img align='top' hspace='2' style='cursor:hand' src='calendar.gif'
title='Calendar'/></td>
  * </tr>
  * </table>
  *
- * The DateField control provides a Date entry field where users can key in a
- * Date value.
+ * The DateField control provides a Date entry field and a popup Calendar
+ * &lt;div&gt;. Users can either key in a Date value or select a Date using the
+ * Calendar.
  * <p/>
  * Example:
  * <pre class="prettyprint">
@@ -48,26 +57,78 @@
  *         Form form = new Form("form");
  *
  *         // Create new DateField with default date format: 'dd MMM yyyy'
- *         DateField dateField = new DateField("dateField");
+ *         DateField dateField = new DateField("date");
  *
  *         // You can change the format to: 'yyyy-MM-dd'
  *         dateField.setFormatPattern("yyyy-MM-dd");
  *
  *         // Finally add dateField to form
  *         form.add(dateField);
+ *
+ *         addControl(form);
  *     }
  * } </pre>
  *
+ * <p/>
+ * The Calendar popup is provided by the <a target="_blank" class="external" href="http//www.prototypejs.org">Prototype</a>
+ * based <a target="_blank" class="external" href="http://code.google.com/p/calendardateselect/">CalendarDateSelect</a>
+ * library.
+ * <p/>
+ * <b>Please note:</b> if you don't want to have a dependency on the
+ * Prototype library you can use the <a class="external" target="_blank" href="http://code.google.com/p/click-calendar/">Click
Calendar</a>
+ * CalendarField which is based on the <a class="external" target="_blank" href="http://www.dynarch.com/">Dynarch.com</a>
+ * library. Consider this option when using an alternative JavaScript library
+ * than Prototype, such as <a class="external" target="_blank" href="http://jquery.com">JQuery</a>.
+ * <p/>
+ * Alternatively you can switch off the Calendar popup by setting the
+ * {@link #setShowCalendar(boolean)} to false. No JavaScript and CSS will be
+ * included when this option is false.
+ * <p/>
+ * The Calendar popup is created as a &lt;div&gt; element using JavaScript.
+ * To enable the Calendar popup, reference <span class="blue">$headElements</span>
+ * and <span class="blue">$jsElements</span> in the page template. For example:
+ *
+ * <pre class="codeHtml">
+ * &lt;html&gt;
+ * &lt;head&gt;
+ * <span class="blue">$headElements</span>
+ * &lt;/head&gt;
+ * &lt;body&gt;
+ * <span class="red">$form</span>
+ * &lt;/body&gt;
+ * &lt;/html&gt;
+ * <span class="blue">$jsElements</span> </pre>
+ *
+ * The default Calendar style is 'default' which has a gray theme.
+ * The Calendar styles include:
+ * <ul style="margin-top: 0.5em;">
+ * <li>blue</li>
+ * <li>default</li>
+ * <li>plain</li>
+ * <li>red</li>
+ * <li>silver</li>
+ * </ul>
+ *
+ * The DateField JavaScript, CSS and image resources are automatically deployed
+ * to the <tt>click/calendar</tt> web directory on application startup.
+ *
  * See also W3C HTML reference
  * <a class="external" target="_blank" title="W3C HTML 4.01 Specification"
  *    href="http://www.w3.org/TR/html401/interact/forms.html#h-17.4">INPUT</a>
  *
  * @author Malcolm Edgar
+ * @author Bob Schellink
  */
 public class DateField extends TextField {
 
+    // -------------------------------------------------------------- Constants
+
     private static final long serialVersionUID = 1L;
 
+    /** Supported locales. */
+    static final String[] SUPPORTTED_LANGUAGES =
+        {"de", "fi", "fr", "pl", "pt", "ru"};
+
     // ----------------------------------------------------- Instance Variables
 
     /** The DateField's date value. */
@@ -79,6 +140,25 @@
     /** The date format pattern value. */
     protected String formatPattern;
 
+    /** The JavaScript Calendar pattern. */
+    protected String calendarPattern;
+
+    /** The Calendar popup show time display bar flag. */
+    protected boolean showTime;
+
+    /**
+     * Flag indicating if the Calendar popup is displayed or not,
+     * default value is true.
+     */
+    protected boolean showCalendar = true;
+
+    /**
+     * The Calendar CSS style, default value: <tt>default</tt>.
+     * Available styles include:
+     * <tt>[blue, default, plain, red, silver]</tt>
+     */
+    protected String style = "default";
+
     // ----------------------------------------------------------- Constructors
 
     /**
@@ -335,6 +415,7 @@
             throw new IllegalArgumentException("Null pattern parameter");
         }
         formatPattern = pattern;
+        calendarPattern = parseDateFormatPattern(pattern);
     }
 
     /**
@@ -415,6 +496,144 @@
         }
     }
 
+    /**
+     * Return the JavaScript Calendar pattern. The Calendar pattern
+     * is defined when you set the format pattern.
+     *
+     * @return the JavaScript Calendar pattern
+     */
+    public String getCalendarPattern() {
+        return calendarPattern;
+    }
+
+    /**
+     * Return the DateField <tt>calendar.js</tt> and <tt>calendar-{lang}.js</tt>
+     * includes.
+     *
+     * @return the HTML head import statements for the control stylesheet and
+     * JavaScript files
+     */
+    public String getHtmlImports() {
+        return null;
+    }
+
+    /**
+     * Return the CalendarField <tt>prototype.js</tt>,
+     * <tt>calendar_date_select.js</tt>, <tt>{lang}.js</tt>
+     * and <tt>{style}.css</tt> includes.
+     * <p/>
+     * This method delegates to {@link #addCalendarOptions(java.util.List)} to
+     * include the Calendar Options script.
+     *
+     * @return the HTML head import statements for the control stylesheet and
+     * JavaScript files
+     */
+    public List getHeadElements() {
+        // CLK-309. Skip imports if dateField is disabled, readonly or calendar
+        // should not be displayed.
+        if (isReadonly() || isDisabled() || !isShowCalendar()) {
+            return super.getHeadElements();
+        }
+
+        // Check that the field id has been set
+        String fieldName = getName();
+        if (fieldName == null) {
+            throw new IllegalStateException("CalendarField name"
+                + " is not defined. Set the name before calling"
+                + " getHeadElements().");
+        }
+
+        String language = getLocale().getLanguage();
+
+        if (headElements == null) {
+            headElements = super.getHeadElements();
+
+            String versionIndicator = ClickUtils.getResourceVersionIndicator(getContext());
+
+            headElements.add(new CssImport("/click/calendar/" + getStyle()
+                + ".css", versionIndicator));
+            headElements.add(new JsImport("/click/prototype/prototype.js",
+                versionIndicator));
+            headElements.add(new JsImport("/click/calendar/calendar_date_select.js",
+                versionIndicator));
+
+            // English is default language, only include language pack if other
+            // than English
+            if (!"en".equals(language)) {
+                JsImport jsImport = new JsImport("/click/calendar/"
+                    + getLocale().getLanguage() + ".js", versionIndicator);
+                jsImport.setAttribute("charset", "UTF-8");
+                headElements.add(jsImport);
+            }
+        }
+
+        addCalendarOptions(headElements);
+
+        return headElements;
+    }
+
+    /**
+     * Return true if the Calendar popup will show the time display bar.
+     *
+     * @return true if the Calendar popup will show the time display bar
+     */
+    public boolean isShowTime() {
+        return showTime;
+    }
+
+    /**
+     * Set the Calendar popup show the time display bar flag.
+     *
+     * @param showTime the flag to show the Calendar time display bar
+     */
+    public void setShowTime(boolean showTime) {
+        this.showTime = showTime;
+    }
+
+    /**
+     * Return true if the Calendar popup will be displayed, false otherwise.
+     * Default value is true.
+     *
+     * @return true if the Calendar popup will be displayed, false otherwise
+     */
+    public boolean isShowCalendar() {
+        return showCalendar;
+    }
+
+    /**
+     * Set whether the Calendar popup is displayed or not. If set to false the
+     * DateField will not include any JavaScript or CSS.
+     *
+     * @param showCalendar flag indicating whether the Calendar popup is
+     * displayed or not
+     */
+    public void setShowCalendar(boolean showCalendar) {
+        this.showCalendar = showCalendar;
+    }
+
+    /**
+     * Return the Calendar CSS style.
+     * <p/>
+     * Available styles include: <tt>[blue, default, plain, red, silver]</tt>.
+     *
+     * @return the Calendar CSS style
+     */
+    public String getStyle() {
+        return style;
+    }
+
+    /**
+     * Set the Calendar CSS style.
+     *
+     * @param style the Calendar CSS style
+     */
+    public void setStyle(String style) {
+        if (style == null) {
+            throw new IllegalArgumentException("Null style parameter");
+        }
+        this.style = style;
+    }
+
     // --------------------------------------------------------- Public Methods
 
     /**
@@ -472,21 +691,289 @@
      * @param buffer the specified buffer to render the control's output to
      */
     public void render(HtmlStringBuffer buffer) {
+        String help = getHelp();
+        // Nullify help to ensure it is not rendered by super impl.
+        if (help != null) {
+            setHelp(null);
+        }
+
         // Set default title
         if (getTitle() == null) {
             setTitle(getMessage("date-title", formatPattern));
         }
+
         super.render(buffer);
+
+        if (isShowCalendar()) {
+            renderCalendarButton(buffer);
+        }
+
+
+        if (help != null) {
+            buffer.append(help);
+        }
     }
 
     // ------------------------------------------------------ Protected Methods
 
     /**
+     * Render the calendar button HTML representation to the buffer.
+     *
+     * @param buffer the buffer to render the calendar button HTML
+     * representation to
+     */
+    protected void renderCalendarButton(HtmlStringBuffer buffer) {
+
+        if (!isReadonly() && !isDisabled()) {
+            Context context = getContext();
+            buffer.append("<img align=\"top\" ");
+            buffer.append("style=\"cursor:hand\" src=\"");
+            buffer.append(context.getRequest().getContextPath());
+            buffer.append("/click/calendar/calendar");
+            buffer.append(ClickUtils.getResourceVersionIndicator(context));
+            buffer.append(".gif\"");
+            String id = getId();
+            if (id != null) {
+                buffer.append(" id=\"");
+                buffer.append(getId());
+                buffer.append("-button\" ");
+            }
+
+            String calendarTitle = getMessage("calendar-image-title");
+            buffer.appendAttribute("alt", calendarTitle);
+            buffer.appendAttribute("title", calendarTitle);
+            buffer.elementEnd();
+        }
+    }
+
+    /**
+     * Add the calendar options as a script to the list of head elements.
+     * <p/>
+     * The default option script will render as (depending on the values off
+     * course):
+     *
+     * <pre class="prettyprint">
+     * document.observe('dom:loaded', function(){
+     *   Event.observe('my-calendar-button', 'click', function(){
+     *     Date.first_day_of_week=0;
+     *     calendar = new CalendarDateSelect($('my-calendar'), {
+     *       minute_interval: 1,
+     *       popup_by: 'my-calendar-button',
+     *       embedded: false,
+     *       time: 'mixed',
+     *       formatValue: 'dd MMM yyyy',
+     *       year_range: [1930,2050]});
+     *     });
+     * }); </pre>
+     *
+     * You can override this method to set your own options using a
+     * {@link org.apache.click.element.JsScript}.
+     *
+     * @param headElements the list of head elements to include for this control
+     */
+    protected void addCalendarOptions(List headElements) {
+        String fieldId = getId();
+        String imgId = fieldId + "-button";
+
+        JsScript script = new JsScript();
+        script.setId(fieldId + "_calendar_date_select");
+
+        // Note the Calendar options script is recreated and checked if it
+        // is contained in the headElement. This caters for when the field is
+        // used in a fly-weight pattern such as FormTable.
+        if (!headElements.contains(script)) {
+
+            // Script must be executed as soon as browser dom is ready
+            script.setExecuteOnDomReady(true);
+
+            HtmlStringBuffer buffer = new HtmlStringBuffer(150);
+            buffer.append("  Event.observe('").append(imgId).append(
+                "', 'click', function(){");
+            buffer.append("  Date.first_day_of_week=").append(getFirstDayOfWeek() - 1);
+            buffer.append(";    calendar = new CalendarDateSelect($('").append(
+                fieldId).append("'), {");
+
+            buffer.append("minute_interval: 1, popup_by: '").append(imgId).append(
+                "'");
+            buffer.append(", embedded: false");
+            buffer.append(", time: ").append(isShowTime() ? "'mixed'" : "false");
+            buffer.append(", formatValue: '").append(getCalendarPattern()).append(
+                "'");
+            buffer.append(", year_range: [1930,2050]});");
+
+            buffer.append("  });");
+            script.setContent(buffer);
+            headElements.add(script);
+        }
+    }
+
+    /**
+     * Return the first day of the week. For example e.g., Sunday in US,
+     * Monday in France and Australia.
+     *
+     * @return the first day of the week
+     */
+    protected int getFirstDayOfWeek() {
+        Locale locale = getLocale();
+
+        Calendar calendar = Calendar.getInstance(getLocale());
+
+        int dayOfWeek = calendar.getFirstDayOfWeek();
+
+        if ("AU".equals(locale.getCountry())) {
+            dayOfWeek += 1;
+        }
+
+        return dayOfWeek;
+    }
+
+    /**
      * Returns the <tt>Locale</tt> that should be used in this control.
      *
      * @return the locale that should be used in this control
      */
     protected Locale getLocale() {
-        return getContext().getLocale();
+        Locale locale = null;
+
+        locale = getContext().getLocale();
+        String lang = locale.getLanguage();
+        if (Arrays.binarySearch(SUPPORTTED_LANGUAGES, lang) >= 0) {
+            return locale;
+        }
+
+        locale = Locale.getDefault();
+        lang = locale.getLanguage();
+        if (Arrays.binarySearch(SUPPORTTED_LANGUAGES, lang) >= 0) {
+            return locale;
+        }
+
+        return Locale.ENGLISH;
+    }
+
+    /**
+     * Return the JavaScript Calendar pattern for the given Java DateFormat
+     * pattern.
+     *
+     * @param pattern the Java DateFormat pattern
+     * @return JavaScript Calendar pattern
+     */
+    protected String parseDateFormatPattern(String pattern) {
+        HtmlStringBuffer jsPattern = new HtmlStringBuffer(20);
+        int tokenStart = -1;
+        int tokenEnd = -1;
+        boolean debug = false;
+
+        for (int i = 0; i < pattern.length(); i++) {
+            char aChar = pattern.charAt(i);
+            if (debug) {
+                System.err.print("[" + i + "," + tokenStart + "," + tokenEnd
+                                 + "]=" + aChar);
+            }
+
+            // If character is in SimpleDateFormat pattern character set
+            if ("GyMwWDdFEaHkKhmsSzZ".indexOf(aChar) == - 1) {
+                if (debug) {
+                    System.err.println(" N");
+                }
+                if (tokenStart > - 1) {
+                    tokenEnd = i;
+                }
+            } else {
+                if (debug) {
+                    System.err.println(" Y");
+                }
+                if (tokenStart == - 1) {
+                    tokenStart = i;
+                }
+            }
+
+            if (tokenStart > -1) {
+
+                if (tokenEnd == -1 && i == pattern.length() - 1) {
+                    tokenEnd = pattern.length();
+                }
+
+                if (tokenEnd > -1) {
+                    String token = pattern.substring(tokenStart, tokenEnd);
+
+                    if ("yyyy".equals(token)) {
+                        jsPattern.append("yyyy");
+                    } else if ("yy".equals(token)) {
+                        jsPattern.append("yy");
+                    } else if ("y".equals(token)) {
+                        jsPattern.append("y");
+                    } else if ("MMMM".equals(token)) {
+                        jsPattern.append("MMM");
+                    } else if ("MMM".equals(token)) {
+                        jsPattern.append("NNN");
+                    } else if ("MM".equals(token)) {
+                        jsPattern.append("MM");
+                    } else if ("M".equals(token)) {
+                        jsPattern.append("M");
+                    } else if ("dd".equals(token)) {
+                        jsPattern.append("dd");
+                    } else if ("d".equals(token)) {
+                        jsPattern.append("d");
+                    } else if ("EEEE".equals(token)) {
+                        jsPattern.append("EE");
+                    } else if ("EEE".equals(token)) {
+                        jsPattern.append("E");
+                    } else if ("EE".equals(token)) {
+                        jsPattern.append("E");
+                    } else if ("E".equals(token)) {
+                        jsPattern.append("E");
+                    } else if ("aaa".equals(token)) {
+                        jsPattern.append("a");
+                    } else if ("aa".equals(token)) {
+                        jsPattern.append("a");
+                    } else if ("a".equals(token)) {
+                        jsPattern.append("a");
+                    } else if ("HH".equals(token)) {
+                        jsPattern.append("HH");
+                        setShowTime(true);
+                    } else if ("H".equals(token)) {
+                        jsPattern.append("H");
+                        setShowTime(true);
+                    } else if ("hh".equals(token)) {
+                        jsPattern.append("hh");
+                        setShowTime(true);
+                    } else if ("h".equals(token)) {
+                        jsPattern.append("h");
+                        setShowTime(true);
+                    } else if ("mm".equals(token)) {
+                        jsPattern.append("mm");
+                        setShowTime(true);
+                    } else if ("m".equals(token)) {
+                        jsPattern.append("m");
+                        setShowTime(true);
+                    } else if ("ss".equals(token)) {
+                        jsPattern.append("ss");
+                        setShowTime(true);
+                    } else if ("s".equals(token)) {
+                        jsPattern.append("s");
+                        setShowTime(true);
+                    } else {
+                        if (debug) {
+                            System.err.println("Not mapped:" + token);
+                        }
+                    }
+
+                    if (debug) {
+                        System.err.println("token[" + tokenStart + ","
+                                           + tokenEnd + "]='" + token + "'");
+                    }
+                    tokenStart = -1;
+                    tokenEnd = -1;
+                }
+            }
+
+            if (tokenStart == -1 && tokenEnd == -1) {
+                if ("GyMwWDdFEaHkKhmsSzZ".indexOf(aChar) == -1) {
+                    jsPattern.append(aChar);
+                }
+            }
+        }
+
+        return jsPattern.toString();
     }
 }

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.properties
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.properties?rev=776472&r1=776471&r2=776472&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.properties
(original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/control/DateField.properties
Tue May 19 21:28:00 2009
@@ -16,4 +16,5 @@
 # under the License.
 
 date-format-error={0} is invalid. Date format is {1}
-date-title=Date format: {0}
\ No newline at end of file
+date-title=Date format: {0}
+calendar-image-title=Calendar
\ No newline at end of file

Modified: incubator/click/trunk/click/extras/test/org/apache/click/extras/control/DateFieldTest.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/test/org/apache/click/extras/control/DateFieldTest.java?rev=776472&r1=776471&r2=776472&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/test/org/apache/click/extras/control/DateFieldTest.java
(original)
+++ incubator/click/trunk/click/extras/test/org/apache/click/extras/control/DateFieldTest.java
Tue May 19 21:28:00 2009
@@ -91,4 +91,40 @@
         
         assertEquals(requestParam, dateField.getValue());
     }
+
+    /**
+     * Test Calendar format pattern.
+     *
+     * @throws java.lang.Exception
+     */
+    public void testFormatPattern() {
+        DateField calendarField = new DateField("Delivery date");
+        assertEquals("dd MMM yyyy", calendarField.getFormatPattern());
+        assertEquals("dd NNN yyyy", calendarField.getCalendarPattern());
+
+        calendarField = new DateField("Delivery date");
+        calendarField.setFormatPattern(" dd MMM yyyy ");
+        assertEquals(" dd MMM yyyy ", calendarField.getFormatPattern());
+        assertEquals(" dd NNN yyyy ", calendarField.getCalendarPattern());
+
+        calendarField = new DateField("Delivery date");
+        calendarField.setFormatPattern("dd/MMM/yyyy");
+        assertEquals("dd/MMM/yyyy", calendarField.getFormatPattern());
+        assertEquals("dd/NNN/yyyy", calendarField.getCalendarPattern());
+
+        calendarField = new DateField("Delivery date");
+        calendarField.setFormatPattern("dd.MMM.yyyy");
+        assertEquals("dd.MMM.yyyy", calendarField.getFormatPattern());
+        assertEquals("dd.NNN.yyyy", calendarField.getCalendarPattern());
+
+        calendarField = new DateField("Delivery date");
+        calendarField.setFormatPattern("dd.MM.yy");
+        assertEquals("dd.MM.yy", calendarField.getFormatPattern());
+        assertEquals("dd.MM.yy", calendarField.getCalendarPattern());
+
+        calendarField = new DateField("Delivery date");
+        calendarField.setFormatPattern("d/M/yy");
+        assertEquals("d/M/yy", calendarField.getFormatPattern());
+        assertEquals("d/M/yy", calendarField.getCalendarPattern());
+    }
 }



Mime
View raw message