Permalink
Browse files

making good progress!

  • Loading branch information...
1 parent fb355a7 commit e7fdca6a5c94acd48277a620eb058ce40f8a63a7 @seanhess committed May 19, 2009
View
41 examples/CafeTownsend/src/cafe/glue/MainGlue.mxml
@@ -6,38 +6,28 @@
]]>
</mx:Script>
- <!-- Storage -->
- <store:EmployeeStore id="employees"/>
- <store:NavigationStore id="navigation"/>
+ <Command id="login" user="user" pass="pass">
+ <Action call="authManager.login(scope.user, scope.pass)"/>
+ <Action call="navManager.loginChanged(authManager.state)"/>
+ </Command>
<!-- Manager -->
- <manager:AuthorizationManager id="authManager"
- navigation="{navigation}"
- />
-
- <manager:EmployeeManager id="employeeManager"
- employees="{employees}"
- utils="{utils}"
- navigation="{navigation}"
- loadEmployeeService="{mock.employeesService}"
- />
-
- <!-- Services -->
- <service:MockServices id="mock"/>
- <service:EmployeeUtils id="utils"/>
-
+ <manager:AuthorizationManager id="authManager" />
+ <manager:EmployeeManager id="employeeManager" />
+ <manager:NavigationManager id="navManager"/>
+
<!-- Views -->
<Glue match="MainUI">
- <Inject selectedPage="{navigation.mainPage}"/>
- <Route event="{FlexEvent.CREATION_COMPLETE}" call="employeeManager.loadEmployees()"/>
+ <Inject selectedPage="{navManager.currentPage}"/>
+ <!--<Route event="{FlexEvent.CREATION_COMPLETE}" call="employeeManager.loadEmployees()"/>-->
</Glue>
<Glue match="EmployeeLogin">
- <Inject authState="{navigation.authState}"/>
- <Route event="login" call="authManager.login(scope.target.username, scope.target.password)"/>
+ <Inject authState="{authManager.state}"/>
+ <Route event="login" call="login.execute({user:view.username, pass:view.password})"/>
</Glue>
- <Glue match="EmployeeList">
+ <!--<Glue match="EmployeeList">
<Inject employees="{employees.employeeList}"/>
<Route event="logout" call="authManager.logout()"/>
<Route event="newEmployee" call="employeeManager.newEmployee()"/>
@@ -49,8 +39,9 @@
<Route event="back" call="employeeManager.goBack()"/>
<Route event="remove" call="employeeManager.deleteEmployee(employees.employee)"/>
<Route event="save" call="employeeManager.saveEmployee(view.tempEmployee)"/>
- </Glue>
-
+ </Glue>-->
+ <!-- Services :: Put these in another file -->
+ <mx:HTTPService id="employeesService" url="assets/data/Employees.xml" resultFormat="e4x" />
</GlueMap>
View
18 examples/CafeTownsend/src/cafe/manager/AuthorizationManager.as 100755 → 100644
@@ -1,30 +1,28 @@
package cafe.manager
{
- import cafe.store.NavigationStore;
+ import cafe.vo.Authentication;
+ [Bindable]
public class AuthorizationManager
{
- public var navigation:NavigationStore;
+ public var state:String = Authentication.LOGOUT;
- public function login(username:String, password:String):Boolean
+ public function login(username:String, password:String):void
{
+ //check hardcoded username and password
if (username == 'Flex' && password == 'Glue')
{
- navigation.mainPage = NavigationStore.EMPLOYEE_LIST;
- navigation.authState = NavigationStore.LOGGED_IN;
+ state = Authentication.AUTHENTICATED;
}
else
{
- navigation.authState = NavigationStore.LOGIN_FAILED;
+ state = Authentication.FAILED;
}
-
- return false;
}
public function logout():void
{
- navigation.mainPage = NavigationStore.LOGIN_SCREEN;
- navigation.authState = NavigationStore.LOGGED_OUT;
+ state = Authentication.LOGOUT;
}
}
}
View
89 examples/CafeTownsend/src/cafe/manager/EmployeeManager.as
@@ -1,79 +1,64 @@
package cafe.manager
{
- import cafe.model.Employee;
- import cafe.service.EmployeeUtils;
- import cafe.store.EmployeeStore;
- import cafe.store.NavigationStore;
+ import cafe.vo.Employee;
+
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
import mx.collections.ArrayCollection;
- import mx.collections.IList;
- import mx.rpc.events.FaultEvent;
- import mx.rpc.events.ResultEvent;
- import mx.rpc.http.HTTPService;
- public class EmployeeManager
- {
- public var employees:EmployeeStore;
- public var navigation:NavigationStore;
+ public class EmployeeManager extends EventDispatcher
+ {
+ /*-.........................................Properties..........................................*/
- public var utils:EmployeeUtils;
- public var loadEmployeeService:HTTPService;
+ private var _employeeList:ArrayCollection;
- public function loadEmployees():void
- {
- loadEmployeeService.addEventListener(ResultEvent.RESULT, onEmployeesLoaded);
- loadEmployeeService.addEventListener(FaultEvent.FAULT, onFault);
- loadEmployeeService.send();
- }
+ /*-.........................................Setters and Getters..........................................*/
- private function onFault(event:FaultEvent):void
+ [Bindable (event="employeeListChanged")]
+ public function get employeeList():ArrayCollection
{
- throw new Error("Fault: "+ event.fault);
+ return _employeeList;
}
- private function onEmployeesLoaded(event:ResultEvent):void
- {
- loadEmployeeService.removeEventListener(ResultEvent.RESULT, onEmployeesLoaded);
- var employees:Array = utils.loadFromXML(event.result as XML);
- saveEmpoyeeList(employees);
- }
+ private var _employee:Employee;
- public function goBack():void
+ [Bindable (event="employeeChanged")]
+ public function get employee():Employee
{
- navigation.mainPage = NavigationStore.EMPLOYEE_LIST;
+ return _employee;
}
- public function saveEmpoyeeList(value:Array):void
- {
- employees.employeeList = new ArrayCollection(value);
- }
-
- public function selectEmployee(value:Employee):void
- {
- employees.employee = value;
- navigation.mainPage = NavigationStore.EMPLOYEE_DETAIL;
+ /*-.........................................Methods..........................................*/
+
+ // -----------------------------------------------------------
+ public function saveEmpoyeeList(employees:Array):void {
+ _employeeList = new ArrayCollection(employees);
+ dispatchEvent(new Event('employeeListChanged'));
}
- public function deleteEmployee (employee:Employee) : void
- {
- employees.employeeList.removeItemAt(employees.employeeList.getItemIndex(employee));
- selectEmployee(null);
- navigation.mainPage = NavigationStore.EMPLOYEE_LIST;
+ // -----------------------------------------------------------
+ public function selectEmployee(employee:Employee):void {
+ _employee = employee;
+ dispatchEvent(new Event('employeeChanged'));
}
- public function newEmployee():void
- {
- saveEmployee(new Employee());
- navigation.mainPage = NavigationStore.EMPLOYEE_DETAIL;
+ // -----------------------------------------------------------
+ public function deleteEmployee (employee:Employee) : void {
+
+ _employeeList.removeItemAt(_employeeList.getItemIndex(employee));
+
+ // clear out the selected employee just in case
+ selectEmployee(null);
}
+ // -----------------------------------------------------------
public function saveEmployee (employee:Employee) : void {
// assume the edited fields are not an existing employee, but a new employee
// and set the ArrayCollection index to -1, which means this employee is not in our existing
// employee list anywhere
var dpIndex : int = -1;
- var employeeList:IList = employees.employeeList;
// loop thru the employee list
for ( var i : uint = 0; i < employeeList.length; i++ ) {
@@ -87,20 +72,18 @@ package cafe.manager
// if it was an existing employee already in the ArrayCollection
if ( dpIndex >= 0 ) {
// update that employee's values
- utils.copyFrom(employeeList.getItemAt(dpIndex) as Employee, employee);
+ (employeeList.getItemAt(dpIndex) as Employee).copyFrom(employee);
}
// otherwise, if it didn't match any existing employees
else {
// add the temp employee to the ArrayCollection
var tempEmployee:Employee = new Employee();
- utils.copyFrom(tempEmployee,employee);
-
+ tempEmployee.copyFrom(employee);
employeeList.addItem(tempEmployee);
}
// clear out the selected employee
selectEmployee(null);
- navigation.mainPage = NavigationStore.EMPLOYEE_LIST;
}
}
View
16 examples/CafeTownsend/src/cafe/manager/NavigationManager.as
@@ -0,0 +1,16 @@
+package cafe.manager
+{
+ import cafe.vo.Authentication;
+ import cafe.vo.Navigation;
+
+ [Bindable]
+ public class NavigationManager
+ {
+ public var currentPage:int = Navigation.LOGIN;
+
+ public function loginChanged(state:String):void
+ {
+ currentPage = (state == Authentication.AUTHENTICATED) ? Navigation.LIST : Navigation.LOGIN;
+ }
+ }
+}
View
16 examples/CafeTownsend/src/cafe/model/Employee.as
@@ -1,16 +0,0 @@
-package cafe.model
-{
-
- /**
- * An object representing an employee
- */
- [Bindable]
- public class Employee
- {
- public var emp_id : uint;
- public var firstname : String = "";
- public var lastname : String = "";
- public var email : String = "";
- public var startdate : Date;
- }
-}
View
20 ...ownsend/src/cafe/service/EmployeeUtils.as → ...wnsend/src/cafe/service/EmployeeParser.as 100755 → 100644
@@ -1,10 +1,13 @@
package cafe.service
{
- import cafe.model.Employee;
-
- public class EmployeeUtils
+ import com.cafetownsend.vos.Employee;
+
+ public class EmployeeParser
{
- public function loadFromXML(employees:XML):Array
+
+ /*-.........................................Methods..........................................*/
+
+ public function loadEmployeesFromXML(employees:XML):Array
{
var employeeList:Array = new Array();
@@ -22,15 +25,6 @@ package cafe.service
return employeeList;
}
-
- public function copyFrom(employee:Employee, newEmployee:Employee):void
- {
- employee.emp_id = newEmployee.emp_id;
- employee.email = newEmployee.email;
- employee.firstname = newEmployee.firstname;
- employee.lastname = newEmployee.lastname;
- employee.startdate = newEmployee.startdate;
- }
}
}
View
6 examples/CafeTownsend/src/cafe/service/MockServices.mxml
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<mx:Object xmlns:mx="http://www.adobe.com/2006/mxml">
-
- <mx:HTTPService id="employeesService" url="assets/data/Employees.xml" resultFormat="e4x" />
-
-</mx:Object>
View
13 examples/CafeTownsend/src/cafe/store/EmployeeStore.as
@@ -1,13 +0,0 @@
-package cafe.store
-{
- import cafe.model.Employee;
-
- import mx.collections.IList;
-
- [Bindable]
- public class EmployeeStore
- {
- public var employeeList:IList;
- public var employee:Employee;
- }
-}
View
17 examples/CafeTownsend/src/cafe/store/NavigationStore.as
@@ -1,17 +0,0 @@
-package cafe.store
-{
- [Bindable]
- public class NavigationStore
- {
- public static const LOGIN_SCREEN:int = 0;
- public static const EMPLOYEE_LIST:int = 1;
- public static const EMPLOYEE_DETAIL:int = 2;
-
- public static const LOGGED_OUT:int = 0;
- public static const LOGGED_IN:int = 1;
- public static const LOGIN_FAILED:int = 2;
-
- public var mainPage:int = LOGIN_SCREEN;
- public var authState:int = LOGGED_OUT;
- }
-}
View
21 examples/CafeTownsend/src/cafe/view/EmployeeDetail.mxml
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" width="100%"
xmlns:vos="com.cafetownsend.vos.*" xmlns:mate="http://mate.asfusion.com/"
- title="Employee Details" xmlns:model="cafe.model.*">
+ title="Employee Details" xmlns:model="cafe.model.*" xmlns:vo="cafe.vo.*">
<mx:Script>
<![CDATA[
- import cafe.model.Employee;
+ import cafe.vo.Employee;
import mx.events.ValidationResultEvent;
import mx.controls.Alert;
import mx.events.CloseEvent;
import mx.validators.Validator;
[Bindable]
- public var selectedEmployee:cafe.model.Employee;
+ public var selectedEmployee:Employee;
// mutate the back button's click event
private function cancelEmployeeEdits() : void
@@ -46,14 +46,13 @@
- <model:Employee id="tempEmployee">
- <model:firstname>{firstname.text}</model:firstname>
- <model:lastname>{lastname.text}</model:lastname>
- <model:email>{email.text}</model:email>
- <model:startdate>{startdate.selectedDate}</model:startdate>
- <model:emp_id>{selectedEmployee.emp_id}</model:emp_id>
- </model:Employee>
-
+ <vo:Employee id="tempEmployee">
+ <vo:firstname>{firstname.text}</vo:firstname>
+ <vo:lastname>{lastname.text}</vo:lastname>
+ <vo:email>{email.text}</vo:email>
+ <vo:startdate>{startdate.selectedDate}</vo:startdate>
+ <vo:emp_id>{selectedEmployee.emp_id}</vo:emp_id>
+ </vo:Employee>
<mx:Button label="&lt;&lt; Back" click="cancelEmployeeEdits()" />
<mx:Form defaultButton="{submit}">
View
2 examples/CafeTownsend/src/cafe/view/EmployeeList.mxml
@@ -5,7 +5,7 @@
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
- import cafe.model.Employee;
+ import cafe.vo.Employee;
[Bindable]
public var employees:ArrayCollection = null;
View
7 examples/CafeTownsend/src/cafe/view/EmployeeLogin.mxml
@@ -5,7 +5,8 @@
<mx:Script>
<![CDATA[
- import cafe.store.NavigationStore;
+ import cafe.vo.Authentication;
+ import cafe.vo.Navigation;
import mx.core.UIComponent;
import mx.validators.Validator;
import mx.events.ValidationResultEvent;
@@ -26,9 +27,9 @@
}
}
- public function set authState(value:int):void
+ public function set authState(value:String):void
{
- if (value == NavigationStore.LOGIN_FAILED)
+ if (value == Authentication.FAILED)
{
error = true;
}
View
2 examples/CafeTownsend/src/cafe/view/MainUI.mxml
@@ -16,4 +16,4 @@
</mx:ViewStack>
</mx:HBox>
-</mx:VBox>
+</mx:VBox>
View
9 examples/CafeTownsend/src/cafe/vo/Authentication.as
@@ -0,0 +1,9 @@
+package cafe.vo
+{
+ public class Authentication
+ {
+ public static const FAILED:String = "failed";
+ public static const AUTHENTICATED:String = "authenticated";
+ public static const LOGOUT:String = "logout";
+ }
+}
View
41 examples/CafeTownsend/src/cafe/vo/Employee.as
@@ -0,0 +1,41 @@
+package cafe.vo
+{
+
+ [Bindable]
+ public class Employee
+ {
+ /*-.........................................Properties..........................................*/
+ public var emp_id : uint;
+ public var firstname : String;
+ public var lastname : String;
+ public var email : String;
+ public var startdate : Date;
+
+ static public var currentIndex : uint = 1000;
+
+ /*-.........................................Constructor..........................................*/
+ public function Employee( emp_id : uint = 0,
+ firstname : String = "",
+ lastname : String = "",
+ email : String = "",
+ startdate : Date = null )
+ {
+ this.emp_id = ( emp_id == 0 ) ? currentIndex += 1 : emp_id;
+ this.firstname = firstname;
+ this.lastname = lastname;
+ this.email = email;
+ this.startdate = ( startdate == null ) ? new Date() : startdate;
+ }
+
+ /*-.........................................Methods..........................................*/
+ public function copyFrom(newEmployee:Employee):void
+ {
+ this.emp_id = newEmployee.emp_id;
+ this.email = newEmployee.email;
+ this.firstname = newEmployee.firstname;
+ this.lastname = newEmployee.lastname;
+ this.startdate = newEmployee.startdate;
+
+ }
+ }
+}
View
9 examples/CafeTownsend/src/cafe/vo/Navigation.as
@@ -0,0 +1,9 @@
+package cafe.vo
+{
+ public class Navigation
+ {
+ public static const LOGIN:int = 0;
+ public static const LIST:int = 1;
+ public static const DETAILS:int = 2;
+ }
+}

0 comments on commit e7fdca6

Please sign in to comment.