This topic describes how to add client-side events to spaces and space templates. It explains how to add the required preference to a template so that it know where to locate the life-cycle extension. It also explains how to add the metadata to existing spaces using the Mashup Enable API. Finally, it provides an example of a JavaScriptâ„¢ (JS) file that you can create to define the life-cycle events.
To add client-side events to templates, you must add a preference to a template so that the template knows where to locate the JS file that contains the life-cycle extension. To add metadata, do the following steps:
Now, any new space that you create with this template will have life-cycle events.
If you are working with an existing space, you can add metadata similar to the template preference by using the Mashup Enabler API. Refer to
for more information. The name of the metadata is
After the metadata is added, the space will begin to have life-cycle events. All copies of this space will inherit those events.
When creating the JS file that defines life-cycle events for spaces and space templates, your implementation must extend the client-side SpaceExtension API and must be saved to the location that you specified in the metadata for the space or template, as described in the section above. If the location of the JS is remote, be sure to use a fully qualified URL.
/* Copyright IBM Corp. 2009 All Rights Reserved. */
/**
* Any JavaScript file that defines the subclass of
SpaceExtension has three sections in order:
* section 1: define the constructor of the subclass.
* section 2: specify the prototype of the subclass.
* section 3: overwrite all or part of the SpaceExtension methods.
*/
/**
* section 1: define the constructor of the subclass.
*/
function AlertSpaceExtension() {
}
/**
* section 2: specify the prototype of this subclass.
The prototype should be the instance of superclass (SpaceExtension)
*/
AlertSpaceExtension.prototype = new SpaceExtension();
/**
* section 3: overwrite all or part of the SpaceExtension methods.
*/
AlertSpaceExtension.prototype.onSpaceCreate =
function(spaceId,
spaceName, spaceDescription, optionalInfo) {
alert("AlertSpaceExtension.onSpaceCreate \n spaceId = " +
spaceId + "\n spaceName = " + spaceName + "\n
spaceDescription = " + spaceDescription);
};
AlertSpaceExtension.prototype.onSpaceCopy =
function(sourceSpaceId, targetSpaceId, optionalInfo) {
alert("AlertSpaceExtension.onSpaceCopy \n sourceSpaceId =
" + sourceSpaceId + "\n targetSpaceId = " + targetSpaceId);
};
AlertSpaceExtension.prototype.onSpaceUpdate =
function(spaceId, spaceData, optionalInfo) {
alert("AlertSpaceExtension.onSpaceUpdate \n
spaceId = " + spaceId + " \n spaceData = " + spaceData);
};
AlertSpaceExtension.prototype.onSpaceDelete =
function(spaceId, optionalInfo) {
alert("AlertSpaceExtension.onSpaceDelete \n
spaceId = " + spaceId);
};
AlertSpaceExtension.prototype.canCopySpace =
function(spaceId, optionalInfo) {
alert("AlertSpaceExtension.canCopySpace \n
spaceId = " + spaceId);
};
// canExportSpace
// create a SpaceExtensionResult object as the return.
AlertSpaceExtension.prototype.canExportSpace =
function(spaceId, optionalInfo) {
alert("AlertSpaceExtension.canExportSpace \n
spaceId = " + spaceId);
};
// canDeleteSpace
// no return in this method. Which means ok.
AlertSpaceExtension.prototype.canDeleteSpace =
function(spaceId, optionalInfo) {
alert("AlertSpaceExtension.canDeleteSpace
\n spaceId = " + spaceId);
};