alfresco-ng2-components/docs/content-services/document-actions.service.md
Andy Stark 69d8ff147e [ADF-3323] Updated doc tools to use DocFX intermediate files (#3601)
* [ADF-3323] Moved source file parsing to main doc tool

* [ADF-3323] Moved source info classes

* [ADF-3323] Added doc YAML generator tool

* [ADF-3323] Added doc YAML/JSON source paths to gitignore

* [ADF-3323] Completed templates and template context code

* [ADF-3323] Added source paths and updated type linker

* [ADF-3323] Final fixes to templates and type linking

* [ADF-3323] Fixed filter for private and protected methods

* [ADF-3323] Content services docs after check and rebuild

* [ADF-3323] Updated docbuild script in package.json
2018-08-14 15:42:25 +01:00

3.0 KiB

Added, Status, Last reviewed
Added Status Last reviewed
v2.0.0 Active 2018-03-29

Document Actions service

Implements the document menu actions for the Document List component.

Class members

Methods

  • canExecuteAction(obj: any): boolean
    Checks if actions can be executed for an item.
    • obj: any - Item to receive an action
    • Returns boolean - True if the action can be executed on this item, false otherwise
  • getHandler(key: string): ContentActionHandler
    Gets the handler for an action.
    • key: string - Identifier of the action
    • Returns ContentActionHandler - The handler for the action
  • setHandler(key: string, handler: ContentActionHandler): boolean
    Sets a new handler for an action.
    • key: string - Identifier of the action
    • handler: ContentActionHandler - Handler for the action
    • Returns boolean - False if the key was an empty/null string, true otherwise

Details

This service implements the built-in actions that can be applied to a document shown in a Document List component: delete, download, copy and move (see the Content Action component for further details and examples of these menu items). However, you can also use the service to add extra actions or replace the built-in ones with your own implementation.

Registering an action

In the example below, a custom handler called my-handler is registered with the service. This action will invoke the myDocumentActionHandler function each time it is selected from the Document List menu.

import { DocumentActionsService } from '@alfresco/adf-content-services';

export class MyView {

    constructor(documentActions: DocumentActionsService) {
        documentActions.setHandler(
            'my-handler',
            this.myDocumentActionHandler.bind(this)
        );
    }

    myDocumentActionHandler(obj: any) {
        window.alert('my custom action handler');
    }
}

The action can then be used from the component in the usual way:

<adf-document-list ...>
    <content-actions>

        <content-action
            target="document"
            title="My action"
            handler="my-handler">
        </content-action>

    </content-actions>
</adf-document-list>

You can also override a built-in handler (eg, 'download') with your own function:

export class MyView {

    constructor(documentActions: DocumentActionsService) {
        documentActions.setHandler(
            'download',
            this.customDownloadBehavior.bind(this)
        );
    }

    customDownloadBehavior(obj: any) {
        window.alert('my custom download behavior');
    }
}

You will probably want to set up all your custom actions at the application root level or with a custom application service.

See also