cancel
Showing results for 
Search instead for 
Did you mean: 

Share 3.2 Custom Example - Not working

ahamed_rasmi
Champ in-the-making
Champ in-the-making
Hi,

Example given in following link not working for me.

http://wiki.alfresco.com/wiki/Custom_Document_Library_Action

I am in Alfresco 3.2 RC share site..

The Script backup-action-min.js is found when i view source in IE7..

The relative paths are correct..

Webscripts also responds to URL POST..

Help is sought.
28 REPLIES 28

mikeh
Star Contributor
Star Contributor
Where did you insert the
<script type="text/javascript" src="/share/components/documentlibrary/backup-action.js"></script>
line? Please post the whole .head.ftl file.

Thanks,
Mike

dark_rider
Champ on-the-rise
Champ on-the-rise
C:\Alfresco\tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\documentlibrary\documentlist.get.head.ftl

here is the content

<#include "../component.head.inc">
<!– Document List –>
<@link rel="stylesheet" type="text/css" href="${page.url.context}/components/documentlibrary/documentlist.css" />
<@script type="text/javascript" src="${page.url.context}/components/documentlibrary/documentlist.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>


and here is the registrered web scripts controls by browsing to:
http://localhost:8080/alfresco/service/script/org/alfresco/slingshot/documentlibrary/action/backup.p...


Web Script: org/alfresco/slingshot/documentlibrary/action/backup.post
Generated from /alfresco/service/script/org/alfresco/slingshot/documentlibrary/action/backup.post on May 17, 2010 1:23:30 AM

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

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

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]

I am trying to solve this problem last 2 days , I could not find the bug :?

mycroes
Champ in-the-making
Champ in-the-making
dark_Rider: a new set of questions:
  1. Is the client side javascript being executed when you click the action? (Use firebug and breakpoints or something similar that verifies it's being executed)

  2. Is a request being made to the server from the client side javascript? (Use firebug, keep console open and the request should show up when you click the link)

  3. What is the response of the request? Is it a JSON encoded error? Does any message trigger in the client when the response is returned? Again, use firebug

  4. Does the backup action create any files at all?
Up to now you haven't really provided enough information for anyone to figure out where the problem is. I think the missing .json in the filename contributed to the problem, however it doesn't seem to be the only issue…
Regards,

Michael

euphoria
Champ in-the-making
Champ in-the-making
http://wiki.alfresco.com/wiki/Custom_Document_Library_Action

I am also unable to get it working. A confusion on the tutorial is this:

To ensure both these files are served to the web browser, you need to add two lines (and a suitable comment is recommended) to the documentlist.get.head.html presentation template. Question: Is the document we edit documentlist.get.html.ftl or documentlist.get.head.ftl?

First there is no file like this: "documentlist.get.head.html". And yes, the question: which file should we edit?
If this is a tutorial for beginners, can someone please tell us what we should do?
I am trying many things but still it does not work. (I see the Backup icon, but when I click nothing happens.)
For now, I don't need to learn every detail about what is happening behind the scenes. I want to be able to write simple web scripts quickly first.

If this tutorial is updated, it will be really good for beginners. It is really painful to apply all the steps and see that it does not work. Any help is appreciated.

mycroes
Champ in-the-making
Champ in-the-making
http://wiki.alfresco.com/wiki/Custom_Document_Library_Action

I am also unable to get it working. A confusion on the tutorial is this:

To ensure both these files are served to the web browser, you need to add two lines (and a suitable comment is recommended) to the documentlist.get.head.html presentation template. Question: Is the document we edit documentlist.get.html.ftl or documentlist.get.head.ftl?

First there is no file like this: "documentlist.get.head.html".

It says documentlist.get.head.ftl right where you quoted. You should add the two lines to that file. Also, it's a wiki, if you notice stuff like this please fix it (i.e. if it works for you, remove the question). If you can't get it working I'll be able to help (I have a working custom action), but it's been too long ago for me to remember everything I did back then…
Regards,

Michael

euphoria
Champ in-the-making
Champ in-the-making
If you can't get it working I'll be able to help (I have a working custom action), but it's been too long ago for me to remember everything I did back then…

I still can't get it working. Can you please share your working custom action?

And here is what I've done:

1) NOTE: I'm using community Version 3.2R, so I don't change "documentlist.get.html.ftl" file. (Tutorial says it is for pre 3.2)
Here is my
documentlist.get.config.xml  :

