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);
}
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);
}
Aggregations