use of org.komunumo.data.db.tables.records.NewsRecord in project komunumo-server by komunumo.
the class NewsDialog method createForm.
@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<NewsRecord> binder) {
final var title = new TextField("Title");
final var subtitle = new TextField("Subtitle");
final var teaser = new RichTextEditor();
final var message = new RichTextEditor();
final var showFrom = new DateTimePicker("Show from");
final var showTo = new DateTimePicker("Show to");
title.setRequiredIndicatorVisible(true);
title.setValueChangeMode(EAGER);
subtitle.setValueChangeMode(EAGER);
formLayout.add(title, subtitle, new CustomLabel("Teaser"), teaser, new CustomLabel("Message"), message, showFrom, showTo);
binder.forField(title).withValidator(new StringLengthValidator("Please enter the title of the news (max. 255 chars)", 1, 255)).bind(NewsRecord::getTitle, NewsRecord::setTitle);
binder.forField(subtitle).withValidator(new StringLengthValidator("The subtitle is too long (max. 255 chars)", 0, 255)).bind(NewsRecord::getSubtitle, NewsRecord::setSubtitle);
binder.forField(teaser.asHtml()).withValidator(new StringLengthValidator("The teaser is too long (max. 1'000 chars)", 0, 1_000)).bind(NewsRecord::getTeaser, NewsRecord::setTeaser);
binder.forField(message.asHtml()).withValidator(new StringLengthValidator("The message is too long (max. 100'000 chars)", 0, 100_000)).bind(NewsRecord::getMessage, NewsRecord::setMessage);
binder.forField(showFrom).withValidator(value -> value == null || showTo.isEmpty() || value.isBefore(showTo.getValue()), "The show from date must be before the show to date").bind(NewsRecord::getShowFrom, NewsRecord::setShowFrom);
binder.forField(showTo).withValidator(value -> value == null || showFrom.isEmpty() || value.isAfter(showFrom.getValue()), "The show to date must be after the show from date").bind(NewsRecord::getShowTo, NewsRecord::setShowTo);
}
Aggregations