Search in sources :

Example 6 with StringOutput

use of org.olat.core.gui.render.StringOutput in project OpenOLAT by OpenOLAT.

the class FormDecorator method appendFlexiFormDirty.

public String appendFlexiFormDirty(String id) {
    StringOutput sb = new StringOutput(256);
    FormJSHelper.appendFlexiFormDirty(sb, container.getRootForm(), id);
    return sb.toString();
}
Also used : StringOutput(org.olat.core.gui.render.StringOutput)

Example 7 with StringOutput

use of org.olat.core.gui.render.StringOutput in project OpenOLAT by OpenOLAT.

the class RichTextElementRenderer method renderTinyMCE_4.

private void renderTinyMCE_4(StringOutput sb, String domID, RichTextElementComponent teC, URLBuilder ubu, Translator translator) {
    RichTextElementImpl te = teC.getRichTextElementImpl();
    te.setRenderingMode(TextMode.formatted);
    RichTextConfiguration config = te.getEditorConfiguration();
    List<String> onInit = config.getOnInit();
    StringOutput configurations = new StringOutput();
    config.appendConfigToTinyJSArray_4(configurations, translator);
    if (config.getAdditionalConfiguration() != null) {
        config.getAdditionalConfiguration().appendConfigToTinyJSArray_4(configurations, translator);
    }
    StringOutput baseUrl = new StringOutput();
    StaticMediaDispatcher.renderStaticURI(baseUrl, "js/tinymce4/tinymce/tinymce.min.js", true);
    // Read write view
    renderTinyMCETextarea(sb, domID, teC);
    Form form = te.getRootForm();
    configurations.append("ffxhrevent: { formNam:\"").append(form.getFormName()).append("\", dispIdField:\"").append(form.getDispatchFieldId()).append("\",").append(" dispId:\"").append(teC.getFormDispatchId()).append("\", eventIdField:\"").append(form.getEventFieldId()).append("\"},\n");
    if (te.getMaxLength() > 0) {
        configurations.append("maxSize:").append(te.getMaxLength()).append("\n");
    }
    sb.append("<script type='text/javascript'>/* <![CDATA[ */\n");
    // file browser url
    sb.append("  BTinyHelper.editorMediaUris.put('").append(domID).append("','");
    ubu.buildURI(sb, null, null);
    sb.append("');\n");
    sb.append("  jQuery('#").append(domID).append("').tinymce({\n").append("    selector: '#").append(domID).append("',\n").append("    script_url: '").append(baseUrl.toString()).append("',\n").append("    setup: function(ed){\n").append("      ed.on('init', function(e) {\n").append("        ").append(onInit.get(0).replace(".curry(", "(")).append(";\n").append("      });\n").append("      ed.on('change', function(e) {\n").append("        BTinyHelper.triggerOnChange('").append(domID).append("');\n").append("      });\n");
    if (config.isSendOnBlur()) {
        sb.append("      ed.on('blur', function(e) {\n").append("        o_ffXHREvent('").append(form.getFormName()).append("','").append(form.getDispatchFieldId()).append("','").append(teC.getFormDispatchId()).append("','").append(form.getEventFieldId()).append("', 2, false, false, false, 'cmd','saveinlinedtiny','").append(domID).append("',ed.getContent());\n").append("      });\n");
    }
    sb.append("    },\n").append(configurations).append("  });\n").append("/* ]]> */</script>\n");
}
Also used : Form(org.olat.core.gui.components.form.flexible.impl.Form) StringOutput(org.olat.core.gui.render.StringOutput)

Example 8 with StringOutput

use of org.olat.core.gui.render.StringOutput in project OpenOLAT by OpenOLAT.

the class LinkRenderer method render.

