Пример #1
0
 /**
  * used to position help icon inside div-class o_chelp_wrapper
  *
  * @param packageName
  * @param pageName
  * @param hoverTextKey
  * @return
  */
 public StringOutput contextHelpWithWrapper(
     String packageName, String pageName, String hoverTextKey) {
   StringOutput sb = new StringOutput(100);
   if (ContextHelpModule.isContextHelpEnabled()) {
     sb.append("<span class=\"o_chelp_wrapper\">");
     sb.append(contextHelp(packageName, pageName, hoverTextKey));
     sb.append("</span>");
   }
   return sb;
 }
Пример #2
0
 /**
  * Create a js command to open a specific context help page
  *
  * @param packageName
  * @param pageName
  * @return
  */
 public StringOutput contextHelpJSCommand(String packageName, String pageName) {
   StringOutput sb = new StringOutput(100);
   if (ContextHelpModule.isContextHelpEnabled()) {
     String langCode = renderer.getTranslator().getLocale().toString();
     sb.append("contextHelpWindow('");
     Renderer.renderNormalURI(sb, "help/");
     sb.append(langCode).append("/").append(packageName).append("/").append(pageName);
     sb.append("')");
   }
   return sb;
 }
Пример #3
0
 private void render(StringOutput sb, MemberView member) {
   List<BusinessGroupShort> groups = member.getGroups();
   if (groups != null && !groups.isEmpty()) {
     boolean and = false;
     for (BusinessGroupShort group : groups) {
       and = and(sb, and);
       if (group.getName() == null) {
         sb.append(group.getKey());
       } else {
         sb.append(StringHelper.escapeHtml(group.getName()));
       }
     }
   }
 }
Пример #4
0
 public StringOutput contextHelpWithWrapper(String page) {
   StringOutput sb = new StringOutput(192);
   if (ContextHelpModule.isContextHelpEnabled()) {
     HelpModule helpModule = CoreSpringFactory.getImpl(HelpModule.class);
     Locale locale = renderer.getTranslator().getLocale();
     String url = helpModule.getHelpProvider().getURL(locale, page);
     if (url != null) {
       sb.append("<span class=\"o_chelp_wrapper\">")
           .append("<a href=\"")
           .append(url)
           .append("\" class=\"o_chelp\" target=\"_blank\"><i class='o_icon o_icon_help'></i> ")
           .append(renderer.getTranslator().translate("help"))
           .append("</a></span>");
     }
   }
   return sb;
 }
Пример #5
0
 @Override
 public void render(
     final StringOutput sb,
     final Renderer renderer,
     final Object val,
     final Locale locale,
     final int alignment,
     final String action) {
   if (renderer == null) {
     // render for export
     String value = getCellValue(val);
     if (!StringHelper.containsNonWhitespace(value)) {
       value = getHoverText(val);
     }
     sb.append(value);
   } else {
     sb.append("<i class='").append(getCssClass(val)).append("'> </i> <span");
     String hoverText = getHoverText(val);
     if (StringHelper.containsNonWhitespace(hoverText)) {
       sb.append(" title=\"");
       sb.append(StringEscapeUtils.escapeHtml(hoverText));
     }
     sb.append("\">");
     sb.append(getCellValue(val));
     sb.append("</span>");
   }
 }
Пример #6
0
 private StringOutput doRender(String componentName, String[] args) {
   Component source = renderer.findComponent(componentName);
   StringOutput sb;
   if (source == null) {
     sb = new StringOutput(128);
     sb.append(
         ">>>>>>>>>>>>>>>>>>>>>>>>>> component "
             + componentName
             + " could not be found to be rendered!");
   } else if (target == null) {
     sb = new StringOutput(10000);
     renderer.render(source, sb, args);
   } else {
     sb = new StringOutput(1);
     renderer.render(source, target, args);
   }
   return sb;
 }
 private void renderPageNextLink(StringOutput sb, FlexiTableComponent ftC, int page, int maxPage) {
   boolean disabled = (page >= maxPage);
   FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
   Form theForm = ftE.getRootForm();
   sb.append("<li ").append(" class='disabled'", disabled).append("><a href=\"");
   if (disabled) {
     sb.append("#");
   } else {
     sb.append("javascript:")
         .append(
             FormJSHelper.getXHRFnCallFor(
                 theForm,
                 ftC.getFormDispatchId(),
                 1,
                 new NameValuePair("page", Integer.toString(page + 1))));
   }
   sb.append("\">").append("&raquo;").append("</li></a>");
 }
  private void renderPagesLinks(StringOutput sb, FlexiTableComponent ftC, Translator translator) {
    FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
    int pageSize = ftE.getPageSize();
    FlexiTableDataModel<?> dataModel = ftE.getTableDataModel();
    int rows = dataModel.getRowCount();

    if (rows > 20) {
      renderPageSize(sb, ftC, translator);
    }

    sb.append("<ul class='pagination'>");
    if (pageSize > 0 && rows > pageSize) {
      int page = ftE.getPage();
      int maxPage = (int) Math.ceil(((double) rows / (double) pageSize));
      renderPageBackLink(sb, ftC, page);
      renderPageNumberLinks(sb, ftC, page, maxPage);
      renderPageNextLink(sb, ftC, page, maxPage);
    }
    sb.append("</ul>");
  }