<documentList>
   <actionSets>
      <actionSet id="empty"></actionSet>

      <actionSet id="document">
         <action type="simple-link" id="onActionDownload" href="{downloadUrl}" label="actions.document.download" />
         <action type="action-link" id="onActionDetails" permission="edit" label="actions.document.edit-metadata" />
         <action type="action-link" id="onActionUploadNewVersion" permission="edit" label="actions.document.upload-new-version" />
         <action type="action-link" id="onActionEditOnline" permission="edit,online-edit" label="actions.document.edit-online" />
         <action type="action-link" id="onActionEditOffline" permission="edit" label="actions.document.edit-offline" />
         <action type="action-link" id="onActionCopyTo" label="actions.document.copy-to" />
         <action type="action-link" id="onActionMoveTo" permission="delete" label="actions.document.move-to" />
         <action type="action-link" id="onActionDelete" permission="delete" label="actions.document.delete" />
         <action type="action-link" id="onActionAssignWorkflow" label="actions.document.assign-workflow" />
         <action type="action-link" id="onActionManagePermissions" permission="permissions" label="actions.document.manage-permissions" />
         <action type="action-link" id="onActionManageAspects" permission="edit" label="actions.document.manage-aspects" />
   <action id="onActionBackup" type="action-link" permission="" label="actions.document.backup" />
      </actionSet>

      <actionSet id="locked">
         <action type="simple-link" id="onActionDownload" href="{downloadUrl}" label="actions.document.download" />
      </actionSet>

      <actionSet id="lockOwner">
         <action type="simple-link" id="onActionDownload" href="{downloadUrl}" label="actions.document.download-original" />
      </actionSet>

      <actionSet id="workingCopyOwner">
         <action type="action-link" id="onActionUploadNewVersion" label="actions.document.upload-new-version" />
         <action type="simple-link" id="onActionDownload" href="{downloadUrl}" label="actions.document.download-again" />
         <action type="action-link" id="onActionCancelEditing" permission="edit" label="actions.document.cancel-editing" />
      </actionSet>

      <actionSet id="folder">
         <action type="simple-link" id="onActionMetadata" href="{folderDetailsUrl}" label="actions.folder.view-metadata" />
         <action type="action-link" id="onActionDetails" permission="edit" label="actions.folder.edit-metadata" />
         <action type="action-link" id="onActionCopyTo" label="actions.folder.copy-to" />
         <action type="action-link" id="onActionMoveTo" permission="delete" label="actions.folder.move-to" />
         <action type="action-link" id="onActionDelete" permission="delete" label="actions.folder.delete" />
         <action type="action-link" id="onActionManagePermissions" permission="permissions" label="actions.folder.manage-permissions" />
         <action type="action-link" id="onActionManageAspects" permission="edit" label="actions.folder.manage-aspects" />
      </actionSet>

      <actionSet id="link">
         <action type="action-link" id="onActionDelete" permission="delete" label="actions.link.delete" />
      </actionSet>
   </actionSets>
</documentList>

2) documentlist.get.properties is updated.
    icon image is put into images folder.
    backup-action.css is created.

3) Here is the backup-action.js which is in folder: \tomcat\webapps\share\components\documentlibrary

/**
* 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)
   {
   alert("TEST")
   this.modules.actions.genericAction(
      {
         success:
         {
            message: this._msg("message.backup.success", file.displayName)
         },
         failure:
         {
            message: this._msg("message.backup.failure", file.displayName)
         },
         webscript:
         {
            name: "/slingshot/doclib/action/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]
            }
         }
      });
   };
})();

4) Here is documentlist.get.head.ftl :
(Is there any problem with <link rel="…">  instead of <@link rel="…">  ?)

<#include "../component.head.inc">
<!– Document List –>
<@link rel="stylesheet" type="text/css" href="${page.url.context}/components/documentlibrary/documentlist.css" />
<@script type="text/javascript" src="${page.url.context}/components/documentlibrary/documentlist.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>

5)From Alfresco's Data Dictionary, I create following content:
Under /org/alfresco/slingshot/documentlibrary/action

backup-action.post.desc.xml
backup-action.post.json.js
backup-action.post.json.ftl

These files are copy-pasted from the tutorial:
http://wiki.alfresco.com/wiki/Custom_Document_Library_Action

I can navigate to
http://localhost:8080/alfresco/service/script/org/alfresco/slingshot/documentlibrary/action/backup-a...

and see the script properties successfuly.

I restart the server, create a site, upload a document. On the document library, hover the mouse on the document. On the right, I can see the "Backup" icon. Click on it. Nothing happens.

Any help is appreciated. I can support more info if needed.

euphoria
Champ in-the-making
Champ in-the-making
And here are some parts from generated HTML code:



<!– Document List –>
   <script type="text/javascript" src="/share/components/documentlibrary/documentlist-min.js"></script>
<!– Backup Action –>
<link rel="stylesheet" type="text/css" href="/share/components/documentlibrary/backup-action.css" />
<script type="text/javascript" src="/share/components/documentlibrary/backup-action.js"></script>
   <style type="text/css" media="screen">
      @import "/share/components/documentlibrary/documentlist.css";
   </style>


<div class="onActionManageAspects"><a rel="edit" href="" class="action-link" title="Manage Aspects"><span>Manage Aspects</span></a></div>
<div class="onActionBackup"><a rel="" href="" class="action-link" title="Backup"><span>Backup</span></a></div>


When user clicks on <div> of Backup action, how would the client-side Javascript be triggered if there was no problem?
Why does the javascript code not called here?
When I click on "Manage Aspects" action, an HTTP GET request is sent. But nothing happens for "Backup".

mycroes
Champ in-the-making
Champ in-the-making
I PMed this to euphoria on request, thought it might benefit other people too:

I have the following file:
/var/lib/tomcat6/shared/classes/alfresco/web-extension/site-webscripts/org/alfresco/components/documentlibrary/actions-common.get.head.ftl, which has same contents as the original (in WEB-INF) with the following appended:
<@link rel="stylesheet" type="text/css" href="${page.url.context}/res/components/documentlibrary/download-pdf-action.css" />
<script type="text/javascript" src="${page.url.context}/res/components/documentlibrary/download-pdf-action.js"></script>

These refer to the client side files that are needed to invoke the action.

It's been a while since I created the action, otherwise I would detail my complete implementation on the wiki. However if someone gets stuck just tell me where and I'll see what I can do.
Regards,

Michael

euphoria
Champ in-the-making
Champ in-the-making
The problem is the invocation of client-side Javascript. In my posts I tried to give information on my code. What can be the possible reason of the fact that clicking on "Backup" action does not trigger the Javascript? Any idea?

mycroes
Champ in-the-making
Champ in-the-making
What can be the possible reason of the fact that clicking on "Backup" action does not trigger the Javascript? Any idea?

Please, please, please; use a javascript debugger. Just set a few breakpoints in the code to see what's executed. There's only two things you need to verify:
  1. Verify that the prototype of Alfresco document list is extended with a function named to your action id,

  2. Verify that the function is executed on click.
It should not be possible that only point 1 occurs and point 2 does not work. However, you need something like a javascript debugger to see if it worked or not…

One other way that you could at least verify the prototype is properly extended is by typing the following in the address bar after page load:
javascript:alert(Alfresco.DocumentList.prototype.onActionBackup);
This should show something like 'function …', if it says undefined you're client side javascript didn't extend the object.
Regards,

Michael