. Added 'script' element config support to externally configured UI action definitions.

. ActionLink component now renders any params found from config definition as URL arguments for an 'href' style action (to support above change)
. Added new root scope object 'logger' to the JavaScript API to aid with debugging of scripts

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3480 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-08-10 17:08:17 +00:00
parent 4fc5704b62
commit 60cf6056c5
5 changed files with 72 additions and 7 deletions

View File

@@ -229,6 +229,7 @@ public class ActionsConfigElement extends ConfigElementAdapter
public String Action;
public String Href;
public String Target;
public String Script;
public String Onclick;
}

View File

@@ -50,6 +50,7 @@ public class ActionsElementReader implements ConfigElementReader
public static final String ELEMENT_ONCLICK = "onclick";
public static final String ELEMENT_HREF = "href";
public static final String ELEMENT_TARGET = "target";
public static final String ELEMENT_SCRIPT = "script";
public static final String ELEMENT_PARAMS = "params";
public static final String ELEMENT_PARAM = "param";
public static final String ATTRIBUTE_ID = "id";
@@ -252,6 +253,7 @@ public class ActionsElementReader implements ConfigElementReader
actionDef.TooltipMsg = actionElement.elementTextTrim(ELEMENT_TOOLTIPMSG);
actionDef.Href = actionElement.elementTextTrim(ELEMENT_HREF);
actionDef.Target = actionElement.elementTextTrim(ELEMENT_TARGET);
actionDef.Script = actionElement.elementTextTrim(ELEMENT_SCRIPT);
actionDef.Action = actionElement.elementTextTrim(ELEMENT_ACTION);
actionDef.ActionListener = actionElement.elementTextTrim(ELEMENT_ACTIONLISTENER);
actionDef.Onclick = actionElement.elementTextTrim(ELEMENT_ONCLICK);

View File

@@ -17,7 +17,9 @@
package org.alfresco.web.ui.common.renderer;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.URLEncoder;
import java.util.Map;
import javax.faces.component.UIComponent;
@@ -133,13 +135,44 @@ public class ActionLinkRenderer extends BaseRenderer
else
{
String href = link.getHref();
if (href.startsWith("http") == false && href.startsWith("file") == false)
// prefix the web context path if required
linkBuf.append("<a href=\"");
if (href.startsWith("/"))
{
href = context.getExternalContext().getRequestContextPath() + href;
linkBuf.append(context.getExternalContext().getRequestContextPath());
}
linkBuf.append("<a href=\"")
.append(href)
.append('"');
linkBuf.append(href);
// append arguments if specified
Map<String, String> actionParams = getParameterComponents(link);
if (actionParams != null)
{
boolean first = (href.indexOf('?') == -1);
for (String name : actionParams.keySet())
{
String paramValue = actionParams.get(name);
if (first)
{
linkBuf.append('?');
first = false;
}
else
{
linkBuf.append('&');
}
try
{
linkBuf.append(name).append("=").append(URLEncoder.encode(paramValue, "UTF-8"));
}
catch (UnsupportedEncodingException err)
{
// if this happens we have bigger problems than a missing URL parameter...!
}
}
}
linkBuf.append('"');
// output href 'target' attribute if supplied
if (link.getTarget() != null)

View File

@@ -17,6 +17,7 @@
package org.alfresco.web.ui.repo.component;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -30,6 +31,7 @@ import javax.faces.el.ValueBinding;
import org.alfresco.config.Config;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.config.ActionsConfigElement;
@@ -369,6 +371,7 @@ public class UIActions extends SelfRenderingComponent
control.setOnclick(actionDef.Onclick);
}
}
if (actionDef.Href != null)
{
if (UIComponentTagUtils.isValueReference(actionDef.Href))
@@ -380,6 +383,29 @@ public class UIActions extends SelfRenderingComponent
control.setHref(actionDef.Href);
}
}
else if (actionDef.Script != null && actionDef.Script.length() != 0)
{
// found a script reference - may be a Path or a NodeRef
StringBuilder scriptHref = new StringBuilder(100);
scriptHref.append("/command/script/execute");
if (actionDef.Script.charAt(0) == '/')
{
// found a Path - encode it as a URL argument
scriptHref.append("?scriptPath=");
scriptHref.append(Utils.replace(URLEncoder.encode(actionDef.Script, "UTF-8"), "+", "%20"));
}
else
{
// found a NodeRef string, encode as URL elements
NodeRef ref = new NodeRef(actionDef.Script);
scriptHref.append('/').append(ref.getStoreRef().getProtocol())
.append('/').append(ref.getStoreRef().getIdentifier())
.append('/').append(ref.getId());
}
// set the full script execution URL as the href for the control
control.setHref(scriptHref.toString());
}
control.setTarget(actionDef.Target);
control.setImage(actionDef.Image);