use of com.liferay.faces.alloy.component.inputtime.InputTime in project liferay-faces-alloy by liferay.
the class InputTimeRenderer method getAlloyClassName.
@Override
public String getAlloyClassName(FacesContext facesContext, UIComponent uiComponent) {
String alloyClassName = super.getAlloyClassName(facesContext, uiComponent);
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
InputTime inputTime = (InputTime) uiComponent;
if (isNative(browserSniffer, inputTime)) {
alloyClassName = alloyClassName.concat("Native");
}
return alloyClassName;
}
use of com.liferay.faces.alloy.component.inputtime.InputTime in project liferay-faces-alloy by liferay.
the class InputTimeRenderer method getModules.
@Override
public String[] getModules(FacesContext facesContext, UIComponent uiComponent) {
String[] modules = getModules(MODULES[0], facesContext, uiComponent);
InputTime inputTime = (InputTime) uiComponent;
String filterType = inputTime.getFilterType();
if ((filterType != null) && (filterType.length() > 0)) {
modules = StringHelper.append(modules, "autocomplete-filters");
}
String highlighterType = inputTime.getHighlighterType();
if ((highlighterType != null) && (highlighterType.length() > 0)) {
modules = StringHelper.append(modules, "autocomplete-highlighters");
}
return modules;
}
use of com.liferay.faces.alloy.component.inputtime.InputTime in project liferay-faces-alloy by liferay.
the class InputTimeRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
InputTime inputTime = (InputTime) uiComponent;
String clientVarName = getClientVarName(facesContext, inputTime);
String clientKey = inputTime.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
ResponseWriter responseWriter = facesContext.getResponseWriter();
BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
if (isNative(browserSniffer, inputTime)) {
JavaScriptFragment liferayComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
String clientId = uiComponent.getClientId(facesContext);
String inputClientId = clientId.concat(INPUT_SUFFIX);
// Get the max and min times in the HTML5 format which does not include seconds.
int defaultHTML5PatternLength = InputTime.DEFAULT_HTML5_TIME_PATTERN.length();
String maxTime = inputTime.getMaxTime().substring(0, defaultHTML5PatternLength);
String minTime = inputTime.getMinTime().substring(0, defaultHTML5PatternLength);
encodeFunctionCall(responseWriter, "LFAI.initDateTimePickerMobile", liferayComponent, inputClientId, maxTime, minTime);
} else {
encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
// Replace the default TimePicker._setValues() method with setValues() (defined in alloy.js) which simply
// passes values through to the autocomplete without processing them.
responseWriter.write(clientVarName);
responseWriter.write("._setValues=LFAI.timePickerSetValues;");
// Set the values of the timePicker.
responseWriter.write(clientVarName);
responseWriter.write(".set('values',[");
String minTimeStamp = inputTime.getMinTime();
String maxTimeStamp = inputTime.getMaxTime();
long minTime;
long maxTime;
try {
minTime = getMillisFromTimeStamp(minTimeStamp);
maxTime = getMillisFromTimeStamp(maxTimeStamp);
} catch (ParseException e) {
throw new IOException(e);
}
if (minTime > maxTime) {
throw new IOException("minTime must not be later than maxTime.");
}
String timePattern = inputTime.getPattern();
Object objectLocale = inputTime.getLocale();
Locale locale = inputTime.getObjectAsLocale(objectLocale);
TimeZone timeZone = TimeZone.getTimeZone("Greenwich");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timePattern, locale);
simpleDateFormat.setTimeZone(timeZone);
Integer millisecondStep = inputTime.getStep() * 1000;
boolean firstTimeStamp = true;
if (millisecondStep < 1) {
throw new IOException("step cannot be less than 1.");
}
// step, and printing each resulting value.
for (long milliseconds = minTime; milliseconds <= maxTime; milliseconds = milliseconds + millisecondStep) {
if (!firstTimeStamp) {
responseWriter.write(",");
} else {
firstTimeStamp = false;
}
Date time = new Date(milliseconds);
String dateString = simpleDateFormat.format(time);
String escapedDateString = RendererUtil.escapeJavaScript(dateString);
responseWriter.write("'");
responseWriter.write(escapedDateString);
responseWriter.write("'");
}
responseWriter.write("]);");
}
}
use of com.liferay.faces.alloy.component.inputtime.InputTime in project liferay-faces-alloy by liferay.
the class InputTimeRendererBase method encodeAlloyAttributes.
@Override
public void encodeAlloyAttributes(FacesContext facesContext, ResponseWriter responseWriter, UIComponent uiComponent) throws IOException {
InputTime inputTime = (InputTime) uiComponent;
boolean first = true;
String pattern = inputTime.getPattern();
if (pattern != null) {
encodeMask(responseWriter, inputTime, pattern, first);
first = false;
}
encodeHiddenAttributes(facesContext, responseWriter, inputTime, first);
}
use of com.liferay.faces.alloy.component.inputtime.InputTime in project liferay-faces-alloy by liferay.
the class WorkHoursValidator method validate.
@Override
public void validate(FacesContext facesContext, UIComponent uiComponent, Object object) throws ValidatorException {
if (object != null) {
Date date;
InputTime inputTime = (InputTime) uiComponent;
String timeZoneString = inputTime.getTimeZone();
TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
if (object instanceof Date) {
date = (Date) object;
} else {
String dateString = object.toString();
String datePattern = inputTime.getPattern();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
simpleDateFormat.setTimeZone(timeZone);
try {
date = simpleDateFormat.parse(dateString);
} catch (ParseException e) {
String message = AlloyValidatorHelper.getMessage(facesContext, inputTime, "invalid-selection");
FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message);
throw new ValidatorException(facesMessage, e);
}
}
Calendar calendar = new GregorianCalendar(timeZone);
calendar.setTime(date);
final int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minOfHour = calendar.get(Calendar.MINUTE);
if ((hourOfDay == 12) || ((hourOfDay == 13) && (minOfHour == 0))) {
String message = AlloyValidatorHelper.getMessage(facesContext, inputTime, "lunchtime-is-not-valid");
FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_WARN, message, message);
throw new ValidatorException(facesMessage);
}
}
}
Aggregations