0

I am allowing deletion of attachments in the File Download control. If a user deletes an attachment and navigates away from the page (without saving), the attachment does not actually get removed.

There is an onclick event for the control, but it isn't specific to deletion. Is there a way to automatically call a .save() after deletion of an attachment?

Ryan Buening
  • 1,559
  • 2
  • 22
  • 60

2 Answers2

6

Here is a SSJS snippet which allows to add an action to the delete function of a FileDownload control.

<xp:this.beforeRenderResponse>
    <![CDATA[#{javascript:

    /***
     * adds an additional method to "delete action"
     * of a UIFileDownload control
     *  
     * @param UIFileDownload component
     * @author Sven Hasselbach
     * @category SSJS
     * @category UI
     * @version 0.3
     */
    function overrideFileDownloadAction( fDownload ){
        if( fDownload === null )
            return;
        rekOverrideFileDownloadAction( fDownload, fDownload );
    }

    function rekOverrideFileDownloadAction( component:javax.faces.component.UIOutput, fDownload:com.ibm.xsp.component.UIFileDownload  ){
        try{
            var children:java.util.List = component.getChildren();
            var it:java.util.Iterator = children.iterator();
            var curChild:javax.faces.component.UIOutput;

            while( it.hasNext() ){
                curChild = it.next();
                if( typeof( curChild ) === 'com.ibm.xsp.component.xp.XspEventHandler' ){

                    var group = new com.ibm.xsp.actions.ActionGroup();
                    var list = new java.util.ArrayList();
                    group.setComponent( fDownload );
                    list.add( curChild.getAction() );
                    list.add( mBinding );
                    group.setActions( list );
                    curChild.setAction(group);
                }
                rekOverrideFileDownloadAction( curChild , fDownload );
            }
        }catch(e){}    
    }

    var mBinding = facesContext.getApplication().createMethodBinding("#{javascript:document1.save()}", null );
    overrideFileDownloadAction( getComponent( 'fileDownload1' ) );
    }]]>
</xp:this.beforeRenderResponse>

You have to change the code in the MethodBinding mBinding and the name of the FileDownLoad control. Please keep in mind that this code will only save the document if there are no validation problems. To disable required fields you have to add the following line of code curChild.setDisableValidators( true ); in the if block.

Sven Hasselbach
  • 10,455
  • 1
  • 18
  • 26
  • Thanks, Sven! Worked perfectly. – Ryan Buening Oct 30 '12 at 13:20
  • this code does not work in Notes 9. I get: com.ibm.xsp.actions.ActionGroup incompatible with com.ibm.xsp.actions.DeleteAttachmentsAction. Any ideas? What has changed in the new version? – mike_x_ Sep 09 '15 at 10:11
  • 1
    @mike_x_: IBM has changed the internal objects of the FileDownload control. Before ND9, the action was an action group, that's why it was possible to overwrite it / append a binding to it. Now, it is an instance of *DeleteAttachmentsAction* and can not be changed anymore this way. – Sven Hasselbach Sep 09 '15 at 12:19
  • 1
    Thank you Sven! Is there any workaround for this? I haven't found anything until now... – mike_x_ Sep 10 '15 at 07:24
2

An alternative is to use the enableModifiedFlag property to ensure that the user is prompted if leaving the page without saving.

More details at http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/topic/com.ibm.designer.domino.ui.doc/wpd_controls_pref_enablemodifiedflag.html

Per Henrik Lausten
  • 21,331
  • 3
  • 29
  • 76