new BackendCancelableEvents()

Description

DEPRECATED

This component has been deprecated. Use components in the frontend extensibility API, or SuiteScript 2.0 modules and methods instead.

CancelableEvents is a class that allows an operation to be canceled before it is completed.

In the SuiteCommerce Extensibility API, most operations have a before and after event. The operation can be canceled before it is executed by creating a component listener that subscribes to the before event. Business logic in the listener can then throw an error or return a Deferred object in the rejected state.

For example, in CartComponent.js, the AddLine method is used to add a line to the cart. The beforeAddLine event occurs before the line is added and the afterAddLine events occurs after the line is added.

Examples

Canceling an option selection from a listener by throwing an error:

pdp_component.on('beforeOptionSelection', function()	{
	if(someCondition)
		throw new Error('Canceling select option.');
});

Canceling an option selection from a listener by returning a rejected promise:

pdp_component.on('beforeOptionSelection', function()	{
  if(someCondition)
     return jQuery.Deferred().reject(new Error('Canceling select option.'));
});

Methods


cancelableOn( event_name, handler ) → {void}

Description

Attaches an event handler to an event.

Parameters
Name Type Description
event_name String

The event name that the handler will be attached to.

handler function

The event handler (function) that will be invoked when event_name is triggered. The event handler can accept one optional callback parameter. The event handler can return a Deferred object, which if resolved, executes the callback function. If the promise is rejected, the callback function does not execute.

Returns

cancelableOff( event_name, handler ) → {void}

Description

Detaches an event handler from an event.

Parameters
Name Type Description
event_name String

The event name that the handler will be detached from. This argument is required.

handler function

The event handler (function) that will be removed from the list of registered handlers. This argument is required.

Returns

cancelableDisable( event_name ) → {void}

Description

Disables all event handlers attached to an event.

Parameters
Name Type Description
event_name String

The name of the event for which event handlers will be disabled.

Returns

cancelableEnable( event_name ) → {Void}

Description

Re-enables all event handlers attached to an event.

Parameters
Name Type Description
event_name String

The name of the event for which event handlers will be re-enabled.

Returns

cancelableTrigger( event_name, ...args ) → {Deferred}

Description

Triggers an event with one or more arguments. If any of the event handlers associated with the event are rejected, callbacks will not be executed.

Parameters
Name Type Attributes Description
event_name String

The name of the event to trigger.

args params <repeatable>

Any arguments to be passed to all event handlers attached to the event.

Returns

Returns a Deferred object. Because event handlers are sometimes asynchronous, any callbacks in the event handlers will also be asynchronous.


cancelableTriggerUnsafe( event_name, ...args ) → {Deferred}

Description

Triggers an event with one or more unsanitized arguments. If any of the event handlers associated with the event are rejected, callbacks will not be executed.

Parameters
Name Type Attributes Description
event_name String

The name of the event to trigger.

args params <repeatable>

Any arguments to be passed to all event handlers attached to the event.

Returns

Returns a Deferred object. Because event handlers are sometimes asynchronous, any callbacks in the event handlers will also be asynchronous.