Search in sources :

Example 21 with RenderResult

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

the class TextElementImpl method initInlineEditing.

private void initInlineEditing(String predefinedValue) {
    // init the inline editing element component.
    transientValue = predefinedValue;
    AbstractInlineElementComponent aiec = new AbstractInlineElementComponent(this, new ComponentRenderer() {

        public void renderHeaderIncludes(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderingState rstate) {
        // nothing to do here
        }

        public void renderBodyOnLoadJSFunctionCall(Renderer renderer, StringOutput sb, Component source, RenderingState rstate) {
        // nothing to do here
        }

        public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
            AbstractInlineElementComponent aiec = (AbstractInlineElementComponent) source;
            InlineTextElement itei = (InlineTextElement) aiec.getInlineElement();
            StringBuilder htmlVal = new StringBuilder();
            /**
             * in case of an error show the test which caused the error which must be stored by the textelement in the transientValue.
             * the last valid value is always set over setValue(..) by the textelement, and thus can be retrieved as such here.
             */
            String tmpVal;
            String emptyVal = (itei.isInlineEditingOn() ? "" : itei.getEmptyDisplayText());
            if (itei.hasError()) {
                tmpVal = StringHelper.containsNonWhitespace(transientValue) ? transientValue : emptyVal;
            } else {
                tmpVal = StringHelper.containsNonWhitespace(getValue()) ? getValue() : emptyVal;
            }
            // append the html safe value
            htmlVal.append(StringEscapeUtils.escapeHtml(tmpVal));
            if (!itei.isEnabled()) {
                // RO view and not clickable
                String id = aiec.getFormDispatchId();
                sb.append("<div class='form-control-static' id=\"").append(id).append("\" ").append(" >").append(htmlVal).append("</div>");
            } else {
                // .......presssing ESC -> restore previous value and submit this one.
                if (itei.isInlineEditingOn()) {
                    String id = aiec.getFormDispatchId();
                    // read write view
                    sb.append("<input type=\"").append("input").append("\" class=\"form-control\" id=\"");
                    sb.append(id);
                    sb.append("\" name=\"");
                    sb.append(id);
                    sb.append("\" size=\"");
                    sb.append("30");
                    // if(itei.maxlength > -1){
                    // sb.append("\" maxlength=\"");
                    // sb.append(itei.maxlength);
                    // }
                    sb.append("\" value=\"");
                    sb.append(htmlVal);
                    sb.append("\" ");
                    sb.append(" />");
                    // Javascript
                    sb.append(FormJSHelper.getJSStart());
                    // clicking outside or pressing enter -> OK, pressing ESC -> Cancel
                    FormJSHelper.getInlineEditOkCancelJS(sb, id, StringEscapeUtils.escapeHtml(getValue()), itei.getRootForm());
                    sb.append(FormJSHelper.getJSEnd());
                } else {
                    // RO<->RW view which can be clicked
                    Translator trans = Util.createPackageTranslator(TextElementImpl.class, translator.getLocale(), translator);
                    String id = aiec.getFormDispatchId();
                    sb.append("<div id='").append(id).append("' class='form-control-static' title=\"").append(StringEscapeUtils.escapeHtml(trans.translate("inline.edit.help"))).append("\" ").append(FormJSHelper.getRawJSFor(itei.getRootForm(), id, itei.getAction())).append("> ").append(htmlVal).append(" <i class='o_icon o_icon_inline_editable'> </i></div>");
                }
            }
        // endif
        }
    });
    setInlineEditingComponent(aiec);
}
Also used : RenderingState(org.olat.core.gui.render.RenderingState) RenderResult(org.olat.core.gui.render.RenderResult) StringOutput(org.olat.core.gui.render.StringOutput) URLBuilder(org.olat.core.gui.render.URLBuilder) InlineTextElement(org.olat.core.gui.components.form.flexible.elements.InlineTextElement) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Translator(org.olat.core.gui.translator.Translator) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Renderer(org.olat.core.gui.render.Renderer) Component(org.olat.core.gui.components.Component)

Example 22 with RenderResult

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

the class MailFromCellRenderer method render.

@Override
public void render(StringOutput sb, Renderer renderer, Object val, Locale locale, int alignment, String action) {
    if (val instanceof Identity) {
        Identity identity = (Identity) val;
        String fullName = userManager.getUserDisplayName(identity);
        if (renderer == null) {
            sb.appendHtmlEscaped(fullName);
        } else {
            Link link = LinkFactory.createLink("bp_" + counter.incrementAndGet(), container, listeningController);
            link.setCustomDisplayText(StringHelper.escapeHtml(fullName));
            link.setUserObject("[Identity:" + identity.getKey() + "]");
            URLBuilder ubu = renderer.getUrlBuilder().createCopyFor(link);
            RenderResult renderResult = new RenderResult();
            link.getHTMLRendererSingleton().render(renderer, sb, link, ubu, translator, renderResult, null);
        }
    } else if (val instanceof String) {
        sb.append("<span>").appendHtmlEscaped((String) val).append("</span>");
    }
}
Also used : RenderResult(org.olat.core.gui.render.RenderResult) Identity(org.olat.core.id.Identity) Link(org.olat.core.gui.components.link.Link) URLBuilder(org.olat.core.gui.render.URLBuilder)

Example 23 with RenderResult

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

the class QTI21ResultsExportMediaResource method createResultHTML.

private String createResultHTML(Component results) {
    String pagePath = Util.getPackageVelocityRoot(this.getClass()) + "/qti21results.html";
    URLBuilder ubu = new URLBuilder("auth", "1", "0");
    // generate VelocityContainer and put Component
    VelocityContainer mainVC = new VelocityContainer("html", pagePath, translator, null);
    mainVC.contextPut("rootTitle", translator.translate("table.grading"));
    mainVC.put("results", results);
    // render VelocityContainer to StringOutPut
    Renderer renderer = Renderer.getInstance(mainVC, translator, ubu, new RenderResult(), new EmptyGlobalSettings());
    try (StringOutput sb = new StringOutput(32000);
        VelocityRenderDecorator vrdec = new VelocityRenderDecorator(renderer, mainVC, sb)) {
        mainVC.contextPut("r", vrdec);
        renderer.render(sb, mainVC, null);
        vrdec.close();
        return sb.toString();
    } catch (Exception e) {
        log.error("", e);
        return "";
    }
}
Also used : Renderer(org.olat.core.gui.render.Renderer) RenderResult(org.olat.core.gui.render.RenderResult) StringOutput(org.olat.core.gui.render.StringOutput) IOException(java.io.IOException) URLBuilder(org.olat.core.gui.render.URLBuilder) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) VelocityRenderDecorator(org.olat.core.gui.render.velocity.VelocityRenderDecorator)

Example 24 with RenderResult

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

the class AssessmentObjectComponentRenderer method renderEndAttemptInteraction.

private void renderEndAttemptInteraction(AssessmentRenderer renderer, StringOutput sb, EndAttemptInteraction interaction, ItemSessionState itemSessionState, AssessmentObjectComponent component, URLBuilder ubu, Translator translator) {
    if (QTI21Constants.HINT_REQUEST_IDENTIFIER.equals(interaction.getResponseIdentifier()) && component.isHideFeedbacks()) {
        // don't show our hint's, they trigger feedbacks
        return;
    }
    boolean ended = component.isItemSessionEnded(itemSessionState, renderer.isSolutionMode());
    AssessmentObjectFormItem item = component.getQtiItem();
    String responseUniqueId = component.getResponseUniqueIdentifier(itemSessionState, interaction);
    String id = "qtiworks_response_".concat(responseUniqueId);
    if (!ended) {
        sb.append("<input name=\"qtiworks_presented_").append(responseUniqueId).append("\" type=\"hidden\" value=\"1\"/>");
    }
    FormItem endAttemptButton = item.getFormComponent(id);
    if (endAttemptButton == null) {
        String title = StringHelper.escapeHtml(interaction.getTitle());
        FormLink button = FormUIFactory.getInstance().addFormLink(id, id, title, null, null, Link.BUTTON | Link.NONTRANSLATED);
        // use specific icon for known types
        if (interaction.getResponseIdentifier().equals(QTI21Constants.HINT_REQUEST_IDENTIFIER)) {
            button.setIconLeftCSS("o_icon o_icon-fw o_icon_qti_hint");
            button.setElementCssClass("o_sel_assessment_item_hint");
        }
        endAttemptButton = button;
        endAttemptButton.setTranslator(translator);
        endAttemptButton.setUserObject(interaction);
        if (item.getRootForm() != endAttemptButton.getRootForm()) {
            endAttemptButton.setRootForm(item.getRootForm());
        }
        item.addFormItem(endAttemptButton);
    }
    endAttemptButton.setEnabled(!ended);
    endAttemptButton.getComponent().getHTMLRendererSingleton().render(renderer.getRenderer(), sb, endAttemptButton.getComponent(), ubu, translator, new RenderResult(), null);
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) RenderResult(org.olat.core.gui.render.RenderResult) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 25 with RenderResult

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

