use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.
the class FlexiTableClassicRenderer method renderHeader.
private void renderHeader(StringOutput sb, FlexiTableComponent ftC, FlexiColumnModel fcm, Translator translator) {
String header = getHeader(fcm, translator);
sb.append("<th");
// append sort key to make column width set via css
if (fcm.getSortKey() != null) {
sb.append(" class='o_col_").append(fcm.getSortKey()).append("'");
}
sb.append(">");
// sort is not defined
if (!fcm.isSortable() || fcm.getSortKey() == null) {
sb.append(header);
} else {
FlexiTableElementImpl ftE = ftC.getFlexiTableElement();
Boolean asc = null;
String sortKey = fcm.getSortKey();
SortKey[] orderBy = ftE.getOrderBy();
if (orderBy != null && orderBy.length > 0) {
for (int i = orderBy.length; i-- > 0; ) {
if (sortKey.equals(orderBy[i].getKey())) {
asc = new Boolean(orderBy[i].isAsc());
}
}
}
Form theForm = ftE.getRootForm();
if (asc == null) {
sb.append("<a class='o_orderby' href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, ftC.getFormDispatchId(), 1, true, true, true, new NameValuePair("sort", sortKey), new NameValuePair("asc", "asc"))).append("\">");
} else if (asc.booleanValue()) {
sb.append("<a class='o_orderby o_orderby_asc' href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, ftC.getFormDispatchId(), 1, true, true, true, new NameValuePair("sort", sortKey), new NameValuePair("asc", "desc"))).append("\">");
} else {
sb.append("<a class='o_orderby o_orderby_desc' href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(theForm, ftC.getFormDispatchId(), 1, true, true, true, new NameValuePair("sort", sortKey), new NameValuePair("asc", "asc"))).append("\">");
}
sb.append(header).append("</a>");
}
sb.append("</th>");
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair 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("'");
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>");
}
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.
the class TableRenderer method appendSelectDeselectAllButtons.
private void appendSelectDeselectAllButtons(StringOutput target, Translator translator, Table table, String formName, int rows, int resultsPerPage, boolean ajaxEnabled, URLBuilder ubu) {
if (table.isMultiSelect() && !table.isMultiSelectAsDisabled()) {
target.append("<div class='o_table_checkall input-sm'>").append("<label class='checkbox-inline'>").append("<a href='#' onclick=\"javascript:o_table_toggleCheck('").append(formName).append("', true)\">").append("<i class='o_icon o_icon-lg o_icon_check_on'> </i> ").append(translator.translate("checkall")).append("</a></label>");
target.append("<label class='checkbox-inline'><a href=\"#\" onclick=\"javascript:o_table_toggleCheck('").append(formName).append("', false)\">").append("<i class='o_icon o_icon-lg o_icon_check_off'> </i> ").append(translator.translate("uncheckall")).append("</a></label>").append("</div>");
}
if (table.isShowAllSelected() && (rows > resultsPerPage)) {
target.append("<div class='o_table_pagination'><ul class='pagination'><li>").append("<a class=\"").append("btn btn-sm btn-default").append("\" ");
ubu.buildHrefAndOnclick(target, ajaxEnabled, new NameValuePair(Table.FORM_CMD, Table.COMMAND_PAGEACTION), new NameValuePair(Table.FORM_PARAM, Table.COMMAND_SHOW_PAGES)).append(">").append(translator.translate("table.showpages")).append("</a>").append("</li><ul></div>");
}
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.
the class MenuTreeRenderer method renderOpenClose.
private void renderOpenClose(TreeNode curRoot, StringOutput target, int level, boolean renderChildren, URLBuilder ubu, AJAXFlags flags, MenuTree tree) {
int chdCnt = curRoot.getChildCount();
// add ajax support and real open/close function
if (((tree.isRootVisible() && level != 0) || !tree.isRootVisible()) && chdCnt > 0) {
// root has not open/close icon, append open / close icon only if there is children
target.append("<a ");
ubu.buildHrefAndOnclick(target, null, flags.isIframePostEnabled(), tree.getMenuTreeItem() != null, true, new NameValuePair(COMMAND_ID, COMMAND_TREENODE_CLICKED), new NameValuePair(NODE_IDENT, curRoot.getIdent()), new NameValuePair(COMMAND_TREENODE, renderChildren ? MenuTree.TREENODE_CLOSE : MenuTree.TREENODE_OPEN));
String openCloseCss = renderChildren ? "close" : "open";
target.append(" class='o_tree_oc_l").append(level).append("'><i class='o_icon o_icon_").append(openCloseCss).append("_tree'></i></a>");
} else if (level != 0 && chdCnt == 0) {
target.append("<span class=\"o_tree_leaf o_tree_oc_l").append(level).append("\"> </span>");
}
}
use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.
the class MenuTreeRenderer method renderLink.
private void renderLink(Renderer renderer, TreeNode curRoot, int level, boolean selected, boolean renderChildren, INode curSel, StringOutput target, URLBuilder ubu, AJAXFlags flags, MenuTree tree) {
int chdCnt = curRoot.getChildCount();
boolean iframePostEnabled = flags.isIframePostEnabled();
if (tree.getMenuTreeItem() != null) {
tree.getMenuTreeItem().trackVisibleNode(curRoot);
}
target.append("<span class='o_tree_link o_tree_l").append(level);
// add icon css class
if (selected) {
// add css class to identify active element
target.append(" active");
} else if (curSel == curRoot) {
// add css class to identify parents of active element
target.append(" active_parent");
}
boolean insertionSource = (tree.getTreeModel() instanceof InsertionTreeModel && ((InsertionTreeModel) tree.getTreeModel()).isSource(curRoot));
if (insertionSource) {
target.append(" o_insertion_source");
}
// reapply the same rules to the second link
if (level != 0 && chdCnt > 0) {
if (renderChildren) {
target.append(" o_tree_level_label_close");
} else {
target.append(" o_tree_level_label_open");
}
} else if (level != 0 && chdCnt == 0) {
target.append(" o_tree_level_label_leaf");
}
target.append("'>");
if (tree.isMultiSelect() && tree.getMenuTreeItem() != null) {
renderCheckbox(target, curRoot, tree);
}
// Build menu item URI
target.append("<a ");
boolean dirtyCheck = tree.getMenuTreeItem() == null || !tree.getMenuTreeItem().isNoDirtyCheckOnClick();
ubu.buildHrefAndOnclick(target, null, iframePostEnabled, dirtyCheck, true, new NameValuePair(COMMAND_ID, COMMAND_TREENODE_CLICKED), new NameValuePair(NODE_IDENT, curRoot.getIdent()));
// Add menu item title as alt hoover text
String alt = curRoot.getAltText();
if (alt != null) {
target.append(" title=\"").append(StringEscapeUtils.escapeHtml(alt).toString()).append("\"");
}
target.append(">");
String iconCssClass = curRoot.getIconCssClass();
if (iconCssClass != null) {
target.append("<i class='o_icon o_icon-fw ").append(iconCssClass).append("'></i> ");
}
renderDisplayTitle(renderer, target, curRoot, tree);
// display title and close menu item
appendDecorators(curRoot, target);
target.append("</a></span>");
}
Aggregations