cancel
Showing results for 
Search instead for 
Did you mean: 

New Action in Alfresco Share

massanen
Champ in-the-making
Champ in-the-making
hi everybody,
I've got a pretty urgent problem and at the moment, even seemed that it's really easy, I couldn't solve it. Let's see:

I'm working with Alfresco Share 3.4.d, and in the documentlibrary, in a personal space that I've created, I have a list of folders representing workflow spaces. I've got "creation", "edition", … What I have to do is to move a folder (not a document) through these state-folders. So what I did was to create some rules in every state-folder, with the idea that my elements (folders) changed its state-folder when a specific metadata was changed. I did it with the next simply Script (this script pretend to move my element (the folder) from "creation" to "edition"):

var Folder_edi = space.parent.childByNamePath("Edition");
if (Folder_edi == null)
{
   Folder_edi = space.parent.createFolder("Edition");
}

if(Folder_edi != null && Folder_edi.hasPermission("CreateChildren"))
{
   var childrenList = space.children;
   for (var i = 0; i < childrenList.length; i++) {
      var copy = childrenList[i].move(Folder_edi);
      if(copy != null)
      {
         childrenList[i].save();
         //space.save();
      }
   }
}

Here two problemes: 1) Once I executed this script in the state-folder, when I came back to the same folder and I try to set the rules, the next typical alfresco Error is thrown "A problem has ocurred. This page could not be rendered…" bla bla bla. 2)My client wants that the element (the folder) change its state-folder with an action, not with a meta-data modification.

Ok. So what I did was follow these steps: http://wiki.alfresco.com/wiki/Custom_Document_Library_Action , and in this example they do a new action that throws a web sccript. So, following these steps I have not any result. When I click my button action, it doesn't do anything.

Do you know any other solution?? any advice?? what typical mistake I must be doing with the web script?? in the link's example, they do a document backup, and I've to do a move of a folder (not a document), it is not a problem, isn't it??

If you could help me, I'll be really grateful…
5 REPLIES 5

massanen
Champ in-the-making
Champ in-the-making
no ideas??? I "only" need to know how to code a web script that when I push the button of the action, it could move the folder from its state-folder to another state-folder….. in my documentlibrary in my personal site…. Does anybody know how??? Smiley Sad

loftux
Star Contributor
Star Contributor
you can find some example actions here http://code.google.com/p/share-extras/

massanen
Champ in-the-making
Champ in-the-making
thanks a lot for answering Loftux. Yes, that's exactly what I've checked, and what i've done. Look:

1) I've created a new action modifying documentlist.get.config.xml:
<actionSet id="folder">

<action type="action-link" id="onActionMoveToEdition" permission="" label="actions.folder.movetoedition"/>

2)  I've created a new .css, and download an icon to move my folder to another-state folder

.doclist .folder .onActionMoveToEdition a
{
   background-image: url(images/workflowpermissionIcon.png);
}

3) I've modyfied the slingshot.properties (this is where you have to define the new labels):

actions.document.movetoedition=Move to edition
message.movetoedition.success='{0}' successfully moved to edition.
message.movetoedition.failure=Couldn't move to edition'{0}

4)  I've modyfied the template documentlist.get.head.ftl
<!– Backup Action –>
<@link rel="stylesheet" type="text/css" href="${page.url.context}/components/documentlibrary/movetoedition-action.css" />
<@script type="text/javascript" src="${page.url.context}/components/documentlibrary/movetoedition-action.js"></@script>

————————– until here, everything perfect. Ok, next: ——————————————————

5) I've created the next web script in: tomcat/webapps/share/WEB-INF/classes/alfresco/site-webscripts/demo/change-to-edition

a) movetoedition.post.desc.xml
<webscript>
   <shortname>movetoedition</shortname>
   <description>Folder List Action - Start workflow </description>
   <url>/demo/change-to-edition/{site}/{container}</url>
   <format default="json">argument</format>
   <authentification>user</authentification>
   <transaction>required</transaction>
</webscript>

b) movetoedition.post.json.js
var Folder_edi = space.parent.childByNamePath("Edition");
if (Folder_edi == null)
{
   Folder_edi = space.parent.createFolder("Edition");
}

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("/Edition");
   if (destNode == null)
   {
      destNode = p_params.rootNode.createFolder("Edition");
   }

   // Must have destNode by this point
   if (destNode == null)
   {
      status.setCode(status.STATUS_NOT_FOUND, "Could not find or create /Edicio 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: "iniciWF",
         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();

c) movetoedition.post.json.ftl
<#import "action.lib.ftl" as actionLib />
<@actionLib.resultsJSON results=results />

d) I've defined the js movetoedition.js
(function()
{
   Alfresco.doclib.Actions.prototype.onActionMoveToEdition= function DL_onActionMoveToEdition(file)
   {
      this.modules.actions.genericAction(
      {
         success:
         {
            message: this.msg("message.movetoedition.success", file.displayName)
         },
         failure:
         {
            message: this.msg("message.movetoedition.failure", file.displayName)
         },
         webscript:
         {
            name: "demo/change-to-edition/{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 execute my action in my documentlibrary, in my pesrsonal site. And it doesn't do anything. Any ideas (please)??

loftux
Star Contributor
Star Contributor
Have you checked with some web developer tool that the XHR request is sent, and if so do you get the json response?

If you action is actually called, then you may need to refresh the page after the result
success:
         {
            message: this.msg("message.movetoedition.success", file.displayName),
                        events : [
                           {
                              name : "folderCreated"
                           }]
         },
That will trigger a reload of the document listing.

massanen
Champ in-the-making
Champ in-the-making
it didn't work….

finally I made an action in the web client. This action executes a javascript:

<action id="moveToEdicio">
            <permissions>
               <permission allow="true">Write</permission>
            </permissions>
            <label>Moure la carpeta a Edicio</label>
            <image>/images/icons/listar_docs_expediente.gif</image>
            <tooltip>Moure destat</tooltip>
            <script>/Espacio de empresa/Diccionario de datos/Scripts/cM_mouEdicio.js</script>
            <params>
               <param name="id">#{actionContext.id}</param>
            </params>
         </action>

But it doesn't work… look my (more than simple) script:

var Folder_edi = companyhome.childByNamePath("/Espacio de empresa/ELISAVA/GESTIO DE TREBALLS/EDICIO");

space.move(Folder_edi);
space.save();

// Volvemos a la pantalla desde donde se lanza el script
var goBack = "<script>history.back()</script>";
goBack;

do you know how I have to refer the folder where I'm triggering my action, in the javascript?? because it looks like that "space" doesn't work. Webclient, not share…

Thanks man…