Skip to content
Snippets Groups Projects
Commit 21c93e2a authored by strentini's avatar strentini
Browse files

OO-154 : two new subclasses of DatePropertyHandler. (futureDate* and...

OO-154 : two new subclasses of DatePropertyHandler. (futureDate* and pastDate*).  replace DatePropertyHandler for userPopertyBirthday with PastDatePropertyHandler ( in userPropertiesHandlersContext.xml ). two new i18nkeys for error-message added (in en and de)
parent 005305c4
No related branches found
No related tags found
No related merge requests found
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.user.propertyhandlers;
import java.util.Date;
import java.util.Map;
import org.apache.commons.lang.time.DateUtils;
import org.olat.core.gui.components.form.flexible.FormItem;
import org.olat.core.gui.components.form.flexible.elements.DateChooser;
/**
* <h3>Description:</h3> The FutureDatePropertyHandler offers the functionality
* of a date which lies in the future. (i.e. does not validate on dates that are
* in the past !)
* <p>
* Initial Date: 12.04.2012 <br>
*
* @author strentini, sergio.trentini@frentix.com, http://www.frentix.com
*/
public class FutureDatePropertyHandler extends DatePropertyHandler {
/**
* @see org.olat.user.propertyhandlers.UserPropertyHandler#isValid(org.olat.core.gui.components.form.flexible.FormItem,
* java.util.Map)
*/
public boolean isValid(FormItem formItem, Map formContext) {
boolean isValidDate = super.isValid(formItem, formContext);
if (!isValidDate)
return false;
if (isDateInTheFuture(((DateChooser) formItem).getDate())) {
return true;
} else {
formItem.setErrorKey("form.name.date.future.error", null);
return false;
}
}
/**
* checks whether the given date is in the future.
* if the two dates are on the same date, false is returned!
*
* @param dateToCheck
* @return true if the given date is in the future
*/
private static boolean isDateInTheFuture(Date dateToCheck) {
Date now = new Date();
return (!DateUtils.isSameDay(now, dateToCheck)) && dateToCheck.after(now);
}
}
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.user.propertyhandlers;
import java.util.Date;
import java.util.Map;
import org.apache.commons.lang.time.DateUtils;
import org.olat.core.gui.components.form.flexible.FormItem;
import org.olat.core.gui.components.form.flexible.elements.DateChooser;
/**
* <h3>Description:</h3> The PastDatePropertyHandler offers the functionality of
* a date which lies in the past. (i.e. does not validate on future dates!)
* <p>
* Initial Date: 12.04.2012 <br>
*
* @author strentini, sergio.trentini@frentix.com, http://www.frentix.com
*/
public class PastDatePropertyHandler extends DatePropertyHandler {
/**
* @see org.olat.user.propertyhandlers.UserPropertyHandler#isValid(org.olat.core.gui.components.form.flexible.FormItem,
* java.util.Map)
*/
public boolean isValid(FormItem formItem, Map formContext) {
boolean isValidDate = super.isValid(formItem, formContext);
if (!isValidDate)
return false;
// check for date in the past
if (isDateInThePast(((DateChooser) formItem).getDate())) {
return true;
} else {
formItem.setErrorKey("form.name.date.past.error", null);
return false;
}
}
/**
* checks whether the given date is in the past. if the two dates are on
* the same date, false is returned!
*
* @param dateToCheck
* @return true if the given date is in the past
*/
private static boolean isDateInThePast(Date dateToCheck) {
Date now = new Date();
return (!DateUtils.isSameDay(now, dateToCheck)) && dateToCheck.before(now);
}
}
......@@ -17,6 +17,8 @@ form.group.person=Person
form.name.birthDay=Geburtsdatum
form.name.birthDay.error=Bitte geben Sie ein g\u00FCltiges Datum an.
form.name.birthDay.error.empty=Das Feld "Geburtsdatum" darf nicht leer sein.
form.name.date.future.error=Das gewhlte Datum muss in der Zukunft liegen
form.name.date.past.error=Das gewhlte Datum muss in der Vergangenheit liegen
form.name.city=Stadt
form.name.city.error.empty=Das Feld "Stadt" darf nicht leer sein.
form.name.country=Land
......
......@@ -17,6 +17,8 @@ form.group.person=Person
form.name.birthDay=Date of birth
form.name.birthDay.error=Please provide a valid date.
form.name.birthDay.error.empty=The field "Date of birth" is mandatory.
form.name.date.future.error=The chosen Date must lie in the future
form.name.date.past.error=The chosen Date must lie in the past
form.name.city=City
form.name.city.error.empty=The field "City" is mandatory.
form.name.country=Country
......
......@@ -30,7 +30,7 @@
<property name="deletable" value="false" />
</bean>
<bean name="userPropertyBirthDay" class="org.olat.user.propertyhandlers.DatePropertyHandler">
<bean name="userPropertyBirthDay" class="org.olat.user.propertyhandlers.PastDatePropertyHandler">
<property name="name" value="birthDay" />
<property name="group" value="person" />
<property name="deletable" value="true" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment