Search in sources :

Example 1 with DateChooser

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

the class PastDatePropertyHandler method isValid.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#isValid(org.olat.core.gui.components.form.flexible.FormItem,
 *      java.util.Map)
 */
@Override
public boolean isValid(User user, FormItem formItem, Map<String, String> formContext) {
    boolean isValidDate = super.isValid(user, formItem, formContext);
    if (!isValidDate)
        return false;
    // check for date in the past
    Date date = ((DateChooser) formItem).getDate();
    if (date == null || isDateInThePast(date)) {
        return true;
    } else {
        formItem.setErrorKey("form.name.date.past.error", null);
        return false;
    }
}
Also used : DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) Date(java.util.Date)

Example 2 with DateChooser

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

the class MetadatasStepController method forgeRow.

private DueDateWrapper forgeRow(int i, FormLayoutContainer tableCont) {
    String title = data.getNodePrefix() + " " + (i + 1);
    TextElement titleEl = uifactory.addTextElement("title_" + i, null, 32, title, tableCont);
    titleEl.setDisplaySize(21);
    DateChooser dueDateEl = uifactory.addDateChooser("duedate_" + i, "config.due.date", null, tableCont);
    dueDateEl.setDateChooserTimeEnabled(true);
    DueDateWrapper wrapper = new DueDateWrapper(titleEl, dueDateEl);
    return wrapper;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser)

Example 3 with DateChooser

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

the class ProjectEditDetailsFormController method initForm.

