Search in sources :

Example 1 with AutoCompleter

use of org.olat.core.gui.components.form.flexible.elements.AutoCompleter in project openolat by klemens.

the class AutoCompleterRenderer method render.

@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();
    final int inputSize = 72;
    String id = autoCompleter.getFormDispatchId();
    if (autoCompleter.isEnabled()) {
        boolean showDisplayKey = false;
        String mapperUri = autoCompleter.getMapperUri();
        int minLength = autoCompleter.getMinLength();
        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 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
        "/?place=holder&term=%QUERY',\n").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: ").append(minLength).append("\n").append(" },{\n").append("	  minLength: ").append(minLength).append(",\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>");
    } else {
        String value = "";
        if (StringHelper.containsNonWhitespace(autoCompleter.getValue())) {
            value = autoCompleter.getValue();
        }
        sb.append("<input id=\"").append(id).append("\" type=\"test\" disabled=\"disabled\" class=\"form-control o_disabled\" size=\"").append(inputSize).append("\" value=\"").append(value).append("\" />").append("</span>");
    }
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) StringOutput(org.olat.core.gui.render.StringOutput) AutoCompleter(org.olat.core.gui.components.form.flexible.elements.AutoCompleter)

Example 2 with AutoCompleter

use of org.olat.core.gui.components.form.flexible.elements.AutoCompleter in project OpenOLAT by OpenOLAT.

the class AutoCompleterRenderer method render.

@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();
    final int inputSize = 72;
    String id = autoCompleter.getFormDispatchId();
    if (autoCompleter.isEnabled()) {
        boolean showDisplayKey = false;
        String mapperUri = autoCompleter.getMapperUri();
        int minLength = autoCompleter.getMinLength();
        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 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
        "/?place=holder&term=%QUERY',\n").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: ").append(minLength).append("\n").append(" },{\n").append("	  minLength: ").append(minLength).append(",\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>");
    } else {
        String value = "";
        if (StringHelper.containsNonWhitespace(autoCompleter.getValue())) {
            value = autoCompleter.getValue();
        }
        sb.append("<input id=\"").append(id).append("\" type=\"test\" disabled=\"disabled\" class=\"form-control o_disabled\" size=\"").append(inputSize).append("\" value=\"").append(value).append("\" />").append("</span>");
    }
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) StringOutput(org.olat.core.gui.render.StringOutput) AutoCompleter(org.olat.core.gui.components.form.flexible.elements.AutoCompleter)

Aggregations

AutoCompleter (org.olat.core.gui.components.form.flexible.elements.AutoCompleter)2 NameValuePair (org.olat.core.gui.components.form.flexible.impl.NameValuePair)2 StringOutput (org.olat.core.gui.render.StringOutput)2