Implémentation de la gestion d’une action personnalisée

Pour implémenter la gestion d’une action personnalisée, définissez une classe implémentant IActionHandler. Le constructeur de cette classe doit être sans argument.
package com.adobe.acm.solutions.authoring.domain.extensions 
{ 
    import com.adobe.icc.vo.CustomAction; 
 
    import flash.events.IEventDispatcher; 
 
    /** 
     * Interface for adding and handling custom actions in Extensible Toolbar. 
     * One instance of handler will be created for each action. 
     */ 
    public interface IActionHandler extends IEventDispatcher 
    { 
 
        /** 
         * Set action associated with this handler instance. 
         */ 
        function set action(value:CustomAction):void; 
 
        [Bindable(event="actionChange")] 
        /** 
         * Fetch action associated with this handler instance. 
         */ 
        function get action():CustomAction; 
 
        /** 
         * Set Flex Domain Model for on which the action is being taken 
         */ 
        function set model(value:*):void; 
 
        [Bindable(event="modelChange")] 
        /** 
         * Get Flex Domain Model for on which the action is being taken 
         */ 
        function get model():*; 
 
        /** 
         * Called when user user click an action 
         */ 
        function handleAction(extraParams:Object=null):void; 
 
        [Bindable(event="actionEnabledChange")] 
        /** 
         * Should the action be enabled in toolbar 
         */ 
        function actionEnabled(extraParams:Object=null):Boolean; 
 
        [Bindable(event="actionVisibleChange")] 
        /** 
         * Should the action be visible in toolbar 
         */ 
        function actionVisible(extraParams:Object=null):Boolean; 
    } 
}

L’application de création de correspondance est accompagnée de l’implémentation par défaut d’IActionHandler com.adobe.acm.solutions.ccr.domain.extensions.CCRDefaultActionHandler qui fait partie d’adobe-acm-ccr-domain-impl.swc et qui se trouve dans le dossier [SDK]\riaservices\assetcomposer\10.0.0.0\flex. Tout gestionnaire d’action personnalisée permet d’étendre cette classe. Pour lancer l’implémentation, ouvrez le projet Flex du modèle de solution de création de correspondance importé dans Flash Builder, puis créez les classes nécessaires dans un package personnalisé.

Etendez le gestionnaire CCRDefaultActionHandler pour qu’il prenne en charge l’action nouvellement ajoutée. Pour ce faire, les trois éléments ci-dessous sont nécessaires :
  • La logique permettant de faire apparaître ou non la nouvelle action en remplaçant la fonction actionVisible(extraParams:Object=null):Boolean.

  • La logique d’activation et de désactivation de la nouvelle action en remplaçant la fonction actionEnabled(extraParams:Object=null):Boolean.

  • Le traitement de l’action lorsque l’utilisateur clique sur le bouton en remplaçant l’implémentation de la fonction handleAction(extraParams:Object=null):void.

L’implémentation de la classe com.adobe.solutions.cmg.ccr.custom.CCRCustomActionHandler ci-dessous étend CCRDefaultActionHandler.
package com.adobe.solutions.cmg.ccr.custom 
{ 
    import com.adobe.acm.solutions.ccr.domain.extensions.CCRDefaultActionHandler; 
    import com.adobe.icc.services.ServiceProvider; 
    import com.adobe.icc.services.submit.ISubmitService; 
    import com.adobe.icc.util.Debug; 
    import com.adobe.icc.util.UrlHelper; 
 
    import flash.display.DisplayObject; 
    import flash.events.Event; 
    import flash.net.URLRequest; 
    import flash.net.navigateToURL; 
 
    import mx.controls.Alert; 
    import mx.core.FlexGlobals; 
    import mx.managers.PopUpManager; 
    import mx.rpc.events.FaultEvent; 
    import mx.rpc.events.ResultEvent; 
    import mx.utils.ObjectUtil; 
 
    public class CCRCustomActionHandler extends CCRDefaultActionHandler 
    { 
 
        protected static const SEND_FOR_REVIEW:String = "sendForReview"; 
 
        public var encodedString:String = ""; 
        public var mailTo:String = ""; 
 
        public function CCRCustomActionHandler() 
        { 
            super(); 
        } 
 
        override public function handleAction(extraParams:Object=null):void 
        { 
            if(action.name == SEND_FOR_REVIEW) 
            { 
                                //open the Send For Review Pop-up on click of newly added action 
                var addDocPopUp:SendForReviewPopUp = SendForReviewPopUp(PopUpManager.createPopUp(FlexGlobals.topLevelApplication as DisplayObject ,SendForReviewPopUp, true)); 
 
                                //sendforreview listens the 'onClose' event dispatched when user clicks on Send button in the Pop-up. 
                addDocPopUp.addEventListener('onClose',sendforreview); 
 
                                //referencing to update the 'encodedString' and 'mailTo' variables when user clicks on Send button in the Pop-up. 
                addDocPopUp.ccrCustomObject = this; 
            } 
        } 
 
        override public function actionEnabled(extraParams:Object=null):Boolean 
        { 
                       //can be customized as per user requirement 
            return true; 
        } 
 
        override public function actionVisible(extraParams:Object=null):Boolean 
        { 
                        //Show the added button only when Letter is opened in Non-Preview mode. 
            return (invokeParams && !invokeParams.preview); 
        } 
 
        protected function sendforreview(ev:Event):void 
        { 
            var service:ISubmitService = ServiceProvider.getSubmitService(); 
 
            var params:Object = new Object(); 
            if(action.actionConfig) 
                params = ObjectUtil.copy(action.actionConfig); 
 
                        //Add additional custom params here which will be available under <icc:meta> tag. 
            if(encodedString.length>0) 
                        { 
                                //the encodedString contains base64 encoded string of the supporting document attached 
                params["cm_supportDoc"] = encodedString; 
                        } 
 
            params["cm_mailTo"] = mailTo; 
 
            var reload:Boolean = false; 
            if(!(invokeParams.letterId) && !(invokeParams.letterName)) 
            { 
                //If Letter is loaded without letterName or letterId then it must be reload 
                reload = true; 
            } 
            //Invoke the default letter post process 
            service.submitLetterWithParams(letterVO, letterData, 
                false, invokeParams.useLatest, reload, null, params).addHandlers 
                ( 
                    // result handler 
                    function(event:ResultEvent):void 
                    { 
                        var response:Object = event.result as Object; 
                        //Redirect to success page if mentioned 
                        if (response.redirect) 
                        { 
                            // redirect via new window or else the user will be prompted to close the DC window before proceeding 
                            if (UrlHelper.isValid(response.redirect)) 
                                navigateToURL((new URLRequest(response.redirect)), "_blank"); 
                            else 
                                Debug.error("server returned invalid redirect URL: " + response.redirect); 
                        } 
                        Alert.show('Letter Sent for Review - Successful'); 
 
                    }, 
                    // fault handler 
                    function(event:FaultEvent):void 
                    { 
                        Debug.error("failed to send " + letterVO + ":\n\t", event); 
                        Alert.show('Letter Sent for Review - Failed'); 
                    } 
                ); 
        } 
    } 
}