Search in sources :

Example 1 with SponsorRecord

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);
}
Also used : SponsorRecord(org.komunumo.data.db.tables.records.SponsorRecord) Arrays(java.util.Arrays) CustomLabel(org.komunumo.ui.component.CustomLabel) TagField(org.komunumo.ui.component.TagField) ImageUploadField(org.komunumo.ui.component.ImageUploadField) SponsorLevel(org.komunumo.data.db.enums.SponsorLevel) Binder(com.vaadin.flow.data.binder.Binder) Set(java.util.Set) ComboBox(com.vaadin.flow.component.combobox.ComboBox) DatePicker(org.komunumo.ui.component.DatePicker) Collectors(java.util.stream.Collectors) EditDialog(org.komunumo.ui.component.EditDialog) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) Nullable(org.jetbrains.annotations.Nullable) DatabaseService(org.komunumo.data.service.DatabaseService) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor) NotNull(org.jetbrains.annotations.NotNull) Callback(org.komunumo.Callback) TextField(com.vaadin.flow.component.textfield.TextField) EAGER(com.vaadin.flow.data.value.ValueChangeMode.EAGER) CustomLabel(org.komunumo.ui.component.CustomLabel) ImageUploadField(org.komunumo.ui.component.ImageUploadField) ComboBox(com.vaadin.flow.component.combobox.ComboBox) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) SponsorRecord(org.komunumo.data.db.tables.records.SponsorRecord) TextField(com.vaadin.flow.component.textfield.TextField) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor) DatePicker(org.komunumo.ui.component.DatePicker) TagField(org.komunumo.ui.component.TagField)

Aggregations

ComboBox (com.vaadin.flow.component.combobox.ComboBox)1 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)1 RichTextEditor (com.vaadin.flow.component.richtexteditor.RichTextEditor)1 TextField (com.vaadin.flow.component.textfield.TextField)1 Binder (com.vaadin.flow.data.binder.Binder)1 StringLengthValidator (com.vaadin.flow.data.validator.StringLengthValidator)1 EAGER (com.vaadin.flow.data.value.ValueChangeMode.EAGER)1 Arrays (java.util.Arrays)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 Callback (org.komunumo.Callback)1 SponsorLevel (org.komunumo.data.db.enums.SponsorLevel)1 SponsorRecord (org.komunumo.data.db.tables.records.SponsorRecord)1 DatabaseService (org.komunumo.data.service.DatabaseService)1 CustomLabel (org.komunumo.ui.component.CustomLabel)1 DatePicker (org.komunumo.ui.component.DatePicker)1 EditDialog (org.komunumo.ui.component.EditDialog)1 ImageUploadField (org.komunumo.ui.component.ImageUploadField)1