use of org.olat.core.gui.translator.Translator 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.translator.Translator in project OpenOLAT by OpenOLAT.
the class TextBoxListElementImpl method setTranslator.
@Override
public void setTranslator(Translator translator) {
// wrap package translator with fallback form translator
Translator elmTranslator = Util.createPackageTranslator(TextBoxListElementImpl.class, translator.getLocale(), translator);
super.setTranslator(elmTranslator);
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class TextElementImpl method setTranslator.
@Override
public void setTranslator(Translator translator) {
// wrap package translator with fallback form translator
// hint: do not take this.getClass() but the real class! for package translator creation
Translator elmTranslator = Util.createPackageTranslator(TextElementImpl.class, translator.getLocale(), translator);
super.setTranslator(elmTranslator);
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class SegmentViewRenderer method render.
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
SegmentViewComponent component = (SegmentViewComponent) source;
if (component.isEmpty() || (component.isDontShowSingleSegment() && component.getSegments().size() == 1)) {
return;
}
sb.append("<div class='o_segments btn-group btn-group-justified'>");
for (Component segment : component.getSegments()) {
ComponentRenderer subRenderer = segment.getHTMLRendererSingleton();
Translator subTranslator = segment.getTranslator();
subRenderer.render(renderer, sb, segment, ubu, subTranslator, renderResult, args);
}
sb.append("</div>");
}
use of org.olat.core.gui.translator.Translator in project OpenOLAT by OpenOLAT.
the class DefaultXlsTableExporter method export.
/**
* @see org.olat.core.gui.components.table.TableExporter#export(org.olat.core.gui.components.table.Table)
*/
@Override
public MediaResource export(final Table table) {
Translator translator = table.getTranslator();
int cdcnt = table.getColumnCount();
int rcnt = table.getRowCount();
String label = "TableExport_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".xlsx";
return new OpenXMLWorkbookResource(label) {
@Override
protected void generate(OutputStream out) {
try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1)) {
OpenXMLWorksheet sheet = workbook.nextWorksheet();
createHeader(table, translator, cdcnt, sheet, workbook);
createData(table, cdcnt, rcnt, sheet);
} catch (IOException e) {
log.error("", e);
}
}
};
}
Aggregations