use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project OpenOLAT by OpenOLAT.
the class FileElementRenderer method render.
/* (non-Javadoc)
* @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) {
// Use translator with flexi form elements fallback
Translator trans = Util.createPackageTranslator(FileElementRenderer.class, translator.getLocale(), translator);
//
FileElementComponent fileComp = (FileElementComponent) source;
FileElementImpl fileElem = fileComp.getFileElementImpl();
String id = fileComp.getFormDispatchId();
// Calculate current file name: either from already uploaded file or
// from initial file or empty
String fileName = fileElem.getUploadFileName();
if (fileName == null) {
// try fallback: default file
File initialFile = fileElem.getInitialFile();
if (initialFile != null) {
fileName = initialFile.getName();
} else {
fileName = "";
}
}
// Read-write view
if (fileComp.isEnabled()) {
ImageFormItem previewCmp = fileElem.getPreviewFormItem();
if (previewCmp != null && previewCmp.isEnabled() && previewCmp.isVisible()) {
sb.append("<div class='o_filepreview'>");
renderer.render(previewCmp.getComponent(), sb, args);
sb.append("</div>");
}
boolean showDeleteButton = fileElem.isDeleteEnabled() && (fileElem.getInitialFile() != null || fileElem.getUploadFile() != null);
sb.append("<div class='o_fileinput'>");
// See http://www.quirksmode.org/dom/inputfile.html
if (fileElem.isButtonsEnabled()) {
sb.append("<input type='file' name=\"");
// name for form labeling
sb.append(id);
sb.append("\" id=\"");
// id to make dirty button work
sb.append(id);
sb.append("\" class='form-control o_realchooser ").append(" o_chooser_with_delete", showDeleteButton).append("' ");
// Add on* event handlers
StringBuilder eventHandlers = FormJSHelper.getRawJSFor(fileElem.getRootForm(), id, fileElem.getAction());
int onChangePos = eventHandlers.indexOf("onchange=");
if (onChangePos != -1) {
// add file upload change handler
sb.append(eventHandlers.substring(0, onChangePos + 10)).append("b_handleFileUploadFormChange(this, this.form.fake_").append(id).append(", this.form.upload);").append(eventHandlers.substring(onChangePos + 10, eventHandlers.length()));
} else {
sb.append(eventHandlers).append(" onchange=\"b_handleFileUploadFormChange(this, this.form.fake_").append(id).append(", this.form.upload)\"");
}
// Add pseudo focus marker on fake file chooser button
sb.append(" onfocus=\"this.form.fake_").append(id).append(".nextSibling.style.border = '1px dotted black';\"").append(" onblur=\"this.form.fake_").append(id).append(".nextSibling.style.border = '0';\"");
// Add select text (hover)
sb.append(" title=\"").append(StringEscapeUtils.escapeHtml(trans.translate("file.element.select"))).append("\" />");
}
// Add the visible but fake input field and a styled faked file chooser button
sb.append("<div class='o_fakechooser input-group'>");
sb.append("<input class='form-control' name='fake_").append(id).append("' value=\"").append(StringEscapeUtils.escapeHtml(fileName)).append("\" placeholder=\"").append(StringEscapeUtils.escapeHtml(trans.translate("file.element.select"))).append("\" />");
sb.append("<span class='input-group-addon'><a href='javascript:;'><i class='o_icon o_icon_upload'> </i></a></span>");
if (showDeleteButton) {
sb.append("<a class='input-group-addon' href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(fileElem.getRootForm(), fileComp.getFormDispatchId(), 1, false, false, new NameValuePair("delete", "delete"))).append(";\" onclick=\"\" ").append(" title=\"").append(StringEscapeUtils.escapeHtml(trans.translate("file.element.delete"))).append("\" ><i class='o_icon o_icon_delete'> </i></a>");
}
sb.append("</div></div>");
// Add example text and max upload size
if (fileElem.getExampleText() != null) {
sb.append("<div class='help-block'>").append(fileElem.getExampleText());
if (fileElem.getMaxUploadSizeKB() != FileElement.UPLOAD_UNLIMITED) {
String maxUpload = Formatter.formatBytes(fileElem.getMaxUploadSizeKB() * 1000);
sb.append(" (").append(trans.translate("file.element.select.maxsize", new String[] { maxUpload })).append(")");
}
sb.append("</div>");
} else if (fileElem.getMaxUploadSizeKB() != FileElement.UPLOAD_UNLIMITED) {
String maxUpload = Formatter.formatBytes(fileElem.getMaxUploadSizeKB() * 1000);
sb.append("<div class='help-block o_maxsize'>(").append(trans.translate("file.element.select.maxsize", new String[] { maxUpload })).append(")</div>");
}
// Add set dirty form on change
FormJSHelper.appendFlexiFormDirty(sb, fileElem.getRootForm(), fileComp.getFormDispatchId());
} else {
// Read only view
sb.append("<span id=\"").append(id).append("\" ").append(FormJSHelper.getRawJSFor(fileElem.getRootForm(), id, fileElem.getAction())).append(" >").append("<input type='text' disabled=\"disabled\" class=\"form-control o_disabled\" size=\"").append("\" value=\"").append(StringEscapeUtils.escapeHtml(fileName)).append("\" ").append("\" />").append("</span>");
}
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project OpenOLAT by OpenOLAT.
the class StaticFlexiCellRenderer method render.
@Override
public void render(Renderer renderer, StringOutput target, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
String cellAction = getAction();
if (StringHelper.containsNonWhitespace(cellAction)) {
FlexiTableElementImpl ftE = source.getFlexiTableElement();
String id = source.getFormDispatchId();
Form rootForm = ftE.getRootForm();
NameValuePair pair = new NameValuePair(cellAction, Integer.toString(row));
String jsCode = FormJSHelper.getXHRFnCallFor(rootForm, id, 1, true, true, pair);
target.append("<a href=\"javascript:").append(jsCode).append(";\"");
if (StringHelper.containsNonWhitespace(linkTitle)) {
target.append(" title=\"").append(StringEscapeUtils.escapeHtml(linkTitle)).append("\"");
}
if (StringHelper.containsNonWhitespace(linkCSS)) {
target.append(" class=\"").append(linkCSS).append("\"");
}
target.append(">");
if (StringHelper.containsNonWhitespace(iconLeftCSS)) {
target.append("<i class=\"o_icon ").append(iconLeftCSS).append("\"> </i>");
}
if (labelDelegate == null) {
target.append(getLabel());
} else {
labelDelegate.render(renderer, target, cellValue, row, source, ubu, translator);
}
if (StringHelper.containsNonWhitespace(iconRightCSS)) {
target.append(" <i class=\"o_icon ").append(iconRightCSS).append("\"> </i>");
}
target.append("</a>");
} else if (labelDelegate == null) {
target.append(getLabel());
} else {
labelDelegate.render(renderer, target, cellValue, row, source, ubu, translator);
}
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project OpenOLAT by OpenOLAT.
the class FlexiTableClassicRenderer method renderRow.
@Override
protected void renderRow(Renderer renderer, StringOutput target, FlexiTableComponent ftC, String rowIdPrefix, int row, URLBuilder ubu, Translator translator, RenderResult renderResult) {
FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
FlexiTableColumnModel columnsModel = ftE.getTableDataModel().getTableColumnModel();
int numOfCols = columnsModel.getColumnCount();
Form theForm = ftE.getRootForm();
// use alternating css class
int numOfColumns = 0;
target.append("<tr id='").append(rowIdPrefix).append(row).append("'");
if (ftE.getCssDelegate() != null) {
String cssClass = ftE.getCssDelegate().getRowCssClass(FlexiTableRendererType.classic, row);
if (StringHelper.containsNonWhitespace(cssClass)) {
target.append(" class='").append(cssClass).append("'");
}
}
target.append(">");
if (ftE.isMultiSelect()) {
target.append("<td>").append("<input type='checkbox' name='tb_ms' value='").append(rowIdPrefix).append(row).append("'").append(" onclick=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, ftC.getFormDispatchId(), 1, false, false, false, new NameValuePair("chkbox", Integer.toString(row)))).append(";\"");
if (ftE.isMultiSelectedIndex(row)) {
target.append(" checked='checked'");
}
boolean selectable = ftE.getTableDataModel().isSelectable(row);
if (!selectable) {
target.append(" disabled='disabled'");
}
target.append("/></td>");
}
for (int j = 0; j < numOfCols; j++) {
FlexiColumnModel fcm = columnsModel.getColumnModel(j);
if (ftE.isColumnModelVisible(fcm)) {
renderCell(renderer, target, ftC, fcm, row, ubu, translator, renderResult);
numOfColumns++;
}
}
target.append("</tr>");
if (ftE.isDetailsExpended(row)) {
target.append("<tr id='").append(rowIdPrefix).append(row).append("_details' class='o_table_row_details'>");
VelocityContainer container = ftE.getDetailsRenderer();
Object rowObject = ftE.getTableDataModel().getObject(row);
container.contextPut("row", rowObject);
FlexiTableComponentDelegate cmpDelegate = ftE.getComponentDelegate();
if (cmpDelegate != null) {
Iterable<Component> cmps = cmpDelegate.getComponents(row, rowObject);
if (cmps != null) {
for (Component cmp : cmps) {
container.put(cmp.getComponentName(), cmp);
}
}
}
if (ftE.isMultiSelect()) {
target.append("<td></td>");
}
target.append("<td colspan='").append(numOfColumns).append("'>");
container.getHTMLRendererSingleton().render(renderer, target, container, ubu, translator, renderResult, null);
container.contextRemove("row");
target.append("</td></tr>");
}
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project OpenOLAT by OpenOLAT.
the class TabbedPaneRenderer method render.
/**
* @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 sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
TabbedPane tb = (TabbedPane) source;
int cnt = tb.getTabCount();
// nothing to render
if (cnt == 0)
return;
int selPane = tb.getSelectedPane();
boolean iframePostEnabled = renderer.getGlobalSettings().getAjaxFlags().isIframePostEnabled();
sb.append("<div id=\"o_c").append(tb.getDispatchID()).append("\" class='o_tabbed_pane'>");
sb.append("<ul class='nav nav-tabs");
String css = tb.getElementCssClass();
if (StringHelper.containsNonWhitespace(css)) {
sb.append(" ").append(css);
}
sb.append("'>");
for (int i = 0; i < cnt; i++) {
String tabName = tb.getDisplayNameAt(i);
// Render active tab as non clickable, passive tabs with link
sb.append("<li");
if (i != selPane && cnt > 1) {
if (tb.isEnabled(i)) {
sb.append("><a ");
ubu.buildHrefAndOnclick(sb, iframePostEnabled, new NameValuePair(TabbedPane.PARAM_PANE_ID, String.valueOf(i)));
sb.append(">").append(tabName).append("</a></li>");
} else {
// disabled panels can not be clicked, but for layout reason needs still a a href
sb.append(" class='disabled'><a href='javascript:;' title='").append(StringHelper.escapeHtml(translator.translate("disabled"))).append("'>").append(tabName).append("</a></li>");
}
} else {
sb.append(" class='active'><a href='javascript:;'>").append(tabName).append("</a></li>");
}
}
sb.append("</ul>");
// now let the selected component render itself
Component paneToRender = tb.getTabAt(selPane);
sb.append("<div class='o_tabbed_pane_content'>");
if (paneToRender != null) {
renderer.render(sb, paneToRender, null);
}
sb.append("</div></div>");
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project OpenOLAT by OpenOLAT.
the class RatingRenderer method render.
/**
* @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) {
RatingComponent rating = (RatingComponent) source;
sb.append("<div class='o_rating ");
// Add custom css class
if (rating.getCssClass() != null)
sb.append(rating.getCssClass());
sb.append("'>");
// Add Title
String title = rating.getTitle();
if (title != null) {
sb.append("<div class='o_rating_title'>");
if (rating.isTranslateTitle()) {
if (translator != null) {
title = translator.translate(title);
} else {
title = "";
}
}
sb.append(title);
// o_rating_title
sb.append("</div>");
}
// Add ratings and labels
List<String> labels = rating.getRatingLabel();
sb.append("<div class='o_rating_items");
if (rating.isAllowUserInput()) {
sb.append(" o_enabled");
}
sb.append("'>");
for (int i = 0; i < labels.size(); i++) {
// Add css class
sb.append("<a class='o_icon o_icon-lg ");
if (rating.getCurrentRating() >= i + 1) {
sb.append("o_icon_rating_on");
} else {
sb.append("o_icon_rating_off");
}
sb.append("'");
// Add action
if (rating.isAllowUserInput() && rating.isEnabled()) {
sb.append(" ");
RatingFormItem rfi = rating.getFormItem();
NameValuePair cmd = new NameValuePair(VelocityContainer.COMMAND_ID, Integer.toString(i + 1));
if (rfi == null) {
ubu.buildHrefAndOnclick(sb, true, cmd);
} else {
sb.append("href=\"javascript:;\" onclick=\"javascript:").append(FormJSHelper.getXHRFnCallFor(rfi.getRootForm(), rfi.getFormDispatchId(), 1, false, false, true, cmd)).append("\" ");
}
} else {
// Disabled link
sb.append(" href='javascript:;' onclick='return false;'");
}
// Add item label
String label = rating.getRatingLabel(i);
if (label != null) {
if (rating.isTranslateRatingLabels()) {
if (translator != null) {
label = translator.translate(label);
} else {
label = "";
}
}
sb.append(" title=\"").append(StringHelper.escapeHtml(label)).append("\"");
}
sb.append("></a>");
}
// Add text output
if (rating.isShowRatingAsText()) {
sb.append("<span class='o_legend'>");
sb.append(Formatter.roundToString(rating.getCurrentRating(), 1));
sb.append(" / ");
sb.append(labels.size());
sb.append("</span>");
}
// o_rating_items
sb.append("</div>");
// Add explanation
String expl = rating.getExplanation();
if (expl != null) {
sb.append("<div class='o_rating_explanation'>");
if (rating.isTranslateExplanation()) {
if (translator != null) {
expl = translator.translate(expl);
} else {
expl = "";
}
}
sb.append(expl);
// o_rating_explanation
sb.append("</div>");
}
// o_rating
sb.append("</div>");
if (rating.getFormItem() != null) {
RatingFormItem rfi = rating.getFormItem();
FormJSHelper.appendFlexiFormDirtyForClick(sb, rfi.getRootForm(), rfi.getFormDispatchId());
}
}
Aggregations