Search in sources :

Example 1 with TextModeState

use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl.TextModeState in project OpenOLAT by OpenOLAT.

the class RichTextElementRenderer method render.

@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    RichTextElementComponent teC = (RichTextElementComponent) source;
    RichTextElementImpl te = teC.getRichTextElementImpl();
    // DOM ID used to identify the rich text element in the browser DOM
    String domID = teC.getFormDispatchId();
    if (!source.isEnabled()) {
        renderDisabled(sb, domID, teC);
    } else {
        sb.append("<div id='").append(domID).append("_diw' class='o_richtext_mce");
        if (!te.getEditorConfiguration().isPathInStatusBar()) {
            sb.append(" o_richtext_mce_without_path");
        }
        sb.append("'>");
        // switches
        TextMode currentTextMode;
        if (te.getEditorConfiguration().getTextModes().size() > 1) {
            TextModeState textModeState = te.getAvailableTextModes();
            currentTextMode = textModeState.getCurrentMode();
            List<TextMode> modes = textModeState.getAvailableTextModes();
            if (modes.size() > 0) {
                Form form = te.getRootForm();
                sb.append("<div class='o_richtext_mce_modes'><div class='btn-group'>");
                for (TextMode mode : modes) {
                    sb.append("<a href='javascript:;' class='btn btn-default btn-xs").append(" active", currentTextMode == mode).append("'").append(" onclick=\"").append(FormJSHelper.getXHRFnCallFor(form, teC.getFormDispatchId(), 1, false, false, true, new NameValuePair("cmd", mode.name()))).append("\">").append(source.getTranslator().translate(mode.name())).append("</a>");
                }
                sb.append("</div></div>");
            }
        } else {
            currentTextMode = TextMode.formatted;
        }
        switch(currentTextMode) {
            case formatted:
                renderTinyMCE_4(sb, domID, teC, ubu, source.getTranslator());
                break;
            case multiLine:
                renderMultiLine(sb, domID, teC);
                break;
            case oneLine:
                renderOneLine(sb, domID, teC);
                break;
        }
        sb.append("</div>");
    }
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Form(org.olat.core.gui.components.form.flexible.impl.Form) TextModeState(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl.TextModeState)

Example 2 with TextModeState

use of org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl.TextModeState in project openolat by klemens.

the class RichTextElementRenderer method render.

@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    RichTextElementComponent teC = (RichTextElementComponent) source;
    RichTextElementImpl te = teC.getRichTextElementImpl();
    // DOM ID used to identify the rich text element in the browser DOM
    String domID = teC.getFormDispatchId();
    if (!source.isEnabled()) {
        renderDisabled(sb, domID, teC);
    } else {
        sb.append("<div id='").append(domID).append("_diw' class='o_richtext_mce");
        if (!te.getEditorConfiguration().isPathInStatusBar()) {
            sb.append(" o_richtext_mce_without_path");
        }
        sb.append("'>");
        // switches
        TextMode currentTextMode;
        if (te.getEditorConfiguration().getTextModes().size() > 1) {
            TextModeState textModeState = te.getAvailableTextModes();
            currentTextMode = textModeState.getCurrentMode();
            List<TextMode> modes = textModeState.getAvailableTextModes();
            if (modes.size() > 0) {
                Form form = te.getRootForm();
                sb.append("<div class='o_richtext_mce_modes'><div class='btn-group'>");
                for (TextMode mode : modes) {
                    sb.append("<a href='javascript:;' class='btn btn-default btn-xs").append(" active", currentTextMode == mode).append("'").append(" onclick=\"").append(FormJSHelper.getXHRFnCallFor(form, teC.getFormDispatchId(), 1, false, false, true, new NameValuePair("cmd", mode.name()))).append("\">").append(source.getTranslator().translate(mode.name())).append("</a>");
                }
                sb.append("</div></div>");
            }
        } else {
            currentTextMode = TextMode.formatted;
        }
        switch(currentTextMode) {
            case formatted:
                renderTinyMCE_4(sb, domID, teC, ubu, source.getTranslator());
                break;
            case multiLine:
                renderMultiLine(sb, domID, teC);
                break;
            case oneLine:
                renderOneLine(sb, domID, teC);
                break;
        }
        sb.append("</div>");
    }
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Form(org.olat.core.gui.components.form.flexible.impl.Form) TextModeState(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl.TextModeState)

Aggregations

Form (org.olat.core.gui.components.form.flexible.impl.Form)2 NameValuePair (org.olat.core.gui.components.form.flexible.impl.NameValuePair)2 TextModeState (org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl.TextModeState)2