Adding custom action buttons

You can use the Asset Manager building block to add new actions to the Manage Assets UI for a particular asset type. For example, you can add an action button that downloads a layout XDP in the Layout toolbar. The rest of this section describes how to implement this example scenario.

For background information on this user story, see Story: Customizing the Manage Assets UI.

Permission creation

Edit the CMSAUserRoleMapping.xml file and add the permission for Layout download. Assign this permission to appropriate role, for example, Correspondence Management Administrator.

Note: The CMSAUserRoleMapping.xml file is not part of the Asset Manager building block. It is provided as part of the Correspondence Management solution template. The Asset Manager building block on its own does not provide automatic capabilities for creation of permissions for the actions defined in the asset types.
<cmsa> 
    <permissions> 
        ............ 
        <permission name="CM Layout Download" description="$LayoutDownloadPermissionDescription"/> 
           ... ... ... .. .   
     </permissions> 
    <roles> 
        <role name="Correspondence Management Administrator" displayName="$CMAdminRoleDisplayName" description="$CMAdminRoleDescription"> 
        ......... 
        <permission ref="CM Layout Download" /> 
        ......... 
        </role> 
    </roles> 
</cmsa>
Note: $LayoutDownloadPermissionDescription is a resource key for a localized string whose value has to be defined in the bootstrap resource bundle that is located parallel to CMSAUserRoleMapping.xml. For example, LayoutDownloadPermissionDescription=Correspondence Management permission to Download Layout.

Asset FML modification

Modify the WEB-INF/assetDefinitions/Layout.fml to add a new Download action. (See the bold section in the sample below):

<model xmlns="http://ns.adobe.com/Fiber/1.0"> 
<annotation name="DDS"> 
..... 
<item name="assetActions"> 
    <![CDATA[ 
    <?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    <actions> 
         <action name="Create" enabledIcon="assets/icons/LC_New_Md_N.png" disabledIcon="assets/icons/LC_New_Md_D.png" toolTip="loc.layout.tooltip.create" label="loc.layout.tooltip.create" defaultEnabled="true"/> 
         <action name="Edit" enabledIcon="assets/icons/LC_Edit_Md_N.png" disabledIcon="assets/icons/LC_Edit_Md_D.png" toolTip="loc.layout.tooltip.edit" label="loc.layout.tooltip.edit"/> 
         <action name="View" enabledIcon="assets/icons/LC_ViewInfo_Md_N.png" disabledIcon="assets/icons/LC_ViewInfo_Md_D.png" toolTip="loc.layout.tooltip.view" label="loc.layout.tooltip.view"/> 
         <action name="Copy" enabledIcon="assets/icons/LC_Copy_Md_N.png" disabledIcon="assets/icons/LC_Copy_Md_D.png" toolTip="loc.layout.tooltip.copy" label="loc.layout.tooltip.copy"/> 
         <action name="Delete" enabledIcon="assets/icons/LC_Delete_Md_N.png" disabledIcon="assets/icons/LC_Delete_Md_D.png" toolTip="loc.layout.tooltip.delete" label="loc.layout.tooltip.delete"/> 
         <action name="Activate" enabledIcon="assets/icons/LC_Activate_Md_N.png" disabledIcon="assets/icons/LC_Activate_Md_D.png" toolTip="loc.layout.tooltip.activate" label="loc.layout.tooltip.activate"/>  
         <action name="Download" enabledIcon="assets/icons/LC_Download_Md_N.png" disabledIcon="assets/icons/LC_Download_Md_D.png" toolTip="loc.layout.tooltip.download" label="loc.layout.tooltip.download"/>  
    </actions> 
    ]]> 
</item> 
..........
Note: * loc.layout.tooltip.download is a resource key for a localized string whose value has to be defined in the DataDictionaryMessages resource bundle, which is located in the WEB-INF/assetDefinitions/locale folder. For example, loc.layout.tooltip.download=Download. Also, the LC_Download_Md_D.png and LC_Download_Md_N.png files should be at appropriate location in ManageTemplates project.

Extending Asset Handler

The next step is to extend the existing handler to support the newly added action. There are two requirements:

  • Logic for enabling/disabling newly added action based on currently selected items. This is done by overriding the function set selectedAssets(selectedAssets:Array):void.

  • Actual handling of AssetActionEvent when a user clicks the action. This is done by overriding function handleAction(event:AssetActionEvent):void.

Here is the implementation for com.adobe.icc.ams.handler.CustomLayoutHandler that extends LayoutHandler:

package com.adobe.icc.ams.handler 
{ 
    import com.adobe.consulting.pst.vo.Form; 
    import com.adobe.icc.editors.handlers.LayoutHandler; 
    import com.adobe.icc.editors.managers.ErrorManager; 
    import com.adobe.icc.services.ServiceProvider; 
    import com.adobe.icc.vo.DataDownload; 
    import com.adobe.livecycle.assetmanager.client.event.AssetActionEvent; 
    import com.adobe.livecycle.assetmanager.client.model.AssetAction; 
     
    import flash.net.FileReference; 
     
    import mx.controls.Alert; 
    import mx.rpc.events.FaultEvent; 
    import mx.rpc.events.ResultEvent; 
     
    public class CustomLayoutHandler extends LayoutHandler 
    { 
        /** 
         * Constant for the name of the action related to creation of an asset. 
         */ 
        static public const ACTION_DOWNLOAD:String = "Download"; 
         
        override public function set selectedAssets(selectedAssets:Array):void 
        { 
            super.selectedAssets = selectedAssets; 
            for each(var assetAction:AssetAction in assetActions) 
            { 
                if(assetAction.name == ACTION_DOWNLOAD) 
                { 
                    assetAction.enabled = (selectedAssets!=null) && (selectedAssets.length==1); 
                        break; 
                } 
            } 
        } 
         
        override public function handleAction(event:AssetActionEvent):void 
        { 
            if(event.actionName == ACTION_DOWNLOAD) 
            { 
                downloadLayout(); 
            } 
            else 
            { 
                super.handleAction(event); 
            } 
             
        } 
         
        protected function downloadLayout():void 
        { 
            var selectedLayout:Form = selectedAssets[0]; 
            ServiceProvider.getDownloadService().getFormData(selectedLayout.id) 
                .addHandlers( layoutDownloadResultHandler, 
                                                function(faultEvent:FaultEvent){ 
                                                    ErrorManager.handleFault(faultEvent.fault, selectedLayout); 
                                                } 
                ); 
        } 
 
        private function layoutDownloadResultHandler(event:ResultEvent):void 
        { 
            var data : DataDownload = event.result as DataDownload; 
            Alert.show("Pick a location to download Layout XDP", "Download Layout",    Alert.OK | Alert.CANCEL, null, 
                function (event:*):void 
                { 
                    if ( event.detail == Alert.OK ) { 
                        var fileReference:FileReference = new FileReference(); 
                        fileReference.save(data.objByteArray ,data.objFileName);     
                    } 
                } 
            ); 
        } 
    } 
}

Registering the modified asset handler

The final step is to register the CustomLayoutHandler in place of LayoutHandler in AssetHandlerRegistry.This has to be done in ManageTemplates/index.mxml at function init(event:FlexEvent):void function:
    registry.register(new CustomLayoutHandler());