Search in sources :

Example 16 with StaticTextElement

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

the class BusinessGroupFormController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // Create the business group name input text element
    if (bulkMode) {
        businessGroupName = uifactory.addTextElement("create.form.title.bgnames", "create.form.title.bgnames", 10 * BusinessGroup.MAX_GROUP_NAME_LENGTH, "", formLayout);
        businessGroupName.setExampleKey("create.form.message.example.group", null);
    } else {
        businessGroupName = uifactory.addTextElement("create.form.title.bgname", "create.form.title.bgname", BusinessGroup.MAX_GROUP_NAME_LENGTH, "", formLayout);
        businessGroupName.setNotLongerThanCheck(BusinessGroup.MAX_GROUP_NAME_LENGTH, "create.form.error.nameTooLong");
        businessGroupName.setRegexMatchCheck(BusinessGroup.VALID_GROUPNAME_REGEXP, "create.form.error.illegalName");
    }
    businessGroupName.setElementCssClass("o_sel_group_edit_title");
    businessGroupName.setMandatory(true);
    businessGroupName.setEnabled(!BusinessGroupManagedFlag.isManaged(businessGroup, BusinessGroupManagedFlag.title));
    formLayout.setElementCssClass("o_sel_group_edit_group_form");
    // Create the business group description input rich text element
    businessGroupDescription = uifactory.addRichTextElementForStringDataMinimalistic("create.form.title.description", "create.form.title.description", "", 10, -1, formLayout, getWindowControl());
    businessGroupDescription.setEnabled(!BusinessGroupManagedFlag.isManaged(businessGroup, BusinessGroupManagedFlag.description));
    if (businessGroup != null && !bulkMode) {
        // link to group direct jump in business path
        BusinessControlFactory bcf = BusinessControlFactory.getInstance();
        List<ContextEntry> entries = bcf.createCEListFromString("[BusinessGroup:" + businessGroup.getKey() + "]");
        String url = bcf.getAsURIString(entries, true);
        url = "<span class='o_copy_code o_nowrap'><input type='text' value='" + url + "' onclick='this.select()'/></span>";
        StaticTextElement urlEl = uifactory.addStaticTextElement("create.form.businesspath", url, formLayout);
        urlEl.setElementCssClass("o_sel_group_url");
        // link to group visiting card
        bcf = BusinessControlFactory.getInstance();
        entries = bcf.createCEListFromString("[GroupCard:" + businessGroup.getKey() + "]");
        url = "<span class='o_copy_code o_nowrap'><input type='text' value='" + bcf.getAsURIString(entries, true) + "' onclick='this.select()'/></span>";
        StaticTextElement cardEl = uifactory.addStaticTextElement("create.form.groupcard", url, formLayout);
        cardEl.setElementCssClass("o_sel_group_card_url");
    }
    uifactory.addSpacerElement("myspacer", formLayout, true);
    // Minimum members input
    businessGroupMinimumMembers = uifactory.addTextElement("create.form.title.min", "create.form.title.min", 5, "", formLayout);
    businessGroupMinimumMembers.setDisplaySize(6);
    // currently the minimum feature is not enabled
    businessGroupMinimumMembers.setVisible(false);
    businessGroupMinimumMembers.setElementCssClass("o_sel_group_edit_min_members");
    // Maximum members input
    businessGroupMaximumMembers = uifactory.addTextElement("create.form.title.max", "create.form.title.max", 5, "", formLayout);
    businessGroupMaximumMembers.setDisplaySize(6);
    businessGroupMaximumMembers.setElementCssClass("o_sel_group_edit_max_members");
    // Checkboxes
    enableWaitingList = uifactory.addCheckboxesHorizontal("create.form.enableWaitinglist", null, formLayout, waitingListKeys, waitingListValues);
    enableWaitingList.setElementCssClass("o_sel_group_edit_waiting_list");
    enableAutoCloseRanks = uifactory.addCheckboxesHorizontal("create.form.enableAutoCloseRanks", null, formLayout, autoCloseKeys, autoCloseValues);
    enableAutoCloseRanks.setElementCssClass("o_sel_group_edit_auto_close_ranks");
    // Enable only if specification of min and max members is possible
    // currently the minimum feature is not enabled
    businessGroupMinimumMembers.setVisible(false);
    businessGroupMaximumMembers.setVisible(true);
    enableWaitingList.setVisible(true);
    enableAutoCloseRanks.setVisible(true);
    boolean managedSettings = BusinessGroupManagedFlag.isManaged(businessGroup, BusinessGroupManagedFlag.settings);
    businessGroupMinimumMembers.setEnabled(!managedSettings);
    businessGroupMaximumMembers.setEnabled(!managedSettings);
    enableWaitingList.setEnabled(!managedSettings);
    enableAutoCloseRanks.setEnabled(!managedSettings);
    if ((businessGroup != null) && (!bulkMode)) {
        businessGroupName.setValue(businessGroup.getName());
        businessGroupDescription.setValue(businessGroup.getDescription());
        Integer minimumMembers = businessGroup.getMinParticipants();
        Integer maximumMembers = businessGroup.getMaxParticipants();
        businessGroupMinimumMembers.setValue(minimumMembers == null || minimumMembers.intValue() <= 0 ? "" : minimumMembers.toString());
        businessGroupMaximumMembers.setValue(maximumMembers == null || maximumMembers.intValue() < 0 ? "" : maximumMembers.toString());
        if (businessGroup.getWaitingListEnabled() != null) {
            enableWaitingList.select("create.form.enableWaitinglist", businessGroup.getWaitingListEnabled());
        }
        if (businessGroup.getAutoCloseRanksEnabled() != null) {
            enableAutoCloseRanks.select("create.form.enableAutoCloseRanks", businessGroup.getAutoCloseRanksEnabled());
        }
    }
    if (!embbeded) {
        // Create submit and cancel buttons
        final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
        formLayout.add(buttonLayout);
        FormSubmit submit = uifactory.addFormSubmitButton("finish", buttonLayout);
        submit.setEnabled(!BusinessGroupManagedFlag.isManaged(businessGroup, BusinessGroupManagedFlag.details));
        uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
    }
    if ((businessGroup != null) && (!bulkMode)) {
        // managed group information
        boolean managed = StringHelper.containsNonWhitespace(businessGroup.getExternalId()) || businessGroup.getManagedFlags().length > 0;
        if (managed) {
            uifactory.addSpacerElement("managedspacer", formLayout, false);
            String extId = businessGroup.getExternalId() == null ? "" : businessGroup.getExternalId();
            StaticTextElement externalIdEl = uifactory.addStaticTextElement("create.form.externalid", extId, formLayout);
            externalIdEl.setElementCssClass("o_sel_group_external_id");
            FormLayoutContainer flagsFlc = FormLayoutContainer.createHorizontalFormLayout("flc_flags", getTranslator());
            flagsFlc.setLabel("create.form.managedflags", null);
            formLayout.add(flagsFlc);
            String flags = businessGroup.getManagedFlagsString() == null ? "" : businessGroup.getManagedFlagsString().trim();
            String flagsFormatted = null;
            if (flags.length() > 0) {
                // use translator from REST admin package to import managed flags context help strings
                Translator managedTrans = Util.createPackageTranslator(RestapiAdminController.class, ureq.getLocale());
                StringBuffer flagList = new StringBuffer();
                flagList.append("<p class=\"o_important\">");
                flagList.append(translate("create.form.managedflags.intro"));
                flagList.append("</div>");
                flagList.append("<ul>");
                for (String flag : flags.split(",")) {
                    flagList.append("<li>");
                    flagList.append(managedTrans.translate("managed.flags.group." + flag));
                    flagList.append("</li>");
                }
                flagsFormatted = flagList.toString();
            } else {
                flagsFormatted = flags;
            }
            StaticTextElement flagsEl = uifactory.addStaticTextElement("create.form.managedflags", flagsFormatted, flagsFlc);
            flagsEl.showLabel(false);
            flagsEl.setElementCssClass("o_sel_group_managed_flags");
        }
    }
}
Also used : FormSubmit(org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit) Translator(org.olat.core.gui.translator.Translator) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 17 with StaticTextElement

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