/**
 * Initialize form.
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // create form elements
    projectTitle = uifactory.addTextElement("title", "detailsform.title.label", 100, project.getTitle(), formLayout);
    // account-Managers
    StringBuilder projectLeaderString = new StringBuilder();
    for (Iterator<Identity> iterator = project.getProjectLeaders().iterator(); iterator.hasNext(); ) {
        Identity identity = iterator.next();
        String last = identity.getUser().getProperty(UserConstants.LASTNAME, getLocale());
        String first = identity.getUser().getProperty(UserConstants.FIRSTNAME, getLocale());
        if (projectLeaderString.length() > 0) {
            projectLeaderString.append(",");
        }
        projectLeaderString.append(first);
        projectLeaderString.append(" ");
        projectLeaderString.append(last);
    }
    projectLeaders = uifactory.addTextElement("projectleaders", "detailsform.projectleaders.label", 100, projectLeaderString.toString(), formLayout);
    projectLeaders.setEnabled(false);
    // add the learning objectives rich text input element
    projectDescription = uifactory.addRichTextElementForStringData("description", "detailsform.description.label", project.getDescription(), 10, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
    projectDescription.setMaxLength(2500);
    stateLayout = FormLayoutContainer.createHorizontalFormLayout("stateLayout", getTranslator());
    stateLayout.setLabel("detailsform.state.label", null);
    formLayout.add(stateLayout);
    String stateValue = getTranslator().translate(projectBrokerManager.getStateFor(project, ureq.getIdentity(), projectBrokerModuleConfiguration));
    projectState = uifactory.addStaticTextElement("detailsform.state", stateValue + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", stateLayout);
    projectState.setLabel(null, null);
    String keyDetailsformMax = null;
    if (projectBrokerModuleConfiguration.isAcceptSelectionManually()) {
        keyDetailsformMax = "detailsform.max.candidates.label";
    } else {
        keyDetailsformMax = "detailsform.max.members.label";
    }
    selectionMaxMembers = uifactory.addCheckboxesHorizontal(keyDetailsformMax, formLayout, keys, values);
    maxMembers = uifactory.addIntegerElement("form.options.number.of.participants.per.topic_nbr", project.getMaxMembers(), formLayout);
    maxMembers.setMinValueCheck(0, null);
    maxMembers.setDisplaySize(3);
    if (project.getMaxMembers() == Project.MAX_MEMBERS_UNLIMITED) {
        maxMembers.setVisible(false);
        selectionMaxMembers.select(keys[0], false);
    } else {
        selectionMaxMembers.select(keys[0], true);
    }
    selectionMaxMembers.addActionListener(FormEvent.ONCLICK);
    String[] deselectValues = new String[] { translate("detailsform.allow.deselection.hint") };
    allowDeselection = uifactory.addCheckboxesHorizontal("detailsform.allow.deselection", formLayout, keys, deselectValues);
    allowDeselection.select(keys[0], projectGroupManager.isDeselectionAllowed(project));
    allowDeselection.addActionListener(FormEvent.ONCLICK);
    uifactory.addSpacerElement("spacer_1", formLayout, false);
    // customfields
    List<CustomField> customFields = projectBrokerModuleConfiguration.getCustomFields();
    int customFieldIndex = 0;
    for (Iterator<CustomField> iterator = customFields.iterator(); iterator.hasNext(); ) {
        CustomField customField = iterator.next();
        getLogger().debug("customField: " + customField.getName() + "=" + customField.getValue());
        StringTokenizer tok = new StringTokenizer(customField.getValue(), ProjectBrokerManager.CUSTOMFIELD_LIST_DELIMITER);
        if (customField.getValue() == null || customField.getValue().equals("") || !tok.hasMoreTokens()) {
            // no value define => Text-input
            // Add StaticTextElement as workaroung for non translated label
            // null > no label
            uifactory.addStaticTextElement("customField_label" + customFieldIndex, null, customField.getName(), formLayout);
            TextElement textElement = uifactory.addTextElement("customField_" + customFieldIndex, "", 150, project.getCustomFieldValue(customFieldIndex), formLayout);
            textElement.setDisplaySize(60);
            // textElement.setTranslator(null);
            // textElement.setLabel(customField.getName(), null);
            textElement.showLabel(false);
            customfieldElementList.add(textElement);
        } else {
            // values define => dropdown selection
            List<String> valueList = new ArrayList<String>();
            while (tok.hasMoreTokens()) {
                String value = tok.nextToken();
                valueList.add(value);
                getLogger().debug("valueList add: " + value);
            }
            String[] theValues = new String[valueList.size() + 1];
            String[] theKeys = new String[valueList.size() + 1];
            int arrayIndex = 0;
            theValues[arrayIndex] = translate(DROPDOWN_NO_SELECETION);
            theKeys[arrayIndex] = DROPDOWN_NO_SELECETION;
            arrayIndex++;
            for (Iterator<String> iterator2 = valueList.iterator(); iterator2.hasNext(); ) {
                String value = iterator2.next();
                theValues[arrayIndex] = value;
                theKeys[arrayIndex] = Integer.toString(arrayIndex);
                arrayIndex++;
            }
            // Add StaticTextElement as workaround for non translated label
            // null > no label
            uifactory.addStaticTextElement("customField_label" + customFieldIndex, null, customField.getName(), formLayout);
            SingleSelection selectionElement = uifactory.addDropdownSingleselect("customField_" + customFieldIndex, null, formLayout, theKeys, theValues, null);
            if (project.getCustomFieldValue(customFieldIndex) != null && !project.getCustomFieldValue(customFieldIndex).equals("")) {
                if (valueList.contains(project.getCustomFieldValue(customFieldIndex))) {
                    // '+1' because no-selection at the beginning
                    String key = Integer.toString(valueList.indexOf(project.getCustomFieldValue(customFieldIndex)) + 1);
                    selectionElement.select(key, true);
                } else {
                    this.showInfo("warn.customfield.key.does.not.exist", project.getCustomFieldValue(customFieldIndex));
                }
            }
            customfieldElementList.add(selectionElement);
        }
        uifactory.addSpacerElement("customField_spacer" + customFieldIndex, formLayout, false);
        customFieldIndex++;
    }
    // Events
    for (Project.EventType eventType : Project.EventType.values()) {
        if (projectBrokerModuleConfiguration.isProjectEventEnabled(eventType)) {
            ProjectEvent projectEvent = project.getProjectEvent(eventType);
            DateChooser dateChooserStart = uifactory.addDateChooser(eventType + "start", eventType.getI18nKey() + ".start.label", null, formLayout);
            dateChooserStart.setDateChooserTimeEnabled(true);
            dateChooserStart.setDisplaySize(CUSTOM_DATE_FORMAT.length());
            getLogger().info("Event=" + eventType + ", startDate=" + projectEvent.getStartDate());
            dateChooserStart.setDate(projectEvent.getStartDate());
            eventStartElementList.put(eventType, dateChooserStart);
            DateChooser dateChooserEnd = uifactory.addDateChooser(eventType + "end", eventType.getI18nKey() + ".end.label", null, formLayout);
            dateChooserEnd.setDateChooserTimeEnabled(true);
            dateChooserEnd.setDisplaySize(CUSTOM_DATE_FORMAT.length());
            getLogger().debug("Event=" + eventType + ", endDate=" + projectEvent.getEndDate());
            dateChooserEnd.setDate(projectEvent.getEndDate());
            eventEndElementList.put(eventType, dateChooserEnd);
            uifactory.addSpacerElement(eventType + "spacer", formLayout, false);
        }
    }
    attachmentFileName = uifactory.addFileElement(getWindowControl(), "detailsform.attachmentfilename.label", formLayout);
    attachmentFileName.setLabel("detailsform.attachmentfilename.label", null);
    if (project.getAttachmentFileName() != null && !project.getAttachmentFileName().equals("")) {
        attachmentFileName.setInitialFile(new File(project.getAttachmentFileName()));
        removeAttachmentLink = uifactory.addFormLink("detailsform.remove.attachment", formLayout, Link.BUTTON_XSMALL);
    }
    attachmentFileName.addActionListener(FormEvent.ONCHANGE);
    mailNotification = uifactory.addCheckboxesHorizontal("detailsform.mail.notification.label", formLayout, keys, values);
    mailNotification.select(keys[0], project.isMailNotificationEnabled());
    FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
    formLayout.add(buttonGroupLayout);
    uifactory.addFormSubmitButton("save", buttonGroupLayout);
    if (this.enableCancel) {
        // TODO: Frage an PB: Warum flc hier noetig ???
        uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
    }
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Project(org.olat.course.nodes.projectbroker.datamodel.Project) StringTokenizer(java.util.StringTokenizer) RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) CustomField(org.olat.course.nodes.projectbroker.datamodel.CustomField) DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) Identity(org.olat.core.id.Identity) File(java.io.File) ProjectEvent(org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)

Example 4 with DateChooser

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

the class PastDatePropertyHandler method isValid.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#isValid(org.olat.core.gui.components.form.flexible.FormItem,
 *      java.util.Map)
 */
@Override
public boolean isValid(User user, FormItem formItem, Map<String, String> formContext) {
    boolean isValidDate = super.isValid(user, formItem, formContext);
    if (!isValidDate)
        return false;
    // check for date in the past
    Date date = ((DateChooser) formItem).getDate();
    if (date == null || isDateInThePast(date)) {
        return true;
    } else {
        formItem.setErrorKey("form.name.date.past.error", null);
        return false;
    }
}
Also used : DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) Date(java.util.Date)

Example 5 with DateChooser

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

the class EPShareListController method initPolicyUI.

/**
 * creates the custom formLayoutContainer and adds a form-component for every
 * EPSharePolicyWrapper, according to its type.
 */
protected void initPolicyUI() {
    String template = Util.getPackageVelocityRoot(this.getClass()) + "/sharePolicy.html";
    for (EPSharePolicyWrapper policyWrapper : policyWrappers) {
        String cmpName = policyWrapper.getComponentName();
        if (cmpName != null && flc.getFormComponent(cmpName) != null) {
            flc.remove(cmpName);
        }
        cmpName = Integer.toString(cmpSuffixGenerator.getAndIncrement());
        policyWrapper.setComponentName(cmpName);
        FormLayoutContainer container = FormLayoutContainer.createCustomFormLayout(cmpName, getTranslator(), template);
        container.contextPut("wrapper", policyWrapper);
        container.setRootForm(mainForm);
        if (policyWrapper.getType() != null) {
            String[] curatedTargetKeys;
            String[] curatedTargetValues;
            if (!Type.invitation.equals(policyWrapper.getType()) && !loginModule.isInvitationEnabled()) {
                curatedTargetKeys = new String[targetKeys.length - 1];
                curatedTargetValues = new String[targetKeys.length - 1];
                int pos = 0;
                for (int i = targetKeys.length; i-- > 0; ) {
                    if (!targetKeys[i].equals(Type.invitation.name())) {
                        curatedTargetKeys[pos] = targetKeys[i];
                        curatedTargetValues[pos++] = targetValues[i];
                    }
                }
            } else {
                curatedTargetKeys = targetKeys;
                curatedTargetValues = targetValues;
            }
            SingleSelection type = uifactory.addDropdownSingleselect("map.share.target." + cmpName, "map.share.target", container, curatedTargetKeys, curatedTargetValues, null);
            type.addActionListener(FormEvent.ONCHANGE);
            type.setUserObject(policyWrapper);
            type.select(policyWrapper.getType().name(), true);
            switch(policyWrapper.getType()) {
                case user:
                    createContainerForUser(policyWrapper, cmpName, container);
                    break;
                case group:
                    createContainerForGroup(policyWrapper, cmpName, container);
                    break;
                case invitation:
                    Invitation invitation = policyWrapper.getInvitation();
                    if (invitation == null) {
                        invitation = invitationDao.createAndPersistInvitation();
                        policyWrapper.setInvitation(invitation);
                    }
                    createContainerForInvitation(invitation, policyWrapper, cmpName, container);
                    break;
                case allusers:
                    String text = translate("map.share.with.allOlatUsers");
                    uifactory.addStaticTextElement("map.share.with." + cmpName, text, container);
                    break;
            }
        }
        if (policyWrapper instanceof TutorEPSharePolicyWrapper) {
            String text = translate("map.share.with.tutor");
            uifactory.addStaticTextElement("map.share.text." + cmpName, text, container);
        } else {
            DateChooser fromChooser = uifactory.addDateChooser("map.share.from." + cmpName, "map.share.from", null, container);
            fromChooser.setDate(policyWrapper.getFrom());
            fromChooser.setValidDateCheck("map.share.date.invalid");
            policyWrapper.setFromChooser(fromChooser);
            DateChooser toChooser = uifactory.addDateChooser("map.share.to." + cmpName, "map.share.to", null, container);
            toChooser.setDate(policyWrapper.getTo());
            toChooser.setValidDateCheck("map.share.date.invalid");
            policyWrapper.setToChooser(toChooser);
            FormLink addLink = uifactory.addFormLink("map.share.policy.add." + cmpName, "map.share.policy.add", null, container, Link.BUTTON);
            addLink.setIconLeftCSS("o_icon o_icon-fw o_icon_add");
            addLink.setUserObject(policyWrapper);
            FormLink removeLink = uifactory.addFormLink("map.share.policy.delete." + cmpName, "map.share.policy.delete", null, container, Link.BUTTON);
            removeLink.setIconLeftCSS("o_icon o_icon-fw o_icon_delete_item");
            removeLink.setUserObject(policyWrapper);
            if (!policyWrapper.getType().equals(EPMapPolicy.Type.allusers)) {
                FormLink inviteLink = uifactory.addFormLink("map.share.policy.invite." + cmpName, "map.share.policy.invite", null, container, Link.BUTTON);
                inviteLink.setIconLeftCSS("o_icon o_icon-fw o_icon_share");
                inviteLink.setUserObject(policyWrapper);
                inviteLink.setEnabled(!policyWrapper.isInvitationSend() && (loginModule.isInvitationEnabled() || !policyWrapper.getType().equals(Type.invitation)));
            }
            StaticTextElement genErrorPanel = uifactory.addStaticTextElement("errorpanel." + cmpName, "", container);
            genErrorPanel.setUserObject(policyWrapper);
            policyWrapper.setErrorEl(genErrorPanel);
        }
        policyWrapper.setComponentName(cmpName);
        flc.add(container);
        flc.contextPut("wrapper", policyWrapper);
    }
    flc.contextPut("wrappers", policyWrappers);
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) Invitation(org.olat.basesecurity.Invitation) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) DateChooser(org.olat.core.gui.components.form.flexible.elements.DateChooser) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Aggregations

DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)12 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)4 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 File (java.io.File)2 SimpleDateFormat (java.text.SimpleDateFormat)2 StringTokenizer (java.util.StringTokenizer)2 TimeZone (java.util.TimeZone)2 Invitation (org.olat.basesecurity.Invitation)2 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)2 FormLinkImpl (org.olat.core.gui.components.form.flexible.impl.elements.FormLinkImpl)2 Identity (org.olat.core.id.Identity)2 ValidationStatus (org.olat.core.util.ValidationStatus)2 CustomField (org.olat.course.nodes.projectbroker.datamodel.CustomField)2 Project (org.olat.course.nodes.projectbroker.datamodel.Project)2 ProjectEvent (org.olat.course.nodes.projectbroker.datamodel.ProjectEvent)2