cancel
Showing results for 
Search instead for 
Did you mean: 

New Action Page Sample Backup Action not running

rcrittendon
Champ in-the-making
Champ in-the-making
I tried the backup-action example on the page http://wiki.alfresco.com/wiki/Custom_Document_Library_Action.  The Backup menu displays for documents, but when I select the menu nothing happens.  No message results, I do not think anything ran.

I added the web-scripts to Alfresco, made sure that the script was added to Alfresco etc.

Rollin

P.S.  Is there any documentation on best-practices to get a dialog to display for a custom action?
12 REPLIES 12

joaotpd
Champ on-the-rise
Champ on-the-rise
Hi!…
Same problem here… Anyone with a solution??
Thanks!

João Duarte

mikeh
Star Contributor
Star Contributor
The code has moved on a bit since that article was written, so the javascript won't run correctly. change backup-action.js to change the extended class namespace and remove the getRecord() function call:
   Alfresco.doclib.Actions.prototype.onActionBackup = function DL_onActionBackup(file)
   {
      this.modules.actions.genericAction(
      …

Thanks,
Mike

rcrittendon
Champ in-the-making
Champ in-the-making
Thank you for the info on this Mike.

I made the change to the javascript as you indicated.  Unfortunately I am not seeing it run (cleared my cache on the browser too).

Am I missing something else?

 
Alfresco.doclib.Actions.prototype.onActionBackup = function DL_onActionBackup(file)
   {
      //var file = this.widgets.dataTable.getRecord(row).getData();

Rollin

mikeh
Star Contributor
Star Contributor
Is the JavaScript included with a <script> tag, or a <@script> tag?
<script type="text/javascript" src="${page.url.context}/components/documentlibrary/backup-action.js"></script>
vs
<@script type="text/javascript" src="${page.url.context}/components/documentlibrary/backup-action.js"></@script>

If it's the <@script> version, you'll also have to have a backup-action-min.js file alongside the backup-action.js one as I suspect you'll be running with the client-side debug flag off (in web-framework-config-application.xml or an override in web-extensions). You don't need to compress the file, but it does need to be there. The symptom will be pretty obvious if you're running Firefox with Firebug, or Safari with Inspector on, as the -min.js will show as an HTTP 404 error.

Thanks,
Mike

rcrittendon
Champ in-the-making
Champ in-the-making
I am running that without the @ modification.

mikeh
Star Contributor
Star Contributor
We tested the backup action at the recent Madrid meet-up, so unless I've forgotten something, I know it works ok.

You'll need to get Firebug or something similar set-up, so you can see exactly where the action is failing, as it's not clear what's going on at the moment.

Thanks,
Mike

joaotpd
Champ on-the-rise
Champ on-the-rise
Hi Mike! …
I made the changes you suggest but nothing happens when I click in the new Backup action… Smiley Sad
I'm running alfresco-community-tomcat-3.2 on linux…

What I did:

<share>/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/documentlibrary/documentlist.get.config.xml

     …
     <action id="onActionManageAspects" type="action-link" permission="edit" label="actions.document.manage-aspects" />
     <action id="onActionBackup" type="action-link" permission="" label="actions.document.backup" />
</actionSet>
<share>/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/documentlibrary/documentlist.get.head.ftl


<!– Manage Aspects –>
<@link rel="stylesheet" type="text/css" href="${page.url.context}/modules/documentlibrary/aspects.css" />
<@script type="text/javascript" src="${page.url.context}/modules/documentlibrary/aspects.js"></@script>
<!– Backup Action –>
<@link rel="stylesheet" type="text/css" href="${page.url.context}/components/documentlibrary/backup-action.css" />
<@script type="text/javascript" src="${page.url.context}/components/documentlibrary/backup-action.js"></@script>
<share>/components/documentlibrary/backup-action.js

/**
* DocumentList "Backup" action
*
* @namespace Alfresco
* @class Alfresco.DocumentList
*/
(function()
{
   /**
    * Backup single document.
    *
    * @method onActionBackup
    * @param row {object} DataTable row representing file to be actioned
    */
   Alfresco.doclib.Actions.prototype.onActionBackup = function DL_onActionBackup(file)
   {
      //var file = this.widgets.dataTable.getRecord(row).getData();

      this.modules.actions.genericAction(
      {
         success:
         {
            message: this._msg("message.backup.success", file.displayName)
         },
         failure:
         {
            message: this._msg("message.backup.failure", file.displayName)
         },
         webscript:
         {
            name: "backup/site/{site}/{container}",
            method: Alfresco.util.Ajax.POST
         },
         params:
         {
            site: this.options.siteId,
            container: this.options.containerId
         },
         config:
         {
            requestContentType: Alfresco.util.Ajax.JSON,
            dataObj:
            {
               nodeRefs: [file.nodeRef]
            }
         }
      });
   };
})();
I Use the YUI Compressor to compress the backup-action.js and create <share>/components/documentlibrary/backup-action-min.js:
java -jar yuicompressor-2.4.2.jar <share>/components/documentlibrary/backup-action.js -o <share>/components/documentlibrary/backup-action-min.js

I Create the following space hierarchy, in the Repository, under Company Home > Data Dictionary > Web Scripts Extensions

/org
   /alfresco
      /slingshot
         /documentlibrary
            /action
and then the following three files, which will form our backup repository action:
backup.post.desc.xml

<webscript>
  <shortname>backup</shortname>
  <description>Document List Action - Backup document(s)</description>
  <url>/slingshot/doclib/action/backup/site/{site}/{container}</url>
  <format default="json">argument</format>
  <authentication>user</authentication>
  <transaction>required</transaction>
</webscript>
backup.post.json.js

<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/action.lib.js">

/**
* Backup multiple 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 results = [];
   var files = p_params.files;
   var file, fileNode, result, nodeRef;

   // Find destination node
   var destNode = p_params.rootNode.childByNamePath("/Backup");
   if (destNode == null)
   {
      destNode = p_params.rootNode.createFolder("Backup");
   }

   // Must have destNode by this point
   if (destNode == null)
   {
      status.setCode(status.STATUS_NOT_FOUND, "Could not find or create /Backup folder.");
      return;
   }

   // Must have array of files
   if (!files || files.length == 0)
   {
      status.setCode(status.STATUS_BAD_REQUEST, "No files.");
      return;
   }

   for (file in files)
   {
      nodeRef = files[file];
      result =
      {
         nodeRef: nodeRef,
         action: "backupFile",
         success: false
      }

      try
      {
         fileNode = search.findNode(nodeRef);
         if (fileNode === null)
         {
            result.id = file;
            result.nodeRef = nodeRef;
            result.success = false;
         }
         else
         {
            result.id = fileNode.name;
            result.type = fileNode.isContainer ? "folder" : "document";
            // copy the node to the backup folder
            result.nodeRef = fileNode.copy(destNode);
            result.success = (result.nodeRef !== null);
         }
      }
      catch (e)
      {
         result.id = file;
         result.nodeRef = nodeRef;
         result.success = false;
      }

      results.push(result);
   }

   return results;
}

/* Bootstrap action script */
main();
backup.post.json.ftl

<#import "action.lib.ftl" as actionLib />
<@actionLib.resultsJSON results=results />
I browse to the Web Scripts Home, (http://<server>/alfresco/service/index) and after "Refresh Web Scripts" I "Browse all Web Scripts":

backup
POST /alfresco/service/slingshot/doclib/action/backup/site/{site}/{container}

Document List Action - Backup document(s)

Authentication:   user
Transaction:   required
Format Style:   argument
Default Format:   json
Id:   org/alfresco/slingshot/documentlibrary/action/backup.post
Descriptor:   workspace://SpacesStore/app:company_home/app:dictionary/cm:extensionwebscripts/org/alfresco/slingshot/documentlibrary/action/backup.post.desc.xml
finally I Check if the webscripts have registered correctly by browsing to: http://<server>/alfresco/service/script/org/alfresco/slingshot/documentlibrary/action/backup.post:

Web Script: org/alfresco/slingshot/documentlibrary/action/backup.post
Generated from /alfresco/service/script/org/alfresco/slingshot/documentlibrary/action/backup.post on 4/Nov/2009 11:32:58

Script Properties
Id:   org/alfresco/slingshot/documentlibrary/action/backup.post
Short Name:   backup
Description:   Document List Action - Backup document(s)
Authentication:   user
Transaction:   required
Method:   POST
URL Template:   /slingshot/doclib/action/backup/site/{site}/{container}
Format Style:   argument
Default Format:   json
Negotiated Formats:   [undefined]
Implementation:   class org.alfresco.web.scripts.DeclarativeWebScript
Extensions:   [undefined]

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:extensionwebscripts

File: org/alfresco/slingshot/documentlibrary/action/backup.post.desc.xml

<webscript>
  <shortname>backup</shortname>
  <description>Document List Action - Backup document(s)</description>
  <url>/slingshot/doclib/action/backup/site/{site}/{container}</url>
  <format default="json">argument</format>
  <authentication>user</authentication>
  <transaction>required</transaction>
</webscript>

File: org/alfresco/slingshot/documentlibrary/action/backup.post.json.ftl

<#import "action.lib.ftl" as actionLib />
<@actionLib.resultsJSON results=results />

File: org/alfresco/slingshot/documentlibrary/action/backup.post.json.js

<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/action.lib.js">

     /**
      * Backup multiple 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 results = [];
    var files = p_params.files;
    var file, fileNode, result, nodeRef;

    // Find destination node
    var destNode = p_params.rootNode.childByNamePath("/Backup");
    if (destNode == null)
   {
       destNode = p_params.rootNode.createFolder("Backup");
   }

    // Must have destNode by this point
    if (destNode == null)
   {
       status.setCode(status.STATUS_NOT_FOUND, "Could not find or create /Backup folder.");
       return;
   }

    // Must have array of files
    if (!files || files.length == 0)
   {
       status.setCode(status.STATUS_BAD_REQUEST, "No files.");
       return;
   }

    for (file in files)
   {
       nodeRef = files[file];
      result =
       {
      nodeRef: nodeRef,
      action: "backupFile",
      success: false
       }

      try
     {
         fileNode = search.findNode(nodeRef);
         if (fileNode === null)
        {
            result.id = file;
            result.nodeRef = nodeRef;
            result.success = false;
        }
         else
        {
            result.id = fileNode.name;
            result.type = fileNode.isContainer ? "folder" : "document";
            // copy the node to the backup folder
            result.nodeRef = fileNode.copy(destNode);
            result.success = (result.nodeRef !== null);
        }
     }
      catch (e)
     {
         result.id = file;
         result.nodeRef = nodeRef;
         result.success = false;
     }

       results.push(result);
   }

    return results;
}

/* Bootstrap action script */
     main();

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:webscripts

[No implementation files]

Store: classpath:alfresco/templates/webscripts

[No implementation files]

Store: classpath:alfresco/webscripts

[No implementation files]

and… like I said, nothing happens… Am I missing something??
Can anyone help?! …
Thanks!!

João Duarte

jmi9999
Champ in-the-making
Champ in-the-making
Hi,

Same problem, do you find a solution ?

Thanks
JMi

jmi9999
Champ in-the-making
Champ in-the-making
Well, after some investigations, it appears that there are errors in the wiki page for backup-action.js. 

You have to use the compressed script: backup-action-min.js compressed with yuicompressor-2.4.2.jar, don't forget it, otherwise the toolbar is not present.

Here is the corrected code for backup-action.js (don't forget to compress and set @script):

/**
* DocumentList "Backup" action
*
* @namespace Alfresco
* @class Alfresco.DocumentList
*/
(function()
{
   /**
    * Backup single document.
    *
    * @method onActionBackup
    * @param row {object} DataTable row representing file to be actioned
    */
    Alfresco.DocumentList.prototype.onActionBackup = function DL_onActionBackup(row)
    {
        var file = row;
        var displayName = file.displayName;
        var nodeRef = file.nodeRef;

        this.modules.actions.genericAction(
        {
            success:
            {
                message: this.msg("message.backup.success", displayName) // previously _msg
            },
            failure:
            {
                message: this.msg("message.backup.failure", displayName)
            },
            webscript:
            {
                name: "backup/site/{site}/{container}",
                method: Alfresco.util.Ajax.POST
            },
            params:
            {
                site: this.options.siteId,
                container: this.options.containerId
            },
            wait:
            {
                message: this.msg("message.please-wait")
            },
            config:
            {
                requestContentType: Alfresco.util.Ajax.JSON,
                dataObj:
                {
                    nodeRefs: [nodeRef]
                }
            }
        });
    };
})();

HTH
JMi