the class EPShareListController method createContainerForInvitation.

private void createContainerForInvitation(Invitation invitation, EPSharePolicyWrapper policyWrapper, String cmpName, FormLayoutContainer container) {
    FormLayoutContainer invitationContainer = FormLayoutContainer.createDefaultFormLayout("map.share.with." + cmpName, getTranslator());
    invitationContainer.contextPut("wrapper", policyWrapper);
    invitationContainer.setRootForm(mainForm);
    container.add("map.share.with." + cmpName, invitationContainer);
    TextElement firstNameEl = uifactory.addTextElement("map.share.with.firstName." + cmpName, "map.share.with.firstName", 64, invitation.getFirstName(), invitationContainer);
    firstNameEl.setMandatory(true);
    firstNameEl.setNotEmptyCheck("map.share.empty.warn");
    TextElement lastNameEl = uifactory.addTextElement("map.share.with.lastName." + cmpName, "map.share.with.lastName", 64, invitation.getLastName(), invitationContainer);
    lastNameEl.setMandatory(true);
    lastNameEl.setNotEmptyCheck("map.share.empty.warn");
    TextElement mailEl = uifactory.addTextElement("map.share.with.mail." + cmpName, "map.share.with.mail", 128, invitation.getMail(), invitationContainer);
    mailEl.setMandatory(true);
    mailEl.setNotEmptyCheck("map.share.empty.warn");
    if (StringHelper.containsNonWhitespace(invitation.getMail()) && MailHelper.isValidEmailAddress(invitation.getMail())) {
        SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
        List<Identity> shareWithIdentities = userManager.findIdentitiesByEmail(Collections.singletonList(invitation.getMail()));
        if (isAtLeastOneInSecurityGroup(shareWithIdentities, allUsers)) {
            mailEl.setErrorKey("map.share.with.mail.error.olatUser", new String[] { invitation.getMail() });
        }
    }
    policyWrapper.setFirstNameEl(firstNameEl);
    policyWrapper.setLastNameEl(lastNameEl);
    policyWrapper.setMailEl(mailEl);
    String link = getInvitationLink(invitation, map);
    StaticTextElement linkEl = uifactory.addStaticTextElement("map.share.with.link." + cmpName, link, invitationContainer);
    linkEl.setLabel("map.share.with.link", null);
}
Also used : StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity)

