Writing a Space Admin Screen

Applicable:

This tutorial applies to Confluence 5.0.

Level of experience:

This is an intermediate tutorial. You should have completed at least one beginner tutorial before working through this tutorial. See the list of developer tutorials.

If your plugin needs per-space configuration, you will need to create a screen in Space Tools.

Preparation

The example below is available on the following BitBucket repository:

https://bitbucket.org/atlassian_tutorial/space-plugin-example

You need to create a Confluence plugin and update the version of Confluence to 5.0-beta5.

Creating a Space Tools screen

You need two web-items, for Space Tools (5.0 themes) and Space Admin (pre-5.0 themes). If the screen should only be visible to space admins, you will need to use a Condition to check this.

atlassian-plugin.xml
       <!-- Item in Space Tools -->
    <web-item key="space-admin-quick-link-manager" name="Quick Link Manager in Space Admin" section="system.space.tools/addons" weight="100">
        <label key="space.admin.quick.link.manager" />
        <link linkId="space-admin-quick-link-manager-id">/plugins/${project.artifactId}/add-link.action?key=$generalUtil.urlEncode($helper.spaceKey)</link>
        <conditions type="AND">
            <condition class="com.atlassian.confluence.plugin.descriptor.web.conditions.SpacePermissionCondition">
                <param name="permission">administer</param>
            </condition>
                    <condition class="com.atlassian.confluence.plugin.descriptor.web.conditions.SpaceSidebarCondition"/>
        </conditions>
    </web-item>
    <!-- Item in Space Admin (for Doc Theme) -->
    <web-item key="space-admin-quick-link-manager-2" name="Quick Link Manager in Space Admin" section="system.space.admin/addons" weight="100">
        <label key="space.admin.quick.link.manager" />
        <link linkId="space-admin-quick-link-manager-id">/plugins/${project.artifactId}/add-link.action?key=$generalUtil.urlEncode($helper.spaceKey)</link>
        <conditions type="AND">
            <condition class="com.atlassian.confluence.plugin.descriptor.web.conditions.SpacePermissionCondition">
                <param name="permission">administer</param>
            </condition>
                    <condition class="com.atlassian.confluence.plugin.descriptor.web.conditions.SpaceSidebarCondition" invert="true"/>
        </conditions>
    </web-item>

For this example, we will also declare an action:

atlassian-plugin.xml
    <xwork name="Example Actions" key="example-actions">
        <description>Examples of actions</description>
        <package name="space-links-xwork-package" extends="default" namespace="/plugins/${project.artifactId}">
            <default-interceptor-ref name="validatingStack"/>
            <action name="add-link" class="com.atlassian.examples.MyAdminAction">
                <result name="input" type="velocity">/templates/add-link-action.vm</result>
                <result name="success" type="velocity">/templates/add-link-action.vm</result>
            </action>
        </package>
    </xwork>

The action must extend SpaceAdminAction, this will check whether the user has permissions for the space:

public class MyAdminAction extends SpaceAdminAction
{
    @Override
    public String doDefault()
    {
        return INPUT;
    }
}

The template needs two decorators:

add-link-action.vm
<html>
    <head>
        <title>$action.getText("add.link.action")</title>
        <meta name="decorator" content="main"/>
    </head>
    #applyDecorator("root")
        #decoratorParam("helper" $action.helper)
        ## Name of the tab to highlight: space-operations is also valid.
        #decoratorParam("context" "space-administration") 

        #applyDecorator ("root")
            ## The .vmd to use - This one displays both in Space Admin and Space Tools.
            #decoratorParam ("context" "spaceadminpanel") 
            ## Key of the web-item to highlight in Space Admin
            #decoratorParam ("selection" "quick-link-manager-2") 
            ## Key of the web-item to highlight in Space Tools
            #decoratorParam ("selectedSpaceToolsWebItem" "quick-link-manager") 
            #decoratorParam ("helper" $action.helper)
            <body>
                <div class="pagecontent">
                    <p>${message}</p>
                </div>
            </body>
        #end
    #end
</html>

Context:

  • spaceadminpanel: Valid for Space Tools (for the new 5.0 themes) and Space Admin (in pre-5.0 themes).
  • spacecontentpanel: Valid for Space Tools (new 5.0 themes) and Space Operations (pre-5.0 themes).
  • spacetoolspanels: Valid for Space Tools only.

Here is the result:

The example above is also compatible with the Doc Theme and other pre-5.0 themes:

Related Content

Web UI Modules

Was this page helpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport