Index: lams_central/src/flash/org/lamsfoundation/lams/monitoring/CreateLessonDialog.as =================================================================== diff -u --- lams_central/src/flash/org/lamsfoundation/lams/monitoring/CreateLessonDialog.as (revision 0) +++ lams_central/src/flash/org/lamsfoundation/lams/monitoring/CreateLessonDialog.as (revision f78df0243786dd75c117ded523b67367bc30ee9c) @@ -0,0 +1,810 @@ +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ************************************************************************ + */ + +import mx.controls.* +import mx.utils.* +import mx.managers.* +import mx.events.* +import org.lamsfoundation.lams.monitoring.*; +import org.lamsfoundation.lams.common.ws.* +import org.lamsfoundation.lams.common.util.* +import org.lamsfoundation.lams.common.dict.* +import org.lamsfoundation.lams.common.style.* +import org.lamsfoundation.lams.common.ui.* +import it.sephiroth.TreeDnd; +/** +* @author DI & DC +*/ +class CreateLessonDialog extends MovieClip{ + + //private static var OK_OFFSET:Number = 50; + //private static var CANCEL_OFFSET:Number = 50; + + //References to components + clips + private var _container:MovieClip; //The container window that holds the dialog + private var ok_btn:Button; //OK+Cancel buttons + private var cancel_btn:Button; + private var panel:MovieClip; //The underlaying panel base + + private var switchView_tab:TabBar; + + //location tab elements + private var treeview:Tree; //Treeview for navigation through workspace folder structure + private var location_dnd:TreeDnd; + private var input_txt:TextInput; + private var currentPath_lbl:Label; + private var name_lbl:Label; + private var resourceTitle_txi:TextInput; + private var new_btn:Button; + //private var cut_btn:Button; + private var copy_btn:Button; + private var paste_btn:Button; + private var delete_btn:Button; + private var rename_btn:Button; + + + //properties + private var description_lbl:Label; + private var license_lbl:Label; + private var resourceDesc_txa:TextArea; + private var license_txa:TextArea; + private var licenseID_cmb:ComboBox; + private var licenseImg_pnl:MovieClip; + private var viewLicense_btn:Button; + + + + private var fm:FocusManager; //Reference to focus manager + private var themeManager:ThemeManager; //Theme manager + + private var _workspaceView:WorkspaceView; + private var _workspaceModel:WorkspaceModel; + private var _workspaceController:WorkspaceController; + + + //Dimensions for resizing + private var xOkOffset:Number; + private var yOkOffset:Number; + private var xCancelOffset:Number; + private var yCancelOffset:Number; + + private var _resultDTO:Object; //This is an object to contain whatever the user has selected / set - will be passed back to the calling function + + + private var _selectedDesignId:Number; + + //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 + */ + function WorkspaceDialog(){ + //trace('WorkSpaceDialog.constructor'); + //Set up this class to use the Flash event delegation model + EventDispatcher.initialize(this); + _resultDTO = new Object(); + + //Create a clip that will wait a frame before dispatching init to give components time to setup + this.onEnterFrame = init; + } + + /** + * Called a frame after movie attached to allow components to initialise + */ + private function init(){ + //Delete the enterframe dispatcher + delete this.onEnterFrame; + //TODO: DC apply the themes here + + //set the reference to the StyleManager + themeManager = ThemeManager.getInstance(); + + //Set the container reference + Debugger.log('container=' + _container,Debugger.GEN,'init','org.lamsfoundation.lams.WorkspaceDialog'); + + //set up the tab bar: + + switchView_tab.addItem({label:Dictionary.getValue('ws_dlg_location_button'), data:'LOCATION'}); + switchView_tab.addItem({label:Dictionary.getValue('ws_dlg_properties_button'), data:'PROPERTIES'}); + + + //Set the text on the labels + + //Set the text for buttons + currentPath_lbl.text = ""+Dictionary.getValue('ws_dlg_location_button')+":" + ok_btn.label = Dictionary.getValue('ws_dlg_ok_button'); + cancel_btn.label = Dictionary.getValue('ws_dlg_cancel_button'); + viewLicense_btn.label = Dictionary.getValue('ws_view_license_button'); + new_btn.label = Dictionary.getValue('new_btn'); + copy_btn.label = Dictionary.getValue('copy_btn'); + paste_btn.label = Dictionary.getValue('paste_btn'); + delete_btn.label = Dictionary.getValue('delete_btn'); + rename_btn.label = Dictionary.getValue('rename_btn'); + //TODO: Dictionary calls for all the rest of the buttons + + //TODO: Make setStyles more efficient + setStyles(); + + //get focus manager + set focus to OK button, focus manager is available to all components through getFocusManager + fm = _container.getFocusManager(); + fm.enabled = true; + ok_btn.setFocus(); + //fm.defaultPushButton = ok_btn; + + Debugger.log('ok_btn.tabIndex: '+ok_btn.tabIndex,Debugger.GEN,'init','org.lamsfoundation.lams.WorkspaceDialog'); + + + //Tie parent click event (generated on clicking close button) to this instance + _container.addEventListener('click',this); + //Register for LFWindow size events + _container.addEventListener('size',this); + + //panel.setStyle('backgroundColor',0xFFFFFF); + + //Debugger.log('setting offsets',Debugger.GEN,'init','org.lamsfoundation.lams.common.ws.WorkspaceDialog'); + + //work out offsets from bottom RHS of panel + xOkOffset = panel._width - ok_btn._x; + yOkOffset = panel._height - ok_btn._y; + xCancelOffset = panel._width - cancel_btn._x; + yCancelOffset = panel._height - cancel_btn._y; + + //Register as listener with StyleManager and set Styles + themeManager.addEventListener('themeChanged',this); + + treeview = location_dnd.getTree(); + //Fire contentLoaded event, this is required by all dialogs so that creator of LFWindow can know content loaded + + _container.contentLoaded(); + } + + /** + * Called by the worspaceView after the content has loaded + * @usage + * @return + */ + public function setUpContent():Void{ + + //register to recive updates form the model + WorkspaceModel(_workspaceView.getModel()).addEventListener('viewUpdate',this); + + Debugger.log('_workspaceView:'+_workspaceView,Debugger.GEN,'setUpContent','org.lamsfoundation.lams.common.ws.WorkspaceDialog'); + //get a ref to the controller and kkep it here to listen for events: + _workspaceController = _workspaceView.getController(); + Debugger.log('_workspaceController:'+_workspaceController,Debugger.GEN,'setUpContent','org.lamsfoundation.lams.common.ws.WorkspaceDialog'); + + + //Add event listeners for ok, cancel and close buttons + ok_btn.addEventListener('click',Delegate.create(this, ok)); + cancel_btn.addEventListener('click',Delegate.create(this, cancel)); + switchView_tab.addEventListener("change",Delegate.create(this, switchTab)); + //think this is failing.... + switchView_tab.setSelectedIndex(0); + + new_btn.addEventListener('click',Delegate.create(_workspaceController, _workspaceController.fileOperationRequest)); + //cut_btn.addEventListener('click',Delegate.create(_workspaceController, _workspaceController.fileOperationRequest)); + copy_btn.addEventListener('click',Delegate.create(_workspaceController, _workspaceController.fileOperationRequest)); + paste_btn.addEventListener('click',Delegate.create(_workspaceController, _workspaceController.fileOperationRequest)); + delete_btn.addEventListener('click',Delegate.create(_workspaceController, _workspaceController.fileOperationRequest)); + rename_btn.addEventListener('click',Delegate.create(_workspaceController, _workspaceController.fileOperationRequest)); + + viewLicense_btn.addEventListener('click',Delegate.create(this, openLicenseURL)); + licenseID_cmb.addEventListener('change',Delegate.create(this, onLicenseComboSelect)); + + //Set up the treeview + setUpTreeview(); + + itemSelected(treeview.selectedNode); + } + + /** + * Recieved update events from the WorkspaceModel. Dispatches to relevent handler depending on update.Type + * @usage + * @param event + */ + public function viewUpdate(event:Object):Void{ + Debugger.log('Recived an Event dispather UPDATE!, updateType:'+event.updateType+', target'+event.target,4,'viewUpdate','org.lamsfoundation.lams.ws.WorkspaceDialog'); + //Update view from info object + //Debugger.log('Recived an UPDATE!, updateType:'+infoObj.updateType,4,'update','CanvasView'); + var wm:WorkspaceModel = event.target; + //set a permenent ref to the model for ease (sorry mvc guru) + _workspaceModel = wm; + + switch (event.updateType){ + case 'POPULATE_LICENSE_DETAILS' : + populateAvailableLicenses(event.data, wm); + case 'REFRESH_TREE' : + refreshTree(wm); + break; + case 'UPDATE_CHILD_FOLDER' : + updateChildFolderBranches(event.data,wm); + case 'ITEM_SELECTED' : + itemSelected(event.data,wm); + break; + case 'OPEN_FOLDER' : + openFolder(event.data, wm); + break; + case 'REFRESH_FOLDER' : + refreshFolder(event.data, wm); + break; + case 'SHOW_TAB' : + showTab(event.data,wm); + break; + case 'SET_UP_BRANCHES_INIT' : + setUpBranchesInit(); + break; + + default : + Debugger.log('unknown update type :' + event.updateType,Debugger.GEN,'viewUpdate','org.lamsfoundation.lams.ws.WorkspaceDialog'); + } + + } + + + + /** + * called witht he result when a child folder is opened.. + * updates the tree branch satus, then refreshes. + * @usage + * @param changedNode + * @param wm + * @return + */ + private function updateChildFolderBranches(changedNode:XMLNode,wm:WorkspaceModel){ + Debugger.log('updateChildFolder....:' ,Debugger.GEN,'updateChildFolder','org.lamsfoundation.lams.ws.WorkspaceDialog'); + //we have to set the new nodes to be branches, if they are branches + if(changedNode.attributes.isBranch){ + treeview.setIsBranch(changedNode,true); + //do its kids + for(var i=0; i 0){ + for(var i=0; i + * _resultDTO.selectedResourceID //The ID of the resource that was selected when the dialogue closed + * _resultDTO.resourceName //The contents of the Name text field + * _resultDTO.resourceDescription //The contents of the description field on the propertirs tab + * _resultDTO.resourceLicenseText //The contents of the license text field + * _resultDTO.resourceLicenseID //The ID of the selected license from the drop down. + * + */ + private function ok(){ + trace('OK'); + _global.breakpoint(); + + //TODO: Rmeove this code as its been here only for deflopment + //set the selectedDesignId + /**/ + if(StringUtils.isNull(input_txt.text)){ + //get the selected value off the tree + var snode = treeview.selectedNode; + input_txt.text = snode.attributes.data.resourceID; + + } + _selectedDesignId = Number(input_txt.text); + + + //TODO: Validate you are allowed to use the name etc... Are you overwriting - NOTE Same names are nto allowed in this version + + var snode = treeview.selectedNode; + Debugger.log('_workspaceModel.currentMode: ' + _workspaceModel.currentMode,Debugger.GEN,'ok','org.lamsfoundation.lams.WorkspaceDialog'); + if(_workspaceModel.currentMode=="SAVE" || _workspaceModel.currentMode=="SAVEAS"){ + //var rid:Number = Number(snode.attributes.data.resourceID); + if(snode.attributes.data.resourceType==_workspaceModel.RT_LD){ + //run a confirm dialogue as user is about to overwrite a design! + LFMessage.showMessageConfirm(Dictionary.getValue('ws_chk_overwrite_resource'), Proxy.create(this,doWorkspaceDispatch,true), Proxy.create(this,closeThisDialogue)); + + }else if (snode.attributes.data.resourceType==_workspaceModel.RT_FOLDER){ + doWorkspaceDispatch(false); + }else{ + LFMessage.showMessageAlert(Dictionary.getValue('ws_click_folder_file'),null); + } + }else{ + doWorkspaceDispatch(true); + } + + } + + + + /** + * Dispatches an event - picked up by the canvas in authoring + * sends paramter containing: + * _resultDTO.selectedResourceID + * _resultDTO.targetWorkspaceFolderID + * _resultDTO.resourceName + _resultDTO.resourceDescription + _resultDTO.resourceLicenseText + _resultDTO.resourceLicenseID + * @usage + * @param useResourceID //if its true then we will send the resorceID of teh item selected in the tree - usually this means we are overwriting something + * @return + */ + public function doWorkspaceDispatch(useResourceID:Boolean){ + //ObjectUtils.printObject(); + var snode = treeview.selectedNode; + + if(useResourceID){ + //its an LD + _resultDTO.selectedResourceID = Number(snode.attributes.data.resourceID); + _resultDTO.targetWorkspaceFolderID = Number(snode.attributes.data.workspaceFolderID); + }else{ + //its a folder + _resultDTO.selectedResourceID = null; + _resultDTO.targetWorkspaceFolderID = Number(snode.attributes.data.resourceID); + + } + + _resultDTO.resourceName = resourceTitle_txi.text; + _resultDTO.resourceDescription = resourceDesc_txa.text; + _resultDTO.resourceLicenseText = license_txa.text; + _resultDTO.resourceLicenseID = licenseID_cmb.value.licenseID; + + + dispatchEvent({type:'okClicked',target:this}); + + closeThisDialogue(); + + } + + public function closeThisDialogue(){ + _container.deletePopUp(); + } + + + /** + * Called when the tabs are clicked + * @usage + * @param e + * @return + */ + private function switchTab(e){ + Debugger.log('Switch tab called!',Debugger.GEN,'switchTab','org.lamsfoundation.lams.common.ws.WorkspaceDialog'); + if(e.newIndex == 0){ + dispatchEvent({type:'locationTabClick',target:this}); + }else if(e.newIndex ==1){ + dispatchEvent({type:'propertiesTabClick',target:this}); + } + /* + for (var item:String in e) { + trace("Item: " + item + "=" + e[item]); + } + */ + } + + /** + * Event dispatched by parent container when close button clicked + */ + private function click(e:Object){ + trace('WorkspaceDialog.click'); + e.target.deletePopUp(); + } + + + /** + * Recursive function to set any folder with children to be a branch + * TODO: Might / will have to change this behaviour once designs are being returned into the mix + * @usage + * @param node + * @return + */ + private function setBranches(node:XMLNode){ + if(node.hasChildNodes() || node.attributes.isBranch){ + treeview.setIsBranch(node, true); + for (var i = 0; i