Search in sources :

Example 1 with ImageUploadField

use of org.komunumo.ui.component.ImageUploadField in project komunumo-server by komunumo.

the class SpeakerDialog method createForm.

@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<SpeakerRecord> binder) {
    final var firstName = new TextField("First name");
    final var lastName = new TextField("Last name");
    final var company = new TextField("Company");
    final var bio = new RichTextEditor();
    final var photo = new ImageUploadField("Photo");
    final var email = new EmailField("Email");
    final var twitter = new TextField("Twitter");
    final var linkedIn = new TextField("LinkedIn");
    final var website = new TextField("Website");
    final var address = new TextField("Address");
    final var zipCode = new TextField("Zip code");
    final var city = new TextField("City");
    final var state = new TextField("State");
    final var country = new TextField("Country");
    firstName.setRequiredIndicatorVisible(true);
    firstName.setValueChangeMode(EAGER);
    lastName.setRequiredIndicatorVisible(true);
    lastName.setValueChangeMode(EAGER);
    photo.setMaxPreviewSize("150px", "150px");
    email.addValueChangeListener(changeEvent -> {
        final var newEmail = changeEvent.getValue();
        final var photoValue = photo.getValue();
        if (!newEmail.isBlank() && (photoValue.isBlank() || photoValue.startsWith(GRAVATAR_URL))) {
            photo.setValue(GravatarUtil.getGravatarAddress(newEmail, 150));
        } else if (newEmail.isBlank() && photoValue.startsWith(GRAVATAR_URL)) {
            photo.setValue("");
        }
    });
    formLayout.add(firstName, lastName, company, new CustomLabel("Bio"), bio, photo, email, twitter, linkedIn, website, address, zipCode, city, state, country);
    binder.forField(firstName).withValidator(new StringLengthValidator("Please enter the first name of the speaker (max. 255 chars)", 1, 255)).bind(SpeakerRecord::getFirstName, SpeakerRecord::setFirstName);
    binder.forField(lastName).withValidator(new StringLengthValidator("Please enter the last name of the speaker (max. 255 chars)", 1, 255)).bind(SpeakerRecord::getLastName, SpeakerRecord::setLastName);
    binder.forField(company).withValidator(new StringLengthValidator("The company name is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getCompany, SpeakerRecord::setCompany);
    binder.forField(bio.asHtml()).withValidator(new StringLengthValidator("The bio is too long (max. 100'000 chars)", 0, 100_000)).bind(SpeakerRecord::getBio, SpeakerRecord::setBio);
    binder.forField(photo).withValidator(value -> value.isEmpty() || value.startsWith("data:") || value.startsWith("https://"), "The photo must be uploaded or the photo address must be secure (HTTPS)").withValidator(new StringLengthValidator("The photo is too big (max. 250 KB)", 0, 250_000)).bind(SpeakerRecord::getPhoto, SpeakerRecord::setPhoto);
    binder.forField(email).withValidator(new EmailValidator("Please enter a correct email address or leave this field empty", true)).withValidator(new StringLengthValidator("The email address is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getEmail, SpeakerRecord::setEmail);
    binder.forField(twitter).withValidator(new StringLengthValidator("The twitter username is too long (max. 15 chars)", 0, 15)).bind(SpeakerRecord::getTwitter, SpeakerRecord::setTwitter);
    binder.forField(linkedIn).withValidator(value -> value.isEmpty() || value.startsWith("https://"), "The LinkedIn address must start with \"https://\"").withValidator(new StringLengthValidator("The LinkedIn address is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getLinkedin, SpeakerRecord::setLinkedin);
    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(SpeakerRecord::getWebsite, SpeakerRecord::setWebsite);
    binder.forField(address).withValidator(new StringLengthValidator("The address is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getAddress, SpeakerRecord::setAddress);
    binder.forField(zipCode).withValidator(new StringLengthValidator("The zip code is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getZipCode, SpeakerRecord::setZipCode);
    binder.forField(city).withValidator(new StringLengthValidator("The city is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getCity, SpeakerRecord::setCity);
    binder.forField(state).withValidator(new StringLengthValidator("The state is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getState, SpeakerRecord::setState);
    binder.forField(country).withValidator(new StringLengthValidator("The country is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getCountry, SpeakerRecord::setCountry);
}
Also used : CustomLabel(org.komunumo.ui.component.CustomLabel) EmailValidator(com.vaadin.flow.data.validator.EmailValidator) ImageUploadField(org.komunumo.ui.component.ImageUploadField) SpeakerRecord(org.komunumo.data.db.tables.records.SpeakerRecord) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) EmailField(com.vaadin.flow.component.textfield.EmailField) TextField(com.vaadin.flow.component.textfield.TextField) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor)

Example 2 with ImageUploadField

use of org.komunumo.ui.component.ImageUploadField 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

RichTextEditor (com.vaadin.flow.component.richtexteditor.RichTextEditor)2 TextField (com.vaadin.flow.component.textfield.TextField)2 StringLengthValidator (com.vaadin.flow.data.validator.StringLengthValidator)2 CustomLabel (org.komunumo.ui.component.CustomLabel)2 ImageUploadField (org.komunumo.ui.component.ImageUploadField)2 ComboBox (com.vaadin.flow.component.combobox.ComboBox)1 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)1 EmailField (com.vaadin.flow.component.textfield.EmailField)1 Binder (com.vaadin.flow.data.binder.Binder)1 EmailValidator (com.vaadin.flow.data.validator.EmailValidator)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 SpeakerRecord (org.komunumo.data.db.tables.records.SpeakerRecord)1 SponsorRecord (org.komunumo.data.db.tables.records.SponsorRecord)1