Custom content

A Confluence specific JavaScript module which provides functions to interact with the custom content.

Methods

getEditComponent()

Intercept edit component events of custom content. If the intercept function was invoked for an event then Confluence will wait for the data from the corresponding callback function up to 10 seconds. If add-on didn't return data, a timeout error message will be shown.

Submit event: confluence.customcontent.submit

Add-on must intercept this event to provide the content body. The confluence.customcontent.submit event will be emitted when user clicks the save button on the custom content edit component.
You can call submitCallback function to return the data:

Return a content body string The string will be used as the content body.

1
2
3
4
5
var editComponent = AP.customContent.getEditComponent();
editComponent.intercept('confluence.customcontent.submit');
AP.events.on('confluence.customcontent.submit', function (context) {
    editComponent.submitCallback(document.querySelector("#textarea").value);
});

Return a complete content object Add-on can return a complete content object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var editComponent = AP.customContent.getEditComponent();
editComponent.intercept('confluence.customcontent.submit');
AP.events.on('confluence.customcontent.submit', function (context) {
    editComponent.submitCallback({
        "title": context.title,
        "space": {"key": context.spaceKey},
        "type": context.contentType,
        "body": {
            "storage": {
                "value": "<p>New page data.</p>",
                "representation": "storage"
            }
        }
    });
});

Return false Add-on can also return false to cancel the submit action. Additionally you can return an extra string as the error message. It will be shown as a flag message.

1
2
3
4
5
6
var editComponent = AP.customContent.getEditComponent();
editComponent.intercept('confluence.customcontent.submit');
AP.events.on('confluence.customcontent.submit', function (context) {
    editComponent.submitCallback(false);
    // editComponent.submitCallback(false, 'Cannot save the content');
});

Submit success event: confluence.customcontent.submitSuccess

The confluence.customcontent.submitSuccess event will be emitted when Confluence successfully saved the content. If add-on didn't intercept this event, user will be redirected to the content view page.
You can call submitSuccessCallback function to return the data:

Return false Return false will prevent Confluence redirect user to the content view page. In this case, add-on can redirect user using the JavaScript Navigator API. Additionally you can return an extra string as the error message. It will be shown as a flag message.

1
2
3
4
5
6
7
8
var editComponent = AP.customContent.getEditComponent();
...
editComponent.intercept('confluence.customcontent.submitSuccess');
AP.events.on('confluence.customcontent.submitSuccess', function (newContent) {
    // newContent is the saved content object
    editComponent.submitSuccessCallback(false);
    // editComponent.submitSuccessCallback(false, 'Some error message');
});

Return true User will not be redirected until submitSuccessCallback has been called.

1
2
3
4
5
6
7
var editComponent = AP.customContent.getEditComponent();
...
editComponent.intercept('confluence.customcontent.submitSuccess');
AP.events.on('confluence.customcontent.submitSuccess', function (newContent) {
    // newContent is the saved content object
    editComponent.submitSuccessCallback(true);
});

Submit error event: confluence.customcontent.submitError

The confluence.customcontent.submitError event will be emitted when Confluence encountered problem when saving the content. If add-on didn't intercept this event, a flag message will be shown.
You can call submitErrorCallback function to return the data:

Return false Return false will prevent error message be shown. Additionally you can return an extra string as the error message. It will be shown as a flag message.

1
2
3
4
5
6
var editComponent = AP.customContent.getEditComponent();
...
editComponent.intercept('confluence.customcontent.submitError');
AP.events.on('confluence.customcontent.submitError', function (errorMessage) {
    editComponent.submitErrorCallback(false, 'My own error message');
});

Return true Error message will not be shown until submitErrorCallback has been called.

1
2
3
4
5
6
var editComponent = AP.customContent.getEditComponent();
...
editComponent.intercept('confluence.customcontent.submitError');
AP.events.on('confluence.customcontent.submitError', function (errorMessage) {
    editComponent.submitErrorCallback(true);
});

Cancel event: confluence.customcontent.cancel

The confluence.customcontent.cancel event will be emitted when user clicks close button. If add-on didn't intercept this event, user will be redirected to the custom content list or the container page depending on the content type.
You can call cancelCallback function to return the data:

Return false Return false will prevent user being redirected. In this case, add-on can redirect user using the JavaScript Navigator API. Additionally you can return an extra string as the error message. It will be shown as a flag message.

1
2
3
4
5
6
7
var editComponent = AP.customContent.getEditComponent();
...
editComponent.intercept('confluence.customcontent.cancel');
AP.events.on('confluence.customcontent.cancel', function (errorMessage) {
    editComponent.cancelCallback(false, 'My error message');
    //  editComponent.cancelCallback(false);
});

Return true User will not be redirected until cancelCallback has been called.

1
2
3
4
5
6
var editComponent = AP.customContent.getEditComponent();
...
editComponent.intercept('confluence.customcontent.cancel');
AP.events.on('confluence.customcontent.cancel', function (errorMessage) {
    editComponent.cancelCallback(true);
});

Rate this page: