AnsweredAssumed Answered

Faire fonctionner le 'sample datalist action'

Question asked by nancygaillard on May 31, 2016
Bonjour,

Je travaille sur Alfresco 4.2.f sur Windows 7x64bits : j'aimerais ajouter deux actions dans la liste "Elements sélectionnés" des listes de données, malheureusement, ce que j'ai fait ne fonctionne pas.Pourtant j'ai essayé le projet tel qu'il était et ça ne fonctionnait déjà pas.

J'ai trouvé des sujets sur Alfresco à propos de cet extension, mais ils ne m'ont pas permis de plus avancer.

Pour ajouter les actions voici comment j'ai procédé :

J'ai téléchargé le projet "datalist action sample" ici => https://github.com/share-extras/sdk-sample-datalist-action

J'ai copié les fichiers datagrid.get.config.xml, toolbar.get.config.xml et actions-common.get.head.ftl du dossier
C:/Alfresco/tomcat/webapp/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/data-lists
dans
C:/Alfresco/tomcat/shared/classes/alfresco/web-extension/site-webscripts/org/alfresco/components/data-lists


dans datagrid.get.config.xml
J'ai ajouté la ligne
<action type="action-link" id="onActionSample" permission="" label="actions.datalist.sample" />
dans le bloc actionset.

dans toolbar.get.config.xml
J'ai ajouté la ligne


dans action-common.get.head.ftl
J'ai ajouté les lignes en fin de fichier
<#– Custom Backup Action –>
<@link rel="stylesheet" type="text/css" href="${page.url.context}/res/extras/components/data-lists/sample-action.css" />
<@script type="text/javascript" src="${page.url.context}/res/extras/components/data-lists/sample-action.js"></@script>

En compilant le projet en l'état, la nouvelle action apparaît sans image dans la liste des actions pour un élément de liste ainsi que dans les Elements sélectionnés sans îcone, et l'action ne fonctionne pas.

pour faire afficher l'îcone :
dans
sdk-sample-datalist-action/source/web/extras/components/data-lists/sample-action.css

<blockcode>.doclist .onActionSample a
{
   background-image: url(file-16.png) !important;
}
</blockcode>
est remplacé par
<blockcode>.toolbar.onActionSample
{
   background-image: url(file-16.png) !important;
}

.datalist.onActionSample a
{
   background-image: url(file-16.png) !important;
}
</blockcode>

Les autres fichiers, je les ai laissé tel quel :

Dans sdk-sample-datalist-action/source/web/extras/components/data-lists/
J'ai donc file-16.png, sample-action.css, sample-action.js
avec sample-action.js contenant :
<blockcode>
/**
* DataList "Sample" action
*
* @namespace Alfresco
* @class Alfresco.service.DataListActions
*/
(function()
{
   /**
    * Sample datalist action
    *
    * @method onActionSample
    * @param file {object} Object literal representing one or more file(s) or folder(s) to be actioned
    */
    Alfresco.service.DataListActions.prototype.onActionSample = function DL_onActionSample(file)
    {
        Alfresco.util.PopupManager.displayMessage({
            text:this.msg('actions.datalist.sample.message')
        });
       
        /*
         * Example using genericAction() function
         *
         this.modules.actions.genericAction(
         {
            success:
            {
               event:
               {
                  name: "dataItemsDuplicated",
                  obj:
                  {
                     items: items
                  }
               },
               message: this.msg("message.duplicate.success", items.length)
            },
            failure:
            {
               message: this.msg("message.duplicate.failure")
            },
            webscript:
            {
               method: Alfresco.util.Ajax.POST,
               name: "duplicate/node/" + destinationNodeRef.uri
            },
            config:
            {
               requestContentType: Alfresco.util.Ajax.JSON,
               dataObj:
               {
                  nodeRefs: nodeRefs
               }
            }
         });
      */
   };
})();
</blockcode>

Dans sdk-sample-datalist-action/lib/
J'ai trois jar :
ml-ant-http-1.1.1.jar, yui-compressor-ant-task-0.5.jar, yuicompressor-2.4.2.jar

Dans sdk-sample-datalist-action/config/alfresco/messages/slingshot-sample-datalist-action.properties
<blockcode>
# Custom action labels
actions.datalist.sample=My Sample Action
actions.datalist.sample.message=It works!
</blockcode>

Dans  sdk-sample-datalist-action/config/org/springframework/extensions/surf/slingshot-custom-backup-action-context.xml
<blockcode>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
   <!– Add custom application messages –>
   <bean id="webscripts.resources.slingshot-sample-datalist-action" class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
      <property name="resourceBundles">
         <list>
            <value>alfresco.messages.slingshot-sample-datalist-action</value>
         </list>
      </property>
   </bean>
</beans>
</blockcode>

Dans sdk-sample-datalist-action
j'ai .project, build.properties, build.xml

.project contient :
<blockcode><?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
   <name>Datalist Sample Action</name>
   <comment></comment>
   <projects>
   </projects>
   <buildSpec>
   </buildSpec>
   <natures>
   </natures>
</projectDescription></blockcode>

build.properties
<blockcode>jar.name=sample-datalist-action.jar
</blockcode>

build.xml contient
<blockcode>
<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="" />
    <!– Paths to local Tomcat instances –>
    <property name="tomcat.repo.home" value="${tomcat.home}" />
    <property name="tomcat.share.home" value="${tomcat.home}" />
  
    <!– 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="${build.dir}/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" />
                <exclude name="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>
        <copy todir="${build.jar.dir}/META-INF" includeEmptyDirs="false">
            <fileset dir="${config.dir}">
                <filename name="share-config-custom.xml" />
            </fileset>
        </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>
   
    <!– Shared path definition used to copy files into the local Tomcat instance(s) –>
    <patternset id="hotcopy-tomcat-zip-patternset">
        <!– 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" />
    </patternset>

    <!–
        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 without restarting Tomcat.
    –> 
    <target name="hotcopy-tomcat-zip" depends="build-zip-tomcat" description="Hot copy individual files into a local Tomcat instance">
        <echo message="Copying repository files" />
        <copy todir="${tomcat.repo.home}" includeEmptyDirs="false">
            <fileset dir="${build.zip.dir}">
                <patternset refid="hotcopy-tomcat-zip-patternset" />
                <!– Exclude static resources –>
                <exclude name="${build.res.dir}/**" />
                <!– Exclude web-tier config –>
                <exclude name="**/classes/alfresco/site-webscripts/**" />
                <exclude name="**/classes/alfresco/site-data/**" />
                <exclude name="**/classes/alfresco/web-extension/**" />
                <exclude name="**/classes/org/springframework/extensions/surf/**" />
            </fileset>
        </copy>
        <echo message="Copying Share files" />
        <copy todir="${tomcat.share.home}" includeEmptyDirs="false">
            <fileset dir="${build.zip.dir}">
                <patternset refid="hotcopy-tomcat-zip-patternset" />
                <!– Exclude repo-tier web scripts config –>
                <exclude name="**/classes/alfresco/extension/**" />
                <exclude name="**/classes/alfresco/templates/webscripts/**" />
            </fileset>
         </copy>
    </target>

    <!–
        Hot copy JAR file into a local Tomcat instance.
    –>
    <target name="hotcopy-tomcat-jar" depends="dist-jar" description="Hot copy JAR file into a local Tomcat instance">
        <mkdir dir="${tomcat.repo.home}/${build.lib.dir}" />
        <mkdir dir="${tomcat.share.home}/${build.lib.dir}" />
        <copy todir="${tomcat.repo.home}/${build.lib.dir}">
            <fileset file="${dist.dir}/${jar.name}" />
        </copy>
        <copy todir="${tomcat.share.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>
</blockcode>

Outcomes