use of org.komunumo.data.db.tables.records.SponsorRecord in project komunumo-server by komunumo.
the class SponsorDialog method createForm.
@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<SponsorRecord> binder) {
final var name = new TextField("Name");
final var website = new TextField("Website");
final var level = new ComboBox<SponsorLevel>("Level");
final var logo = new ImageUploadField("Logo");
final var description = new RichTextEditor();
final var validFrom = new DatePicker("Valid from");
final var validTo = new DatePicker("Valid to");
final var domains = new TagField("Domains");
name.setRequiredIndicatorVisible(true);
name.setValueChangeMode(EAGER);
website.setValueChangeMode(EAGER);
level.setItems(SponsorLevel.values());
formLayout.add(name, website, level, logo, new CustomLabel("Description"), description, validFrom, validTo, domains);
binder.forField(name).withValidator(new StringLengthValidator("Please enter the name of the sponsor (max. 255 chars)", 1, 255)).bind(SponsorRecord::getName, SponsorRecord::setName);
binder.forField(website).withValidator(value -> value.isEmpty() || value.startsWith("https://"), "The website address must start with \"https://\"").withValidator(new StringLengthValidator("The website address is too long (max. 255 chars)", 0, 255)).bind(SponsorRecord::getWebsite, SponsorRecord::setWebsite);
binder.forField(level).bind(SponsorRecord::getLevel, SponsorRecord::setLevel);
binder.forField(logo).withValidator(value -> value.isEmpty() || value.startsWith("data:") || value.startsWith("https://"), "The logo must be uploaded or the logo address must be secure (HTTPS)").withValidator(new StringLengthValidator("The logo is too big (max. 100 KB)", 0, 100_000)).bind(SponsorRecord::getLogo, SponsorRecord::setLogo);
binder.forField(description.asHtml()).withValidator(new StringLengthValidator("The description is too long (max. 100'000 chars)", 0, 100_000)).bind(SponsorRecord::getDescription, SponsorRecord::setDescription);
binder.forField(validFrom).withValidator(value -> value == null || validTo.isEmpty() || value.isBefore(validTo.getValue()), "The valid from date must be before the valid to date").bind(SponsorRecord::getValidFrom, SponsorRecord::setValidFrom);
binder.forField(validTo).withValidator(value -> value == null || validFrom.isEmpty() || value.isAfter(validFrom.getValue()), "The valid to date must be after the valid from date").bind(SponsorRecord::getValidTo, SponsorRecord::setValidTo);
binder.forField(domains).bind(this::getDomains, this::setDomains);
}
Aggregations