Commit 0f4fa63d authored by Arthur Bogaart's avatar Arthur Bogaart Committed by Jeroen Hoffman

CMS-11068 [back port to 11.2] Use YuiDateField or YuiDateTimeField

(cherry picked from commit 1ab35a67)
parent bf026c29
......@@ -17,19 +17,21 @@ package org.hippoecm.frontend.plugins.yui.datetime;
import java.util.Date;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.html.panel.GenericPanel;
import org.apache.wicket.model.IModel;
import org.hippoecm.frontend.plugin.IPluginContext;
import org.hippoecm.frontend.plugin.config.IPluginConfig;
import org.hippoecm.frontend.util.MappingException;
import org.hippoecm.frontend.util.PluginConfigMapper;
public class DateFieldWidget extends Panel {
public class DateFieldWidget extends GenericPanel<Date> {
public static final String CONFIG_HIDE_TIME = "time.hide";
public static final String CONFIG_SHOW_TODAY_BUTTON = "show.today.button";
private final IPluginConfig config;
public DateFieldWidget(String id, IModel<Date> model, IPluginContext context, IPluginConfig config) {
public DateFieldWidget(final String id, final IModel<Date> model, final IPluginContext context, final IPluginConfig config) {
super(id, model);
this.config = config;
}
......@@ -37,25 +39,34 @@ public class DateFieldWidget extends Panel {
@Override
protected void onInitialize() {
super.onInitialize();
final IModel<Date> model = getModel();
final YuiDatePickerSettings settings = getSettings();
final YuiDateTimeField dateTimeField = newYuiDateTimeField("widget", model, settings);
final boolean currentDateLinkVisible = config.getAsBoolean(CONFIG_SHOW_TODAY_BUTTON, true);
dateTimeField.setCurrentDateLinkVisible(currentDateLinkVisible);
add(dateTimeField);
}
private YuiDatePickerSettings getSettings() {
final YuiDatePickerSettings settings = new YuiDatePickerSettings();
settings.setLanguage(getLocale().getLanguage());
if (config.containsKey("datepicker")) {
try {
PluginConfigMapper.populate(settings, config.getPluginConfig("datepicker"));
} catch (MappingException e) {
} catch (final MappingException e) {
throw new RuntimeException(e);
}
}
final IModel<Date> model = (IModel<Date>) getDefaultModel();
final YuiDateTimeField dateTimeField = newYuiDateTimeField("widget", model, settings);
boolean todayLinkVisible = config.getAsBoolean("show.today.button", true);
dateTimeField.setTodayLinkVisible(todayLinkVisible);
add(dateTimeField);
return settings;
}
protected YuiDateTimeField newYuiDateTimeField(String id, final IModel<Date> model, final YuiDatePickerSettings settings) {
protected YuiDateTimeField newYuiDateTimeField(final String id, final IModel<Date> model, final YuiDatePickerSettings settings) {
final boolean hideTime = config.getAsBoolean(CONFIG_HIDE_TIME, false);
return new YuiDateTimeField(id, model, settings, hideTime);
return hideTime
? new YuiDateField(id, model, settings)
: new YuiDateTimeField(id, model, settings);
}
}
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