cancel
Showing results for 
Search instead for 
Did you mean: 

Download and delete

landerigeno
Champ in-the-making
Champ in-the-making
Hello:
I have to develop in alfresco a feature that delete a document once the user download it.
I tried to create a new action that launch a js when the user click the document to download it but it's not working
Someone have an idea how I can do it?
Thank you
8 REPLIES 8

mikeh
Star Contributor
Star Contributor

landerigeno
Champ in-the-making
Champ in-the-making
Thank you for the reply.
I tried to execute a script that delete the file, I also tried to execute a scrit that modify an aspect (to delete later with a cron job) but it seems imposible to execute an action and a script at the same time.
Any ideas?
Thank you

mikeh
Star Contributor
Star Contributor
It's not impossible - you just need to add JavaScript behaviour when you click the download link, then redirect the browser to the document.

Thanks,
Mike

landerigeno
Champ in-the-making
Champ in-the-making
Hello:
Sorry, I'm quite newbie in alfresco, can you explain a little bit more?

In the file web-client-config-action.xml  I modify the download action:
        
         <action id="download_doc">
             <label-id>download_doc</label-id>
             <image>/images/icons/download_doc.gif</image>
            <href>#{actionContext.downloadUrl}</href>
            <permissions>
               <permission allow="true">Delete</permission>
            </permissions>
            <params>
               <param name="ref">#{actionContext.nodeRef}</param>
            </params>
           <script>/Company Home/Diccionario de datos/Scripts/delete.js</script>
         </action>

And this is the script to delete the document(right now I have some problems to make it work)
var nodeRef = args[0];
var node = search.findNode(nodeRef);
node.remove();

I can't download and execute the script at the same time (I have to comment one)
There is another way to make it work?
Thank You very much, it's really helpfull

mikeh
Star Contributor
Star Contributor
<sigh> It would be really helpful if you could try to post your question in the correct forum. I had assumed you were talking about the Share web client, not the Explorer one.

Anyway, thinking about the issue a bit further, you can't in fact use the method I described as it won't work for large documents and they'll be removed before they've been downloaded. Instead you'll likely have to add a "toBeDeleted" custom aspect and then create a scheduled task to go around and delete these later.

http://wiki.alfresco.com/wiki/Scheduled_Actions

Thanks,
Mike

landerigeno
Champ in-the-making
Champ in-the-making
Thank you for the advise and I'll move it to alfresco explorer

I follow your advice and I create a new Aspect toDelete and works fine.

Now I want to execute an scrpt each time I download a file so I edit web-client-config-actions.xml

         <!– Download document –>
         <action id="download_doc">
             <label-id>download_doc</label-id>
             <image>/images/icons/download_doc.gif</image>          
    <permissions>
               <permission allow="true">Write</permission>
            </permissions>
            <params>
               <param name="ref">#{actionContext.nodeRef}</param>
            </params>      
            <script>/Company Home/Diccionario de datos/Scripts/addaspect.js</script>
        <href>#{actionContext.downloadUrl}</href>
         </action>

And also create an script addaspect.js:
var nodeRef = args[0];
var document = search.findNode(nodeRef);
props = new Array(1);
props["cm:toDelete"] = true;
document.addAspect("cm:toDelete", props);

document.save;

But the script it's not working.
Someone have an example about how to add an aspect to an item?
Thank you

landerigeno
Champ in-the-making
Champ in-the-making
Hello:
I'm quite desperate with the addaspect.js script, I tried to add a different aspect but I can't make it work.
I try to send the parameter nodeRef and the ID parameter to the script but it says "Invalid nodeRef" or "does not contain forward slash"

I'll be happy with any clue
var nodeRef = args[0];
var document = search.findNode(nodeRef);
props["cm:template"] = document.nodeRef;
document.addAspect("cm:templatable", props);


Thank you

landerigeno
Champ in-the-making
Champ in-the-making
Hello:
i can add an aspect to an item but I can't redirect the script to the file so the user can download it.
In web-client-config-actions I have:
  <action id="download_doc">
      <label-id>download_doc</label-id>
      <image>/images/icons/download_doc.gif</image>
      <permissions>
           <permission allow="true">Write</permission>
      </permissions>
      <params>
<param name="ref">#{actionContext.nodeRef}</param>
<param name="dow">#{actionContext.downloadUrl}</param>
       </params>      
    <script>/Company Home/Diccionario de Datos/Scripts/addaspect.js</script>
         </action>
I had to comment the line <href>#{actionContext.downloadUrl}</href> because the script didn't work
Now I'm trying to redirect it with this script:
var noderef = args["ref"];  
var node = search.findNode(noderef);
if (node != null)
{
  node.addAspect("cm:taggable");
}
var dir = args["dow"];
var redir = "<script> window.open = ";
redir += noderef;
redir +="</script>"
redir;

Where I can get the right reference?
Thank you