CalendarRenderer extends AbstractHtmlTagRenderer<HtmlCalendar> { String createJQueryPluginCall(HtmlCalendar calendar) { final StringBuilder jQueryPluginCall = new StringBuilder(); jQueryPluginCall.append("find('.input-group')"); jQueryPluginCall.append(".attr('id', elementId)"); jQueryPluginCall.append(".attr('data-target-input', 'nearest')"); jQueryPluginCall.append(".find('input')"); jQueryPluginCall.append(".attr('data-target', '#' + elementId)"); jQueryPluginCall.append(".addClass('datetimepicker-input')"); jQueryPluginCall.append(".siblings('.input-group-append')"); jQueryPluginCall.append(".attr('data-target', '#' + elementId)"); jQueryPluginCall.append(".parent()"); jQueryPluginCall.append(".datetimepicker({"); if (StringUtils.isNotEmpty(calendar.getFormat())) { jQueryPluginCall.append("format: '").append(calendar.getFormat()).append("',"); } else { if (calendar.isPickDate() && !calendar.isPickTime()) { jQueryPluginCall.append("format: 'L',"); } else if (!calendar.isPickDate() && calendar.isPickTime()) { jQueryPluginCall.append("format: 'LT',"); } } if (StringUtils.isNotEmpty(calendar.getLocale())) { jQueryPluginCall.append("locale: '" + calendar.getLocale() + "',"); } if (calendar.getViewMode() != null) { jQueryPluginCall.append("viewMode: '" + calendar.getViewMode().getValue() + "',"); } if (calendar.isSideBySide()) { jQueryPluginCall.append("sideBySide: true,"); } final String calendarDate = StringUtils.getNotNullValue(calendar.getIconDate(), "glyphicon glyphicon-calendar"); final String calendarTime = StringUtils.getNotNullValue(calendar.getIconTime(), "glyphicon glyphicon-time"); final String calendarUp = StringUtils.getNotNullValue(calendar.getIconUp(), "glyphicon glyphicon-chevron-up"); final String calendarDown = StringUtils.getNotNullValue(calendar.getIconDown(), "glyphicon glyphicon-chevron-down"); jQueryPluginCall.append("icons: {"); jQueryPluginCall.append("time: '" + calendarTime + "',"); jQueryPluginCall.append("date: '" + calendarDate + "',"); jQueryPluginCall.append("up: '" + calendarUp + "',"); jQueryPluginCall.append("down: '" + calendarDown + "'"); jQueryPluginCall.append("}"); jQueryPluginCall.append("})"); return jQueryPluginCall.toString(); }  @Override void encodeEnd(final FacesContext context, final UIComponent component);  }
@Test void createJQueryPluginCall() { final CalendarRenderer calendarRenderer = new CalendarRenderer(); HtmlCalendar htmlCalendar = new HtmlCalendar(); assertThat(calendarRenderer.createJQueryPluginCall(htmlCalendar)).isEqualTo(PREPEND + "datetimepicker({icons: {time: 'glyphicon glyphicon-time',date: 'glyphicon glyphicon-calendar',up: 'glyphicon glyphicon-chevron-up',down: 'glyphicon glyphicon-chevron-down'}})"); htmlCalendar.setSideBySide(true); assertThat(calendarRenderer.createJQueryPluginCall(htmlCalendar)).isEqualTo(PREPEND + "datetimepicker({sideBySide: true,icons: {time: 'glyphicon glyphicon-time',date: 'glyphicon glyphicon-calendar',up: 'glyphicon glyphicon-chevron-up',down: 'glyphicon glyphicon-chevron-down'}})"); htmlCalendar.setSideBySide(false); htmlCalendar.setIconTime("fa fa-clock-o"); htmlCalendar.setIconDate("fa fa-calendar"); htmlCalendar.setIconUp("fa fa-arrow-up"); htmlCalendar.setIconDown("fa fa-arrow-down"); assertThat(calendarRenderer.createJQueryPluginCall(htmlCalendar)) .isEqualTo(PREPEND + "datetimepicker({icons: {time: 'fa fa-clock-o',date: 'fa fa-calendar',up: 'fa fa-arrow-up',down: 'fa fa-arrow-down'}})"); htmlCalendar.setLocale("ru"); assertThat(calendarRenderer.createJQueryPluginCall(htmlCalendar)) .isEqualTo(PREPEND + "datetimepicker({locale: 'ru',icons: {time: 'fa fa-clock-o',date: 'fa fa-calendar',up: 'fa fa-arrow-up',down: 'fa fa-arrow-down'}})"); htmlCalendar.setLocale(""); htmlCalendar.setFormat("DD-MM-YYYY"); assertThat(calendarRenderer.createJQueryPluginCall(htmlCalendar)).isEqualTo( PREPEND + "datetimepicker({format: 'DD-MM-YYYY',icons: {time: 'fa fa-clock-o',date: 'fa fa-calendar',up: 'fa fa-arrow-up',down: 'fa fa-arrow-down'}})"); htmlCalendar.setPickDate(true); htmlCalendar.setPickTime(true); assertThat(calendarRenderer.createJQueryPluginCall(htmlCalendar)).isEqualTo( PREPEND + "datetimepicker({format: 'DD-MM-YYYY',icons: {time: 'fa fa-clock-o',date: 'fa fa-calendar',up: 'fa fa-arrow-up',down: 'fa fa-arrow-down'}})"); htmlCalendar.setFormat(null); assertThat(calendarRenderer.createJQueryPluginCall(htmlCalendar)) .isEqualTo(PREPEND + "datetimepicker({icons: {time: 'fa fa-clock-o',date: 'fa fa-calendar',up: 'fa fa-arrow-up',down: 'fa fa-arrow-down'}})"); htmlCalendar.setPickTime(false); assertThat(calendarRenderer.createJQueryPluginCall(htmlCalendar)) .isEqualTo(PREPEND + "datetimepicker({format: 'L',icons: {time: 'fa fa-clock-o',date: 'fa fa-calendar',up: 'fa fa-arrow-up',down: 'fa fa-arrow-down'}})"); htmlCalendar.setPickDate(false); htmlCalendar.setPickTime(true); assertThat(calendarRenderer.createJQueryPluginCall(htmlCalendar)) .isEqualTo(PREPEND + "datetimepicker({format: 'LT',icons: {time: 'fa fa-clock-o',date: 'fa fa-calendar',up: 'fa fa-arrow-up',down: 'fa fa-arrow-down'}})"); htmlCalendar.setViewMode(HtmlCalendarViewMode.YEARS); assertThat(calendarRenderer.createJQueryPluginCall(htmlCalendar)).isEqualTo(PREPEND + "datetimepicker({format: 'LT',viewMode: 'years',icons: {time: 'fa fa-clock-o',date: 'fa fa-calendar',up: 'fa fa-arrow-up',down: 'fa fa-arrow-down'}})"); }