Example #1
0
 /** {@inheritDoc} */
 @Override
 protected void formOK(UserRequest ureq) {
   // read data from form elements
   for (int i = 0; i < lTargetInputList.size(); i++) {
     LLModel link = (LLModel) lTargetInputList.get(i).getUserObject();
     String linkValue = lTargetInputList.get(i).getValue();
     if (link.isIntern()) {
       if (!linkValue.contains("://") && !linkValue.startsWith("/")) {
         linkValue = "/".concat(linkValue.trim());
         lTargetInputList.get(i).setValue(linkValue);
       }
     } else if (!linkValue.contains("://")) {
       linkValue = "http://".concat(linkValue.trim());
       lTargetInputList.get(i).setValue(linkValue);
     }
     link.setTarget(linkValue);
     boolean blank = lHtmlTargetInputList.get(i).isSelected(0);
     if (linkValue.startsWith(Settings.getServerContextPathURI())) {
       // links to OO pages open in same window
       blank = false;
       lHtmlTargetInputList.get(i).select(SELF_KEY, true);
     }
     link.setHtmlTarget(blank ? BLANK_KEY : SELF_KEY);
     link.setDescription(lDescriptionInputList.get(i).getValue());
     link.setComment(lCommentInputList.get(i).getValue());
   }
   moduleConfig.set(LLCourseNode.CONF_LINKLIST, linkList);
   // Inform all listeners about the changes
   fireEvent(ureq, NodeEditController.NODECONFIG_CHANGED_EVENT);
 }
Example #2
0
  @Override
  protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == mediaDialogBox) {
      removeAsListenerAndDispose(mediaDialogBox);
      removeAsListenerAndDispose(mediaChooserController);
      mediaDialogBox = null;
      mediaChooserController = null;
    } else if (source == mediaChooserController) {
      if (event instanceof URLChoosenEvent) {
        URLChoosenEvent choosenEvent = (URLChoosenEvent) event;
        String url = choosenEvent.getURL();
        if (url.startsWith(Settings.getServerContextPathURI())) {
          // doesn't allow absolute path -> the mapper check if the link is in the list!
          url = url.substring(Settings.getServerContextPathURI().length());
        }
        currentLink.setTarget(url);
        currentLink.setIntern(true);
        currentLink.setHtmlTarget(SELF_KEY);
        if (StringHelper.containsNonWhitespace(choosenEvent.getDisplayName())) {
          currentLink.setDescription(choosenEvent.getDisplayName());
        }

        int index = 0;
        for (TextElement targetEl : lTargetInputList) {
          if (currentLink.equals(targetEl.getUserObject())) {
            targetEl.setValue(url);
            targetEl.setEnabled(false);
            lDescriptionInputList.get(index).setValue(currentLink.getDescription());
            lHtmlTargetInputList.get(index).select(SELF_KEY, true);
            break;
          }
          index++;
        }
      }
      mediaDialogBox.deactivate();
      removeAsListenerAndDispose(mediaDialogBox);
      removeAsListenerAndDispose(mediaChooserController);
      mediaDialogBox = null;
      mediaChooserController = null;
    }

    super.event(ureq, source, event);
  }
Example #3
0
  /**
   * Add a new form link line to the list of link elements.
   *
   * @param link the link model object
   */
  private void addNewFormLink(int index, final LLModel link) {
    // add link target
    TextElement lTarget =
        uifactory.addTextElement("target" + counter, null, -1, link.getTarget(), flc);
    lTarget.clearError();
    lTarget.setEnabled(!link.isIntern());
    lTarget.setDisplaySize(40);
    lTarget.setMandatory(true);
    lTarget.setExampleKey("target.example", null);
    lTarget.setNotEmptyCheck("ll.table.target.error");
    lTarget.setItemValidatorProvider(
        new ItemValidatorProvider() {
          public boolean isValidValue(
              String value, ValidationError validationError, Locale locale) {
            try {
              if (!value.contains("://")) {
                value = "http://".concat(value);
              }
              new URL(value);
            } catch (MalformedURLException e) {
              validationError.setErrorKey("ll.table.target.error.format");
              return false;
            }
            return true;
          }
        });
    lTarget.addActionListener(FormEvent.ONCHANGE);
    lTarget.setUserObject(link);
    lTargetInputList.add(index, lTarget);
    // add html target
    SingleSelection htmlTargetSelection =
        uifactory.addDropdownSingleselect(
            "html_target" + counter,
            flc,
            new String[] {BLANK_KEY, SELF_KEY},
            new String[] {
              translate("ll.table.html_target"), translate("ll.table.html_target.self")
            },
            null);
    htmlTargetSelection.setUserObject(link);
    htmlTargetSelection.select(
        (SELF_KEY.equals(link.getHtmlTarget()) ? SELF_KEY : BLANK_KEY), true);
    lHtmlTargetInputList.add(index, htmlTargetSelection);

    // add link description
    TextElement lDescription =
        uifactory.addTextElement("description" + counter, null, -1, link.getDescription(), flc);
    lDescription.clearError();
    lDescription.setDisplaySize(20);
    lDescription.setNotEmptyCheck("ll.table.description.error");
    lDescription.setMandatory(true);
    lDescription.setExampleKey("ll.table.description", null);
    lDescription.setUserObject(link);
    lDescriptionInputList.add(index, lDescription);

    // add link comment
    TextElement lComment =
        uifactory.addTextAreaElement(
            "comment" + counter, null, -1, 2, 50, true, link.getComment(), flc);
    lComment.setDisplaySize(20);
    lComment.setExampleKey("ll.table.comment", null);
    lComment.setUserObject(link);
    lCommentInputList.add(index, lComment);

    // add link add action button
    FormLink addButton =
        new FormLinkImpl(
            "add" + counter, "add" + counter, "", Link.BUTTON_SMALL + Link.NONTRANSLATED);
    addButton.setUserObject(link);
    addButton.setIconLeftCSS("o_icon o_icon-lg o_icon-fw o_icon_add");
    flc.add(addButton);
    lAddButtonList.add(index, addButton);
    // add link deletion action button
    FormLink delButton =
        new FormLinkImpl(
            "delete" + counter, "delete" + counter, "", Link.BUTTON_SMALL + Link.NONTRANSLATED);
    delButton.setUserObject(link);
    delButton.setIconLeftCSS("o_icon o_icon-lg o_icon-fw o_icon_delete_item");
    flc.add(delButton);
    lDelButtonList.add(index, delButton);
    // custom media action button
    FormLink mediaButton =
        new FormLinkImpl("media" + counter, "media" + counter, "  ", Link.NONTRANSLATED);
    mediaButton.setIconLeftCSS("o_icon o_icon_browse o_icon-lg");
    mediaButton.setUserObject(link);
    flc.add(mediaButton);
    lCustomMediaButtonList.add(index, mediaButton);

    // increase the counter to enable unique component names
    counter++;
  }