コード例 #1
0
  public void setItem(QuestionItem item) {
    QEducationalContext context = item.getEducationalContext();
    if (context == null || context.getLevel() == null) {
      contextEl.setValue("");
    } else {
      String translation = translate("item.level." + context.getLevel().toLowerCase());
      if (translation.length() > 128) {
        translation = context.getLevel();
      }
      contextEl.setValue(translation);
    }

    String learningTime = durationToString(item);
    learningTimeEl.setValue(learningTime);
  }
コード例 #2
0
  /**
   * @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);
      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 = bcf.getAsURIString(entries, true);
      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);
    businessGroupMinimumMembers.setVisible(false); // currently the minimum feature is not enabled
    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
    businessGroupMinimumMembers.setVisible(false); // currently the minimum feature is not enabled
    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");
      }
    }
  }
コード例 #3
0
  /** 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 iterator = project.getProjectLeaders().iterator(); iterator.hasNext(); ) {
      Identity 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(
                ProjectBrokerManagerFactory.getProjectBrokerManager()
                    .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, null);
    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(listener, 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
        uifactory.addStaticTextElement(
            "customField_label" + customFieldIndex,
            null,
            customField.getName(),
            formLayout); // null > no label
        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
        uifactory.addStaticTextElement(
            "customField_label" + customFieldIndex,
            null,
            customField.getName(),
            formLayout); // null > no label
        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))) {
            String key =
                Integer.toString(
                    valueList.indexOf(project.getCustomFieldValue(customFieldIndex))
                        + 1); // '+1' because no-selection at the beginning
            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("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(this, FormEvent.ONCHANGE);

    mailNotification =
        uifactory.addCheckboxesHorizontal(
            "detailsform.mail.notification.label", formLayout, keys, values, null);
    mailNotification.select(keys[0], project.isMailNotificationEnabled());

    FormLayoutContainer buttonGroupLayout =
        FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
    formLayout.add(buttonGroupLayout);
    uifactory.addFormSubmitButton("save", buttonGroupLayout);
    if (this.enableCancel) {
      uifactory.addFormCancelButton(
          "cancel",
          buttonGroupLayout,
          ureq,
          getWindowControl()); // TODO: Frage an PB: Warum flc hier noetig ???
    }
  }