Exemple #1
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>");
  }
  @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>");
  }