To implement the handling of custom action, define a class
that implements IActionHandler. This class must have a no argument
constructor. 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;
}
}
Create Correspondence is shipped with default implementation
of IActionHandler com.adobe.acm.solutions.ccr.domain.extensions.CCRDefaultActionHandler
which is part of adobe-acm-ccr-domain-impl.swc found in the [SDK]\riaservices\assetcomposer\10.0.0.0\flex
folder. Any Custom Action handler extends this class. To start the
implementation, open Create Correspondence solution template Flex
project that was imported in Flash Builder, then create the required
classes in custom package.
Extend the CCRDefaultActionHandler to support newly added action.
For this three things are required: Logic for making the
newly added action visible or invisible by overriding the function
actionVisible(extraParams:Object=null):Boolean.
Logic for enabling or disabling newly added action by overriding
the function actionEnabled(extraParams:Object=null):Boolean.
The handling of action when user clicks the button by overriding
the implementation for function handleAction(extraParams:Object=null):void
The Sample Implementation of com.adobe.solutions.cmg.ccr.custom.CCRCustomActionHandler
below extends 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');
}
);
}
}
}
|
|
|