09-19-2011 05:08 AM
03-07-2012 10:07 AM
03-07-2012 10:28 AM
03-07-2012 10:35 AM
03-07-2012 11:00 AM
03-08-2012 03:20 AM
|–config
|–|–alfresco
|–|–|–messeges
|–|–|–|–slingshot-compile-email-action.properties
|–|–|–templates
|–|—–|–webscripts
|–|——–|–org
|–|————|–sharextras
|–|—————-|–slingshot
|–|——————–|–documentlibrary
|–|————————|–action
|–|—————————-|–sample-script.post.desc.xml
|–|—————————-|–sample-script.post.json.ftl
|–|—————————-|–sample-script.post.json.js
|–|–org
|—–|–springframework
|——–|–extensions
|———–|–surf
|—————|–slingshot-compile-email-action-context.xml
|–lib
|–|–ml-ant-http-1.1.1.jar
|–|–yui-compressor-ant-task-0.5.jar
|–|–yuicompressor-2.4.2.jar
|
|–source
|–|–web
|——|–extras
|———-|–components
|————-|–documentlibrary
|—————–|–compile-email-action.css
|—————–|–compile-email-action.js
|—————–|–sample-script-action-16.gif
|–build.properties
|–build.xml
|–README.txt
<#include "../component.head.inc">
<#– Data List Actions: Supports concatenated JavaScript files via build scripts –>
<#if DEBUG>
<script type="text/javascript" src="${page.url.context}/res/components/data-lists/actions.js"></script>
<script type="text/javascript" src="${page.url.context}/res/modules/simple-dialog.js"></script>
<#else>
<script type="text/javascript" src="${page.url.context}/res/js/datalist-actions-min.js"></script>
</#if>
<#– Custom Script Action –>
<@link rel="stylesheet" type="text/css" href="${page.url.context}/res/extras/components/documentlibrary/compile-email-action.css" />
<@script type="text/javascript" src="${page.url.context}/res/extras/components/documentlibrary/compile-email-action.js"></@script>
<dataGrid>
<actionSet>
<action type="action-link" id="onActionEdit" permission="edit" label="actions.edit" />
<action type="action-link" id="onActionDelete" permission="delete" label="actions.delete-row" />
<action type="action-link" id="onActionCompileEmail" permission="edit" label="actions.document.compile-email" />
</actionSet>
</dataGrid>
.doclist .onActionCompileEmail a
{
background-image: url(sample-script-action-16.gif) !important;
}
compile-email-action.js/**
* Document Library Sample Script action
*
* @namespace Alfresco
* @class Alfresco.doclib.Actions
*/
(function()
{
/**
* Name of the script below Data Dictionary/Scripts to execute, e.g. "my test script.js"
*/
var JSCRIPT_NAME = "CompileEmail.js";
/**
* Base name for message bundle strings used for success/failure messages. Messages should
* be defined in your own global message bundle.
*/
var MSG_BASE = "compile-email";
/**
* Name of the JavaScript function to be added to the Alfresco.doclib.Actions prototype,
* e.g. onActionMyTestScript
*/
var FN_NAME = "onActionCompileEmail";
/**
* Execute a specific script against a document.
*
* @method onActionSampleScript
* @param file {object} Object literal representing one or more file(s) or folder(s) to be actioned
*/
Alfresco.doclib.Actions.prototype[FN_NAME] = function DL_onActionSampleScript(file)
{
var nodeRef = new Alfresco.util.NodeRef(file.nodeRef);
this.modules.actions.genericAction(
{
success:
{
event:
{
name: "metadataRefresh"
},
message: this.msg("message." + MSG_BASE + ".success", file.displayName)
},
failure:
{
message: this.msg("message." + MSG_BASE + ".failure", file.displayName)
},
webscript:
{
name: "sample-script/node/{nodeRef}",
method: Alfresco.util.Ajax.POST,
params:
{
nodeRef: nodeRef.uri
}
},
config:
{
requestContentType: Alfresco.util.Ajax.JSON,
dataObj:
{
scriptName: JSCRIPT_NAME
}
}
});
};
})();
slingshot-compile-email-action-context.xml<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<!– Additional Share message bundle –>
<bean id="sharextras.compile-email.resources" class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
<property name="resourceBundles">
<list>
<value>alfresco.messages.slingshot-compile-email-action</value>
</list>
</property>
</bean>
</beans>
slingshot-compile-email-action.properties# Custom Sample Script action
actions.document.compile-email=Compile email
message.compile-email.success=Executed script successfully against '{0}'
message.compile-email.failure=Couldn't execute script against '{0}'
build.propertiesjar.name=compile-email-action.jar
var mail = actions.create("mail");
mail.parameters.to = person.properties["cm:email"];
mail.parameters.subject = document.properties["ce:ceID"] + " - "+ document.properties["ce:ceTitle"];
mail.parameters.from = "projects";
mail.parameters.template = companyhome.childByNamePath("Data Dictionary/email templates/task notify/compile_email_CE.ftl");
mail.parameters.text = document.properties["ce:ceID"] + " - "+ document.properties["ce:ceTitle"];
mail.execute(document);
<webscript>
<shortname>Sample Script Action</shortname>
<description>Document List Action - Execute a specific script against document(s)</description>
<url>/slingshot/doclib/action/sample-script/node/{store_type}/{store_id}/{id}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>
sample-script.post.json.ftl<#import "/org/alfresco/slingshot/documentlibrary/action/action.lib.ftl" as actionLib />
<@actionLib.resultsJSON results=results />
sample-script.post.json.js<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/action.lib.js">
/**
* Execute script against files action
* @method POST
*/
/**
* Entrypoint required by action.lib.js
*
* @method runAction
* @param p_params {object} Object literal containing files array
* @return {object|null} object representation of action results
*/
function runAction(p_params)
{
var result,
assetNode = p_params.destNode,
scriptName = json.get("scriptName"),
scriptResults,
scriptNode;
// Must have script name
if (scriptName == null)
{
status.setCode(status.STATUS_BAD_REQUEST, "No script provided");
return;
}
scriptResults = search.query({
query: "PATH:\"/app:company_home/app:dictionary/app:scripts/cm:" + search.ISO9075Encode(scriptName) + "\"",
language: "lucene"
});
if (scriptResults.length == 1)
{
scriptNode = scriptResults[0];
}
// Must have script node
if (scriptNode == null)
{
status.setCode(status.STATUS_NOT_FOUND, "Script " + scriptName + " not found");
return;
}
// Must have a single file
if (!assetNode)
{
status.setCode(status.STATUS_BAD_REQUEST, "No file");
return;
}
try
{
result =
{
nodeRef: assetNode.nodeRef,
action: "execute-script",
success: false
}
result.id = assetNode.name;
result.type = assetNode.isContainer ? "folder" : "document";
// Execute the JavaScript file against the node
var scriptAction = actions.create("script");
scriptAction.parameters["script-ref"] = scriptNode;
scriptAction.execute(assetNode);
result.success = true;
}
catch (e)
{
result.success = false;
}
return [result];
}
/* Bootstrap action script */
main();
build.xml<!–
***********************************
Share Extras build script
***********************************
Author: Will Abson
Provides a set of targets for building extensions to Alfresco Share in ZIP, AMP and JAR archive
formats. Since Alfresco 3.3, JAR is the recommended package structure for all simple extensions.
For more complex extensions that add additional Java libraries, AMP should be used.
The following file structure is required in your project directory
/build.xml - This file
/config - All web-tier configuration files, e.g. web scripts and Surf configuration
/source/web - All static resource files, e.g. CSS, JS
For building AMP files, the files module.properties and file-mapping.properties are also required
in the project's root directory.
During the build process, temporary 'build' and 'dist' directories will be created in the base
project directory. These may be removed at any time using the 'clean' target.
–>
<project basedir="." default="dist-jar" name="Share Extras Build Script">
<!– Allow override properties –>
<property file="build.properties" />
<property file="${user.home}/build.properties" />
<!– Property default values. May be overridden using above files or via command-line args –>
<property name="jar.name" value="share-extension.jar" />
<property name="zip.name" value="share-extension.zip" />
<property name="amp.name" value="share-extension.amp" />
<property name="config.includes" value="**/*.*" />
<property name="config.excludes" value="" />
<property name="build.res.includes" value="**/*.*" />
<property name="build.res.excludes" value="" />
<property name="build.res.dir" value="webapps/share" />
<property name="build.classes.dir" value="shared/classes" />
<property name="build.lib.dir" value="shared/lib" />
<property name="yuicompress.warn" value="false" />
<!– Tomcat properties to reload web scripts or the manager webapp –>
<property name="tomcat.url" value="http://localhost:8080" />
<property name="tomcat.repo.url" value="${tomcat.url}" />
<property name="tomcat.share.url" value="${tomcat.url}" />
<!– Tomcat properties to reload web scripts –>
<property name="webapp.alfresco.path" value="/alfresco" />
<property name="webapp.share.path" value="/share" />
<property name="post.verbose" value="false" />
<property name="repo.admin.username" value="admin" />
<property name="repo.admin.password" value="admin" />
<property name="repo.scripts.index" value="${tomcat.repo.url}${webapp.alfresco.path}/service/index" />
<property name="share.scripts.index" value="${tomcat.share.url}${webapp.share.path}/page/index" />
<!– Properties to access the Tomcat Manager application –>
<property name="webapp.manager.url" value="${tomcat.url}/manager" />
<property name="webapp.manager.username" value="admin" />
<property name="webapp.manager.password" value="" />
<!– Additional property values. Generally should not be overridden –>
<property name="config.dir" value="${basedir}/config" />
<property name="res.dir" value="${basedir}/source/web" />
<property name="build.dir" value="${basedir}/build" />
<property name="build.jar.dir" value="${build.dir}/jar" />
<property name="build.zip.dir" value="${build.dir}/war" />
<property name="build.amp.dir" value="${build.dir}/amp" />
<property name="dist.dir" value="${basedir}/dist" />
<property name="amp.file.properties" value="module.properties" />
<property name="amp.file.mappings" value="file-mapping.properties" />
<!– Define optional tasks –>
<!–
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask" />
<taskdef name="post" classname="net.sf.antcontrib.net.PostTask" />
–>
<!– Alias targets –>
<target name="build-zip" depends="build-zip-tomcat" />
<target name="dist-zip" depends="dist-zip-tomcat" />
<!– Additional classpath and task definitions –>
<path id="yuicompressor.classpath">
<fileset dir="lib">
<include name="yuicompressor-2.4.2.jar"/>
<include name="yui-compressor-ant-task-0.5.jar"/>
</fileset>
</path>
<taskdef name="yuicompress" classname="net.noha.tools.ant.yuicompressor.tasks.YuiCompressorTask">
<classpath>
<path refid="yuicompressor.classpath" />
</classpath>
</taskdef>
<path id="ml-ant-http.classpath">
<fileset dir="lib">
<include name="ml-ant-http-1.1.1.jar" />
</fileset>
</path>
<taskdef name="http" classname="org.missinglink.ant.task.http.HttpClientTask">
<classpath>
<path refid="ml-ant-http.classpath" />
</classpath>
</taskdef>
<!– Main build target definitions –>
<!– Clean out the build and distribution directories –>
<target name="clean" description="Clean out all build directories">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<!– Create required prerequisite directory structure –>
<target name="prepare" description="Create initial build structures">
<mkdir dir="${build.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!–
Assemble the configuration and resource files in a JAR file structure. This mechanism
was introduced in Alfresco 3.3 and allows Share extensions containing both repository and
web-tier web scripts, Spring/Surf configuration and static assets to be added to the servlet
container as a single library. For more complex extensions, AMP files should be used.
This target excludes the files custom-slingshot-application-context.xml, share-config-custom.xml
and similar files from being copied into the classpath as these should not generally be included
within JAR files as it could lead to multiple copies of them being present. If found however,
alfresco/web-extension/share-config-custom.xml will be copied into the META-INF directory,
from where it can be loaded in 3.4.
–>
<target name="build-jar" description="Assemble configuration and resource files in a JAR file structure">
<mkdir dir="${build.jar.dir}" />
<!– Copy configuration files, web scripts, etc. directly into the JAR so they appear on the
classpath. –>
<copy todir="${build.jar.dir}" includeEmptyDirs="false">
<fileset dir="${config.dir}" includes="${config.includes}">
<!– Spring config –>
<exclude name="web-application-config.xml" />
<exclude name="surf-config.xml" />
<exclude name="alfresco/slingshot-application-context.xml" />
<exclude name="alfresco/web-extension/custom-slingshot-application-context.xml" />
<!– Surf config –>
<exclude name="alfresco/share*-config.xml" />
<exclude name="alfresco/web-extension/share-config-custom.xml" />
<!– Global excludes –>
<exclude name="${config.excludes}" />
</fileset>
</copy>
<!– Copy web-tier resources into the JAR. These can then be loaded by browsers via Share's resources
servlet by prefixing their path with '/res' –>
<mkdir dir="${build.jar.dir}/META-INF" />
<copy todir="${build.jar.dir}/META-INF" includeEmptyDirs="false">
<fileset dir="${res.dir}" includes="${build.res.includes}" excludes="${build.res.excludes}" />
</copy>
<!– Map alfresco/web-extension/share-config-custom.xml to META-INF/share-config-custom.xml in the JAR –>
<copy todir="${build.jar.dir}/META-INF" includeEmptyDirs="false">
<fileset dir="${config.dir}">
<filename name="alfresco/web-extension/share-config-custom.xml" />
</fileset>
<globmapper from="alfresco/web-extension/*.xml" to="*.xml" handledirsep="true" />
</copy>
<!– Minify JS –>
<yuicompress fromdir="${res.dir}" todir="${build.jar.dir}/META-INF" excludes="**/*-min.js" warn="${yuicompress.warn}">
<include name="**/*.js" />
</yuicompress>
</target>
<!– Build the JAR file –>
<target name="dist-jar" depends="clean, prepare, build-jar"
description="Build a JAR file containing configuration and resource files">
<jar destfile="${dist.dir}/${jar.name}">
<fileset dir="${build.jar.dir}" />
</jar>
</target>
<!–
Assemble the configuration and resource files in a file structure suitable for deploying
into an existing Tomcat installation, with the following directories.
/shared/classes/alfresco Repository/Share configuration files
/webapps/share Share web resources
By default web resources are placed in directly in the 'share' web application. You
can specify a different directory by overriding the build.res.dir property value. Set
this to 'webapps/ROOT/share-extension' to use the pre-3.3 recommended layout.
The share-extension directory is not an official location for storing web resources
required by extensions but worked as an interim measure for versions of Alfresco prior to
version 3.3, provided that the ROOT webapp is enabled in your Tomcat instance.
By default configuration is placed in directly in Tomcat's shared/classes directory. You
can specify a different directory by overriding the build.classes.dir property value. Set
this to 'webapps/share/WEB-INF/classes' to place files on the classpath inside the webapp.
Unlike build-jar this target does not exclude any particular configuration files from the
file structure, however the hotcopy-tomcat-zip task will err on the side of caution and
will not copy files such as share-config-custom.xml itself into Tomcat.
–>
<target name="build-zip-tomcat" depends="build-zip-prepare,build-zip-config"
description="Assemble the configuration and resource files for a Tomcat deployment structure">
<!– Copy web assets –>
<copy todir="${build.zip.dir}/${build.res.dir}">
<fileset dir="${res.dir}" includes="${build.res.includes}" excludes="${build.res.excludes}" />
</copy>
<!– Minify JS –>
<yuicompress fromdir="${res.dir}" todir="${build.zip.dir}/${build.res.dir}" excludes="**/*-min.js" warn="${yuicompress.warn}">
<include name="**/*.js" />
</yuicompress>
</target>
<target name="build-zip-prepare">
<mkdir dir="${build.zip.dir}/${build.classes.dir}" />
<mkdir dir="${build.zip.dir}/${build.res.dir}" />
</target>
<target name="build-zip-config">
<copy todir="${build.zip.dir}/${build.classes.dir}">
<fileset dir="${config.dir}" includes="${config.includes}" excludes="${config.excludes}" />
</copy>
</target>
<!– Build the Tomcat ZIP file –>
<target name="dist-zip-tomcat" depends="clean, prepare, build-zip-tomcat"
description="Build a ZIP file containing the customisations that can be deployed in an existing Tomcat installation">
<zip destfile="${dist.dir}/${zip.name}">
<fileset dir="${build.zip.dir}" />
</zip>
</target>
<!–
Assemble the configuration and resource files in an AMP file structure. The files
module.properties and file-mapping.properties must be present in the root of the
project.
This creates a structure which can be deployed into an exising share.war file using the
Alfresco Module Management Tool (MMT). See http://wiki.alfresco.com/wiki/AMP_Files.
This mechanism is compatible with all versions of Alfresco Share and can therefore be
used as an alternative to the JAR extension mechanism introduced in version 3.3.
Note that this mechanism will place files directly into the webapp structure when the
AMP is deployed, rather than the extension mechanisms used by the JAR and ZIP files that
ensure files are placed outside the webapp for safety during upgrades, etc.
In this case this should be acceptable since the MMT modifies the WAR file itself
rather than just the exploded files, and AMPs can always be re-applied if needed.
In version 3.3 and above the JAR file mechanism is recommended as an alternative for all
non-complex extensions.
–>
<target name="build-amp" description="Assemble the configuration and resource files in an AMP file structure">
<!– Copy properties files –>
<copy todir="${build.amp.dir}" file="${amp.file.properties}" failonerror="true" />
<copy todir="${build.amp.dir}" file="${amp.file.mappings}" failonerror="true" />
<!– Copy config files –>
<mkdir dir="${build.amp.dir}/config" />
<copy todir="${build.amp.dir}/config">
<fileset dir="${config.dir}" includes="${config.includes}" excludes="${config.excludes}" />
</copy>
<!– Copy resource files –>
<mkdir dir="${build.amp.dir}/web" />
<copy todir="${build.amp.dir}/web">
<fileset dir="${res.dir}" includes="${build.res.includes}" excludes="${build.res.excludes}" />
</copy>
<!– Minify JS –>
<yuicompress fromdir="${res.dir}" todir="${build.amp.dir}/web" excludes="**/*-min.js" warn="${yuicompress.warn}">
<include name="**/*.js" />
</yuicompress>
</target>
<!– Build the AMP file –>
<target name="dist-amp" depends="clean, prepare, build-amp" description="Build an AMP file containing all customisations">
<zip destfile="${dist.dir}/${amp.name}">
<fileset dir="${build.amp.dir}" />
</zip>
</target>
<!–
Hot copy individual files into a local Tomcat instance.
In version 3.3 and above the JAR file mechanism is recommended for distributing your
customisations, but this target can still be used during development as it allows you to
reload changes .
–>
<target name="hotcopy-tomcat-zip" depends="build-zip-tomcat" description="Hot copy individual files into a local Tomcat instance">
<copy todir="${tomcat.home}" includeEmptyDirs="false">
<fileset dir="${build.zip.dir}">
<!– Spring config –>
<exclude name="**/classes/web-application-config.xml" />
<exclude name="**/classes/surf-config.xml" />
<exclude name="**/classes/alfresco/slingshot-application-context.xml" />
<exclude name="**/classes/alfresco/web-extension/custom-slingshot-application-context.xml" />
<!– Surf config –>
<exclude name="**/classes/alfresco/share*-config.xml" />
<exclude name="**/classes/alfresco/web-extension/share-config-custom.xml" />
</fileset>
</copy>
</target>
<!–
Hot copy JAR file into a local Tomcat instance.
In version 3.3 and above the JAR file mechanism is recommended for distributing your
customisations, but this target can still be used during development as it allows you to
reload changes without restarting Tomcat.
–>
<target name="hotcopy-tomcat-jar" depends="dist-jar" description="Hot copy JAR file into a local Tomcat instance">
<mkdir dir="${tomcat.home}/${build.lib.dir}" />
<copy todir="${tomcat.home}/${build.lib.dir}">
<fileset file="${dist.dir}/${jar.name}" />
</copy>
</target>
<!–
Web script reloading from Ant. These tasks use the HTTP task from
http://code.google.com/p/missing-link/.
–>
<target name="reload-webscripts-repo" depends="" description="Reload repository webscripts">
<http url="${repo.scripts.index}"
method="POST"
printrequest="false"
printrequestheaders="false"
printresponse="false"
printresponseheaders="false"
expected="200"
failonunexpected="true">
<credentials username="${repo.admin.username}" password="${repo.admin.password}" />
<query>
<parameter name="reset" value="on" />
</query>
</http>
</target>
<target name="reload-webscripts-share" depends="" description="Reload Share webscripts">
<http url="${share.scripts.index}"
method="POST"
printrequest="false"
printrequestheaders="false"
printresponse="false"
printresponseheaders="false"
expected="200"
failonunexpected="true">
<credentials username="${repo.admin.username}" password="${repo.admin.password}" />
<query>
<parameter name="reset" value="on" />
</query>
</http>
</target>
<!–
Uncomment to enable web application reloading from Ant. These tasks use the optional Tomcat
ant tasks from catalina-ant.jar distributed with Tomcat.
To use these tasks you will need to add catalina-ant.jar to your Ant libs and uncomment the
task definitions at the start of this file.
–>
<!–
<target name="reload-webapp-alfresco" description="Reload alfresco web application" depends="">
<reload
url="${webapp.manager.url}"
username="${webapp.manager.username}"
password="${webapp.manager.password}"
path="${webapp.alfresco.path}"/>
</target>
<target name="reload-webapp-share" description="Reload share web application" depends="">
<reload
url="${webapp.manager.url}"
username="${webapp.manager.username}"
password="${webapp.manager.password}"
path="${webapp.share.path}"/>
</target>
–>
</project>
README.txt (instructions)Sample Script Action for Alfresco Share
=======================================
Author: Will Abson
This project defines a custom Document Library action, which can be easily
customised to run a JavaScript file of your choice when run by a
user.
You must create the JavaScript file yourself and place this directly into
the Data Dictionary/Scripts space in the repository. Once you have done
this you are ready to customise this action to use it.
Customisation
————-
The folder source/web/extras/components/documentlibrary contains the
client-side assets used by the custom action. You should rename
sample-script-action.css and sample-script-action.js to something
that better describes your action. This will ensure that your
action can co-exist with any others you create using this method, but
it is recommended you stick to lowercase letters and hyphens (-).
You can leave the file sample-script-action-16.gif untouched, or you
can add your own 16x16 GIF or PNG image into the directory to represent
your action. If you add your own image you will need to update the
CSS file to reference this, instead of sample-script-action-16.gif.
You will then need to edit a few variables near the beginning of
the renamed JS file.
* JSCRIPT_NAME should define the name of the script which you added
to the repository's Data Dictionary/Scripts space.
* MSG_BASE is the prefix used for message bundle labels, which should
be set to a unique value for your action. Generally you should use the
same value you used when renaming the client-side files.
* FN_NAME will be used as the name of the client-side function
used to define the action. Again it should be unique, but it
should normally start with the prefix 'onAction' and be a valid
JavaScript function name, e.g. on onActionMyCustomScript.
After you have updated the JavaScript file, open the CSS file and
replace the '.onActionSampleScript' selector on line 1 with the value
you set FN_NAME to in the JS file. Ensure you do not delete the leading
dot.
Next you will need to define your message bundle labels. Rename the Spring
configuration file in config/org/springframework/extensions/surf to
something unique, and change the bean's 'id' attribute within the file.
Inside the <value> element, the bean defines the path to a single message
bundle using dot notation. You should edit the part following the last dot
to a unique value for your action. After you have done this, rename the
.properties file in config/alfresco/messages to match this value.
Lastly, update the property names inside the .property file, changing
'sample-script' to the value you specified in your MSG_BASE definition in
the client-side JavaScript.
Now you are ready to install the action. Before you do, make sure you update
the jar.name property in the build.properties file to give your JAR file a
unique name.
Installation
————
The action has been developed to install on top of an existing Alfresco
3.3/3.4 installation.
An Ant build script is provided to build a JAR file containing the
custom files, which can then be installed into the 'tomcat/shared/lib' folder
of your Alfresco installation.
To build the JAR file, run the following command from the base project
directory.
ant clean dist-jar
The command should build a JAR file named sample-script-action.jar
in the 'dist' directory within your project.
To deploy the dashlet files into a local Tomcat instance for testing, you can
use the hotcopy-tomcat-jar task. You will need to set the tomcat.home
property in Ant.
ant -Dtomcat.home=C:/Alfresco/tomcat clean hotcopy-tomcat-jar
Once the JAR file has been deployed into your application server you will need to
configure the Share application to display the action.
Firstly, copy the web script configuration file
WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/documentlibrary/documentlist.get.config.xml
from the Share webapp into the directory
alfresco/web-extension/site-webscripts/org/alfresco/components/documentlibrary
in Tomcat’s shared/classes to override it. You should see a section
<actionSet id="document"> which defines all the actions shown for a normal
document in the document list view.
To add the backup action to this list, add the following line just before the
</actionset> element for that block.
<action type="action-link" id="onActionSampleScript" permission="edit" label="actions.document.sample-script" />
Change `onActionSampleScript` to the value you specified for FN_NAME in the Customisation
section above. Set the final part of the value for the 'label' attribute to the value you
specified in your MSG_BASE definition in the client-side JavaScript.
To make the action appear for folder items in addition to documents, add the same
line into the section <actionSet id="folder">.
If you also want the action to show up in the document details view, you need
to copy the file
WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/document-details/document-actions.get.config.xml
into
alfresco/web-extension/site-webscripts/org/alfresco/components/document-details
in shared/classes, and add the extra <action> definition(s) in the same way.
Lastly, you need to ensure that the client-side JS and CSS assets get pulled
into the UI as unfortunately the config files do not allow us to specify these
dependencies.
To do this, you must override the file
WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/documentlibrary/actions-common.get.head.ftl.
Copy this into the directory alfresco/web-extension/site-webscripts/org/alfresco/components/documentlibrary in
shared/classes and add the following lines at the bottom
of the file.
<#– Custom Script Action –>
<@link rel="stylesheet" type="text/css" href="${page.url.context}/res/extras/components/documentlibrary/sample-script-action.css" />
<@script type="text/javascript" src="${page.url.context}/res/extras/components/documentlibrary/sample-script-action.js"></@script>
You should edit the paths above to that the links point correctly to your
client-side assets, as you renamed them in the Customisation section above.
Once you have made these changes you will need to restart Tomcat so that the
configuration and your classpath resources in the JAR file are picked up.
Note: If you want the action to appear in the repository browsing pages or in
Web Quick Start or DOD sites, you will also need to update the corresponding
`.config.xml` and `.head.ftl` files for those page components.
Usage
—–
Log in to Alfresco Share and navigate to the Document Library of any site that
you have write permission on. You should see your custom action -
complete with UI labels and icon - displayed for each file on the document list
page, and also on the document details page if you have configured this too.
Credits
——-
Thanks to Mike Farman for the original suggestion.
03-08-2012 07:41 PM
03-09-2012 01:19 AM
<#include "../component.head.inc">
<#– Data List Actions: Supports concatenated JavaScript files via build scripts –>
<#if DEBUG>
<script type="text/javascript" src="${page.url.context}/res/components/data-lists/actions.js"></script>
<script type="text/javascript" src="${page.url.context}/res/modules/simple-dialog.js"></script>
<#else>
<script type="text/javascript" src="${page.url.context}/res/js/datalist-actions-min.js"></script>
</#if>
<#– Custom Action –>
<@link rel="stylesheet" type="text/css" href="${page.url.context}/res/extras/components/data-lists/compile-email-action.css" />
<@script type="text/javascript" src="${page.url.context}/res/extras/components/data-lists/compile-email-action.js"></@script>
<dataGrid>
<actionSet>
<action type="action-link" id="onActionEdit" permission="edit" label="actions.edit" />
<action type="action-link" id="onActionDelete" permission="delete" label="actions.delete-row" />
<action type="action-link" id="onActionCompileEmail" permission="" label="actions.datalist.compile-email" />
</actionSet>
</dataGrid>
.doclist .onActionCompileEmail a
{
background-image: url(sample-script-action-16.gif) !important;
}
compile-email-action.js/**
* Document Library Sample Script action
*
* @namespace Alfresco
* @class Alfresco.doclib.Actions
*/
(function()
{
/**
* Name of the script below Data Dictionary/Scripts to execute, e.g. "my test script.js"
*/
var JSCRIPT_NAME = "CompileEmail.js";
/**
* Base name for message bundle strings used for success/failure messages. Messages should
* be defined in your own global message bundle.
*/
var MSG_BASE = "compile-email";
/**
* Name of the JavaScript function to be added to the Alfresco.doclib.Actions prototype,
* e.g. onActionMyTestScript
*/
var FN_NAME = "onActionCompileEmail";
/**
* Execute a specific script against a document.
*
* @method onActionSampleScript
* @param file {object} Object literal representing one or more file(s) or folder(s) to be actioned
*/
Alfresco.doclib.Actions.prototype[FN_NAME] = function DL_onActionSampleScript(file)
{
var nodeRef = new Alfresco.util.NodeRef(file.nodeRef);
this.modules.actions.genericAction(
{
success:
{
event:
{
name: "metadataRefresh"
},
message: this.msg("message." + MSG_BASE + ".success", file.displayName)
},
failure:
{
message: this.msg("message." + MSG_BASE + ".failure", file.displayName)
},
webscript:
{
name: "sample-script/node/{nodeRef}",
method: Alfresco.util.Ajax.POST,
params:
{
nodeRef: nodeRef.uri
}
},
config:
{
requestContentType: Alfresco.util.Ajax.JSON,
dataObj:
{
scriptName: JSCRIPT_NAME
}
}
});
};
})();
slingshot-compile-email-action-context.xml<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<!– Additional Share message bundle –>
<bean id="sharextras.compile-email.resources" class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
<property name="resourceBundles">
<list>
<value>alfresco.messages.slingshot-compile-email-action</value>
</list>
</property>
</bean>
</beans>
slingshot-compile-email-action.properties# Custom Sample Script action
actions.datalist.compile-email=Compile email
message.compile-email.success=Executed script successfully against '{0}'
message.compile-email.failure=Couldn't execute script against '{0}'
build.propertiesjar.name=compile-email-action.jar
var mail = actions.create("mail");
mail.parameters.to = person.properties["cm:email"];
mail.parameters.subject = document.properties["ce:ceID"] + " - "+ document.properties["ce:ceTitle"];
mail.parameters.from = "projects";
mail.parameters.template = companyhome.childByNamePath("Data Dictionary/email templates/task notify/compile_email_CE.ftl");
mail.parameters.text = document.properties["ce:ceID"] + " - "+ document.properties["ce:ceTitle"];
mail.execute(document);
03-09-2012 07:55 AM
Alfresco.doclib.Actions.prototype[FN_NAME] = function DL_onActionSampleScript(file)
Alfresco.service.DataListActions.prototype[FN_NAME] = function DL_onActionSample(file)
.datagrid .onActionSample a
{
background-image: url(file-16.png) !important;
}
Finally, you need to increase the width of the Actions column, which is hard-coded
in the client-side file components/data-lists/datagrid.js.
Look for a line beginning with the following comment
// Add actions as last column
The following statement should look something like the following
columnDefinitions.push(
{ key: "actions", label: this.msg("label.column.actions"), sortable: false, formatter: this.fnRenderCellActions(), width: 105 }
);
At the end of the object literal assignment, change the 'width' value to 105, or add 25 for each additional
action you want to add to the row.
Then, go back to the top of the file and look for a property named 'splitActionsAt', which you should
find within the component's options. You can set this to whatever value you need to, so long as it is
larger than the number of actions that you will have in each row (otherwise they will not display!).
03-09-2012 10:03 AM
16:50:07,314 ERROR [extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 02090003 Script url /slingshot/datalists/action/sample-script/node/workspace/SpacesStore/aaf6b262-5443-4665-a915-3555242d173f does not map to a Web Script.
org.springframework.extensions.webscripts.WebScriptException: 02090003 Script url /slingshot/datalists/action/sample-script/node/workspace/SpacesStore/aaf6b262-5443-4665-a915-3555242d173f does not map to a Web Script.
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:153)
at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:619)
16:50:19,841 ERROR [extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 02090004 Script url /slingshot/datalists/action/sample-script/node/workspace/SpacesStore/e675558d-f246-4a5d-aa84-1a29bf6fc03e does not map to a Web Script.
org.springframework.extensions.webscripts.WebScriptException: 02090004 Script url /slingshot/datalists/action/sample-script/node/workspace/SpacesStore/e675558d-f246-4a5d-aa84-1a29bf6fc03e does not map to a Web Script.
at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:153)
at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
at java.lang.Thread.run(Thread.java:619)
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.