cancel
Showing results for 
Search instead for 
Did you mean: 

'Sample custom action' for datalists

efvrvo
Champ on-the-rise
Champ on-the-rise
I have downloaded the "Sample custom action" zip file from the share extras website. I have successfully followed the instructions and constructed a few custom actions for our doc library.
I attempted to use this method to create a custom action for a datalist but It is not working. I have added the the icon to the datagrid but when I press the button it is not calling my javascript. It also does not show my custom icon as per my css file.

Could anyone please give me some pointers on what I need to change to the Sample custom action before compiling it to a jar file to make it work on datalist.
11 REPLIES 11

efvrvo
Champ on-the-rise
Champ on-the-rise
IS there any one that can help me with this please. I really need to get this working and any assistance will greatly be appreciated

mikeh
Star Contributor
Star Contributor

efvrvo
Champ on-the-rise
Champ on-the-rise
Hi Mike

I'm currently downloading this addon and even though it is a great addon it does not address my need to add my own custom action that will simply execute my javascript. I can do this for my document library content without a probelm but not for datalist. I can add the icon to the datalist action column but when I press it it does not execute my script. It also does not see my custom icon and this tells me the probelm shoould be to do with this.

Is there not a pointer that you can give me that explains why the sample custon action works with document library and not with datalist

mikeh
Star Contributor
Star Contributor
Whilst the code backing the two components is similar, it's not identical.

It's pretty difficult to debug these things in someone else's code, but you should try using Firebug and/or Web Inspector to check your custom code is getting loaded by the browser - start with the basics, i.e. an "alert()".

Also it's generally a good idea to post code here rather than try to describe what you've done.

Thanks,
Mike

efvrvo
Champ on-the-rise
Champ on-the-rise
HI Mike

I'm not a programmer by trade so I do not know to much about de-bug etc Smiley Happy But below is what I did

1)Downloaded the sample custom action from share extras website "http://code.google.com/p/share-extras/wiki/SampleScriptAction"
2) Open the zip file with eclipse. This then presented a directory structure with files in
    
|–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

3) The instructions then tell you which files to edit and then you compile it with Ant into a jar file. This is then loaded into "\tomcat\shared\lib"
4) You then add "documentlist.get.config.xml" and "actions-common.get.head.ftl" to "\tomcat\shared\classes\alfresco\web-extension\site-webscripts\org\alfresco\components\documentlibrary"
5) These two files are then edited to point to your new script
6) I then wanted to change this setup to add an action to datalist (very limited insight into how things work). This is how I eddited all the files

"actions-common.get.head.ftl"
<#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.get.config.xml
<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>

7)These two files I then copied to "\tomcat\shared\classes\alfresco\web-extension\site-webscripts\org\alfresco\components\data-lists"
8 ) The other files I edited in eclipse as follows
compile-email-action.css
.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.properties
jar.name=compile-email-action.jar

9) The javascript file I uploaded to datadictionary
CompileEmail.js

   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);
   

10) Ran ant and placed the jar file in "\tomcat\shared\lib"
11) Restarted server

The action icon apears in the datalist but it does not display the correct ison picture and does not do anything when I click on it. So its not picking up the following files
"compile-email-action.css"
"compile-email-action.js"

The other files that I did not edit looks like this
sample-script.post.desc.xml
<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.



Can you please help

mccarthymp
Confirmed Champ
Confirmed Champ
efvro,

Datalist custom actions are different from Share doclib custom actions. The process is the same but the locations of the files differ. It appears as if you have put the files where doclib actions go rather than where datalist actions go. Take a look at Will Abson's Share Extras project with an example (and directions) of a custom datalist action: http://code.google.com/p/share-extras/source/browse/trunk/SDK/Datalist%20Sample%20Action/README.txt

efvrvo
Champ on-the-rise
Champ on-the-rise
HI

I read that readme file thank you and had a look at his source code and from that I made the following changes (it did not work)


     |–config
     |–|–alfresco
     |–|–|–messeges
     |–|–|–|–slingshot-compile-email-action.properties
     |–|–|–templates
     |–|—–|–webscripts
     |–|——–|–org
     |–|————|–sharextras
     |–|—————-|–slingshot
     |–|——————–|–data-lists
     |–|————————|–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
     |————-|–data-lists
     |—————–|–compile-email-action.css
     |—————–|–compile-email-action.js
     |—————–|–sample-script-action-16.gif
     |–build.properties
     |–build.xml
     |–README.txt

"actions-common.get.head.ftl"
    <#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.get.config.xml
<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>

I copied these two files to "\tomcat\shared\classes\alfresco\web-extension\site-webscripts\org\alfresco\components\data-lists"

compile-email-action.css
.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.properties
jar.name=compile-email-action.jar

9) The javascript file I uploaded to datadictionary
CompileEmail.js

   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);
   

10) Ran ant and placed the jar file in "\tomcat\shared\lib"
11) Restarted server

The action icon apears in the datalist but it does not display the correct ison picture and does not do anything when I click on it. So its not picking up the following files again or something.
"compile-email-action.css"
"compile-email-action.js"

Any ideas.

wabson
Star Contributor
Star Contributor
Hi,

As has been discussed in the post I'm the maintainer of the sample projects that you are trying to use. If you have issues with stuff on Share Extras, I'd generally encourage people to use the development mailing list referenced on the Google Code project page, but since I see the discussion's already gained some steam here, I'll go ahead and clarify a couple of details here.

Firstly, yes as mccarthymp says, Datalist actions are subtly different to Document Library actions, and the README that he linked to should cover how to address the former.

From looking at the changes you've made in your most recent post, it seems you've taken the code you implemented based on the Document Library sample action and changed the directory structure to match the structure of the Datalist sample action. Whilst that is where most of the differences are between the two, the README and files supplied with the Datalist sample action actually have a couple more differences.

Firstly, your client-side code in compile-email-action.js is still defining a Document Library action, since you are adding your action function onto the Alfresco.doclib.Actions prototype. You should change the following line

Alfresco.doclib.Actions.prototype[FN_NAME] = function DL_onActionSampleScript(file)

to

Alfresco.service.DataListActions.prototype[FN_NAME] = function DL_onActionSample(file)

in order to define a DL action. I don't think there are any other differences in the client-side code than that and the path, but you should compare your compile-email-action.js with the components/data-lists/sample-action.js file supplied in the datalist sample action project to make sure.

Secondly, there is a slight error in the CSS in compile-email-action.css, again referring to the document library rather than data list actions. You should replace the defintion with the following

.datagrid .onActionSample a
{
   background-image: url(file-16.png) !important;
}

This error is actually in my own Datalist Sample Action project file, so I'll update that there, too.

Thirdly, the README file mentions a couple more changes that are needed in the client-side JavaScript file components/data-lists/datagrid.js, which is supplied by Share (not by the project). it doesn't appear that you have done this.

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!).

You may find that changes to this file do not take effect unless you have the script debug option turned on in your share-config-custom.xml file, since by default Share will use the minified JavaScript in the file components/data-lists/datagrid-min.js (note the extra suffix). See Kevin Roast's blog post at http://blogs.alfresco.com/wp/kevinr/2010/04/07/developer-tips-for-alfresco-share-33/ for more information. When you have finished testing your changes you should run datagrid.js through a JS Compressor such as YUI Compressor to generate the minified version.

Lastly, as MikeH mentions I would encourage you to explore the Firebug add-on or Google Chrome's Developer Tools for debugging client-side code. In particular you can use the console to monitor for errors, the script functions to set breakpoints in your code, and the requests logging to pick up on any resources that are failing to load properly. The tools are very easy to use once you know how and will save you a lot of time when you need to work out why something doesn't work as you expect.

Hope that helps.

Thanks,
Will

efvrvo
Champ on-the-rise
Champ on-the-rise
HI Will

Thanks I made the changes as you suggested and i'm currently installing firebug but still trying to figure out what it is telling me
I can see the icon now and its got my correct picture. When I click on the icon it it Appears to be doing something but brings up the message could not execute script

The alfresco log file shows the following error

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)