0
  1. I need to somehow catch an event when user deletes an attachment in File Download component (bin icon). I'd like to autosave document or at least tell him, that document has been modified and he must save it. User deletes attachment and closes a window and attachment remains undeleted. User doesn't know it, he thinks, that attachment is gone, while it disappears from the attachment list.

  2. I need to somehow catch an event when user downloads a file. I want it to be added to a log. Something like: 1.1.2014 12:33 Johnny Cash downloaded four-roses.pdf

Any solution? Thanks, JiKra

JiKra
  • 1,618
  • 3
  • 29
  • 45

3 Answers3

2

You could track the filedownloads if you overwrite the fileNameHrefValue attribute and redirect the user to an download XPage which logs the file access.

<xp:fileDownload
   rows="30"
   id="fileDownload1"
   displayLastModified="false"
   value="#{document1.Body}"
   allowDelete="true">
      <xp:this.fileNameHrefValue>
         <![CDATA[#{javascript:
            var fName = this.getFileId();
            var docUNID = document1.getDocument().getUniversalID();
            var path = "http://www.example.com/yourdb.nsf/download.xsp";
            path + "?documentId=" + docUNID + "&fileName=" + fName & "&fieldName=Body";
         }]]>
         </xp:this.fileNameHrefValue>
</xp:fileDownload>

The parameter fieldName of the generated URL must match the field the fileDownloadComponent is bound to.

The download.xsp then just have to do another redirect:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
    <xp:dominoDocument var="documentFile"></xp:dominoDocument>
    <xp:dominoDocument
        var="documentLog"
        ignoreRequestParams="true">
    </xp:dominoDocument>
</xp:this.data>


<xp:this.beforeRenderResponse>
    <![CDATA[#{javascript:
    var dbPath = documentFile.getParentDatabase().getFilePath();

    var url = "http://www.example.com/";
    url += dbPath; 
    url += "/xsp/.ibmmodres/domino/OpenAttachment/";
    url += dbPath + "/";
    url += documentFile.getDocument().getUniversalID();
    url += "/" + param.get("fieldName") + "/";
    url += param.get("fileName");
    facesContext.getExternalContext().redirect( url );
    facesContext.responseComplete();

    documentLog.setValue("User", session.getUserName() );
    documentLog.setValue("FileName", param.get("fileName") );
    documentLog.save();

    }]]>
</xp:this.beforeRenderResponse>
</xp:view>

EDIT:

And here you can find a way to manipulate the the delete function of a filedownload control:

Auto-save doc after delete of attachment in File Download control?

Community
  • 1
  • 1
Sven Hasselbach
  • 10,455
  • 1
  • 18
  • 26
1

I've been investigating this myself and, as of yet, haven't found a way to intercept anything to do with the fileDownload control itself.

However, if I've understood what you're trying to do, I had a similar need to tell a user that an attachment had been deleted but not actually delete it - so I spoofed my own download control. Basically, I use a bean to intercept the File Upload ( Mark Leusnik wrote a post about how to do this with SSJS here ) and then saved it to it's own holding document. I use a standard repeat control to list all the holding documents linked to the main record and show a link to the files (See Stephan Wissel's post about XPages File Attachment URLs). The "delete" link simply calls a function which flags the holding document so that it isn't displayed in the repeat control. This lets me capture the username and date as well as being able to recover the "deleted" file.

I haven't implemented a way of tracking downloads but I'd probably take a similar approach - have the "download" link call a function to track the download request and then return the url of the file attachment to the browser location bar.

I'm sure there is a way of actually interacting with the download control itself which is an instance com.ibm.xsp.component.xp.XspFileDownload - but it will take a better mind than mine to do it.

TrailDragon
  • 456
  • 2
  • 14
  • OK, it seems legit. I'll try to do some workaround with custom component. FileDownload control is a very good component, but has a huge problem while it's not more developer friendly and controllable. Anyway, thanks. – JiKra May 09 '13 at 22:28
0

You can specify a custom delete Message with the deleteMessage propertie of the component or i dont know if it is a good idea but its better than nothing:

Add some CSJS to your page to add a event to a element on your page:

dojo.connect(dojo.byId('The Client side id  of the bin icon'), "onclick", function(evt){
    //window.alert("hallo");
...
});

I tryed this and it worked with the alert('hallo') funktion, so you could also add a funktion wich triggers a SSJS event so that you can save your document. The only problem is to find out the client side ID of the image.. maby try to add a special class to the column of the delete icon and search for that in your code or add somithing via the rowAttrs proptertie in the AllProperties tap of the component.

Michael Saiz
  • 1,640
  • 12
  • 20
  • Yeah, I understand the point, but I don't like it. It's too complicated and unreliable. :-) – JiKra May 09 '13 at 22:37