Commit 02c13808 authored by Marijan Milicevic's avatar Marijan Milicevic Committed by Jeroen Hoffman

CMS-11068 [back port to 11.2] Error in calendardate field in hippo

- reuse existing date functionality for calendar field type
- deprecate GMT files

(cherry picked from commit 62220d5d)

# Conflicts:
#	api/src/main/java/org/hippoecm/frontend/plugins/yui/datetime/YuiDateTimeField.java
parent 99f58813
/*
* Copyright 2016 Hippo B.V. (http://www.onehippo.com)
* Copyright 2016-2018 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -28,6 +28,7 @@ import org.apache.wicket.model.IModel;
/**
* Label component to render a date (year-month-day) of the {@link Date} object in GMT timezone.
*/
@Deprecated
public class GMTDateLabel extends ZonedDateLabel {
private static class GMTZonedDateTimeModel extends AbstractReadOnlyModel<ZonedDateTime> {
......
......@@ -55,7 +55,7 @@ public class DateFieldWidget extends Panel {
}
protected YuiDateTimeField newYuiDateTimeField(String id, final IModel<Date> model, final YuiDatePickerSettings settings) {
final boolean isHideTime = config.getAsBoolean(CONFIG_HIDE_TIME, false);
return isHideTime ? new YuiGMTDateField(id, model, settings) : new YuiDateTimeField(id, model, settings);
final boolean hideTime = config.getAsBoolean(CONFIG_HIDE_TIME, false);
return new YuiDateTimeField(id, model, settings, hideTime);
}
}
/*
* Copyright 2008-2017 Hippo B.V. (http://www.onehippo.com)
* Copyright 2008-2018 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -15,10 +15,6 @@
*/
package org.hippoecm.frontend.plugins.yui.datetime;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
......@@ -41,10 +37,14 @@ import org.joda.time.MutableDateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/**
* Semi-fork of YUI DateTimeField from Wicket extensions. Replaces Wicket extensions YUI behaviors with a {@link YuiDatePicker}
* so it fit's in the Hippo ECM YUI framework.
*
* <p>
* DatePicker can be configured using a frontend:pluginconfig node with name <code>datepicker</code>.
*
* @see YuiDatePickerSettings for all configuration options
......@@ -58,12 +58,18 @@ public class YuiDateTimeField extends DateTimeField {
private final YuiDatePickerSettings settings;
private boolean todayLinkVisible = true;
private boolean hideTime;
public YuiDateTimeField(String id, IModel<Date> model) {
public YuiDateTimeField(final String id, final IModel<Date> model) {
this(id, model, null);
}
public YuiDateTimeField(String id, IModel<Date> model, YuiDatePickerSettings settings) {
public YuiDateTimeField(final String id, final IModel<Date> model, YuiDatePickerSettings settings, boolean hideTime) {
this(id, model, settings);
this.hideTime = hideTime;
}
public YuiDateTimeField(final String id, final IModel<Date> model, YuiDatePickerSettings settings) {
super(id, model);
if (settings == null) {
......@@ -95,10 +101,10 @@ public class YuiDateTimeField extends DateTimeField {
minutesField.setLabel(Model.of(getString(MINUTES_LABEL)));
//add "Now" link
AjaxLink<Date> today;
final AjaxLink<Date> today;
add(today = new AjaxLink<Date>("today") {
@Override
public void onClick(AjaxRequestTarget target) {
public void onClick(final AjaxRequestTarget target) {
YuiDateTimeField.this.setDefaultModelObject(new Date());
dateField.clearInput();
hoursField.clearInput();
......@@ -117,22 +123,29 @@ public class YuiDateTimeField extends DateTimeField {
today.add(HippoIcon.fromSprite("current-date-icon", Icon.RESTORE));
//Add change behavior to super fields
for (String name : new String[] { "date", "hours", "minutes", "amOrPmChoice" }) {
get(name).add(new AjaxFormComponentUpdatingBehavior("onChange") {
for (final String name : new String[]{"date", "hours", "minutes", "amOrPmChoice"}) {
get(name).add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
protected void onUpdate(final AjaxRequestTarget target) {
updateDateTime();
send(YuiDateTimeField.this, Broadcast.BUBBLE, new UpdateFeedbackInfo(target));
}
@Override
protected void onError(AjaxRequestTarget target, RuntimeException e){
protected void onError(final AjaxRequestTarget target, final RuntimeException e) {
super.onError(target, e);
send(YuiDateTimeField.this, Broadcast.BUBBLE, new UpdateFeedbackInfo(target));
}
});
}
if (hideTime) {
// hiding the "hours" component hides the entire "hours" wicket:enclosure
get(HOURS).setVisibilityAllowed(false);
// hide the minutes field to prevent wicket.ajax javascript errors
get(MINUTES).setVisibilityAllowed(false);
}
}
private int calculateDateLength() {
......@@ -140,23 +153,26 @@ public class YuiDateTimeField extends DateTimeField {
}
private void updateDateTime() {
Date date = getDate();
final Date date = getDate();
if (date != null) {
MutableDateTime datetime = new MutableDateTime(date);
final MutableDateTime datetime = new MutableDateTime(date);
try {
TimeZone zone = getClientTimeZone();
final TimeZone zone = getClientTimeZone();
if (zone != null) {
datetime.setZone(DateTimeZone.forTimeZone(zone));
}
Integer hours = getHours();
if (hours != null) {
datetime.set(DateTimeFieldType.hourOfDay(), hours % 24);
Integer minutes = getMinutes();
datetime.setMinuteOfHour(minutes != null ? minutes : 0);
if (hideTime) {
datetime.set(DateTimeFieldType.hourOfDay(), 0);
datetime.setMinuteOfHour(0);
} else {
final Integer hours = getHours();
if (hours != null) {
datetime.set(DateTimeFieldType.hourOfDay(), hours % 24);
final Integer minutes = getMinutes();
datetime.setMinuteOfHour(minutes != null ? minutes : 0);
}
}
// the date will be in the server's timezone
setDate(datetime.toDate());
setModelObject(datetime.toDate());
......@@ -172,7 +188,7 @@ public class YuiDateTimeField extends DateTimeField {
return false;
}
public void setTodayLinkVisible(boolean todayLinkVisible) {
public void setTodayLinkVisible(final boolean todayLinkVisible) {
this.todayLinkVisible = todayLinkVisible;
}
......@@ -192,15 +208,15 @@ public class YuiDateTimeField extends DateTimeField {
}
@Override
protected DateTextField newDateTextField(String id, PropertyModel<Date> dateFieldModel) {
protected DateTextField newDateTextField(final String id, final PropertyModel<Date> dateFieldModel) {
return new DateTextField(id, dateFieldModel, new DateConverter(false) {
@Override
public String getDatePattern(Locale locale) {
public String getDatePattern(final Locale locale) {
return YuiDateTimeField.this.getDatePattern();
}
@Override
protected DateTimeFormatter getFormat(Locale locale) {
protected DateTimeFormatter getFormat(final Locale locale) {
return DateTimeFormat.forPattern(YuiDateTimeField.this.getDatePattern()).withLocale(getLocale());
}
});
......
/*
* Copyright 2016-2017 Hippo B.V. (http://www.onehippo.com)
* Copyright 2016-2018 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -23,6 +23,7 @@ import org.apache.wicket.model.IModel;
/**
* The component to represent only the date section of the {@link Date} object value in GMT timezone.
*/
@Deprecated
public class YuiGMTDateField extends YuiDateTimeField {
public YuiGMTDateField(String id, IModel<Date> model, YuiDatePickerSettings settings) {
......
/*
* Copyright 2008-2016 Hippo B.V. (http://www.onehippo.com)
* Copyright 2008-2018 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -65,7 +65,7 @@ public class DatePickerPlugin extends RenderPlugin<Date> {
private Label newLabel(final IModel<Date> valueModel) {
final boolean isHideTime = getPluginConfig().getAsBoolean(DateFieldWidget.CONFIG_HIDE_TIME, false);
return isHideTime ? new GMTDateLabel(VALUE, valueModel, FormatStyle.LONG) :
return isHideTime ? new DateTimeLabel(VALUE, valueModel, "MMMM, dd yyyy") :
new DateTimeLabel(VALUE, valueModel, FormatStyle.LONG, FormatStyle.SHORT);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment