The Application Container

Class Description: This class is expected to render the application container and create the workspaces configured as per the meta data.

Called By: canvas.core.WSManager

Meta data to be considered: canvas.metadata.getWorkspaces() → Returns an array of configured workspaces. The application container has to have that many child items as the length of this array



What developers are expected to do: While activating any of the workspaces, the library developers have to call the workspace selection handler, with a call back function to execute once the workspace has been activated. This is required because the workspace selection might involve asynchronous processing, as the business app developers might have configured certain scripts against workspaces in their on demand JavaScript XML. The core layer takes care of downloading these scripts along with certain other operations like storing the current workspace ID in meta data utilities.

Even though there are no additional events and responsibilities, Canvas Technology recommends component developers to create utilities that take care of activating workspaces because different application layouts have different UI patterns of activating workspaces. It becomes easier to either raise an event or call a library specific API that can do this since the layout developers may or may not always take care of properly wiring the lib layer to the core layer.

APIs to be supported: NA
Registry Signature:

CLCR.registerCmp({'COMP_TYPE':'APPLICATION_CONTAINER'}, <<Application container class>>);

Scope: The core layer passes on view port container element to this class, so that it does not have to query the DOM to get the parent element on which it has to be appended.

Sample Code Snippet:

canvas.lib.ApplicationContainer = Class(canvas.core.Component, 
{
	layoutManager: '',
	constructor: function(config)
	{
		this.wsManagerConfig = config;
		canvas.lib.ApplicationContainer.$super.call(this);
		this.createItems();
	},
	createItems: function() 
	{
		var appContainerConfig = 
		{
			"eleType":"div",
			"id":"application-container"
		};
		var appContainerObj = new canvas.lib.layer(appContainerConfig).getLayer();
		this.addItem(appContainerObj);
		delete appContainerConfig;
		// Start process of creating the workspace and layout
		var wsContainerConfig;
		var wsArr = canvas.core.ws.metadata.getWorkspaces();
		canvas.lib.workspacehandler.createWorkspaces(wsArr,this);
		 
	},
	// Return the object of app container containing the workspaces
	getAppContainer: function() 
	{
		return this.getItem(0);
	}
});
CLCR.registerCmp({'COMP_TYPE':'APPLICATION_CONTAINER'},canvas.lib.ApplicationContainer);

It has to be noted in the above snippet that canvas.lib.workspacehandler.createWorkspaces() is a utility API which creates the workspace elements for the array of the workspaces passed, and finally appends to the parent element. Here is what this utility API is supposed to do.

var workspaceContainerConfig = 
{
	"eleType": "div",
	"id" : wsArray[index].WORKSPACE_ID,
	"class": "workspace "+wsArray[index].WORKSPACE_ID,
	"style": 
	{
		"display":"none"
	}
};
var wcContainerObject = new canvas.lib.layer(workspaceContainerConfig).getLayer();
$(this.appContainer.getItem(0)).append($(wcContainerObject));

The following code snippet shows the usage of workspace selection handler:

activateWorkspace: function(workspaceId,index,callBackFn,scope)
{
	callBackFn = canvas.isFunction(callBackFn)?callBackFn:canvas.emptyFn;
	scope = scope?scope: this;
	var config = 
	{
		WORKSPACE_ID:workspaceId,
		SYSTEM_WORKSPACE_IND:SYSTEM_WORKSPACE_IND
	};

	// Pre workspace activate operations here

	canvas.core.ws.metadata.getWorkspaceManager().wsSelectionHandler(config,null,function(wsContainer)
	{
		// Post workspace activate operations here
	},scope);
}