use of org.olat.core.gui.components.form.flexible.impl.NameValuePair 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>");
}
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.
the class AbstractFlexiTableRenderer method renderHeaderSearch.
protected void renderHeaderSearch(Renderer renderer, StringOutput sb, FlexiTableElementImpl ftE, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
if (ftE.isSearchEnabled()) {
Form theForm = ftE.getRootForm();
String dispatchId = ftE.getFormDispatchId();
sb.append("<div class='o_table_search input-group o_noprint'>");
renderFormItem(renderer, sb, ftE.getSearchElement(), ubu, translator, renderResult, args);
sb.append("<div class='input-group-btn'>");
// reset quick search
String id = ftE.getSearchElement().getFormDispatchId();
sb.append("<a href=\"javascript:jQuery('#").append(id).append("').val('');").append(FormJSHelper.getXHRFnCallFor(theForm, dispatchId, 1, true, true, true, new NameValuePair("reset-search", "true"))).append("\" class='btn o_reset_quick_search'><i class='o_icon o_icon_remove_filters'> </i></a>");
renderFormItem(renderer, sb, ftE.getSearchButton(), ubu, translator, renderResult, args);
if (ftE.getExtendedSearchButton() != null) {
renderFormItem(renderer, sb, ftE.getExtendedSearchButton(), ubu, translator, renderResult, args);
}
StringBuilder filterIndication = new StringBuilder();
if (ftE.getExtendedFilterButton() != null) {
ftE.getSelectedExtendedFilters().forEach(filter -> {
if (filterIndication.length() > 0)
filterIndication.append(", ");
filterIndication.append(filter.getLabel());
});
renderFormItem(renderer, sb, ftE.getExtendedFilterButton(), ubu, translator, renderResult, args);
}
sb.append("</div>");
sb.append("</div>");
if (filterIndication.length() > 0) {
sb.append("<div class='o_table_tools_indications'>").append(filterIndication).append("<a href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, dispatchId, 1, true, true, true, new NameValuePair("rm-extended-filter", "true"))).append("\" title=\"").append(translator.translate("remove.filters")).append("\">").append("<i class='o_icon o_icon_remove o_icon-fw'> </i></a></div>");
}
} else if (ftE.getExtendedSearchButton() != null) {
renderFormItem(renderer, sb, ftE.getExtendedSearchButton(), ubu, translator, renderResult, args);
}
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.
the class AbstractFlexiTableRenderer method renderSortDropdown.
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, true, true, true, 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>");
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.
the class AbstractFlexiTableRenderer method renderPageBackLink.
private void renderPageBackLink(StringOutput sb, FlexiTableComponent ftC, int page) {
boolean disabled = (page <= 0);
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, true, true, true, new NameValuePair("page", Integer.toString(page - 1))));
}
sb.append("\">").append("«").append("</a></li>");
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.
the class AbstractFlexiTableRenderer method renderPageSize.
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 o_noprint'>");
sb.append(translator.translate("page.size.a", new String[] { // for humans
Integer.toString(firstRow + 1), 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 };
int defaultPageSize = ftE.getDefaultPageSize();
if (Arrays.binarySearch(sizes, defaultPageSize) < 0) {
sizes = new int[] { 20, 50, 100, 250, defaultPageSize };
Arrays.sort(sizes);
}
for (int size : sizes) {
sb.append("<li><a href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, dispatchId, 1, true, true, true, new NameValuePair("pagesize", Integer.toString(size)))).append("\">").append(Integer.toString(size)).append("</a></li>");
}
if (ftE.isShowAllRowsEnabled()) {
sb.append("<li><a href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, dispatchId, 1, true, true, true, new NameValuePair("pagesize", "all"))).append("\">").append(translator.translate("show.all")).append("</a></li>");
}
sb.append("</ul></div>").append(" ").append(translator.translate("page.size.b")).append("</div> ");
}
Aggregations