This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch csp
in repository https://gitbox.apache.org/repos/asf/openmeetings.git


The following commit(s) were added to refs/heads/csp by this push:
     new 51743f5  [OPENMEETINGS-2165] minor date-picker tweaks
51743f5 is described below

commit 51743f5ce017d9095e3612069a4b136be153d0ee
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Thu Feb 6 15:06:26 2020 +0700

    [OPENMEETINGS-2165] minor date-picker tweaks
---
 .../web/common/AbstractOmDateTimePicker.java       | 73 ++++++++++++++++++++++
 .../openmeetings/web/common/AjaxOmDatePicker.java  | 52 +++++++++++++++
 .../openmeetings/web/common/GeneralUserForm.java   |  6 +-
 3 files changed, 129 insertions(+), 2 deletions(-)

diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/AbstractOmDateTimePicker.java
 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/AbstractOmDateTimePicker.java
new file mode 100644
index 0000000..aab215a
--- /dev/null
+++ 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/AbstractOmDateTimePicker.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.web.common;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import org.apache.openmeetings.web.app.WebSession;
+import org.apache.wicket.model.IModel;
+
+import 
de.agilecoders.wicket.extensions.markup.html.bootstrap.form.datetime.AbstractDateTimePickerWithIcon;
+import 
de.agilecoders.wicket.extensions.markup.html.bootstrap.form.datetime.DatetimePickerConfig;
+import 
de.agilecoders.wicket.extensions.markup.html.bootstrap.form.datetime.DatetimePickerIconConfig;
+import 
de.agilecoders.wicket.extensions.markup.html.bootstrap.icon.FontAwesome5IconType;
+
+public abstract class AbstractOmDateTimePicker<T> extends 
AbstractDateTimePickerWithIcon<T> {
+       private static final long serialVersionUID = 1L;
+       private static final String DEFAULT_DATE_FORMAT = "yyyy/MM/dd";
+       private static final String DEFAULT_DATE_TIME_FORMAT = 
DEFAULT_DATE_FORMAT + " HH:mm:ss";
+
+       public AbstractOmDateTimePicker(String id, IModel<T> model) {
+               this(id, model, getDateTimeFormat());
+       }
+
+       public AbstractOmDateTimePicker(String id, IModel<T> model, String 
format) {
+               super(id, model, new DatetimePickerConfig()
+                               
.useLocale(WebSession.get().getLocale().toLanguageTag())
+                               .withFormat(format)
+                               .with(new DatetimePickerIconConfig()
+                                               
.useDateIcon(FontAwesome5IconType.calendar_s)
+                                               
.useTimeIcon(FontAwesome5IconType.clock_s)
+                                               
.useUpIcon(FontAwesome5IconType.arrow_up_s)
+                                               
.useDownIcon(FontAwesome5IconType.arrow_down_s)
+                                               
.usePreviousIcon(FontAwesome5IconType.arrow_left_s)
+                                               
.useNextIcon(FontAwesome5IconType.arrow_right_s)
+                                               
.useTodayIcon(FontAwesome5IconType.calendar_check_s)
+                                               
.useClearIcon(FontAwesome5IconType.eraser_s)
+                                               
.useCloseIcon(FontAwesome5IconType.times_s))
+                               );
+       }
+
+       public static String getDateTimeFormat() {
+               DateFormat fmt = 
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, 
WebSession.get().getLocale());
+               if (fmt instanceof SimpleDateFormat) {
+                       return ((SimpleDateFormat)fmt).toPattern();
+               }
+               return DEFAULT_DATE_TIME_FORMAT;
+       }
+
+       public static String getDateFormat() {
+               DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT, 
WebSession.get().getLocale());
+               if (fmt instanceof SimpleDateFormat) {
+                       return ((SimpleDateFormat)fmt).toPattern();
+               }
+               return DEFAULT_DATE_FORMAT;
+       }
+}
diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/AjaxOmDatePicker.java
 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/AjaxOmDatePicker.java
new file mode 100644
index 0000000..82811cd
--- /dev/null
+++ 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/AjaxOmDatePicker.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.web.common;
+
+import java.time.LocalDate;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
+import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
+import 
org.apache.wicket.extensions.markup.html.form.datetime.LocalDateTextField;
+import org.apache.wicket.model.IModel;
+
+public class AjaxOmDatePicker extends AbstractOmDateTimePicker<LocalDate> {
+       private static final long serialVersionUID = 1L;
+
+       public AjaxOmDatePicker(String id, IModel<LocalDate> model) {
+               super(id, model, getDateFormat());
+       }
+
+       @Override
+       protected Component newInput(String wicketId, String dateFormat) {
+               return new LocalDateTextField(wicketId, getModel(), 
dateFormat).add(new OnChangeAjaxBehavior() {
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       protected void onUpdate(AjaxRequestTarget target) {
+                               onValueChanged(target);
+                       }
+               });
+       }
+
+       protected void onValueChanged(IPartialPageRequestHandler target) {
+               //no-op
+       }
+}
diff --git 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/GeneralUserForm.java
 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/GeneralUserForm.java
index 77c7322..fef002d 100644
--- 
a/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/GeneralUserForm.java
+++ 
b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/GeneralUserForm.java
@@ -100,7 +100,7 @@ public class GeneralUserForm extends Form<User> {
                add(new DropDownChoice<>("timeZoneId", AVAILABLE_TIMEZONES));
                add(new LanguageDropDown("languageId"));
                add(new TextField<String>("address.phone"));
-               add(new AjaxOmDatePicker("age", new 
PropertyModel<LocalDate>(this, "age")) {
+               final AjaxOmDatePicker bday = new AjaxOmDatePicker("age", new 
PropertyModel<LocalDate>(this, "age")) {
                        private static final long serialVersionUID = 1L;
 
                        @Override
@@ -108,7 +108,9 @@ public class GeneralUserForm extends Form<User> {
                                User u = GeneralUserForm.this.getModelObject();
                                u.setAge(CalendarHelper.getDate(age, 
u.getTimeZoneId()));
                        }
-               });
+               };
+               bday.getConfig().withMaxDate(LocalDate.now());
+               add(bday);
                add(new TextField<String>("address.street"));
                add(new TextField<String>("address.additionalname"));
                add(new TextField<String>("address.zip"));

Reply via email to