@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    Link link = (Link) source;
    String command = link.getCommand();
    AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
    // a link may force a non ajax-mode and a custom targ
    boolean iframePostEnabled = flags.isIframePostEnabled() && link.isAjaxEnabled() && link.getTarget() == null;
    int presentation = link.getPresentation();
    /*
		 * START && beware! order of this if's are relevant
		 */
    boolean flexiformlink = (presentation - Link.FLEXIBLEFORMLNK) >= 0;
    if (flexiformlink) {
        presentation = presentation - Link.FLEXIBLEFORMLNK;
    }
    boolean nontranslated = (presentation - Link.NONTRANSLATED) >= 0;
    if (nontranslated) {
        presentation = presentation - Link.NONTRANSLATED;
    }
    /*
		 * END && beware! order of this if's are relevant
		 */
    StringBuilder cssSb = new StringBuilder("");
    cssSb.append("class=\"");
    if (!link.isEnabled()) {
        cssSb.append(" o_disabled ");
    }
    if (link.isActive()) {
        cssSb.append(" active ");
    }
    if (presentation == Link.BUTTON_XSMALL) {
        cssSb.append("btn btn-xs ");
        cssSb.append(link.isPrimary() ? "btn-primary" : "btn-default");
    } else if (presentation == Link.BUTTON_SMALL) {
        cssSb.append("btn btn-sm ");
        cssSb.append(link.isPrimary() ? "btn-primary" : "btn-default");
    } else if (presentation == Link.BUTTON) {
        cssSb.append("btn ");
        cssSb.append(link.isPrimary() ? "btn-primary" : "btn-default");
    } else if (presentation == Link.BUTTON_LARGE) {
        cssSb.append("btn btn-lg ");
        cssSb.append(link.isPrimary() ? "btn-primary" : "btn-default");
    } else if (presentation == Link.LINK_BACK) {
        cssSb.append("o_link_back");
    } else if (presentation == Link.TOOLENTRY_DEFAULT) {
        cssSb.append("o_toolbox_link");
    } else if (presentation == Link.TOOLENTRY_CLOSE) {
        cssSb.append("o_toolbox_close");
    } else if (presentation == Link.LINK_CUSTOM_CSS) {
        String customCss = (link.isEnabled() ? link.getCustomEnabledLinkCSS() : link.getCustomDisabledLinkCSS());
        cssSb.append(customCss == null ? "" : customCss);
    }
    if (StringHelper.containsNonWhitespace(link.getElementCssClass())) {
        cssSb.append(" ").append(link.getElementCssClass());
    }
    cssSb.append("\"");
    if (link.isEnabled()) {
        // only set a target on an enabled link, target in span makes no sense
        if (link.getTarget() != null) {
            cssSb.append(" target=\"").append(link.getTarget()).append("\"");
        }
    }
    String elementId = link.getElementId();
    // String buffer to gather all Javascript stuff with this link
    // there is a var elementId = jQuery('#elementId');
    // allowing to reference the link as an Ext.Element
    // Optimize initial length based on heuristic measurements of extJsSb
    StringBuilder jsSb = new StringBuilder(240);
    boolean inForm = isInForm(args);
    String i18n = link.getI18n();
    String title = link.getTitle();
    String customDisplayText = link.getCustomDisplayText();
    // tooltip sets its own id into the <a> tag.
    if (link.isEnabled()) {
        sb.append("<p class='form-control-static'>", inForm).append("<a ").append(cssSb);
        // need also access to a created and id set. -> avoid "o_c"+link.getDispatchID()
        if (elementId != null) {
            sb.append(" id=\"").append(elementId).append("\" ");
        }
        String accessKey = link.getAccessKey();
        if (accessKey != null) {
            sb.append("accesskey=\"").append(accessKey).append("\" ");
        }
        if (flexiformlink) {
            // no target if flexi form link! because target is set on
            // post action of form
            Form theForm = (Form) link.getInternalAttachedObject();
            sb.append("href=\"javascript:").append(FormJSHelper.getJSFnCallFor(theForm, elementId, 1)).append(";\" ");
            if (link.isForceFlexiDirtyFormWarning()) {
                sb.append("onclick=\"return o2cl_dirtyCheckOnly();\" ");
            }
        } else if (link.isPopup()) {
            StringOutput href = new StringOutput();
            LinkPopupSettings popup = link.getPopup();
            ubu.buildURI(href, new String[] { VelocityContainer.COMMAND_ID }, new String[] { command }, null, AJAXFlags.MODE_NORMAL);
            sb.append("href=\"javascript:;\" onclick=\"o_openPopUp('").append(href).append("','").append(popup.getTarget()).append("',").append(popup.getWidth()).append(",").append(popup.getHeight()).append("); return false;\" ");
        } else {
            ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, !link.isSuppressDirtyFormWarning(), true, new NameValuePair(VelocityContainer.COMMAND_ID, command));
        }
        // tooltips
        if (title != null) {
            if (!link.isHasTooltip()) {
                sb.append(" title=\"");
                if (nontranslated) {
                    sb.append(StringEscapeUtils.escapeHtml(title)).append("\"");
                } else {
                    sb.append(StringEscapeUtils.escapeHtml(translator.translate(title))).append("\"");
                }
            }
            // tooltips based on the extjs library, see webapp/static/js/ext*
            if (link.isHasTooltip()) {
                String text;
                if (nontranslated) {
                    text = title;
                } else {
                    text = translator.translate(title);
                }
                sb.append(" title=\"").append(StringEscapeUtils.escapeHtml(text)).append("\"");
            }
        }
        sb.append(">");
        // CSS icon
        if (link.getIconLeftCSS() != null) {
            sb.append("<i class='").append(link.getIconLeftCSS()).append("'");
            // one space needed
            sb.append("></i> ");
        } else if (presentation == Link.LINK_BACK) {
            // one space needed
            sb.append("<i class='o_icon o_icon_back'></i> ");
        }
        // inner wrapper for layouting
        sb.append("<span>");
        if (customDisplayText != null) {
            // link is nontranslated but has custom text
            sb.append(customDisplayText);
        } else if (nontranslated) {
            if (i18n != null) {
                // link name is not a i18n key
                sb.append(i18n);
            } else {
                sb.append("");
            }
        } else {
            // use translator
            if (translator == null) {
                sb.append("Ohoho");
            } else {
                sb.append(translator.translate(i18n));
            }
        }
        sb.append("</span>");
        // CSS icon
        if (link.getIconRightCSS() != null) {
            // one space needed
            sb.append(" <i class='").append(link.getIconRightCSS()).append("'");
            sb.append("></i> ");
        }
        if (link.getBadge() != null) {
            renderer.render(link.getBadge(), sb, args);
        }
        sb.append("</a>").append("</p>", inForm);
        // on click() is part of prototype.js
        if (link.isRegisterForMousePositionEvent()) {
            jsSb.append(elementId).append(".click(function(event) {").append(" jQuery('#").append(elementId).append("').each(function(index, el) {;").append("  var href = jQuery(el).attr('href');").append(" 	if(href.indexOf('x') == -1) jQuery(el).attr('href',href+'x'+event.pageX+'y'+event.pageY+'');").append(" });});");
        }
        /**
         * TODO:gs:b may be usefull as well
         * this binds the event to the function call as argument, usefull if event is needed
         * Event.observe("id", "click", functionName.bindAsEventListener(this));
         */
        if (link.getJavascriptHandlerFunction() != null) {
            jsSb.append(elementId).append(".on('").append(link.getMouseEvent()).append("', ").append(link.getJavascriptHandlerFunction()).append(");");
        }
        /**
         * Focus link so that it can be invoked using the enter key using a keyboard.
         */
        if (link.isFocus()) {
            jsSb.append(elementId).append(".focus();");
        }
    } else {
        String text;
        if (customDisplayText != null) {
            // link is nontranslated but has custom text
            text = customDisplayText;
        } else if (nontranslated) {
            // link name is not a i18n key
            text = (i18n == null ? "" : i18n);
        } else {
            text = translator.translate(i18n);
        }
        sb.append("<a ");
        if (elementId != null)
            sb.append(" id=\"").append(elementId).append("\" ");
        String description = link.getTextReasonForDisabling();
        // fallback to title
        if (description == null)
            description = link.getTitle();
        if (description != null) {
            Matcher msq = singleQuote.matcher(description);
            description = msq.replaceAll("&#39;");
            Matcher mdq = doubleQutoe.matcher(description);
            description = mdq.replaceAll("\\\\\"");
            sb.append(" title=\"").append(description).append("\" ");
        }
        sb.append(cssSb).append(" href='#' onclick='return false;'>");
        // CSS icon
        if (link.getIconLeftCSS() != null) {
            sb.append("<i class='").append(link.getIconLeftCSS()).append("'");
            // one space needed
            sb.append("></i> ");
        }
        sb.append("<span>").append(text).append("</span>");
        // CSS icon
        if (link.getIconRightCSS() != null) {
            // one space needed
            sb.append(" <i class='").append(link.getIconRightCSS()).append("'");
            sb.append("></i> ");
        }
        sb.append("</a>");
    }
    if (link.getTarget() != null) {
        // if the link starts a download -> the o_afterserver is not called in
        // non-ajax mode if a download is started.
        // on click execute the "same" javascript as in o_ainvoke(r,true) for
        // case 3:
        jsSb.append("if (").append(elementId).append(") ").append(elementId).append(".click(function() {setTimeout(removeBusyAfterDownload,1200)});");
    }
    // now append all gathered javascript stuff if any
    if (jsSb.length() > 0) {
        // Execute code within an anonymous function (closure) to not leak
        // variables to global scope (OLAT-5755)
        sb.append(" <script type=\"text/javascript\">\n/* <![CDATA[ */\n").append("(function(){ var ").append(elementId).append(" = jQuery('#").append(elementId).append("');").append(jsSb).append("})();").append("\n/* ]]> */\n</script>");
    }
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) AJAXFlags(org.olat.core.gui.control.winmgr.AJAXFlags) Form(org.olat.core.gui.components.form.flexible.impl.Form) Matcher(java.util.regex.Matcher) StringOutput(org.olat.core.gui.render.StringOutput)

