protected void encodeScript(FacesContext context, Calendar calendar, String value) throws IOException {
String clientId = calendar.getClientId(context);
Locale locale = calendar.calculateLocale(context);
String pattern = calendar.isTimeOnly() ? calendar.calculateTimeOnlyPattern() : calendar.calculatePattern();
String mask = calendar.getMask();
WidgetBuilder wb = getWidgetBuilder(context);
wb.initWithDomReady("Calendar", calendar.resolveWidgetVar(), clientId);
wb.attr("popup", calendar.isPopup())
.attr("locale", locale.toString())
.attr("dateFormat", CalendarUtils.convertPattern(pattern));
//default date
Object pagedate = calendar.getPagedate();
String defaultDate = null;
if(calendar.isConversionFailed()) {
defaultDate = CalendarUtils.getValueAsString(context, calendar, new Date());
}
else if(!isValueBlank(value)) {
defaultDate = value;
}
else if(pagedate != null) {
defaultDate = CalendarUtils.getValueAsString(context, calendar, pagedate);
}
wb.attr("defaultDate", defaultDate, null)
.attr("numberOfMonths", calendar.getPages(), 1)
.attr("minDate", CalendarUtils.getValueAsString(context, calendar, calendar.getMindate()), null)
.attr("maxDate", CalendarUtils.getValueAsString(context, calendar, calendar.getMaxdate()), null)
.attr("showButtonPanel", calendar.isShowButtonPanel(), false)
.attr("showWeek", calendar.isShowWeek(), false)
.attr("disabledWeekends", calendar.isDisabledWeekends(), false)
.attr("disabled", calendar.isDisabled(), false)
.attr("yearRange", calendar.getYearRange(), null);
if(calendar.isNavigator()) {
wb.attr("changeMonth", true).attr("changeYear", true);
}
if(calendar.getEffect() != null) {
wb.attr("showAnim", calendar.getEffect()).attr("duration", calendar.getEffectDuration());
}
String beforeShowDay = calendar.getBeforeShowDay();
if(beforeShowDay != null) {
wb.nativeAttr("preShowDay", beforeShowDay);
}
String showOn = calendar.getShowOn();
if(!showOn.equalsIgnoreCase("focus")) {
wb.attr("showOn", showOn);
}
if(calendar.isShowOtherMonths()) {
wb.attr("showOtherMonths", true).attr("selectOtherMonths", true);
}
if(calendar.hasTime()) {
wb.attr("timeOnly", calendar.isTimeOnly())
.attr("stepHour", calendar.getStepHour())
.attr("stepMinute", calendar.getStepMinute())
.attr("stepSecond", calendar.getStepSecond())
.attr("hourMin", calendar.getMinHour())
.attr("hourMax", calendar.getMaxHour())
.attr("minuteMin", calendar.getMinMinute())
.attr("minuteMax", calendar.getMaxMinute())
.attr("secondMin", calendar.getMinSecond())
.attr("secondMax", calendar.getMaxSecond())
.attr("controlType", calendar.getTimeControlType(), null);
}
if(mask != null && !mask.equals("false")) {
String maskTemplate = (mask.equals("true")) ? pattern.replaceAll("[a-zA-Z]", "9"): mask;
wb.attr("mask", maskTemplate);
}
encodeClientBehaviors(context, calendar);
wb.finish();
}