Пример #9
0
 /**
  * Create a link that can be used within a context help page to link to another context help page
  * from another package. The link text can be specified as a thirt attribute.
  *
  * @param bundleName e.g. "org.olat.core"
  * @param pageName e.g. "my-page.html"
  * @return
  */
 public StringOutput contextHelpRelativeLink(String bundleName, String pageName, String linkText) {
   StringOutput sb = new StringOutput(100);
   if (ContextHelpModule.isContextHelpEnabled()) {
     sb.append("<a href=\"");
     if (bundleName == null) {
       renderer
           .getUrlBuilder()
           .buildURI(
               sb,
               new String[] {VelocityContainer.COMMAND_ID},
               new String[] {pageName},
               isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
     } else {
       renderer
           .getUrlBuilder()
           .buildURI(
               sb,
               new String[] {VelocityContainer.COMMAND_ID, PARAM_CHELP_BUNDLE},
               new String[] {pageName, bundleName},
               isIframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
     }
     sb.append("\" ");
     if (isIframePostEnabled) {
       renderer.getUrlBuilder().appendTarget(sb);
     }
     sb.append(">");
     sb.append(linkText);
     sb.append("</a>");
   }
   return sb;
 }
  protected void renderFooterButtons(
      StringOutput sb, FlexiTableComponent ftC, Translator translator) {
    FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
    if (ftE.isSelectAllEnable()) {
      String formName = ftE.getRootForm().getFormName();
      String dispatchId = ftE.getFormDispatchId();

      sb.append("<div class='o_table_footer'><div class='o_table_checkall input-sm'>");

      sb.append("<label class='checkbox-inline'><a id='")
          .append(dispatchId)
          .append("_sa' href=\"javascript:o_table_toggleCheck('")
          .append(formName)
          .append("', true);")
          .append(
              FormJSHelper.getXHRFnCallFor(
                  ftE.getRootForm(), dispatchId, 1, new NameValuePair("select", "checkall")))
          .append("\"><i class='o_icon o_icon-lg o_icon_check_on'> </i> <span>")
          .append(translator.translate("form.checkall"))
          .append("</span></a></label>");

      sb.append("<label class='checkbox-inline'><a id='")
          .append(dispatchId)
          .append("_dsa' href=\"javascript:o_table_toggleCheck('")
          .append(formName)
          .append("', false);")
          .append(
              FormJSHelper.getXHRFnCallFor(
                  ftE.getRootForm(), dispatchId, 1, new NameValuePair("select", "uncheckall")))
          .append("\"><i class='o_icon o_icon-lg o_icon_check_off'> </i> <span>")
          .append(translator.translate("form.uncheckall"))
          .append("</span></a></label>");

      sb.append("</div></div>");
    }

    if (ftE.getDefaultPageSize() > 0) {
      renderPagesLinks(sb, ftC, translator);
    }
  }
  protected void renderHeaderSearch(
      Renderer renderer,
      StringOutput sb,
      FlexiTableElementImpl ftE,
      URLBuilder ubu,
      Translator translator,
      RenderResult renderResult,
      String[] args) {

    if (ftE.isSearchEnabled()) {
      sb.append("<div class='o_table_search input-group'>");
      renderFormItem(renderer, sb, ftE.getSearchElement(), ubu, translator, renderResult, args);
      sb.append("<div class='input-group-btn'>");
      renderFormItem(renderer, sb, ftE.getSearchButton(), ubu, translator, renderResult, args);
      if (ftE.getExtendedSearchButton() != null) {
        renderFormItem(
            renderer, sb, ftE.getExtendedSearchButton(), ubu, translator, renderResult, args);
      }
      sb.append("</div></div>");
    } else if (ftE.getExtendedSearchButton() != null) {
      renderFormItem(
          renderer, sb, ftE.getExtendedSearchButton(), ubu, translator, renderResult, args);
    }
  }
 private void appendPagenNumberLink(StringOutput sb, FlexiTableComponent ftC, int page, int i) {
   FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
   Form theForm = ftE.getRootForm();
   sb.append("<li")
       .append(" class='active'", (page == i))
       .append("><a href=\"javascript:")
       .append(
           FormJSHelper.getXHRFnCallFor(
               theForm,
               ftC.getFormDispatchId(),
               1,
               new NameValuePair("page", Integer.toString(i))))
       .append("\">")
       .append(i + 1)
       .append("</a></li>");
 }
  protected void renderSortDropdown(
      StringOutput sb, FlexiTableElementImpl ftE, List<FlexiTableSort> sorts) {
    Form theForm = ftE.getRootForm();
    String dispatchId = ftE.getFormDispatchId();

    sb.append("<div class='btn-group'>")
        .append("<button id='table-button-sorters-")
        .append(dispatchId)
        .append("' type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown'>")
        .append("<i class='o_icon o_icon_sort_menu o_icon-lg'> </i> <b class='caret'></b></button>")
        .append("<div id='table-sorters-")
        .append(dispatchId)
        .append("' class='hide'><ul class='o_dropdown list-unstyled' role='menu'>");

    for (FlexiTableSort sort : sorts) {
      if (FlexiTableSort.SPACER.equals(sort)) {
        sb.append("<li class='divider'></li>");
      } else {
        sb.append("<li><a href=\"javascript:")
            .append(
                FormJSHelper.getXHRFnCallFor(
                    theForm,
                    dispatchId,
                    1,
                    new NameValuePair("sort", sort.getSortKey().getKey()),
                    new NameValuePair("asc", sort.getSortKey().isAsc() ? "desc" : "asc")))
            .append("\">");
        if (sort.isSelected()) {
          if (sort.getSortKey().isAsc()) {
            sb.append("<i class='o_icon o_icon_sort_desc o_icon-fw'> </i> ");
          } else {
            sb.append("<i class='o_icon o_icon_sort_asc o_icon-fw'> </i> ");
          }
        }
        sb.append(sort.getLabel()).append("</a></li>");
      }
    }
    sb.append("</ul></div></div> ")
        .append("<script type='text/javascript'>\n")
        .append("/* <![CDATA[ */\n")
        .append("jQuery(function() { o_popover('table-button-sorters-")
        .append(dispatchId)
        .append("','table-sorters-")
        .append(dispatchId)
        .append("'); });\n")
        .append("/* ]]> */\n")
        .append("</script>");
  }
  protected String renderFilterDropdown(
      StringOutput sb, FlexiTableElementImpl ftE, List<FlexiTableFilter> filters) {
    Form theForm = ftE.getRootForm();
    String dispatchId = ftE.getFormDispatchId();
    String selected = null;

    sb.append("<div class='btn-group'>")
        .append("<button id='table-button-filters-")
        .append(dispatchId)
        .append("' type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown'>")
        .append("<i class='o_icon o_icon_filter o_icon-lg'> </i> <b class='caret'></b></button>")
        .append("<div id='table-filters-")
        .append(dispatchId)
        .append("' class='hide'><ul class='o_dropdown list-unstyled' role='menu'>");

    for (FlexiTableFilter filter : filters) {
      if (FlexiTableFilter.SPACER.equals(filter)) {
        sb.append("<li class='divider'></li>");
      } else {
        sb.append("<li><a href=\"javascript:")
            .append(
                FormJSHelper.getXHRFnCallFor(
                    theForm, dispatchId, 1, new NameValuePair("filter", filter.getFilter())))
            .append("\">")
            .append("<i class='o_icon o_icon_check o_icon-fw'> </i> ", filter.isSelected());
        if (filter.getIconLeftCSS() != null) {
          sb.append("<i class='o_icon ").append(filter.getIconLeftCSS()).append("'> </i> ");
        }
        sb.append(filter.getLabel()).append("</a></li>");
        if (filter.isSelected()) {
          selected = filter.getLabel();
        }
      }
    }
    sb.append("</ul></div></div> ")
        .append("<script type='text/javascript'>\n")
        .append("/* <![CDATA[ */\n")
        .append("jQuery(function() { o_popover('table-button-filters-")
        .append(dispatchId)
        .append("','table-filters-")
        .append(dispatchId)
        .append("'); });\n")
        .append("/* ]]> */\n")
        .append("</script>");
    return selected;
  }
Пример #15
0
 /**
  * @param packageName
  * @param pageName
  * @param hoverTextKey
  * @return
  */
 public StringOutput contextHelp(String packageName, String pageName, String hoverTextKey) {
   StringOutput sb = new StringOutput(100);
   if (ContextHelpModule.isContextHelpEnabled()) {
     String hooverText = renderer.getTranslator().translate(hoverTextKey);
     if (hooverText != null) {
       hooverText = StringEscapeUtils.escapeHtml(hooverText);
     }
     sb.append("<a href=\"javascript:");
     sb.append(contextHelpJSCommand(packageName, pageName));
     sb.append("\" title=\"")
         .append(hooverText)
         .append("\" class=\"o_chelp\"><i class='o_icon o_icon_help'></i> ");
     sb.append(renderer.getTranslator().translate("help"));
     sb.append("</a>");
   }
   return sb;
 }
Пример #16
0
  /**
   * @see org.olat.core.gui.render.ui.ComponentRenderer#render(org.olat.core.gui.render.Renderer,
   *     org.olat.core.gui.render.StringOutput, org.olat.core.gui.components.Component,
   *     org.olat.core.gui.render.URLBuilder, org.olat.core.gui.translator.Translator,
   *     org.olat.core.gui.render.RenderResult, java.lang.String[])
   */
  @Override
  public void render(
      Renderer renderer,
      StringOutput target,
      Component source,
      URLBuilder ubu,
      Translator translator,
      RenderResult renderResult,
      String[] args) {

    // Get the model object
    Choice choice = (Choice) source;
    ChoiceModel model = choice.getModel();

    boolean iframePostEnabled = renderer.getGlobalSettings().getAjaxFlags().isIframePostEnabled();
    // form header
    String id = choice.getComponentName() + "_" + choice.hashCode();
    target
        .append("<form method=\"post\" name=\"")
        .append(id)
        .append("\" id=\"")
        .append(id)
        .append("\" action=\"");
    ubu.buildURI(
        target, null, null, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
    target.append("\"");
    if (iframePostEnabled) {
      ubu.appendTarget(target);
    }
    if (choice.getElementCssClass() != null) {
      target.append(" class=\"").append(choice.getElementCssClass()).append("\"");
    }
    target.append(">");

    target.append("<table class=\"o_choice\">");
    int rows = model.getRowCount();
    for (int i = 0; i < rows; i++) {
      Boolean val = model.isEnabled(i);
      boolean selected = val == null ? false : val.booleanValue();
      boolean disabled = model.isDisabled(i);

      String keyN = "c" + i;
      target
          .append("<tr><td class='o_choice_checkrow'><input type='checkbox' class='o_checkbox'")
          .append(" checked='checked'", selected)
          .append(" disabled='disabled'", disabled)
          .append(" name='")
          .append(keyN)
          .append("' onchange=\"return setFormDirty('")
          .append(id)
          .append("')\"  />")
          .append("</td>");

      String label = model.getLabel(i);
      target.append("<td class='o_choice_textrow'>");
      if (choice.isEscapeHtml()) {
        target.append(StringEscapeUtils.escapeHtml(label));
      } else {
        target.append(label);
      }
      target.append("</td></tr>");
    }
    // Toggle all on/off
    target
        .append("<tr><td colspan='2' class=\"o_togglecheck\">")
        .append("<div class=\"o_togglecheck o_block_top\">")
        .append("<a href=\"#\" onclick=\"javascript:o_choice_toggleCheck('" + id + "', true)\">")
        .append("<i class='o_icon o_icon_fw o_icon_checkbox_checked'></i> ")
        .append(translator.translate("checkall"))
        .append(
            "</a> <a href=\"#\" onclick=\"javascript:o_choice_toggleCheck('" + id + "', false)\">")
        .append("<i class='o_icon o_icon_fw o_icon_checkbox'></i> ")
        .append(translator.translate("uncheckall"))
        .append("</a></div></td></tr>");

    // buttons
    target.append("<tr><td colspan='2'><div class='btn-group btn-group-xs o_block_top'>");
    // Submit button
    target
        .append("<input type='submit' name='olat_fosm' value=\"")
        .append(StringEscapeUtils.escapeHtml(translator.translate(choice.getSubmitKey())))
        .append("\" class='btn btn-primary' />");

    // Reset button
    String resetKey = choice.getResetKey();
    if (resetKey != null) {
      target
          .append("<input type='submit' name='")
          .append(Choice.RESET_IDENTIFICATION)
          .append("' value=\"")
          .append(StringEscapeUtils.escapeHtml(translator.translate(resetKey)))
          .append("\" class='btn btn-default' />");
    }

    // Cancel button
    String cancelKey = choice.getCancelKey();
    if (cancelKey != null) {
      target
          .append("<input type='submit' name='")
          .append(Choice.CANCEL_IDENTIFICATION)
          .append("' value=\"")
          .append(StringEscapeUtils.escapeHtml(translator.translate(cancelKey)))
          .append("\" class='btn btn-default' />");
    }
    target.append("</div></td></tr></table></form>");
  }
Пример #17
0
  /**
   * Test methods i18nManager inline translation tool and
   * InlineTranslationInterceptHandlerController
   */
  @Test
  public void testInlineTranslationReplaceLocalizationMarkupWithHTML() {
    // enable inline translation markup
    i18nMgr.setMarkLocalizedStringsEnabled(null, true);
    Translator inlineTrans =
        Util.createPackageTranslator(
            InlineTranslationInterceptHandlerController.class, i18nMgr.getLocaleOrNull("de"));
    URLBuilder inlineTranslationURLBuilder = new jUnitURLBuilder();
    String testBundle = "org.olat.core.util.i18n.junittestdata";
    String testKey = "no.need.to.translate.this";
    String rawtext1 = "Lorem impsum<b>nice stuff</b>";
    String rawtext2 = "Holderadio <ul>lsdfsdf<y  asdf blblb";
    String combinedKey = testBundle + ":" + testKey;
    // test method that adds identifyers around the translation items
    String plainVanillaWrapped =
        i18nMgr.getLocalizedString(
            testBundle, testKey, null, i18nMgr.getLocaleOrNull("de"), false, false);
    String plainVanillaPlain = "just a test";
    Pattern plainVanillaWrappedPattern =
        Pattern.compile(
            I18nManager.IDENT_PREFIX
                + combinedKey
                + ":([0-9]*?)"
                + I18nManager.IDENT_START_POSTFIX
                + plainVanillaPlain
                + I18nManager.IDENT_PREFIX
                + combinedKey
                + ":\\1"
                + I18nManager.IDENT_END_POSTFIX);
    Matcher m = plainVanillaWrappedPattern.matcher(plainVanillaWrapped);
    assertTrue(m.find());

    // test find-replace translator identifyers with HTML markup
    StringOutput inlineTransLink = new StringOutput();
    String[] args = (combinedKey + ":1000000001").split(":");
    InlineTranslationInterceptHandlerController.buildInlineTranslationLink(
        args, inlineTransLink, inlineTrans, inlineTranslationURLBuilder);
    // Plain vanilla text
    String convertedToHTMLMarkup =
        InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(
            plainVanillaWrapped, inlineTranslationURLBuilder, inlineTrans);
    assertEquals(
        "<span class=\"b_translation_i18nitem\">"
            + inlineTransLink.toString()
            + plainVanillaPlain
            + "</span>",
        convertedToHTMLMarkup);
    // Simple link
    String linkOPEN =
        "<a href=\"http://www.olat.org/bla/blu:bli#bla\" title='funny title' class=\"b_css b_anothercss\">";
    String linkCLOSE = "</a>";
    String inlineSpanOPEN = "<span class=\"b_translation_i18nitem\">";
    String inlineSpanCLOSE = "</span>";
    String translatedWithinLink = linkOPEN + plainVanillaWrapped + linkCLOSE + rawtext1;
    convertedToHTMLMarkup =
        InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(
            translatedWithinLink, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinLinkExpected =
        inlineSpanOPEN
            + inlineTransLink.toString()
            + linkOPEN
            + plainVanillaPlain
            + linkCLOSE
            + inlineSpanCLOSE
            + rawtext1;
    assertEquals(convertedWithinLinkExpected, convertedToHTMLMarkup);
    // Simple link with span
    String linkSpanOPEN = "<span class=\"bluber\">";
    String linkSpanCLOSE = "</span>";
    String translatedWithinLinkAndSpan =
        rawtext2 + linkOPEN + linkSpanOPEN + plainVanillaWrapped + linkSpanCLOSE + linkCLOSE;
    convertedToHTMLMarkup =
        InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(
            translatedWithinLinkAndSpan, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinLinkAndSpanExpected =
        rawtext2
            + inlineSpanOPEN
            + inlineTransLink.toString()
            + linkOPEN
            + linkSpanOPEN
            + plainVanillaPlain
            + linkSpanCLOSE
            + linkCLOSE
            + inlineSpanCLOSE;
    assertEquals(convertedWithinLinkAndSpanExpected, convertedToHTMLMarkup);
    // Muliple links
    String translatedWithinMultipleLinks =
        translatedWithinLink + translatedWithinLinkAndSpan + translatedWithinLinkAndSpan;
    convertedToHTMLMarkup =
        InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(
            translatedWithinMultipleLinks, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinMultipleLinksExpected =
        convertedWithinLinkExpected
            + convertedWithinLinkAndSpanExpected
            + convertedWithinLinkAndSpanExpected;
    assertEquals(convertedWithinMultipleLinksExpected, convertedToHTMLMarkup);
    // Input elements
    String inputOPEN = "<input type='submit' class=\"bluber\" value=\"";
    String inputCLOSE = "\" />";
    String translatedWithinInput = inputOPEN + plainVanillaWrapped + inputCLOSE + rawtext1;
    convertedToHTMLMarkup =
        InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(
            translatedWithinInput, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinInputExpected =
        inlineSpanOPEN
            + inlineTransLink.toString()
            + inputOPEN
            + plainVanillaPlain
            + inputCLOSE
            + inlineSpanCLOSE
            + rawtext1;
    assertEquals(convertedWithinInputExpected, convertedToHTMLMarkup);
    // checkbox elements
    String checkboxOPEN = "<input type='submit' class=\"bluber\" type=\"checkbox\" value=\"";
    String checkboxCLOSE = "\" />";
    String translatedWithinCheckbox = checkboxOPEN + plainVanillaWrapped + checkboxCLOSE + rawtext1;
    convertedToHTMLMarkup =
        InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(
            translatedWithinCheckbox, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinCheckboxExpected =
        checkboxOPEN + plainVanillaPlain + checkboxCLOSE + rawtext1;
    assertEquals(convertedWithinCheckboxExpected, convertedToHTMLMarkup);
    // Input and links mixed
    String translatedWithinMultipleLinksAndInput =
        translatedWithinLink
            + rawtext1
            + translatedWithinInput
            + translatedWithinLinkAndSpan
            + rawtext2
            + translatedWithinInput
            + translatedWithinLinkAndSpan;
    convertedToHTMLMarkup =
        InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(
            translatedWithinMultipleLinksAndInput, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinMultipleLinksAndInputExpected =
        convertedWithinLinkExpected
            + rawtext1
            + convertedWithinInputExpected
            + convertedWithinLinkAndSpanExpected
            + rawtext2
            + convertedWithinInputExpected
            + convertedWithinLinkAndSpanExpected;
    assertEquals(convertedWithinMultipleLinksAndInputExpected, convertedToHTMLMarkup);
    // Within element attribute
    String attributeOPEN = "<a href='sdfsdf' title=\"";
    String attributeCLOSE = "\" class=\"b_bluber\">hello world</a>";
    String translatedWithinAttribute =
        attributeOPEN + plainVanillaWrapped + attributeCLOSE + rawtext1;
    convertedToHTMLMarkup =
        InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(
            translatedWithinAttribute, inlineTranslationURLBuilder, inlineTrans);
    String convertedWithinAttributeExpected =
        attributeOPEN + plainVanillaPlain + attributeCLOSE + rawtext1;
    assertEquals(convertedWithinAttributeExpected, convertedToHTMLMarkup);
    // Ultimate test
    String translatedUltimate =
        translatedWithinMultipleLinksAndInput
            + rawtext1
            + translatedWithinAttribute
            + translatedWithinMultipleLinksAndInput
            + rawtext2
            + translatedWithinInput
            + translatedWithinLinkAndSpan;
    convertedToHTMLMarkup =
        InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(
            translatedUltimate, inlineTranslationURLBuilder, inlineTrans);
    String convertedUltimateExpected =
        convertedWithinMultipleLinksAndInputExpected
            + rawtext1
            + convertedWithinAttributeExpected
            + convertedWithinMultipleLinksAndInputExpected
            + rawtext2
            + convertedWithinInputExpected
            + convertedWithinLinkAndSpanExpected;
    assertEquals(convertedUltimateExpected, convertedToHTMLMarkup);

    // don't do inline translation markup
    i18nMgr.setMarkLocalizedStringsEnabled(null, false);
  }
Пример #18
0
 public void buildURI(StringOutput buf, String[] keys, String[] values) {
   buf.append("http://do.test.com");
 }
  /**
   * @see org.olat.core.gui.components.ComponentRenderer#render(org.olat.core.gui.render.Renderer,
   *     org.olat.core.gui.render.StringOutput, org.olat.core.gui.components.Component,
   *     org.olat.core.gui.render.URLBuilder, org.olat.core.gui.translator.Translator,
   *     org.olat.core.gui.render.RenderResult, java.lang.String[])
   */
  @Override
  public void render(
      Renderer renderer,
      StringOutput sb,
      Component source,
      URLBuilder ubu,
      Translator translator,
      RenderResult renderResult,
      String[] args) {
    DateComponent dateC = (DateComponent) source;
    Date date = dateC.getDate();
    Locale locale = translator.getLocale();

    sb.append("<div class=\"b_datecomp ");
    // Optional css class as render arg
    if (args != null && args.length == 1) {
      sb.append(args[0]);
    }
    sb.append("\">");
    // Add year if configured
    if (dateC.isShowYear()) {
      SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy", locale);
      String year = yearFormat.format(date);
      sb.append("<div class=\"b_year b_year_").append(year);
      sb.append("\"><span>");
      sb.append(year);
      sb.append("</span>");
      sb.append("</div>");
    }
    // Add month.
    SimpleDateFormat monthNumberFormat = new SimpleDateFormat("MM", locale);
    sb.append("<div class=\"b_month b_month_").append(monthNumberFormat.format(date));
    sb.append("\"><span>");
    SimpleDateFormat monthDisplayFormat = new SimpleDateFormat("MMM", locale);
    sb.append(monthDisplayFormat.format(date).toUpperCase());
    sb.append("</span>");
    sb.append("</div>");
    // Add day
    SimpleDateFormat dayFormat = new SimpleDateFormat("dd", locale);
    String day = dayFormat.format(date);
    sb.append("<div class=\"b_day b_day_").append(day);
    sb.append("\"><span>");
    sb.append(day);
    sb.append("</span>");
    sb.append("</div>");
    //
    sb.append("</div>");
  }
Пример #20
0
 /**
  * @param prefix e.g. abc for "abc647547326" and so on
  * @return an prefixed id (e.g. f23748932) which is unique in the current render tree.
  */
 public StringOutput getId(String prefix) {
   StringOutput sb = new StringOutput(16);
   sb.append("o_s").append(prefix).append(vc.getDispatchID());
   return sb;
 }
  @Override
  public void render(
      Renderer renderer,
      StringOutput sb,
      Component source,
      URLBuilder ubu,
      Translator translator,
      RenderResult renderResult,
      String[] args) {

    FlexiTableComponent ftC = (FlexiTableComponent) source;
    FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
    String id = ftC.getFormDispatchId();

    renderHeaderButtons(renderer, sb, ftE, ubu, translator, renderResult, args);

    if (ftE.getTableDataModel().getRowCount() == 0
        && StringHelper.containsNonWhitespace(ftE.getEmtpyTableMessageKey())) {
      String emptyMessageKey = ftE.getEmtpyTableMessageKey();
      sb.append("<div class='o_info'>")
          .append(translator.translate(emptyMessageKey))
          .append("</div>");
    } else {
      sb.append("<div class='o_table_wrapper o_table_flexi")
          .append(" o_table_edit", ftE.isEditMode());
      String css = ftE.getElementCssClass();
      if (css != null) {
        sb.append(" ").append(css);
      }
      switch (ftE.getRendererType()) {
        case custom:
          sb.append(" o_rendertype_custom");
          break;
        case classic:
          sb.append(" o_rendertype_classic");
          break;
      }
      sb.append("'");
      String wrapperSelector = ftE.getWrapperSelector();
      if (wrapperSelector != null) {
        sb.append(" id='").append(wrapperSelector).append("'");
      }
      sb.append("><table id=\"")
          .append(id)
          .append("\" class=\"table table-condensed table-striped table-hover\">");

      // render headers
      renderHeaders(sb, ftC, translator);
      // render body
      sb.append("<tbody>");
      renderBody(renderer, sb, ftC, ubu, translator, renderResult);
      sb.append("</tbody></table>");
      renderFooterButtons(sb, ftC, translator);
      // draggable
      if (ftE.getColumnIndexForDragAndDropLabel() > 0) {
        sb.append("<script type='text/javascript'>")
            .append("/* <![CDATA[ */ \n")
            .append("jQuery(function() {\n")
            .append(" jQuery('.o_table_flexi table tr').draggable({\n")
            .append("  containment: '#o_main',\n")
            .append("	 zIndex: 10000,\n")
            .append("	 cursorAt: {left: 0, top: 0},\n")
            .append("	 accept: function(event,ui){ return true; },\n")
            .append("	 helper: function(event,ui,zt) {\n")
            .append("    var helperText = jQuery(this).children('.o_dnd_label').text();\n")
            .append(
                "    return jQuery(\"<div class='ui-widget-header o_table_drag'>\" + helperText + \"</div>\").appendTo('body').css('zIndex',5).show();\n")
            .append("  }\n")
            .append("});\n")
            .append("});\n")
            .append("/* ]]> */\n")
            .append("</script>\n");
      }

      sb.append("</div>");
    }

    // source
    if (source.isEnabled()) {
      FormJSHelper.appendFlexiFormDirty(sb, ftE.getRootForm(), id);
    }
  }
  private void renderPageSize(StringOutput sb, FlexiTableComponent ftC, Translator translator) {
    FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
    FlexiTableDataModel<?> dataModel = ftE.getTableDataModel();

    Form theForm = ftE.getRootForm();
    String dispatchId = ftE.getFormDispatchId();

    int pageSize = ftE.getPageSize();
    int firstRow = ftE.getFirstRow();
    int maxRows = ftE.getMaxRows();
    int rows = dataModel.getRowCount();
    int lastRow = Math.min(rows, firstRow + maxRows);

    sb.append("<div class='o_table_rows_infos'>");
    sb.append(
            translator.translate(
                "page.size.a",
                new String[] {
                  Integer.toString(firstRow + 1), // for humans
                  Integer.toString(lastRow),
                  Integer.toString(rows)
                }))
        .append(" ");

    sb.append(
            "<div class='btn-group dropup'><button type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>")
        .append(" <span>");
    if (pageSize < 0) {
      sb.append(translator.translate("show.all"));
    } else {
      sb.append(Integer.toString(pageSize));
    }

    sb.append("</span> <span class='caret'></span></button>")
        .append("<ul class='dropdown-menu' role='menu'>");

    int[] sizes = new int[] {20, 50, 100, 250};
    for (int size : sizes) {
      sb.append("<li><a href=\"javascript:")
          .append(
              FormJSHelper.getXHRFnCallFor(
                  theForm, dispatchId, 1, new NameValuePair("pagesize", Integer.toString(size))))
          .append("\"  onclick=\"return o2cl();\">")
          .append(Integer.toString(size))
          .append("</a></li>");
    }

    if (ftE.isShowAllRowsEnabled()) {
      sb.append("<li><a href=\"javascript:")
          .append(
              FormJSHelper.getXHRFnCallFor(
                  theForm, dispatchId, 1, new NameValuePair("pagesize", "all")))
          .append("\" onclick=\"return o2cl();\">")
          .append(translator.translate("show.all"))
          .append("</a></li>");
    }

    sb.append("</ul></div>")
        .append(" ")
        .append(translator.translate("page.size.b"))
        .append("</div> ");
  }
Пример #23
0
  @Override
  public void render(
      Renderer renderer,
      StringOutput sb,
      Component source,
      URLBuilder ubu,
      Translator translator,
      RenderResult renderResult,
      String[] args) {

    AutoCompleterComponent cmp = (AutoCompleterComponent) source;
    AutoCompleter autoCompleter = cmp.getAutoCompleter();

    int inputSize = 72;
    boolean showDisplayKey = false;
    String id = autoCompleter.getFormDispatchId();
    String mapperUri = autoCompleter.getMapperUri();
    StringOutput command = new StringOutput(64);
    ubu.createCopyFor(cmp)
        .openXHREvent(
            command, null, false, false, new NameValuePair(VelocityContainer.COMMAND_ID, "select"));

    sb.append("<input type='text' class='form-control' size='")
        .append(inputSize)
        .append("' id='")
        .append(id)
        .append("' name='")
        .append(id)
        .append("' value=\"");
    if (StringHelper.containsNonWhitespace(autoCompleter.getValue())) {
      sb.append(StringHelper.escapeHtml(autoCompleter.getValue()));
    }
    sb.append("\" />");
    sb.append("<script type='text/javascript'>\n")
        .append("/* <![CDATA[ */\n")
        .append("jQuery(function(){\n")
        .append("  var fullNameTypeahead = new Bloodhound({\n")
        .append("	   datumTokenizer: function (d) {\n")
        .append("	     return Bloodhound.tokenizers.whitespace(d.value);\n")
        .append("    },\n")
        .append("	   queryTokenizer: Bloodhound.tokenizers.whitespace,\n")
        .append("	   remote: {\n")
        .append("	    url: '")
        .append(mapperUri)
        .append(
            "/?place=holder&term=%QUERY',\n") // place holder is useless but for tomcat, sometimes
        // it said that the term parameter is corrupted and
        // will not be part of the request send to OpenOLAT
        .append("	    wildcard: '%QUERY',\n")
        .append("     filter: function ( response ) {\n")
        .append("      return jQuery.map(response, function (object) {\n")
        .append("		  return {\n")
        .append("			value: '' + object.key,\n");
    if (showDisplayKey) {
      sb.append("       fullName: object.displayKey + ': ' + object.value\n");
    } else {
      sb.append("       fullName: object.value\n");
    }
    sb.append("         };\n")
        .append("       });\n")
        .append("     }\n")
        .append("   }\n")
        .append(" });\n")
        .append(" fullNameTypeahead.initialize();\n")
        .append(" jQuery('#")
        .append(id)
        .append("').typeahead({\n")
        .append("	  hint: false,\n")
        .append("	  highlight: false,\n")
        .append("	  minLength: 3\n")
        .append(" },{\n")
        .append("	  minLength: 3,\n")
        .append("	  displayKey: 'fullName',\n")
        .append("	  source: fullNameTypeahead.ttAdapter()\n")
        .append(" }).on('typeahead:selected', function (e, object) {\n")
        .append("	  ")
        .append(command)
        .append(",'key',object.value,'value',object.fullName);\n")
        .append(" });\n")
        .append("});\n")
        .append("/* ]]> */\n")
        .append("</script>");
  }
  protected void renderHeaderButtons(
      Renderer renderer,
      StringOutput sb,
      FlexiTableElementImpl ftE,
      URLBuilder ubu,
      Translator translator,
      RenderResult renderResult,
      String[] args) {
    Component searchCmp = ftE.getExtendedSearchComponent();

    if (searchCmp == null
        && !ftE.isExtendedSearchExpanded()
        && !ftE.isNumOfRowsEnabled()
        && !ftE.isFilterEnabled()
        && !ftE.isSortEnabled()
        && !ftE.isExportEnabled()
        && !ftE.isCustomizeColumns()
        && ftE.getAvailableRendererTypes().length <= 1) {
      return;
    }

    if (searchCmp != null && ftE.isExtendedSearchExpanded()) {
      renderer.render(searchCmp, sb, args);
    }

    sb.append("<div class='row clearfix o_table_toolbar'>")
        .append("<div class='col-sm-6 col-xs-12'>");
    if (searchCmp == null || !ftE.isExtendedSearchExpanded()) {
      renderHeaderSearch(renderer, sb, ftE, ubu, translator, renderResult, args);
    }
    sb.append("</div>");

    sb.append("<div class='col-sm-3 col-xs-4 o_table_row_count'>");
    if (ftE.isNumOfRowsEnabled()) {
      int rowCount = ftE.getTableDataModel().getRowCount();
      if (rowCount == 1) {
        sb.append(rowCount).append(" ").append(ftE.getTranslator().translate("table.entry"));
      } else if (rowCount > 1) {
        sb.append(rowCount).append(" ").append(ftE.getTranslator().translate("table.entries"));
      }
    }
    sb.append(
        "</div><div class='col-sm-3 col-xs-8'><div class='pull-right'><div class='o_table_tools'>");

    boolean empty = ftE.getTableDataModel().getRowCount() == 0;

    String filterIndication = null;
    // filter
    if (ftE.isFilterEnabled()) {
      List<FlexiTableFilter> filters = ftE.getFilters();
      if (filters != null && filters.size() > 0) {
        filterIndication = renderFilterDropdown(sb, ftE, filters);
      }
    }

    // sort
    if (ftE.isSortEnabled()) {
      List<FlexiTableSort> sorts = ftE.getSorts();
      if (sorts != null && sorts.size() > 0) {
        renderSortDropdown(sb, ftE, sorts);
      }
    }

    if (ftE.getExportButton() != null && ftE.isExportEnabled()) {
      sb.append("<div class='btn-group'>");
      ftE.getExportButton().setEnabled(!empty);
      renderFormItem(renderer, sb, ftE.getExportButton(), ubu, translator, renderResult, args);
      sb.append("</div> ");
    }
    if (ftE.getCustomButton() != null && ftE.isCustomizeColumns()) {
      sb.append("<div class='btn-group'>");
      renderFormItem(renderer, sb, ftE.getCustomButton(), ubu, translator, renderResult, args);
      sb.append("</div> ");
    }

    // switch type of tables
    FlexiTableRendererType[] types = ftE.getAvailableRendererTypes();
    if (types.length > 1) {
      sb.append("<div class='btn-group'>");
      for (FlexiTableRendererType type : types) {
        renderHeaderSwitchType(type, renderer, sb, ftE, ubu, translator, renderResult, args);
      }
      sb.append("</div> ");
    }
    sb.append("</div>");
    if (StringHelper.containsNonWhitespace(filterIndication)) {
      sb.append(
              "<div class='o_table_tools_indications'><i class='o_icon o_icon_filter o_icon-lg'> </i> ")
          .append(filterIndication)
          .append("</div>");
    }
    sb.append("</div>");

    sb.append("</div></div>");
  }
Пример #25
0
 private final boolean and(StringOutput sb, boolean and) {
   if (and) sb.append(", ");
   return true;
 }
Пример #26
0
 /** @return the componentid (e.g.) o_c32645732 */
 public StringOutput getCId() {
   StringOutput sb = new StringOutput(16);
   sb.append("o_c").append(vc.getDispatchID());
   return sb;
 }
Пример #27
0
 public static String getId(String prefix, VelocityContainer vc) {
   StringOutput sb = StringOutputPool.allocStringBuilder(24);
   sb.append("o_s").append(prefix).append(vc.getDispatchID());
   return StringOutputPool.freePop(sb);
 }