mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
. 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:
@@ -27,13 +27,16 @@
|
|||||||
<style>padding:4px</style>
|
<style>padding:4px</style>
|
||||||
<style-class>inlineAction</style-class>
|
<style-class>inlineAction</style-class>
|
||||||
<image>/images/icons/edit_icon.gif</image>
|
<image>/images/icons/edit_icon.gif</image>
|
||||||
<!-- action, action-listener, onclick, href and target action attributes supported -->
|
<!-- action, action-listener, onclick, href and target action attributes are supported -->
|
||||||
<action-listener>#{CheckinCheckoutBean.editFile}</action-listener>
|
<action-listener>#{CheckinCheckoutBean.editFile}</action-listener>
|
||||||
<action>editDocument</action>
|
<action>editDocument</action>
|
||||||
<href>http://...</href>
|
<href>http://...</href>
|
||||||
<target>new</target>
|
<target>new</target>
|
||||||
<onclick>javascript:myhandler</onclick>
|
<onclick>javascript:myhandler</onclick>
|
||||||
<!-- params specify the f:param tags to be generated as children of the action component -->
|
<!-- script attribute for specifying a javascript file to execute - by Path or NodeRef -->
|
||||||
|
<script>/Company Home/Data Dictionary/Scripts/myjavascript.js</script>
|
||||||
|
<!-- params specify the <f:param> tags to be generated as children of the action component -->
|
||||||
|
<!-- accessable by an ActionEvent handler or passed directly as href/script URL arguments -->
|
||||||
<params>
|
<params>
|
||||||
<param name="id">#{actionContext.id}</param>
|
<param name="id">#{actionContext.id}</param>
|
||||||
</params>
|
</params>
|
||||||
|
@@ -229,6 +229,7 @@ public class ActionsConfigElement extends ConfigElementAdapter
|
|||||||
public String Action;
|
public String Action;
|
||||||
public String Href;
|
public String Href;
|
||||||
public String Target;
|
public String Target;
|
||||||
|
public String Script;
|
||||||
public String Onclick;
|
public String Onclick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -50,6 +50,7 @@ public class ActionsElementReader implements ConfigElementReader
|
|||||||
public static final String ELEMENT_ONCLICK = "onclick";
|
public static final String ELEMENT_ONCLICK = "onclick";
|
||||||
public static final String ELEMENT_HREF = "href";
|
public static final String ELEMENT_HREF = "href";
|
||||||
public static final String ELEMENT_TARGET = "target";
|
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_PARAMS = "params";
|
||||||
public static final String ELEMENT_PARAM = "param";
|
public static final String ELEMENT_PARAM = "param";
|
||||||
public static final String ATTRIBUTE_ID = "id";
|
public static final String ATTRIBUTE_ID = "id";
|
||||||
@@ -252,6 +253,7 @@ public class ActionsElementReader implements ConfigElementReader
|
|||||||
actionDef.TooltipMsg = actionElement.elementTextTrim(ELEMENT_TOOLTIPMSG);
|
actionDef.TooltipMsg = actionElement.elementTextTrim(ELEMENT_TOOLTIPMSG);
|
||||||
actionDef.Href = actionElement.elementTextTrim(ELEMENT_HREF);
|
actionDef.Href = actionElement.elementTextTrim(ELEMENT_HREF);
|
||||||
actionDef.Target = actionElement.elementTextTrim(ELEMENT_TARGET);
|
actionDef.Target = actionElement.elementTextTrim(ELEMENT_TARGET);
|
||||||
|
actionDef.Script = actionElement.elementTextTrim(ELEMENT_SCRIPT);
|
||||||
actionDef.Action = actionElement.elementTextTrim(ELEMENT_ACTION);
|
actionDef.Action = actionElement.elementTextTrim(ELEMENT_ACTION);
|
||||||
actionDef.ActionListener = actionElement.elementTextTrim(ELEMENT_ACTIONLISTENER);
|
actionDef.ActionListener = actionElement.elementTextTrim(ELEMENT_ACTIONLISTENER);
|
||||||
actionDef.Onclick = actionElement.elementTextTrim(ELEMENT_ONCLICK);
|
actionDef.Onclick = actionElement.elementTextTrim(ELEMENT_ONCLICK);
|
||||||
|
@@ -17,7 +17,9 @@
|
|||||||
package org.alfresco.web.ui.common.renderer;
|
package org.alfresco.web.ui.common.renderer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.faces.component.UIComponent;
|
import javax.faces.component.UIComponent;
|
||||||
@@ -133,13 +135,44 @@ public class ActionLinkRenderer extends BaseRenderer
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
String href = link.getHref();
|
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=\"")
|
linkBuf.append(href);
|
||||||
.append(href)
|
|
||||||
.append('"');
|
// 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
|
// output href 'target' attribute if supplied
|
||||||
if (link.getTarget() != null)
|
if (link.getTarget() != null)
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package org.alfresco.web.ui.repo.component;
|
package org.alfresco.web.ui.repo.component;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -30,6 +31,7 @@ import javax.faces.el.ValueBinding;
|
|||||||
|
|
||||||
import org.alfresco.config.Config;
|
import org.alfresco.config.Config;
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.web.app.Application;
|
import org.alfresco.web.app.Application;
|
||||||
import org.alfresco.web.bean.repository.Node;
|
import org.alfresco.web.bean.repository.Node;
|
||||||
import org.alfresco.web.config.ActionsConfigElement;
|
import org.alfresco.web.config.ActionsConfigElement;
|
||||||
@@ -369,6 +371,7 @@ public class UIActions extends SelfRenderingComponent
|
|||||||
control.setOnclick(actionDef.Onclick);
|
control.setOnclick(actionDef.Onclick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionDef.Href != null)
|
if (actionDef.Href != null)
|
||||||
{
|
{
|
||||||
if (UIComponentTagUtils.isValueReference(actionDef.Href))
|
if (UIComponentTagUtils.isValueReference(actionDef.Href))
|
||||||
@@ -380,6 +383,29 @@ public class UIActions extends SelfRenderingComponent
|
|||||||
control.setHref(actionDef.Href);
|
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.setTarget(actionDef.Target);
|
||||||
control.setImage(actionDef.Image);
|
control.setImage(actionDef.Image);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user