Search in sources :

Example 1 with CustomLabel

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

the class PageDialog method createForm.

@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<Page> binder) {
    final var parent = new Select<>(PageParent.values());
    final var pageUrl = new TextField("URL");
    final var title = new TextField("Title");
    final var content = new RichTextEditor();
    parent.setLabel("Parent");
    parent.setRequiredIndicatorVisible(true);
    parent.addValueChangeListener(changeEvent -> pageUrl.setPrefixComponent(new Span("%s/".formatted(URLUtil.createReadableUrl(changeEvent.getValue().getLiteral())))));
    pageUrl.setRequiredIndicatorVisible(true);
    pageUrl.setValueChangeMode(EAGER);
    title.setRequiredIndicatorVisible(true);
    title.setValueChangeMode(EAGER);
    formLayout.add(parent, pageUrl, title, new CustomLabel("Content"), content);
    binder.forField(parent).withValidator(Objects::nonNull, "Please select the parent navigation").bind(Page::getParent, Page::setParent);
    binder.forField(pageUrl).withValidator(new StringLengthValidator("Please enter the URL of the page (max. 255 chars)", 1, 255)).bind(Page::getPageUrl, Page::setPageUrl);
    binder.forField(title).withValidator(new StringLengthValidator("Please enter the title of the page (max. 255 chars)", 1, 255)).bind(Page::getTitle, Page::setTitle);
    binder.forField(content.asHtml()).withValidator(new StringLengthValidator("The content is too long (max. 8'000 chars)", 0, 8_000)).bind(Page::getContent, Page::setContent);
}
Also used : CustomLabel(org.komunumo.ui.component.CustomLabel) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) Select(com.vaadin.flow.component.select.Select) TextField(com.vaadin.flow.component.textfield.TextField) Page(org.komunumo.data.entity.Page) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor) Span(com.vaadin.flow.component.html.Span)

Example 2 with CustomLabel

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

the class MailTemplateDialog method createForm.

@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<MailTemplateRecord> binder) {
    final var id = new Select<>(mailTemplateIds.stream().map(MailTemplateId::name).toArray(String[]::new));
    id.setRequiredIndicatorVisible(true);
    id.setLabel("ID");
    formLayout.add(id);
    final var subject = new TextField("Subject");
    subject.setRequiredIndicatorVisible(true);
    subject.setValueChangeMode(EAGER);
    formLayout.add(subject);
    final var contentText = new TextArea();
    contentText.setRequiredIndicatorVisible(true);
    formLayout.add(new CustomLabel("Content as plain text"), contentText);
    final var contentHTML = new RichTextEditor();
    contentHTML.setRequiredIndicatorVisible(true);
    formLayout.add(new CustomLabel("Content as formatted HTML"), contentHTML);
    binder.forField(id).withValidator(Objects::nonNull, "Please select the ID").bind(MailTemplateRecord::getId, MailTemplateRecord::setId);
    binder.forField(subject).withValidator(new StringLengthValidator("Please enter the subject (max. 255 chars)", 1, 255)).bind(MailTemplateRecord::getSubject, MailTemplateRecord::setSubject);
    binder.forField(contentText).withValidator(new StringLengthValidator("Please enter the content as plain text (max. 8'000 chars)", 1, 8_000)).bind(MailTemplateRecord::getContentText, MailTemplateRecord::setContentText);
    binder.forField(contentHTML.asHtml()).withValidator(new StringLengthValidator("Please enter the content as formattet HTML (max. 8'000 chars)", 1, 8_000)).bind(MailTemplateRecord::getContentHtml, MailTemplateRecord::setContentHtml);
    afterOpen = () -> id.setReadOnly(id.getValue() != null);
}
Also used : CustomLabel(org.komunumo.ui.component.CustomLabel) MailTemplateId(org.komunumo.data.entity.MailTemplateId) TextArea(com.vaadin.flow.component.textfield.TextArea) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) Select(com.vaadin.flow.component.select.Select) TextField(com.vaadin.flow.component.textfield.TextField) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor) MailTemplateRecord(org.komunumo.data.db.tables.records.MailTemplateRecord)

Example 3 with CustomLabel

use of org.komunumo.ui.component.CustomLabel 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 4 with CustomLabel

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

the class EventDialog method createForm.

// just a lot of fields for the form
@SuppressWarnings("checkstyle:MethodLength")
@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<Event> binder) {
    final var type = new Select<>(EventType.values());
    final var title = new TextField("Title");
    final var subtitle = new TextField("Subtitle");
    final var speaker = new MultiselectComboBox<EventSpeakerEntity>("Speaker");
    final var organizer = new MultiselectComboBox<Member>("Organizer");
    final var description = new RichTextEditor();
    final var keyword = new MultiselectComboBox<KeywordEntity>("Keyword");
    final var agenda = new RichTextEditor();
    final var level = new Select<>(EventLevel.values());
    final var language = new Select<>(EventLanguage.values());
    final var room = new TextField("Room");
    final var travelInstructions = new TextField("Travel instructions");
    final var location = new ComboBox<String>("Location");
    final var webinarUrl = new TextField("Webinar URL");
    final var youtTube = new TextField("YouTube");
    final var date = new DateTimePicker("Date & Time");
    final var duration = new TimePicker("Duration");
    final var eventUrl = new TextField("Event URL");
    final var attendeeLimit = new IntegerField("Attendee limit (0 = no limit)");
    final var membersOnly = new Checkbox("Members only");
    final var published = new Checkbox("Published");
    type.setLabel("Type");
    type.setRequiredIndicatorVisible(true);
    title.setRequiredIndicatorVisible(true);
    title.setValueChangeMode(EAGER);
    title.addValueChangeListener(changeEvent -> {
        if (eventUrl.getValue().equals(URLUtil.createReadableUrl(changeEvent.getOldValue()))) {
            eventUrl.setValue(URLUtil.createReadableUrl(changeEvent.getValue()));
        }
    });
    subtitle.setValueChangeMode(EAGER);
    speaker.setOrdered(true);
    speaker.setItemLabelGenerator(EventSpeakerEntity::fullName);
    speaker.setItems(databaseService.getAllEventSpeakers());
    organizer.setOrdered(true);
    organizer.setItemLabelGenerator(value -> String.format("%s %s", value.getFirstName(), value.getLastName()));
    organizer.setItems(databaseService.getAllAdmins());
    organizer.setRequiredIndicatorVisible(true);
    keyword.setOrdered(true);
    keyword.setItemLabelGenerator(KeywordEntity::keyword);
    keyword.setItems(databaseService.getAllKeywords());
    level.setLabel("Level");
    language.setLabel("Language");
    location.setItems(databaseService.getAllEventLocations());
    location.setAllowCustomValue(true);
    location.addValueChangeListener(changeEvent -> {
        final var value = changeEvent.getValue();
        final var isOnline = "Online".equalsIgnoreCase(value);
        webinarUrl.setEnabled(isOnline);
        webinarUrl.setRequiredIndicatorVisible(published.getValue() && isOnline);
        room.setRequiredIndicatorVisible(!isOnline);
        updateEventUrlPrefix(location, date, eventUrl);
        binder.validate();
    });
    room.setValueChangeMode(EAGER);
    travelInstructions.setValueChangeMode(EAGER);
    webinarUrl.setValueChangeMode(EAGER);
    date.setMin(LocalDateTime.now());
    date.addValueChangeListener(changeEvent -> updateEventUrlPrefix(location, date, eventUrl));
    duration.setStep(Duration.ofMinutes(15));
    duration.setMin(LocalTime.of(1, 0));
    duration.setMax(LocalTime.of(3, 0));
    eventUrl.setValueChangeMode(EAGER);
    updateEventUrlPrefix(location, date, eventUrl);
    attendeeLimit.setMin(0);
    attendeeLimit.setMax(500);
    attendeeLimit.setStep(10);
    attendeeLimit.setHasControls(true);
    published.addValueChangeListener(changeEvent -> {
        final var value = changeEvent.getValue();
        speaker.setRequiredIndicatorVisible(value);
        level.setRequiredIndicatorVisible(value);
        description.setRequiredIndicatorVisible(value);
        language.setRequiredIndicatorVisible(value);
        location.setRequiredIndicatorVisible(value);
        room.setRequiredIndicatorVisible(!"Online".equalsIgnoreCase(location.getValue()));
        date.setRequiredIndicatorVisible(value);
        duration.setRequiredIndicatorVisible(value);
        eventUrl.setRequiredIndicatorVisible(value);
        binder.validate();
    });
    formLayout.add(type, title, subtitle, speaker, organizer, level, new CustomLabel("Description"), description, keyword, new CustomLabel("Agenda"), agenda, language, location, room, travelInstructions, webinarUrl, youtTube, date, duration, eventUrl, attendeeLimit, membersOnly, published);
    binder.forField(type).withValidator(value -> !published.getValue() || value != null, "Please select a type").bind(Event::getType, Event::setType);
    binder.forField(title).withValidator(new StringLengthValidator("Please enter a title (max. 255 chars)", 1, 255)).bind(Event::getTitle, Event::setTitle);
    binder.forField(subtitle).withValidator(new StringLengthValidator("The subtitle is too long (max. 255 chars)", 0, 255)).bind(Event::getSubtitle, Event::setSubtitle);
    binder.forField(speaker).withValidator(value -> !published.getValue() || !value.isEmpty(), "Please select at least one speaker").bind(this::getSpeakers, this::setSpeakers);
    binder.forField(organizer).withValidator(value -> !value.isEmpty(), "Please select at least one organizer").bind(this::getOrganizer, this::setOrganizer);
    binder.forField(level).withValidator(value -> !published.getValue() || value != null, "Please select a level").bind(Event::getLevel, Event::setLevel);
    binder.forField(description.asHtml()).withValidator(value -> !published.getValue() || value != null && !value.isBlank(), "Please enter a description").bind(Event::getDescription, Event::setDescription);
    binder.forField(keyword).bind(this::getKeyword, this::setKeyword);
    binder.forField(agenda.asHtml()).bind(Event::getAgenda, Event::setAgenda);
    binder.forField(language).withValidator(value -> !published.getValue() || value != null, "Please select a language").bind(Event::getLanguage, Event::setLanguage);
    binder.forField(location).withValidator(value -> !published.getValue() || value != null, "Please select a location").bind(Event::getLocation, Event::setLocation);
    binder.forField(room).withValidator(value -> !published.getValue() || "Online".equalsIgnoreCase(location.getValue()) || !value.isBlank(), "Please enter a room").bind(Event::getRoom, Event::setRoom);
    binder.forField(travelInstructions).withValidator(value -> value.isBlank() || URLUtil.isValid(value), "Please enter a valid URL").bind(Event::getTravelInstructions, Event::setTravelInstructions);
    binder.forField(webinarUrl).withValidator(value -> !published.getValue() || !"Online".equalsIgnoreCase(location.getValue()) || URLUtil.isValid(value), "Please enter a valid URL").bind(Event::getWebinarUrl, Event::setWebinarUrl);
    binder.forField(youtTube).bind(Event::getYoutube, Event::setYoutube);
    binder.forField(date).withValidator(value -> isPastEvent(date) || !published.getValue() && (value == null || value.isAfter(LocalDateTime.now())) || value != null && value.isAfter(LocalDateTime.now()), "Please enter a date and time in the future").bind(Event::getDate, Event::setDate);
    binder.forField(duration).withValidator(value -> !published.getValue() || (value != null && value.isAfter(LocalTime.MIN) && value.isBefore(LocalTime.MAX)), "Please enter a duration").bind(Event::getDuration, Event::setDuration);
    // TODO check for duplicates
    binder.forField(eventUrl).withValidator(value -> !published.getValue() || value != null && !value.isBlank(), "Please enter a valid event URL").bind(Event::getEventUrl, Event::setEventUrl);
    binder.forField(attendeeLimit).bind(Event::getAttendeeLimit, Event::setAttendeeLimit);
    binder.forField(membersOnly).bind(Event::getMembersOnly, Event::setMembersOnly);
    binder.forField(published).bind(Event::getPublished, Event::setPublished);
    afterOpen = () -> {
        webinarUrl.setEnabled("Online".equalsIgnoreCase(location.getValue()));
        if (isPastEvent(date)) {
            binder.setReadOnly(true);
            binder.setValidatorsDisabled(true);
            youtTube.setReadOnly(false);
        }
    };
}
Also used : Member(org.komunumo.data.entity.Member) EventLevel(org.komunumo.data.db.enums.EventLevel) Event(org.komunumo.data.entity.Event) CustomLabel(org.komunumo.ui.component.CustomLabel) Select(com.vaadin.flow.component.select.Select) Binder(com.vaadin.flow.data.binder.Binder) LocalDateTime(java.time.LocalDateTime) ComboBox(com.vaadin.flow.component.combobox.ComboBox) EditDialog(org.komunumo.ui.component.EditDialog) KeywordEntity(org.komunumo.data.entity.KeywordEntity) EventLanguage(org.komunumo.data.db.enums.EventLanguage) AuthenticatedUser(org.komunumo.security.AuthenticatedUser) MultiselectComboBox(org.vaadin.gatanaso.MultiselectComboBox) IntegerField(com.vaadin.flow.component.textfield.IntegerField) Duration(java.time.Duration) LocalTime(java.time.LocalTime) TextField(com.vaadin.flow.component.textfield.TextField) EAGER(com.vaadin.flow.data.value.ValueChangeMode.EAGER) URLUtil(org.komunumo.util.URLUtil) Set(java.util.Set) TimePicker(com.vaadin.flow.component.timepicker.TimePicker) EventSpeakerEntity(org.komunumo.data.entity.EventSpeakerEntity) Collectors(java.util.stream.Collectors) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) 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) Year(java.time.Year) NotNull(org.jetbrains.annotations.NotNull) Callback(org.komunumo.Callback) DateTimePicker(org.komunumo.ui.component.DateTimePicker) Span(com.vaadin.flow.component.html.Span) EventType(org.komunumo.data.db.enums.EventType) TimePicker(com.vaadin.flow.component.timepicker.TimePicker) DateTimePicker(org.komunumo.ui.component.DateTimePicker) CustomLabel(org.komunumo.ui.component.CustomLabel) MultiselectComboBox(org.vaadin.gatanaso.MultiselectComboBox) EventSpeakerEntity(org.komunumo.data.entity.EventSpeakerEntity) ComboBox(com.vaadin.flow.component.combobox.ComboBox) MultiselectComboBox(org.vaadin.gatanaso.MultiselectComboBox) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) IntegerField(com.vaadin.flow.component.textfield.IntegerField) DateTimePicker(org.komunumo.ui.component.DateTimePicker) KeywordEntity(org.komunumo.data.entity.KeywordEntity) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) Select(com.vaadin.flow.component.select.Select) TextField(com.vaadin.flow.component.textfield.TextField) Event(org.komunumo.data.entity.Event) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor)

Example 5 with CustomLabel

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

the class FaqDialog method createForm.

@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<FaqRecord> binder) {
    final var question = new TextField("Question");
    question.setRequiredIndicatorVisible(true);
    question.setValueChangeMode(EAGER);
    final var answer = new RichTextEditor();
    answer.setRequiredIndicatorVisible(true);
    formLayout.add(question, new CustomLabel("Answer"), answer);
    binder.forField(question).withValidator(new StringLengthValidator("Please enter the question (max. 255 chars)", 1, 255)).bind(FaqRecord::getQuestion, FaqRecord::setQuestion);
    binder.forField(answer.asHtml()).withValidator(new StringLengthValidator("Please enter the question (max. 255 chars)", 1, 10_000)).bind(FaqRecord::getAnswer, FaqRecord::setAnswer);
}
Also used : CustomLabel(org.komunumo.ui.component.CustomLabel) FaqRecord(org.komunumo.data.db.tables.records.FaqRecord) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) TextField(com.vaadin.flow.component.textfield.TextField) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor)

Aggregations

RichTextEditor (com.vaadin.flow.component.richtexteditor.RichTextEditor)7 TextField (com.vaadin.flow.component.textfield.TextField)7 StringLengthValidator (com.vaadin.flow.data.validator.StringLengthValidator)7 CustomLabel (org.komunumo.ui.component.CustomLabel)7 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)3 Select (com.vaadin.flow.component.select.Select)3 Binder (com.vaadin.flow.data.binder.Binder)3 EAGER (com.vaadin.flow.data.value.ValueChangeMode.EAGER)3 NotNull (org.jetbrains.annotations.NotNull)3 EditDialog (org.komunumo.ui.component.EditDialog)3 ComboBox (com.vaadin.flow.component.combobox.ComboBox)2 Span (com.vaadin.flow.component.html.Span)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Nullable (org.jetbrains.annotations.Nullable)2 Callback (org.komunumo.Callback)2 DatabaseService (org.komunumo.data.service.DatabaseService)2 DateTimePicker (org.komunumo.ui.component.DateTimePicker)2 ImageUploadField (org.komunumo.ui.component.ImageUploadField)2 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)1