Search in sources :

Example 1 with AJAXFlags

use of org.olat.core.gui.control.winmgr.AJAXFlags in project OpenOLAT by OpenOLAT.

the class WikiMarkupRenderer method render.

/**
 * @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) {
    WikiMarkupComponent wikiComp = (WikiMarkupComponent) source;
    AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
    boolean iframePostEnabled = flags.isIframePostEnabled();
    ParserInput input = new ParserInput();
    input.setWikiUser(null);
    input.setAllowSectionEdit(false);
    input.setDepth(10);
    input.setContext("");
    // input.setTableOfContents(null);
    input.setLocale(new Locale("en"));
    // input.setVirtualWiki(Long.toString(wikiComp.getOres().getResourceableId()));
    input.setTopicName("dummy");
    input.setUserIpAddress("0.0.0.0");
    OlatWikiDataHandler dataHandler = new OlatWikiDataHandler(wikiComp.getOres(), wikiComp.getImageBaseUri());
    input.setDataHandler(dataHandler);
    StringOutput out = new StringOutput(100);
    ubu.buildURI(out, null, null, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
    String uri = out.toString();
    ParserDocument parsedDoc = null;
    String uniqueId = "o_wiki".concat(wikiComp.getDispatchID());
    try {
        uri = URLDecoder.decode(uri, "utf-8");
        input.setVirtualWiki(uri.substring(1, uri.length() - 1));
        if (iframePostEnabled) {
            String targetUrl = " onclick=\"o_XHREvent(jQuery(this).attr('href'),false,true); return false;\"";
            input.setURLTarget(targetUrl);
        }
        sb.append("<div style=\"min-height:" + wikiComp.getMinHeight() + "px\" id=\"");
        sb.append(uniqueId);
        sb.append("\">");
        JFlexParser parser = new JFlexParser(input);
        parsedDoc = parser.parseHTML(wikiComp.getWikiContent());
    } catch (UnsupportedEncodingException e) {
    // encoding utf-8 should be ok
    } catch (Exception e) {
        throw new OLATRuntimeException(this.getClass(), "error while rendering wiki page with content:" + wikiComp.getWikiContent(), e);
    }
    // Use global js math formatter for latex formulas
    sb.append(Formatter.formatLatexFormulas(parsedDoc.getContent()));
    sb.append("</div>");
    // set targets of media, image and external links to target "_blank"
    sb.append("<script type=\"text/javascript\">/* <![CDATA[ */ ");
    String instanceUrl = Settings.getServerContextPathURI();
    sb.append("changeAnchorTargets('").append(uniqueId).append("','").append(instanceUrl).append("');");
    sb.append("/* ]]> */</script>");
}
Also used : Locale(java.util.Locale) JFlexParser(org.jamwiki.parser.jflex.JFlexParser) AJAXFlags(org.olat.core.gui.control.winmgr.AJAXFlags) ParserInput(org.jamwiki.parser.ParserInput) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StringOutput(org.olat.core.gui.render.StringOutput) ParserDocument(org.jamwiki.parser.ParserDocument) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 2 with AJAXFlags

use of org.olat.core.gui.control.winmgr.AJAXFlags 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 3 with AJAXFlags

use of org.olat.core.gui.control.winmgr.AJAXFlags in project openolat by klemens.

the class WikiMarkupRenderer method render.

/**
 * @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) {
    WikiMarkupComponent wikiComp = (WikiMarkupComponent) source;
    AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
    boolean iframePostEnabled = flags.isIframePostEnabled();
    ParserInput input = new ParserInput();
    input.setWikiUser(null);
    input.setAllowSectionEdit(false);
    input.setDepth(10);
    input.setContext("");
    // input.setTableOfContents(null);
    input.setLocale(new Locale("en"));
    // input.setVirtualWiki(Long.toString(wikiComp.getOres().getResourceableId()));
    input.setTopicName("dummy");
    input.setUserIpAddress("0.0.0.0");
    OlatWikiDataHandler dataHandler = new OlatWikiDataHandler(wikiComp.getOres(), wikiComp.getImageBaseUri());
    input.setDataHandler(dataHandler);
    StringOutput out = new StringOutput(100);
    ubu.buildURI(out, null, null, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
    String uri = out.toString();
    ParserDocument parsedDoc = null;
    String uniqueId = "o_wiki".concat(wikiComp.getDispatchID());
    try {
        uri = URLDecoder.decode(uri, "utf-8");
        input.setVirtualWiki(uri.substring(1, uri.length() - 1));
        if (iframePostEnabled) {
            String targetUrl = " onclick=\"o_XHREvent(jQuery(this).attr('href'),false,true); return false;\"";
            input.setURLTarget(targetUrl);
        }
        sb.append("<div style=\"min-height:" + wikiComp.getMinHeight() + "px\" id=\"");
        sb.append(uniqueId);
        sb.append("\">");
        JFlexParser parser = new JFlexParser(input);
        parsedDoc = parser.parseHTML(wikiComp.getWikiContent());
    } catch (UnsupportedEncodingException e) {
    // encoding utf-8 should be ok
    } catch (Exception e) {
        throw new OLATRuntimeException(this.getClass(), "error while rendering wiki page with content:" + wikiComp.getWikiContent(), e);
    }
    // Use global js math formatter for latex formulas
    sb.append(Formatter.formatLatexFormulas(parsedDoc.getContent()));
    sb.append("</div>");
    // set targets of media, image and external links to target "_blank"
    sb.append("<script type=\"text/javascript\">/* <![CDATA[ */ ");
    String instanceUrl = Settings.getServerContextPathURI();
    sb.append("changeAnchorTargets('").append(uniqueId).append("','").append(instanceUrl).append("');");
    sb.append("/* ]]> */</script>");
}
Also used : Locale(java.util.Locale) JFlexParser(org.jamwiki.parser.jflex.JFlexParser) AJAXFlags(org.olat.core.gui.control.winmgr.AJAXFlags) ParserInput(org.jamwiki.parser.ParserInput) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StringOutput(org.olat.core.gui.render.StringOutput) ParserDocument(org.jamwiki.parser.ParserDocument) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 4 with AJAXFlags

use of org.olat.core.gui.control.winmgr.AJAXFlags in project openolat by klemens.

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 5 with AJAXFlags

use of org.olat.core.gui.control.winmgr.AJAXFlags in project openolat by klemens.

the class MenuTreeRenderer method render.

/**
 * @see org.olat.core.gui.render.ui.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 target, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    MenuTree tree = (MenuTree) source;
    if (tree.getMenuTreeItem() != null) {
        tree.getMenuTreeItem().clearVisibleNodes();
    }
    TreeNode root = tree.getTreeModel().getRootNode();
    // tree is completely empty
    if (root == null)
        return;
    INode selNode = tree.getSelectedNode();
    Collection<String> openNodeIds = tree.getOpenNodeIds();
    List<INode> selPath = new ArrayList<>(5);
    INode cur = selNode;
    if (cur == null && !tree.isUnselectNodes()) {
        cur = root;
    } else if (cur == null && tree.isUnselectNodes() && openNodeIds.isEmpty()) {
        // always open the root
        openNodeIds.add(root.getIdent());
    }
    // selected nodeid of the root node
    while (cur != null) {
        selPath.add(0, cur);
        cur = cur.getParent();
    }
    List<DndElement> elements = new ArrayList<>();
    AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
    target.append("\n<div class='o_tree");
    // marker classes to differentiate rendering when root node is visible
    if (!tree.isRootVisible()) {
        target.append(" o_tree_root_hidden");
    } else {
        target.append(" o_tree_root_visible");
    }
    if (tree.isInsertToolEnabled()) {
        target.append(" o_tree_insert_tool");
    }
    // add element CSS
    if (StringHelper.containsNonWhitespace(tree.getElementCssClass())) {
        target.append(" ").append(tree.getElementCssClass());
    }
    target.append("'><ul class=\"o_tree_l0\">");
    if (tree.isRootVisible()) {
        renderLevel(renderer, target, 0, root, selPath, openNodeIds, elements, ubu, flags, tree);
    } else {
        selPath.remove(0);
        int chdCnt = root.getChildCount();
        for (int i = 0; i < chdCnt; i++) {
            TreeNode curChd = (TreeNode) root.getChildAt(i);
            renderLevel(renderer, target, 0, curChd, selPath, openNodeIds, elements, ubu, flags, tree);
        }
    }
    target.append("</ul>");
    appendDragAndDropScript(elements, tree, target).append("</div>");
}
Also used : INode(org.olat.core.util.nodes.INode) AJAXFlags(org.olat.core.gui.control.winmgr.AJAXFlags) ArrayList(java.util.ArrayList)

Aggregations

AJAXFlags (org.olat.core.gui.control.winmgr.AJAXFlags)8 StringOutput (org.olat.core.gui.render.StringOutput)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 Matcher (java.util.regex.Matcher)2 ParserDocument (org.jamwiki.parser.ParserDocument)2 ParserInput (org.jamwiki.parser.ParserInput)2 JFlexParser (org.jamwiki.parser.jflex.JFlexParser)2 ComponentCollection (org.olat.core.gui.components.ComponentCollection)2 Form (org.olat.core.gui.components.form.flexible.impl.Form)2 NameValuePair (org.olat.core.gui.components.form.flexible.impl.NameValuePair)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 INode (org.olat.core.util.nodes.INode)2