Example 18 with StaticTextElement

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

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)

Example 19 with StaticTextElement

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

the class EPStructureDetailsController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    if (formLayout.getFormComponent("struct.title") != null) {
        formLayout.remove("struct.title");
    }
    titleEl = uifactory.addTextElement("struct.title", "struct.title", 512, editStructure.getTitle(), formLayout);
    titleEl.setNotEmptyCheck("map.title.not.empty");
    titleEl.setMandatory(true);
    // choose representation mode (table or minimized artefact-view)
    if (formLayout.getFormComponent("view.mode") != null) {
        formLayout.remove("view.mode");
    }
    final String[] theKeys = new String[] { VIEWMODE_TABLE, VIEWMODE_MINI };
    final String[] theValues = new String[] { translate("view.mode." + VIEWMODE_TABLE), translate("view.mode." + VIEWMODE_MINI) };
    viewRadio = uifactory.addRadiosHorizontal("view.mode", formLayout, theKeys, theValues);
    final String artRepMode = editStructure.getArtefactRepresentationMode();
    if (artRepMode != null) {
        viewRadio.select(artRepMode, true);
    } else {
        viewRadio.select(VIEWMODE_MINI, true);
    }
    if (formLayout.getFormComponent("struct.description") != null) {
        formLayout.remove("struct.description");
    }
    descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("struct.description", "struct.description", editStructure.getDescription(), -1, -1, formLayout, getWindowControl());
    descriptionEl.setMaxLength(2047);
    descriptionEl.setNotLongerThanCheck(2047, "map.description.too.long");
    // hint for no edit options
    if (formLayout.getFormComponent("noEditInfo") != null) {
        formLayout.remove("noEditInfo");
    }
    noEditInfo = uifactory.addStaticTextElement("noEditInfo", "no.edit.info.label", translate("no.edit.info"), formLayout);
    noEditInfo.setVisible(false);
    if (formLayout.getFormComponent("collect.restriction") != null) {
        formLayout.remove("collect.restriction");
    }
    // show restrictions only for templates and on page/structure-level, as artefacts are not linkable on maps itself
    if (editStructure instanceof EPStructureElement && rootStructure instanceof EPStructuredMapTemplate && editStructure.getRoot() != null) {
        final FormLayoutContainer collectContainer = FormLayoutContainer.createCustomFormLayout("collect.restriction", getTranslator(), velocity_root + "/restrictions.html");
        collectContainer.setRootForm(mainForm);
        collectContainer.setLabel("collect.restriction", null);
        formLayout.add(collectContainer);
        final String[] restrictionKeys = new String[] { "", RestrictionsConstants.MAX, RestrictionsConstants.EQUAL, RestrictionsConstants.MIN };
        final String[] restrictionValues = new String[restrictionKeys.length];
        restrictionValues[0] = "";
        for (int i = 1; i < restrictionKeys.length; i++) {
            restrictionValues[i] = translate("restriction." + restrictionKeys[i]);
        }
        // allow only to use enabled handlers
        final List<EPArtefactHandler<?>> handlers = portfolioModule.getArtefactHandlers();
        final String[] artefactKeys = new String[handlers.size() + 1];
        final String[] artefactValues = new String[artefactKeys.length];
        artefactValues[0] = artefactKeys[0] = "";
        for (int i = 0; i < handlers.size(); i++) {
            final EPArtefactHandler<?> handler = handlers.get(i);
            artefactKeys[i + 1] = handler.getType();
            final String handlerClass = PortfolioFilterController.HANDLER_PREFIX + handler.getClass().getSimpleName() + PortfolioFilterController.HANDLER_TITLE_SUFFIX;
            artefactValues[i + 1] = handler.getHandlerTranslator(getTranslator()).translate(handlerClass);
        }
        if (collectRestrictions.isEmpty()) {
            collectRestrictions.add(new CollectRestriction());
        }
        restrictionElements = new ArrayList<SingleSelection>();
        restrictToArtefactElements = new ArrayList<SingleSelection>();
        amountElements = new ArrayList<TextElement>();
        errorElements = new ArrayList<StaticTextElement>();
        final List<String> counts = new ArrayList<String>();
        for (final CollectRestriction restriction : collectRestrictions) {
            final int count = restrictionElements.size();
            final SingleSelection restrictionElement = uifactory.addDropdownSingleselect("collect.restriction.restriction." + count, "", collectContainer, restrictionKeys, restrictionValues, null);
            restrictionElement.setDomReplacementWrapperRequired(false);
            restrictionElement.setMandatory(true);
            if (restriction != null && StringHelper.containsNonWhitespace(restriction.getRestriction())) {
                restrictionElement.select(restriction.getRestriction(), true);
            }
            restrictionElement.setUserObject(restriction);
            final SingleSelection restrictToArtefactElement = uifactory.addDropdownSingleselect("collect.restriction.artefacts." + count, "", collectContainer, artefactKeys, artefactValues, null);
            restrictToArtefactElement.setDomReplacementWrapperRequired(false);
            restrictToArtefactElement.setMandatory(true);
            if (restriction != null && StringHelper.containsNonWhitespace(restriction.getArtefactType())) {
                restrictToArtefactElement.select(restriction.getArtefactType(), true);
            }
            String amountStr = "";
            if (restriction != null && restriction.getAmount() > 0) {
                amountStr = Integer.toString(restriction.getAmount());
            }
            final TextElement amountElement = uifactory.addTextElement("collect.restriction.amount." + count, null, 2, amountStr, collectContainer);
            amountElement.setDomReplacementWrapperRequired(false);
            amountElement.setDisplaySize(3);
            StaticTextElement errorElement = uifactory.addStaticTextElement("collect.restriction.error." + count, null, "", collectContainer);
            errorElement.setVisible(false);
            restrictionElements.add(restrictionElement);
            restrictToArtefactElements.add(restrictToArtefactElement);
            amountElements.add(amountElement);
            errorElements.add(errorElement);
            final FormLink addLink = uifactory.addFormLink("collect.restriction.add." + count, "collect.restriction.add", "collect.restriction.add", collectContainer, Link.BUTTON_SMALL);
            addLink.setDomReplacementWrapperRequired(false);
            addLink.setUserObject(restriction);
            final FormLink delLink = uifactory.addFormLink("collect.restriction.del." + count, "collect.restriction.delete", "collect.restriction.delete", collectContainer, Link.BUTTON_SMALL);
            delLink.setDomReplacementWrapperRequired(false);
            delLink.setUserObject(restriction);
            counts.add(Integer.toString(count));
        }
        collectContainer.contextPut("counts", counts);
    }
    if (formLayout.getFormComponent("save") != null) {
        formLayout.remove("save");
    }
    uifactory.addFormSubmitButton("save", formLayout);
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) EPArtefactHandler(org.olat.portfolio.EPArtefactHandler) 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) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement)

Example 20 with StaticTextElement

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

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)

Aggregations

StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)30 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)20 ArrayList (java.util.ArrayList)8 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)8 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)8 Identity (org.olat.core.id.Identity)8 SecurityGroup (org.olat.basesecurity.SecurityGroup)6 Date (java.util.Date)4 DateChooser (org.olat.core.gui.components.form.flexible.elements.DateChooser)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)4 FormSubmit (org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit)4 BusinessControlFactory (org.olat.core.id.context.BusinessControlFactory)4 ContextEntry (org.olat.core.id.context.ContextEntry)4 TaskDueDate (org.olat.course.nodes.gta.TaskDueDate)4 DueDate (org.olat.course.nodes.gta.model.DueDate)4 ModuleConfiguration (org.olat.modules.ModuleConfiguration)4 CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)4 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)4 File (java.io.File)2