Index: lams_common/src/flash/org/lamsfoundation/lams/common/ws/WorkspaceModel.as =================================================================== diff -u -r0b5fd68752e8c06594641b539ad5769db759ba1c -rc07e26a5aa5c1472a317ccab4e0c4a594ce24da9 --- lams_common/src/flash/org/lamsfoundation/lams/common/ws/WorkspaceModel.as (.../WorkspaceModel.as) (revision 0b5fd68752e8c06594641b539ad5769db759ba1c) +++ lams_common/src/flash/org/lamsfoundation/lams/common/ws/WorkspaceModel.as (.../WorkspaceModel.as) (revision c07e26a5aa5c1472a317ccab4e0c4a594ce24da9) @@ -1,26 +1,233 @@ import org.lamsfoundation.lams.common.util.Observable; -import org.lamsfoundation.lams.common.ws.*; +import org.lamsfoundation.lams.common.ws.*; +import org.lamsfoundation.lams.common.util.* +import mx.events.* +import mx.utils.* /* * Model for the Canvas */ class org.lamsfoundation.lams.common.ws.WorkspaceModel extends Observable { - - + //ref to the wsp containter + private var _workspace:Workspace; + //private data private var _workspaceID:Number; private var _rootFolderID:Number; + //this is hte inital data + //private var _workspaceData:Object; + //this contains refs to the tree nodes stored by resourceID + private var _workspaceResources:Hashtable; + //this is the dartaprovider for the tree + private var _treeDP:XML; + + + + //These are defined so that the compiler can 'see' the events that are added at runtime by EventDispatcher + private var dispatchEvent:Function; + public var addEventListener:Function; + public var removeEventListener:Function; /* * Constructor. */ - public function WorkspaceModel (){ - + public function WorkspaceModel (w:Workspace){ + //Set up this class to use the Flash event delegation model + EventDispatcher.initialize(this); + _workspace = w; + _workspaceResources = new Hashtable(); + + } + public function openDesignBySelection(){ + //Open the workspace dialog in the centre of the screen + //Pass in the function to be called when a design is selected + //workspaceView.createWorkspaceDialogOpen('centre',Delegate.create(this,itemSelected)); + + var dto:Object = {}; + dto.pos='centre'; + Debugger.log('_workspace.itemSelected:'+_workspace.itemSelected,Debugger.GEN,'openDesignBySelection','WorkspaceModel'); + dto.callback=Delegate.create(_workspace,_workspace.itemSelected); + broadcastViewUpdate('CREATE_DIALOG',dto); + + } + + public function getUsersWorkspace(){ + + } + + public function getFolderContents(){ + + } + + /** + * Notify registered listeners that a data model change has happened + */ + public function broadcastViewUpdate(_updateType,_data){ + dispatchEvent({type:'viewUpdate',target:this,updateType:_updateType,data:_data}); + trace('broadcast'); + } + + /** + * Converts the de-serialised WDDX XML from an object into + * an xml format the tree likes + * This is parsing data from the call to getAccessibleWOrkspaceFolders, so we know that all the + * elements must be folders, as such we must set isBranch to be true; + * @usage + * @param dto - contains: + * PRIVATE The folder which belongs to the given User + * RUN_SEQUENCES The folder in which user stores his lessons + * ORGANISATIONS List of folders (root folder only) which belong to organizations of which user is a member + */ + public function parseDataForTree(dto:Object):Void{ + _treeDP = new XML(); + //add top level + _treeDP.addTreeNode("My Workspace",0); + //add 3 folders + var fChild:XMLNode = _treeDP.firstChild; + var orgNode:XMLNode = fChild.addTreeNode("Organisations",null); + orgNode.attributes.isBranch = true; + + var privateNode:XMLNode = fChild.addTreeNode("Private",dto.PRIVATE); + privateNode.attributes.isBranch = true; + //privateNode.attributes.data = dto.PRIVATE; + _workspaceResources.put(dto.PRIVATE.workspaceFolderID,privateNode); + + + var runNode:XMLNode = fChild.addTreeNode("Run Sequences",dto.RUN_SEQUENCES); + runNode.attributes.isBranch = true; + //runNode.attributes.data = dto.RUN_SEQUENCES; + _workspaceResources.put(dto.RUN_SEQUENCES.workspaceFolderID,runNode); + + + for(var i=0;i