the class AssessmentObjectComponentRenderer method renderVelocity.

private void renderVelocity(AssessmentRenderer renderer, StringOutput sb, QtiNode interaction, Context ctx, String page, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, AssessmentObjectComponent component, URLBuilder ubu, Translator translator) {
    ctx.put("localName", interaction.getQtiClassName());
    ctx.put("assessmentItem", resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful());
    ctx.put("itemSessionState", itemSessionState);
    ctx.put("isItemSessionOpen", component.isItemSessionOpen(itemSessionState, renderer.isSolutionMode()));
    ctx.put("isItemSessionEnded", component.isItemSessionEnded(itemSessionState, renderer.isSolutionMode()));
    Renderer fr = Renderer.getInstance(component, translator, ubu, new RenderResult(), renderer.getGlobalSettings());
    AssessmentRenderer fHints = renderer.newHints(fr);
    try (AssessmentObjectVelocityRenderDecorator vrdec = new AssessmentObjectVelocityRenderDecorator(fHints, sb, component, resolvedAssessmentItem, itemSessionState, ubu, translator)) {
        ctx.put("r", vrdec);
        VelocityHelper vh = VelocityHelper.getInstance();
        vh.mergeContent(page, ctx, sb, null);
        ctx.remove("r");
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : Renderer(org.olat.core.gui.render.Renderer) DefaultComponentRenderer(org.olat.core.gui.components.DefaultComponentRenderer) RenderResult(org.olat.core.gui.render.RenderResult) VelocityHelper(org.olat.core.gui.render.velocity.VelocityHelper) IOException(java.io.IOException)

Aggregations

RenderResult (org.olat.core.gui.render.RenderResult)32 Renderer (org.olat.core.gui.render.Renderer)22 URLBuilder (org.olat.core.gui.render.URLBuilder)22 StringOutput (org.olat.core.gui.render.StringOutput)20 IOException (java.io.IOException)10 Component (org.olat.core.gui.components.Component)10 VelocityRenderDecorator (org.olat.core.gui.render.velocity.VelocityRenderDecorator)8 GlobalSettings (org.olat.core.gui.GlobalSettings)6 ComponentRenderer (org.olat.core.gui.components.ComponentRenderer)6 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)6 RenderingState (org.olat.core.gui.render.RenderingState)6 Translator (org.olat.core.gui.translator.Translator)6 ArrayList (java.util.ArrayList)4 DelegatingComponent (org.olat.core.gui.components.delegating.DelegatingComponent)4 InvalidRequestParameterException (org.olat.core.gui.components.form.flexible.impl.InvalidRequestParameterException)4 Link (org.olat.core.gui.components.link.Link)4 Command (org.olat.core.gui.control.winmgr.Command)4 JSCommand (org.olat.core.gui.control.winmgr.JSCommand)4 AsyncMediaResponsible (org.olat.core.gui.media.AsyncMediaResponsible)4 InterceptHandler (org.olat.core.gui.render.intercept.InterceptHandler)4