private void initTagFlc() {
   tagFlc.setLabel("filter.tag", null);
   tagAllBtn = uifactory.addToggleButton("filter.all", null, tagFlc, null, null);
   tagAllBtn.toggleOff();
   tagNoneBtn = uifactory.addToggleButton("filter.notag", null, tagFlc, null, null);
   final Map<String, String> userTags = ePFMgr.getUsersMostUsedTags(getIdentity(), 8);
   int i = 1;
   tagCmpList = new ArrayList<FormToggle>();
   final LinkedList<Entry<String, String>> sortEntrySet =
       new LinkedList<Entry<String, String>>(userTags.entrySet());
   Collections.sort(
       sortEntrySet,
       new Comparator<Entry<String, String>>() {
         @Override
         public int compare(final Entry<String, String> arg0, final Entry<String, String> arg1) {
           return arg0.getValue().compareTo(arg1.getValue());
         }
       });
   final List<String> allActiveTagToggles = new ArrayList<String>();
   for (final Entry<String, String> entry : sortEntrySet) {
     final String tag = entry.getValue();
     final String tagCmpName = TAG_CMP_IDENTIFIER + i;
     if (tagFlc.getComponent(tagCmpName) != null) {
       tagFlc.remove(tagCmpName);
     }
     final FormToggle link = uifactory.addToggleButton(tagCmpName, tag, tagFlc, null, null);
     link.setLabel("tag.one", new String[] {tag});
     link.setUserObject(tag);
     if (!selectedTagsList.isEmpty() && selectedTagsList.contains(tag)) {
       link.toggleOn();
       allActiveTagToggles.add(tag);
     }
     tagCmpList.add(link);
     i++;
   }
   tagFlc.contextPut("tagCmpList", tagCmpList);
   tagEditBtn = uifactory.addToggleButton("filter.edit", null, tagFlc, null, null);
   tagEditBtn.toggleOff();
   if (!allActiveTagToggles.containsAll(selectedTagsList)) {
     tagEditBtn.toggleOn();
   }
   if (selectedTagsList.isEmpty()) {
     tagAllBtn.toggleOn();
   }
 }
Пример #2
0
  @Override
  protected void initForm(
      final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    setFormTitle("pane.tab.infos_config.title");
    setFormContextHelp(
        InfoConfigForm.class.getPackage().getName(),
        "ced-info-config.html",
        "help.hover.info.config");

    final String page = velocity_root + "/editShow.html";
    final FormLayoutContainer showLayout =
        FormLayoutContainer.createCustomFormLayout(
            "pane.tab.infos_config.shown", getTranslator(), page);
    showLayout.setLabel("pane.tab.infos_config.shown", null);
    formLayout.add(showLayout);

    durationSelection =
        uifactory.addDropdownSingleselect(
            "pane.tab.infos_config.max_duration",
            showLayout,
            maxDurationValues,
            maxDurationValues,
            null);
    durationSelection.setLabel("pane.tab.infos_config.max", null);
    final String durationStr = (String) config.get(InfoCourseNodeConfiguration.CONFIG_DURATION);
    if (StringHelper.containsNonWhitespace(durationStr)) {
      durationSelection.select(durationStr, true);
    } else {
      durationSelection.select("30", true);
    }

    lengthSelection =
        uifactory.addDropdownSingleselect(
            "pane.tab.infos_config.max_shown", showLayout, maxLengthValues, maxLengthValues, null);
    lengthSelection.setLabel("pane.tab.infos_config.max", null);
    final String lengthStr = (String) config.get(InfoCourseNodeConfiguration.CONFIG_LENGTH);
    if (StringHelper.containsNonWhitespace(lengthStr)) {
      lengthSelection.select(lengthStr, true);
    } else {
      lengthSelection.select("5", true);
    }

    uifactory.addFormSubmitButton("save", formLayout);
  }
 private void initOrUpdateTypeFlc(final int limit) {
   typeFlc.setLabel("filter.view", null);
   typeAllBtn = uifactory.addToggleButton("filter.all", null, typeFlc, null, null);
   typeAllBtn.toggleOff();
   final List<EPArtefactHandler<?>> handlers = portfolioModule.getAllAvailableArtefactHandlers();
   typeCmpList = new ArrayList<FormToggle>();
   int i = 0;
   final List<String> allActiveTypeToggles = new ArrayList<String>();
   for (final EPArtefactHandler<?> handler : handlers) {
     final String handlerClass =
         PortfolioFilterController.HANDLER_PREFIX
             + handler.getClass().getSimpleName()
             + HANDLER_TITLE_SUFFIX;
     FormToggle link = (FormToggle) typeFlc.getFormComponent(handlerClass);
     if (link == null) {
       final PackageTranslator handlerTrans = handler.getHandlerTranslator(getTranslator());
       typeFlc.setTranslator(handlerTrans);
       link = uifactory.addToggleButton(handlerClass, null, typeFlc, null, null);
       link.setUserObject(handler.getType());
     }
     if (selectedTypeList.contains(handler.getType())) {
       link.toggleOn();
       allActiveTypeToggles.add(handler.getType());
     } else {
       link.toggleOff();
     }
     typeCmpList.add(link);
     i++;
     if (i > limit) {
       break;
     }
   }
   typeFlc.contextPut("typeCmpList", typeCmpList);
   typeEditBtn = uifactory.addToggleButton("filter.edit", null, typeFlc, null, null);
   typeEditBtn.toggleOff();
   if (!allActiveTypeToggles.containsAll(selectedTypeList)) {
     typeEditBtn.toggleOn();
   }
   if (selectedTypeList.isEmpty()) {
     typeAllBtn.toggleOn();
   }
 }
  /**
   * org.olat.presentation.framework.control.Controller,
   * org.olat.presentation.framework.UserRequest)
   */
  @Override
  protected void initForm(
      final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    emailOrUsername =
        uifactory.addTextElement("emailOrUsername", "email.or.username", -1, null, formLayout);
    emailOrUsername.setMandatory(true);
    emailOrUsername.setNotEmptyCheck("email.or.username.maynotbeempty");

    final FormLayoutContainer buttonLayout =
        FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    this.flc.add(buttonLayout);
    uifactory.addFormSubmitButton("submit", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
  }
  /**
   * Adds a sublayout to the form. If the user selects no from the vertical radio buttons, the
   * sublayout shows up and the user is asked to provide more information.
   *
   * @param formItemsFactory
   * @param form
   */
  private void addSublayout(final FormItemContainer form) {
    // Default Sublayout
    final FormLayoutContainer subLayout =
        FormLayoutContainer.createDefaultFormLayout("why_not_form", getTranslator());
    // This doesn't work for some reason
    // subLayout.setVisible(false);
    form.add(subLayout);

    // Add a text element
    uifactory.addTextElement("why_not", "advanced_form.why_not?", 512, null, subLayout);

    // Let's try some show/hide rules. If 'No' is selected, the sublayout shows
    // up. Note: It's important to set the horizontal radio buttons to a default
    // value.
    RulesFactory.createHideRule(horizontalRadioButtons, yesOrNoKeys[0], subLayout, form);
    RulesFactory.createShowRule(horizontalRadioButtons, yesOrNoKeys[1], subLayout, form);
  }
  @SuppressWarnings("unused")
  protected void initOrUpdateForm(
      final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    // filter by tag
    if (formLayout.getFormComponent("tagLayout") == null) {
      tagFlc =
          FormLayoutContainer.createCustomFormLayout(
              "tagLayout", getTranslator(), this.velocity_root + "/filter-tags.html");
      formLayout.add(tagFlc);
      initTagFlc();
    } else {
      updateTagFlc();
    }

    // filter by type
    if (formLayout.getFormComponent("typeLayout") == null) {
      typeFlc =
          FormLayoutContainer.createCustomFormLayout(
              "typeLayout", getTranslator(), this.velocity_root + "/filter-types.html");
      formLayout.add(typeFlc);
      initOrUpdateTypeFlc(DEFAULT_TYPE_AMOUNT);
    } else {
      updateTypeFlc();
    }

    // filter by date
    if (formLayout.getFormComponent("dateLayout") == null) {
      final String page = this.velocity_root + "/filter_date.html";
      dateFlc = FormLayoutContainer.createCustomFormLayout("dateLayout", getTranslator(), page);
      formLayout.add(dateFlc);
      dateFlc.setLabel("filter.by.date", null);
      dateStart = uifactory.addDateChooser("filter.date.start", "", dateFlc);
      dateStart.addActionListener(this, FormEvent.ONCHANGE);
      dateEnd = uifactory.addDateChooser("filter.date.end", "", dateFlc);
      dateEnd.addActionListener(listener, FormEvent.ONCHANGE);
      dateStart.clearError();
      dateEnd.clearError();
    }

    if (filterSettings.getDateFilter().size() == 2) {
      dateStart.setDate(filterSettings.getDateFilter().get(0));
      dateEnd.setDate(filterSettings.getDateFilter().get(1));
    } else {
      dateStart.setDate(null);
      dateEnd.setDate(new Date());
    }

    // filter by fulltext
    final String searchText = filterSettings.getTextFilter();
    if (formLayout.getFormComponent("search") == null) {
      searchFld = uifactory.addTextElement("search", "filter.search", 20, searchText, formLayout);
      searchFld.addActionListener(listener, FormEvent.ONCHANGE);
    } else {
      searchFld.setValue(searchText);
    }

    // show filter list and save as new
    if (formLayout.getFormComponent("spacer") == null) {
      uifactory.addSpacerElement("spacer", formLayout, false);
    }

    // filter list
    initFilterList(formLayout);
    // filter save
    if (formLayout.getFormComponent("filterSaveLayout") == null) {
      filterFlc =
          FormLayoutContainer.createHorizontalFormLayout("filterSaveLayout", getTranslator());
      formLayout.add(filterFlc);
      filterFlc.setLabel("filter.save", null);
      filterName =
          uifactory.addTextElement(
              "filter.save.name", null, 30, filterSettings.getFilterName(), filterFlc);
      filterSave =
          uifactory.addFormLink(
              "filter.save.link", "filter.save.new", null, filterFlc, Link.BUTTON_XSMALL);
      filterDel =
          uifactory.addFormLink(
              "filter.del.link", "filter.del.link", null, filterFlc, Link.BUTTON_XSMALL);
    } else {
      filterName.setValue(filterSettings.getFilterName());
    }

    final boolean isExistingFilter = filterSettings.getFilterName() != null;
    toggleSaveUpdateFilterButtons(isExistingFilter);
  }
  /**
   * org.olat.presentation.framework.control.Controller,
   * org.olat.presentation.framework.UserRequest)
   */
  @Override
  @SuppressWarnings("unused")
  // listener is never used because listener == this!
  protected void initForm(
      final FormItemContainer formLayout, final Controller listener, final UserRequest ureq) {
    setFormTitle("guidemo_flexi_form_advanced");
    setFormDescription("advanced_form.description");
    // setFormContextHelp(this.getClass().getPackage().getName(),
    // "advancedFormHelp", "advanced_form.description");
    // Mandatory and read-only text fields

    this.addTextFields(formLayout);

    // More form items: Date, link and file selector
    this.addDateLinkAndFileItems(formLayout);

    // Separator with line
    uifactory.addSpacerElement("spacer", formLayout, false);

    // Single and multible selections (radio buttons and checkboxes)
    this.addSelections(formLayout);

    // Separator without line
    uifactory.addSpacerElement("spacernoline", formLayout, true);

    // Sublayout (shown if no is selected)
    this.addSublayout(formLayout);

    // Here's a text area
    uifactory.addTextAreaElement("guidemo.form.textarea", 0, 2, null, formLayout);

    // Add some rich text elements
    richTextElement =
        uifactory.addRichTextElementForStringData(
            "guidemo.form.richtext.simple",
            "guidemo.form.richtext.simple",
            "click <i>to</i> <b>edit</b>. This one has an event listener and an <b>external menu with auto hide</b>",
            -1,
            -1,
            true,
            false,
            null,
            null,
            formLayout,
            ureq.getUserSession(),
            getWindowControl());
    // richTextElement.addActionListener(this, FormEvent.ONCHANGE);

    richTextElement2 =
        uifactory.addRichTextElementForStringData(
            "guidemo.form.richtext.simple2",
            null,
            "one <i>with</i> <b>height</b> and <span style='color:red'>no</span> event listener and an <b>internal</b> menu",
            10,
            40,
            false,
            true,
            null,
            null,
            formLayout,
            ureq.getUserSession(),
            getWindowControl());

    disabledRichTextElement =
        uifactory.addRichTextElementForStringData(
            "guidemo.form.richtext.simple3",
            "guidemo.form.richtext.simple",
            "this <i>is</i> <b>disabled</b>",
            -1,
            -1,
            true,
            false,
            null,
            null,
            formLayout,
            ureq.getUserSession(),
            getWindowControl());
    disabledRichTextElement.setEnabled(false);

    // Button layout
    final FormLayoutContainer buttonLayout =
        FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);

    // Submit and cancel buttons (without effect)
    uifactory.addFormSubmitButton("advanced_form.submit", buttonLayout);
    uifactory.addFormLink("advanced_form.cancel", buttonLayout, Link.BUTTON);
  }