Example 9 with StringOutput

use of org.olat.core.gui.render.StringOutput in project OpenOLAT by OpenOLAT.

the class DefaultCsvTableExporter method createData.

private void createData(final Table table, final int cdcnt, final int rcnt, final StringBuilder sb) {
    for (int r = 0; r < rcnt; r++) {
        for (int c = 0; c < cdcnt; c++) {
            ColumnDescriptor cd = table.getColumnDescriptor(c);
            if (cd instanceof StaticColumnDescriptor) {
                // ignore static column descriptors - of no value in excel download!
                continue;
            }
            StringOutput so = new StringOutput();
            cd.renderValue(so, r, null);
            String cellValue = so.toString();
            cellValue = StringHelper.stripLineBreaks(cellValue);
            cellValue = FilterFactory.getHtmlTagsFilter().filter(cellValue);
            sb.append('\t').append(cellValue);
        }
        sb.append('\n');
    }
}
Also used : StringOutput(org.olat.core.gui.render.StringOutput)

Example 10 with StringOutput

use of org.olat.core.gui.render.StringOutput in project OpenOLAT by OpenOLAT.

the class TableListProvider method getResult.

@Override
public void getResult(String searchValue, ListReceiver receiver) {
    Filter htmlFilter = FilterFactory.getHtmlTagsFilter();
    Set<String> searchEntries = new TreeSet<String>();
    int entryCounter = 1;
    // loop over whole data-model
    TableDataModel<?> unfilteredModel = table.getUnfilteredTableDataModel();
    int rowCount = unfilteredModel.getRowCount();
    int colCount = table.getColumnCountFromAllCDs();
    a_a: for (int colIndex = 0; colIndex < colCount; colIndex++) {
        ColumnDescriptor cd = table.getColumnDescriptorFromAllCDs(colIndex);
        int dataColumn = cd.getDataColumn();
        if (dataColumn >= 0 && table.isColumnDescriptorVisible(cd)) {
            for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
                Object obj = unfilteredModel.getValueAt(rowIndex, dataColumn);
                // When a CustomCellRenderer exist, use this to render cell-value to String
                if (cd instanceof CustomRenderColumnDescriptor) {
                    CustomRenderColumnDescriptor crcd = (CustomRenderColumnDescriptor) cd;
                    CustomCellRenderer customCellRenderer = crcd.getCustomCellRenderer();
                    if (customCellRenderer instanceof CustomCssCellRenderer) {
                        // For css renderers only use the hover
                        // text, not the CSS class name and other
                        // markup
                        CustomCssCellRenderer cssRenderer = (CustomCssCellRenderer) customCellRenderer;
                        obj = cssRenderer.getHoverText(obj);
                        if (!StringHelper.containsNonWhitespace((String) obj)) {
                            continue;
                        }
                    } else {
                        StringOutput sb = StringOutputPool.allocStringBuilder(250);
                        customCellRenderer.render(sb, null, obj, crcd.getLocale(), cd.getAlignment(), null);
                        obj = StringOutputPool.freePop(sb);
                    }
                }
                if (obj instanceof String) {
                    String valueString = (String) obj;
                    // Remove any HTML markup from the value
                    valueString = htmlFilter.filter(valueString);
                    // Finally compare with search value based on a simple lowercase match
                    if (valueString.toLowerCase().indexOf(searchValue.toLowerCase()) != -1) {
                        if (searchEntries.add(valueString)) {
                            // Add to receiver list same entries only once
                            if (searchEntries.size() == 1) {
                                // before first entry, add searchValue. But add only when one search match
                                receiver.addEntry(searchValue, searchValue);
                            }
                            // limit the number of entries
                            if (entryCounter++ > MAX_TABLE_SEARCH_RESULT_ENTRIES) {
                                receiver.addEntry("...", "...");
                                break a_a;
                            }
                            receiver.addEntry(valueString, valueString);
                        }
                    }
                }
            }
        }
    }
}
Also used : Filter(org.olat.core.util.filter.Filter) TreeSet(java.util.TreeSet) StringOutput(org.olat.core.gui.render.StringOutput)

Aggregations

StringOutput (org.olat.core.gui.render.StringOutput)188 IOException (java.io.IOException)48 URLBuilder (org.olat.core.gui.render.URLBuilder)30 Renderer (org.olat.core.gui.render.Renderer)26 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)24 RenderResult (org.olat.core.gui.render.RenderResult)22 Component (org.olat.core.gui.components.Component)10 Translator (org.olat.core.gui.translator.Translator)10 Locale (java.util.Locale)8 Window (org.olat.core.gui.components.Window)8 Form (org.olat.core.gui.components.form.flexible.impl.Form)8 VelocityRenderDecorator (org.olat.core.gui.render.velocity.VelocityRenderDecorator)8 ArrayList (java.util.ArrayList)6 StreamResult (javax.xml.transform.stream.StreamResult)6 Test (org.junit.Test)6 GlobalSettings (org.olat.core.gui.GlobalSettings)6 ComponentRenderer (org.olat.core.gui.components.ComponentRenderer)6 DefaultColumnDescriptor (org.olat.core.gui.components.table.DefaultColumnDescriptor)6 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)6 Matcher (java.util.regex.Matcher)5