Search in sources :

Example 61 with TextElement

use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.

the class ChecklistEditCheckpointsController method addNewFormCheckpoint.

private void addNewFormCheckpoint(int index, Checkpoint checkpoint) {
    // add checkpoint title
    String pointTitle = checkpoint.getTitle() == null ? "" : checkpoint.getTitle();
    TextElement title = uifactory.addTextElement("title" + counter, null, -1, pointTitle, titleContainer);
    // TODO:SK:2009-11-20:PB:should be default -> check layout in velocity.
    title.showError(false);
    title.setDisplaySize(20);
    title.setMandatory(true);
    // TODO:Stefan Köber: please verify that the default not empty check does the same as you ItemValidatorProvider
    title.setNotEmptyCheck("cl.table.title.error");
    title.setUserObject(checkpoint);
    titleInputList.add(index, title);
    // add checkpoint description
    TextElement description = uifactory.addTextElement("description" + counter, null, -1, checkpoint.getDescription(), titleContainer);
    description.setDisplaySize(35);
    description.setMandatory(false);
    description.setUserObject(checkpoint);
    descriptionInputList.add(index, description);
    // add link comment
    String[] keys = CheckpointMode.getModes();
    String[] values = new String[keys.length];
    for (int i = 0; i < keys.length; i++) {
        values[i] = translate(keys[i]);
    }
    SingleSelection mode = uifactory.addDropdownSingleselect("modus" + counter, "form.enableCancelEnroll", titleContainer, keys, values, null);
    mode.select(checkpoint.getMode(), checkpoint.getMode() != null);
    mode.setUserObject(checkpoint);
    modeInputList.add(index, mode);
    // add link deletion action button
    FormLink delButton = new FormLinkImpl("delete" + counter, "delete" + counter, "cl.table.delete", Link.BUTTON_SMALL);
    delButton.setUserObject(checkpoint);
    titleContainer.add(delButton);
    delButtonList.add(index, delButton);
    // increase the counter to enable unique component names
    counter++;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 62 with TextElement

use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.

the class VCEditForm method addRow.

private void addRow(int index, final MeetingDate date) {
    // title
    TextElement vcTitle = uifactory.addTextElement("title" + counter, null, -1, date.getTitle(), editVC);
    vcTitle.setDisplaySize(30);
    vcTitle.setMandatory(true);
    vcTitle.setNotEmptyCheck("vc.table.title.empty");
    vcTitleInputList.add(index, vcTitle);
    // description
    TextElement vcDescription = uifactory.addTextElement("description" + counter, null, -1, date.getDescription(), editVC);
    vcDescription.setDisplaySize(20);
    vcDescription.setNotEmptyCheck("vc.table.description.empty");
    vcDescription.setMandatory(true);
    vcDescriptionInputList.add(index, vcDescription);
    // begin
    DateChooser vcScheduleDate = uifactory.addDateChooser("begin" + counter, "vc.table.begin", null, editVC);
    vcScheduleDate.setNotEmptyCheck("vc.table.begin.empty");
    vcScheduleDate.setValidDateCheck("vc.table.begin.error");
    vcScheduleDate.setMandatory(true);
    vcScheduleDate.setDisplaySize(20);
    vcScheduleDate.setDateChooserTimeEnabled(true);
    vcScheduleDate.setDate(date.getBegin());
    vcCalenderbeginInputList.add(index, vcScheduleDate);
    // add date duration
    SimpleDateFormat sdDuration = new SimpleDateFormat("HH:mm");
    TimeZone tz = TimeZone.getTimeZone("Etc/GMT+0");
    sdDuration.setTimeZone(tz);
    TextElement vcDuration = uifactory.addTextElement("duration" + counter, "vc.table.duration", 5, String.valueOf(0), editVC);
    vcDuration.setDisplaySize(5);
    vcDuration.setValue(sdDuration.format(new Date(date.getEnd().getTime() - date.getBegin().getTime())));
    vcDuration.setRegexMatchCheck("\\d{1,2}:\\d\\d", "form.error.format");
    vcDuration.setExampleKey("vc.table.duration.example", null);
    vcDuration.setNotEmptyCheck("vc.table.duration.empty");
    vcDuration.setErrorKey("vc.table.duration.error", null);
    vcDuration.setMandatory(true);
    vcDuration.showExample(true);
    vcDuration.showError(false);
    this.vcDurationInputList.add(index, vcDuration);
    // add row button
    FormLink addButton = new FormLinkImpl("add" + counter, "add" + counter, "vc.table.add", Link.BUTTON_SMALL);
    editVC.add(addButton);
    vcAddButtonList.add(index, addButton);
    // remove row button
    FormLink delButton = new FormLinkImpl("delete" + counter, "delete" + counter, "vc.table.delete", Link.BUTTON_SMALL);
    editVC.add(delButton);
    vcDelButtonList.add(index, delButton);
    // increase the counter to enable unique component names
    counter++;
}
Also used : TimeZone(java.util.TimeZone) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormLinkImpl(org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl) DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 63 with TextElement

use of org.olat.core.gui.components.form.flexible.elements.TextElement in project openolat by klemens.

the class MembersMailController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String fullName = userManager.getUserDisplayName(getIdentity());
    if (StringHelper.containsNonWhitespace(fullName)) {
        fullName = "[" + fullName + "]";
    }
    TextElement fromEl = uifactory.addTextElement("from", "email.from", 255, fullName, formLayout);
    fromEl.setEnabled(false);
    uifactory.addSpacerElement("space-1", formLayout, false);
    String to = "send.mail.to";
    if (ownerList != null && ownerList.size() > 0) {
        String[] values = new String[] { translate("contact.all.owners") };
        ownerEl = uifactory.addCheckboxesHorizontal("contact.all.owners", to, formLayout, keys, values);
        to = null;
    }
    if (coachList != null && coachList.size() > 0) {
        String[] values = new String[] { translate("contact.all.coaches") };
        coachEl = uifactory.addCheckboxesHorizontal("contact.all.coaches", to, formLayout, keys, values);
        to = null;
    }
    if (participantList != null && participantList.size() > 0) {
        String[] values = new String[] { translate("contact.all.participants") };
        participantEl = uifactory.addCheckboxesHorizontal("contact.all.participants", to, formLayout, keys, values);
        to = null;
    }
    if (waitingList != null && waitingList.size() > 0) {
        String[] values = new String[] { translate("contact.all.waiting") };
        waitingEl = uifactory.addCheckboxesHorizontal("contact.all.waiting", to, formLayout, keys, values);
        to = null;
    }
    if ((ownerList != null && ownerList.size() > 0) || (coachList != null && coachList.size() > 0) || (participantList != null && participantList.size() > 0) || (waitingList != null && waitingList.size() > 0)) {
        String[] values = new String[] { translate("contact.individual") };
        individualEl = uifactory.addCheckboxesHorizontal("contact.individual", to, formLayout, keys, values);
        individualEl.addActionListener(FormEvent.ONCHANGE);
        to = null;
        String attachmentPage = velocity_root + "/individual_members.html";
        individualMemberCont = FormLayoutContainer.createCustomFormLayout("contact.individual.list", getTranslator(), attachmentPage);
        formLayout.add(individualMemberCont);
        individualMemberCont.setRootForm(mainForm);
        individualMemberCont.setVisible(false);
        individualMemberCont.contextPut("selectedMembers", selectedMembers);
        addMemberButton = uifactory.addFormLink("add.member", "add", "", "", individualMemberCont, Link.NONTRANSLATED);
        addMemberButton.setIconLeftCSS("o_icon o_icon-lg o_icon_table_large");
        addMemberButton.setDomReplacementWrapperRequired(false);
        addMemberButton.getComponent().setSuppressDirtyFormWarning(true);
    }
    String[] extValues = new String[] { translate("contact.external") };
    externalEl = uifactory.addCheckboxesHorizontal("contact.external", to, formLayout, keys, extValues);
    externalEl.addActionListener(FormEvent.ONCHANGE);
    externalAddressesEl = uifactory.addTextAreaElement("contact.external.list", null, 4096, 3, 60, false, "", formLayout);
    externalAddressesEl.setExampleKey("contact.external.list.example", null);
    externalAddressesEl.setVisible(false);
    uifactory.addSpacerElement("space-2", formLayout, false);
    subjectEl = uifactory.addTextElement("subject", "mail.subject", 255, "", formLayout);
    subjectEl.setDisplaySize(255);
    subjectEl.setMandatory(true);
    bodyEl = uifactory.addRichTextElementForStringDataMinimalistic("body", "mail.body", "", 15, 8, formLayout, getWindowControl());
    bodyEl.setMandatory(true);
    attachmentEl = uifactory.addFileElement(getWindowControl(), "file_upload_1", "contact.attachment", formLayout);
    attachmentEl.addActionListener(FormEvent.ONCHANGE);
    attachmentEl.setExampleKey("contact.attachment.maxsize", new String[] { Integer.toString(contactAttachmentMaxSizeInMb) });
    String attachmentPage = velocity_root + "/attachments.html";
    uploadCont = FormLayoutContainer.createCustomFormLayout("file_upload_inner", getTranslator(), attachmentPage);
    uploadCont.setRootForm(mainForm);
    uploadCont.setVisible(false);
    uploadCont.contextPut("attachments", attachments);
    formLayout.add(uploadCont);
    String[] copyValues = new String[] { "" };
    copyFromEl = uifactory.addCheckboxesHorizontal("copy.from", "contact.cp.from", formLayout, keys, copyValues);
    FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
    formLayout.add(buttonGroupLayout);
    uifactory.addFormSubmitButton("email.send", buttonGroupLayout);
    uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
}
Also used : RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 64 with TextElement

use of org.olat.core.gui.components.form.flexible.elements.TextElement in project OpenOLAT by OpenOLAT.

the class ProfileFormController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    User user = identityToModify.getUser();
    // show a form element for each property handler
    boolean first = true;
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null) {
            continue;
        }
        // add spacer if necessary (i.e. when group name changes)
        String group = userPropertyHandler.getGroup();
        String formId = "group." + group;
        FormLayoutContainer groupContainer = (FormLayoutContainer) formLayout.getFormComponent(formId);
        if (groupContainer == null) {
            groupContainer = FormLayoutContainer.createDefaultFormLayout(formId, getTranslator());
            groupContainer.setFormTitle(translate("form.group." + group));
            if (first) {
                groupContainer.setFormContextHelp("Configuration");
                first = false;
            }
            formItems.put(formId, groupContainer);
            formLayout.add(groupContainer);
        }
        // add input field to container
        FormItem formItem = userPropertyHandler.addFormItem(getLocale(), user, usageIdentifier, isAdministrativeUser, groupContainer);
        String propertyName = userPropertyHandler.getName();
        formItems.put(propertyName, formItem);
        if (formItem instanceof TextElement) {
            // it's a text field, so get the value of this property into the text field
            TextElement textElement = (TextElement) formItem;
            textElement.setValue(user.getProperty(propertyName, getLocale()));
        } else if (formItem instanceof MultipleSelectionElement) {
            // it's a checkbox, so set the box to checked if the corresponding property is set to "true"
            MultipleSelectionElement checkbox = (MultipleSelectionElement) formItem;
            String value = user.getProperty(propertyName, getLocale());
            if (value != null) {
                checkbox.select(propertyName, value.equals("true"));
            } else {
                // assume "false" if the property is not present
                checkbox.select(propertyName, false);
            }
        }
        // special case for email field
        if (userPropertyHandler.getName().equals("email")) {
            String key = user.getProperty("emchangeKey", null);
            TemporaryKey tempKey = rm.loadTemporaryKeyByRegistrationKey(key);
            if (tempKey != null) {
                XStream xml = XStreamHelper.createXStreamInstance();
                @SuppressWarnings("unchecked") HashMap<String, String> mails = (HashMap<String, String>) xml.fromXML(tempKey.getEmailAddress());
                formItem.setExampleKey("email.change.form.info", new String[] { mails.get("changedEMail") });
            }
            if (!userModule.isEmailMandatory()) {
                formItem.setMandatory(false);
            }
        }
    }
    // add the "about me" text field.
    FormLayoutContainer groupContainer = FormLayoutContainer.createDefaultFormLayout("group.about", getTranslator());
    groupContainer.setFormTitle(translate("form.group.about"));
    groupContainer.setElementCssClass("o_user_aboutme");
    formLayout.add(groupContainer);
    HomePageConfig conf = hpcm.loadConfigFor(identityToModify.getName());
    textAboutMe = uifactory.addRichTextElementForStringData("form.text", "form.text", conf.getTextAboutMe(), 10, -1, false, null, null, groupContainer, ureq.getUserSession(), getWindowControl());
    textAboutMe.setMaxLength(10000);
    // upload image
    groupContainer = FormLayoutContainer.createDefaultFormLayout("portraitupload", getTranslator());
    groupContainer.setFormTitle(translate("ul.header"));
    formLayout.add(groupContainer);
    File portraitFile = dps.getLargestPortrait(identityToModify.getName());
    // Init upload controller
    Set<String> mimeTypes = new HashSet<>();
    mimeTypes.add("image/gif");
    mimeTypes.add("image/jpg");
    mimeTypes.add("image/jpeg");
    mimeTypes.add("image/png");
    portraitUpload = uifactory.addFileElement(getWindowControl(), "ul.select", "ul.select", groupContainer);
    portraitUpload.setMaxUploadSizeKB(10000, null, null);
    portraitUpload.setPreview(ureq.getUserSession(), true);
    portraitUpload.addActionListener(FormEvent.ONCHANGE);
    portraitUpload.setHelpTextKey("ul.select.fhelp", null);
    portraitUpload.setDeleteEnabled(true);
    if (portraitFile != null) {
        portraitUpload.setInitialFile(portraitFile);
    }
    portraitUpload.limitToMimeType(mimeTypes, null, null);
    if (logoEnabled) {
        // upload image
        groupContainer = FormLayoutContainer.createDefaultFormLayout("logoupload", getTranslator());
        groupContainer.setFormTitle(translate("logo.header"));
        formLayout.add(groupContainer);
        File logoFile = dps.getLargestLogo(identityToModify.getName());
        logoUpload = uifactory.addFileElement(getWindowControl(), "logo.select", "logo.select", groupContainer);
        logoUpload.setMaxUploadSizeKB(10000, null, null);
        logoUpload.setPreview(ureq.getUserSession(), true);
        logoUpload.addActionListener(FormEvent.ONCHANGE);
        logoUpload.setHelpTextKey("ul.select.fhelp", null);
        logoUpload.setDeleteEnabled(true);
        if (logoFile != null) {
            logoUpload.setInitialFile(logoFile);
        }
        logoUpload.limitToMimeType(mimeTypes, null, null);
    }
    // Create submit and cancel buttons
    FormLayoutContainer buttonLayoutWrappper = FormLayoutContainer.createDefaultFormLayout("buttonLayoutWrappper", getTranslator());
    formLayout.add(buttonLayoutWrappper);
    FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayoutInner", getTranslator());
    buttonLayoutWrappper.add(buttonLayout);
    uifactory.addFormSubmitButton("save", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
Also used : User(org.olat.core.id.User) HashMap(java.util.HashMap) FormItem(org.olat.core.gui.components.form.flexible.FormItem) TemporaryKey(org.olat.registration.TemporaryKey) XStream(com.thoughtworks.xstream.XStream) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) File(java.io.File) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) HashSet(java.util.HashSet)

Example 65 with TextElement

use of org.olat.core.gui.components.form.flexible.elements.TextElement in project OpenOLAT by OpenOLAT.

the class GenericUnique127CharTextPropertyHandler method isValid.

@Override
public boolean isValid(User user, FormItem formItem, Map<String, String> formContext) {
    boolean allOk = super.isValid(user, formItem, formContext);
    if (formItem instanceof TextElement) {
        String value = ((TextElement) formItem).getValue();
        if (!isUnique(user, value)) {
            List<Identity> found = UserManager.getInstance().findIdentitiesWithProperty(getName(), value);
            Identity propId = null;
            if (found.size() > 0) {
                // only display first one
                propId = found.get(0);
                String username = propId.getName();
                formItem.setErrorKey("general.error.unique", new String[] { username });
                allOk &= false;
            }
        }
    }
    return allOk;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) Identity(org.olat.core.id.Identity)

Aggregations

TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)146 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)40 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)36 FormItem (org.olat.core.gui.components.form.flexible.FormItem)34 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)30 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)26 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)24 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)18 ArrayList (java.util.ArrayList)16 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)16 Identity (org.olat.core.id.Identity)12 HashMap (java.util.HashMap)8 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)8 EmailProperty (org.olat.user.propertyhandlers.EmailProperty)8 Date (java.util.Date)6 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)6 StaticTextElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.StaticTextElementImpl)6 TextElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.TextElementImpl)6 RichTextElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl)6 File (java.io.File)4