Search in sources :

Example 1 with InlineTextElement

use of org.olat.core.gui.components.form.flexible.elements.InlineTextElement 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 2 with InlineTextElement

use of org.olat.core.gui.components.form.flexible.elements.InlineTextElement in project openolat by klemens.

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)

Aggregations

Component (org.olat.core.gui.components.Component)2 ComponentRenderer (org.olat.core.gui.components.ComponentRenderer)2 InlineTextElement (org.olat.core.gui.components.form.flexible.elements.InlineTextElement)2 RenderResult (org.olat.core.gui.render.RenderResult)2 Renderer (org.olat.core.gui.render.Renderer)2 RenderingState (org.olat.core.gui.render.RenderingState)2 StringOutput (org.olat.core.gui.render.StringOutput)2 URLBuilder (org.olat.core.gui.render.URLBuilder)2 Translator (org.olat.core.gui.translator.Translator)2