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

旧街凉风 提交于 2019-11-30 09:52:28

问题


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?


回答1:


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.




回答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



来源:https://stackoverflow.com/questions/13101615/auto-save-doc-after-delete-of-attachment-in-file-download-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!