/ Published in: ActionScript 3
Expand |
Embed | Plain Text
/* This command class is run when the Controller intercepts a Event. Typically, the same Command can handle many events, and figure out how to handle them in the execute method. For now, this guy merely calls the Delegate's method, and when the data comes back, he updates the ModelLocator. Commands should ALWAYS be the ones setting ModelLocator. View's shouldn't, nor should Delegate's. There are times when it's ok for a View to do so, but you should be sure you couldn't do it in a Command instead. View's should technically be "asking" the Controller via Events to change data. ...yes, I know, this is a LOT of events. */ package com.xx.command { import com.adobe.cairngorm.commands.ICommand; import com.adobe.cairngorm.control.CairngormEvent; import com.xx.business.UserDelegate; import com.xx.event.LoginEvent; import com.xx.event.MainMenuEvent; import com.xx.model.DirectModelLocator; import com.xx.model.StateManager; import com.xx.util.ErrorHandling; import mx.controls.Alert; import mx.rpc.IResponder; //import mx.rpc.events.FaultEvent; import org.granite.tide.events.TideResultEvent; import org.granite.tide.events.TideFaultEvent; public class LoginCommand implements ICommand, IResponder { public function LoginCommand():void {} private var model : DirectModelLocator = DirectModelLocator.getInstance(); public function execute(event : CairngormEvent) : void { var delegate : UserDelegate = new UserDelegate( this ); var loginEvent : LoginEvent = LoginEvent( event ); delegate.loginPrincipal( loginEvent.user ); } public function result(data : Object) : void { model.isLoggedIn = data.result; if ( model.isLoggedIn ) { //Update server binding // model.serverBindings.loggedInPrincipal.update(); new MainMenuEvent().dispatch(); model.stateManager.setState(StateManager.APPLICATION_MAIN_VIEW); } else { if(model.stateManager.appViewState == StateManager.APPLICATION_LOGIN_VIEW) { Alert.show( "User or Password is invalid", "Login failed!" ); } else { model.stateManager.setState(StateManager.APPLICATION_LOGIN_VIEW); } } } public function fault(info : Object) : void { var faultEvent : TideFaultEvent = TideFaultEvent( info ); ErrorHandling.tideFault( faultEvent, "Error", "An error occured: " ); } } }
You need to login to post a comment.
