Skip to content
Snippets Groups Projects
Commit 356f1b12 authored by srosse's avatar srosse
Browse files

OO-3938: allow opening a new window from a flexi table

Implement opening a new window from the standard action in a flexi form
(without form submit)
parent 5c00606d
No related branches found
No related tags found
No related merge requests found
...@@ -123,7 +123,17 @@ public class DefaultFlexiColumnModel implements FlexiColumnModel { ...@@ -123,7 +123,17 @@ public class DefaultFlexiColumnModel implements FlexiColumnModel {
* @param action * @param action
*/ */
public DefaultFlexiColumnModel(String headerKey, String label, String action) { public DefaultFlexiColumnModel(String headerKey, String label, String action) {
this(true, true, headerKey, -1, action, false, null, FlexiColumnModel.ALIGNMENT_LEFT, new StaticFlexiCellRenderer(label, action)); this(headerKey, label, action, false);
}
/**
* Always visible
* @param headerKey
* @param label
* @param action
*/
public DefaultFlexiColumnModel(String headerKey, String label, String action, boolean newWindow) {
this(true, true, headerKey, -1, action, false, null, FlexiColumnModel.ALIGNMENT_LEFT, new StaticFlexiCellRenderer(label, action, newWindow));
} }
public DefaultFlexiColumnModel(String headerKey, int columnIndex, boolean sortable, String sortKey) { public DefaultFlexiColumnModel(String headerKey, int columnIndex, boolean sortable, String sortKey) {
......
...@@ -20,14 +20,19 @@ ...@@ -20,14 +20,19 @@
package org.olat.core.gui.components.form.flexible.impl.elements.table; package org.olat.core.gui.components.form.flexible.impl.elements.table;
import java.io.IOException;
import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringEscapeUtils;
import org.olat.core.gui.components.form.flexible.impl.Form; import org.olat.core.gui.components.form.flexible.impl.Form;
import org.olat.core.gui.components.form.flexible.impl.FormJSHelper; import org.olat.core.gui.components.form.flexible.impl.FormJSHelper;
import org.olat.core.gui.components.form.flexible.impl.NameValuePair; import org.olat.core.gui.components.form.flexible.impl.NameValuePair;
import org.olat.core.gui.control.winmgr.AJAXFlags;
import org.olat.core.gui.render.Renderer; import org.olat.core.gui.render.Renderer;
import org.olat.core.gui.render.StringOutput; import org.olat.core.gui.render.StringOutput;
import org.olat.core.gui.render.URLBuilder; import org.olat.core.gui.render.URLBuilder;
import org.olat.core.gui.translator.Translator; import org.olat.core.gui.translator.Translator;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
import org.olat.core.util.StringHelper; import org.olat.core.util.StringHelper;
/** /**
...@@ -37,33 +42,45 @@ import org.olat.core.util.StringHelper; ...@@ -37,33 +42,45 @@ import org.olat.core.util.StringHelper;
* *
*/ */
public class StaticFlexiCellRenderer implements FlexiCellRenderer { public class StaticFlexiCellRenderer implements FlexiCellRenderer {
private static final OLog log = Tracing.createLoggerFor(StaticFlexiCellRenderer.class);
private String label; private String label;
private String action; private String action;
private String iconLeftCSS; private String iconLeftCSS;
private String iconRightCSS; private String iconRightCSS;
private String linkCSS; private String linkCSS;
private String linkTitle; private String linkTitle;
private boolean newWindow = false;
private FlexiCellRenderer labelDelegate; private FlexiCellRenderer labelDelegate;
public StaticFlexiCellRenderer(String label, String action) { public StaticFlexiCellRenderer(String label, String action) {
this(label, action, null, null, null); this(label, action, false, null, null, null);
}
public StaticFlexiCellRenderer(String label, String action, boolean newWindow) {
this(label, action, newWindow, null, null, null);
} }
public StaticFlexiCellRenderer(String label, String action, String linkCSS) { public StaticFlexiCellRenderer(String label, String action, String linkCSS) {
this(label, action, linkCSS, null, null); this(label, action, false, linkCSS, null, null);
} }
public StaticFlexiCellRenderer(String label, String action, String linkCSS, String iconLeftCSS) { public StaticFlexiCellRenderer(String label, String action, String linkCSS, String iconLeftCSS) {
this(label, action, linkCSS, iconLeftCSS, null); this(label, action, false, linkCSS, iconLeftCSS, null);
} }
public StaticFlexiCellRenderer(String label, String action, String linkCSS, String iconLeftCSS, String linkTitle) { public StaticFlexiCellRenderer(String label, String action, String linkCSS, String iconLeftCSS, String linkTitle) {
this(label, action, false, linkCSS, iconLeftCSS, linkTitle);
}
public StaticFlexiCellRenderer(String label, String action, boolean newWindow, String linkCSS, String iconLeftCSS, String linkTitle) {
this.label = label; this.label = label;
this.action = action; this.action = action;
this.linkCSS = linkCSS; this.linkCSS = linkCSS;
this.iconLeftCSS = iconLeftCSS; this.iconLeftCSS = iconLeftCSS;
this.linkTitle = linkTitle; this.linkTitle = linkTitle;
this.newWindow = newWindow;
} }
public StaticFlexiCellRenderer(String action, FlexiCellRenderer labelDelegate) { public StaticFlexiCellRenderer(String action, FlexiCellRenderer labelDelegate) {
...@@ -111,6 +128,14 @@ public class StaticFlexiCellRenderer implements FlexiCellRenderer { ...@@ -111,6 +128,14 @@ public class StaticFlexiCellRenderer implements FlexiCellRenderer {
this.action = action; this.action = action;
} }
public boolean isNewWindow() {
return newWindow;
}
public void setNewWindow(boolean newWindow) {
this.newWindow = newWindow;
}
@Override @Override
public void render(Renderer renderer, StringOutput target, Object cellValue, int row, public void render(Renderer renderer, StringOutput target, Object cellValue, int row,
FlexiTableComponent source, URLBuilder ubu, Translator translator) { FlexiTableComponent source, URLBuilder ubu, Translator translator) {
...@@ -121,7 +146,24 @@ public class StaticFlexiCellRenderer implements FlexiCellRenderer { ...@@ -121,7 +146,24 @@ public class StaticFlexiCellRenderer implements FlexiCellRenderer {
String id = source.getFormDispatchId(); String id = source.getFormDispatchId();
Form rootForm = ftE.getRootForm(); Form rootForm = ftE.getRootForm();
NameValuePair pair = new NameValuePair(cellAction, Integer.toString(row)); NameValuePair pair = new NameValuePair(cellAction, Integer.toString(row));
String jsCode = FormJSHelper.getXHRFnCallFor(rootForm, id, 1, true, true, pair); String jsCode;
if(newWindow) {
URLBuilder subu = ubu.createCopyFor(ftE.getRootForm().getInitialComponent());
try(StringOutput href = new StringOutput()) {
href.append("o_openTab('");
subu.buildURI(href, AJAXFlags.MODE_NORMAL,
new NameValuePair("dispatchuri", ftE.getFormDispatchId()),
new NameValuePair("dispatchevent", "1"),
pair);
href.append("')");
jsCode = href.toString();
} catch(IOException e) {
log.error("", e);
jsCode = "";
}
} else {
jsCode = FormJSHelper.getXHRFnCallFor(rootForm, id, 1, true, true, pair);
}
target.append("<a href=\"javascript:").append(jsCode).append(";\""); target.append("<a href=\"javascript:").append(jsCode).append(";\"");
if(StringHelper.containsNonWhitespace(linkTitle)) { if(StringHelper.containsNonWhitespace(linkTitle)) {
target.append(" title=\"").append(StringEscapeUtils.escapeHtml(linkTitle)).append("\""); target.append(" title=\"").append(StringEscapeUtils.escapeHtml(linkTitle)).append("\"");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment