Permalink
Browse files

big changes, refactor, added cafe townsend example

  • Loading branch information...
1 parent db22fb0 commit 91b094a9b964f9349ecb118a1e56711754d92c5c @seanhess committed May 14, 2009
Showing with 740 additions and 133 deletions.
  1. +19 −0 examples/CafeTownsend/src/GlueCafeTownsend.mxml
  2. +38 −0 examples/CafeTownsend/src/assets/data/Employees.xml
  3. BIN examples/CafeTownsend/src/assets/images/header.jpg
  4. +65 −0 examples/CafeTownsend/src/assets/styles/main.css
  5. +56 −0 examples/CafeTownsend/src/cafe/glue/MainGlue.mxml
  6. +30 −0 examples/CafeTownsend/src/cafe/manager/AuthorizationManager.as
  7. +107 −0 examples/CafeTownsend/src/cafe/manager/EmployeeManager.as
  8. +16 −0 examples/CafeTownsend/src/cafe/model/Employee.as
  9. +36 −0 examples/CafeTownsend/src/cafe/service/EmployeeUtils.as
  10. +6 −0 examples/CafeTownsend/src/cafe/service/MockServices.mxml
  11. +13 −0 examples/CafeTownsend/src/cafe/store/EmployeeStore.as
  12. +17 −0 examples/CafeTownsend/src/cafe/store/NavigationStore.as
  13. +91 −0 examples/CafeTownsend/src/cafe/view/EmployeeDetail.mxml
  14. +60 −0 examples/CafeTownsend/src/cafe/view/EmployeeList.mxml
  15. +76 −0 examples/CafeTownsend/src/cafe/view/EmployeeLogin.mxml
  16. +19 −0 examples/CafeTownsend/src/cafe/view/MainUI.mxml
  17. +1 −1 examples/Library/src/GlueLibrary.mxml
  18. +19 −11 examples/Library/src/books/{control → glue}/MainGlue.mxml
  19. +6 −29 examples/Library/src/books/model/Browse.as
  20. +8 −1 examples/Library/src/books/view/MainPagesView.mxml
  21. +11 −1 examples/Library/src/books/view/pages/AuthorPage.mxml
  22. +3 −1 examples/Library/src/books/view/pages/BookPage.mxml
  23. BIN source/bin/Glue.swc
  24. BIN source/libs/Bifff.swc
  25. BIN source/libs/Bifff0.4.b.swc
  26. +6 −7 source/src/manifest.xml
  27. +0 −34 source/src/net/seanhess/glue/Inject.as
  28. +0 −21 source/src/net/seanhess/glue/Observe.as
  29. +0 −13 source/src/net/seanhess/glue/Route.as
  30. +1 −1 source/src/net/seanhess/glue/{ → core}/GlueExecutor.as
  31. +1 −1 source/src/net/seanhess/glue/{ → core}/IGlueAction.as
  32. +3 −2 source/src/net/seanhess/glue/{ → tags}/Glue.as
  33. +9 −3 source/src/net/seanhess/glue/{Controller.as → tags/GlueMap.as}
  34. +16 −0 source/src/net/seanhess/glue/tags/Inject.as
  35. +6 −6 source/src/net/seanhess/glue/{GlueListen.as → tags/Route.as}
  36. +1 −1 source/src/net/seanhess/glue/{ → utils}/Respond.as
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="1024" minHeight="768" xmlns:view="cafe.view.*" xmlns:glue="cafe.glue.*">
+
+ <!-- Styles______________________________________________________ -->
+
+ <mx:Style source="/assets/styles/main.css" />
+
+
+ <!-- Glue Maps __________________________________________________ -->
+
+ <glue:MainGlue/>
+
+
+ <!-- Views _______________________________________________________ -->
+
+ <view:MainUI/>
+
+
+</mx:Application>
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<employees>
+
+ <employee>
+ <emp_id>1</emp_id>
+ <firstname>Sue</firstname>
+ <lastname>Hove</lastname>
+ <email>shove@cafetownsend.com</email>
+ <startdate>01/07/2006</startdate>
+ </employee>
+
+ <employee>
+ <emp_id>2</emp_id>
+ <firstname>Matt</firstname>
+ <lastname>Boles</lastname>
+ <email>mboles@cafetownsend.com</email>
+ <startdate>02/17/2006</startdate>
+ </employee>
+
+ <employee>
+ <emp_id>3</emp_id>
+ <firstname>Mike</firstname>
+ <lastname>Kollen</lastname>
+ <email>mkollen@cafetownsend.com</email>
+ <startdate>03/01/2006</startdate>
+ </employee>
+
+ <employee>
+ <emp_id>4</emp_id>
+ <firstname>Jennifer</firstname>
+ <lastname>Jaegel</lastname>
+ <email>jjaegel@cafetownsend.com</email>
+ <startdate>04/01/2006</startdate>
+ </employee>
+
+ </employees>
+
+
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,65 @@
+/* CSS file */
+Application {
+ backgroundColor: #000000;
+ themeColor: #4E0E02;
+}
+
+Alert {
+ backgroundColor: #FFFFFF;
+ color: #000000;
+}
+
+
+Panel {
+ borderColor: #7A2828;
+ borderThicknessLeft: 1;
+ borderThicknessRight: 1;
+ borderThicknessBottom: 1;
+ borderAlpha: 1;
+
+ paddingTop: 10;
+ paddingLeft: 10;
+ paddingRight: 10;
+ paddingBottom: 10;
+
+ highlightAlphas: 0.67, 0;
+ headerColors: #000000, #993333;
+
+ titleStyleName: "myPanelStyle";
+}
+
+MainUI {
+ horizontalAlign : center;
+}
+
+.mainBody {
+ backgroundColor: #FFFFFF;
+ paddingTop: 20;
+ horizontalAlign : center;
+}
+
+
+EmployeeLogin {
+ horizontalAlign: center;
+}
+
+
+Form, Label, TextInput {
+ color: #000000;
+ font-weight: normal;
+}
+
+FormItem, List {
+ font-weight: bold;
+ text-align: left;
+}
+
+.myPanelStyle {
+ color: #FFFFFF;
+}
+
+.panelText {
+ color: #000000;
+ font-weight: none;
+ text-align: left;
+}
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<GlueMap xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="http://glue.seanhess.net/2009" xmlns:view="cafe.view.*" xmlns:manager="cafe.manager.*" xmlns:business="com.cafetownsend.business.*" xmlns:store="cafe.store.*" xmlns:bifff="http://bifff.seanhess.net/2009" xmlns:service="cafe.service.*">
+ <mx:Script>
+ <![CDATA[
+ import mx.events.FlexEvent;
+ ]]>
+ </mx:Script>
+
+ <!-- Storage -->
+ <store:EmployeeStore id="employees"/>
+ <store:NavigationStore id="navigation"/>
+
+ <!-- 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"/>
+
+ <!-- Views -->
+ <Glue match="MainUI">
+ <Inject selectedPage="{navigation.mainPage}"/>
+ <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)"/>
+ </Glue>
+
+ <Glue match="EmployeeList">
+ <Inject employees="{employees.employeeList}"/>
+ <Route event="logout" call="authManager.logout()"/>
+ <Route event="newEmployee" call="employeeManager.newEmployee()"/>
+ <Route event="selectEmployee" call="employeeManager.selectEmployee(scope.target.selectedEmployee)"/>
+ </Glue>
+
+ <Glue match="EmployeeDetail">
+ <Inject selectedEmployee="{employees.employee}"/>
+ <Route event="back" call="employeeManager.goBack()"/>
+ <Route event="remove" call="employeeManager.deleteEmployee(employees.employee)"/>
+ <Route event="save" call="employeeManager.saveEmployee(view.tempEmployee)"/>
+ </Glue>
+
+
+
+</GlueMap>
@@ -0,0 +1,30 @@
+package cafe.manager
+{
+ import cafe.store.NavigationStore;
+
+ public class AuthorizationManager
+ {
+ public var navigation:NavigationStore;
+
+ public function login(username:String, password:String):Boolean
+ {
+ if (username == 'Flex' && password == 'Glue')
+ {
+ navigation.mainPage = NavigationStore.EMPLOYEE_LIST;
+ navigation.authState = NavigationStore.LOGGED_IN;
+ }
+ else
+ {
+ navigation.authState = NavigationStore.LOGIN_FAILED;
+ }
+
+ return false;
+ }
+
+ public function logout():void
+ {
+ navigation.mainPage = NavigationStore.LOGIN_SCREEN;
+ navigation.authState = NavigationStore.LOGGED_OUT;
+ }
+ }
+}
@@ -0,0 +1,107 @@
+package cafe.manager
+{
+ import cafe.model.Employee;
+ import cafe.service.EmployeeUtils;
+ import cafe.store.EmployeeStore;
+ import cafe.store.NavigationStore;
+
+ 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 var utils:EmployeeUtils;
+ public var loadEmployeeService:HTTPService;
+
+ public function loadEmployees():void
+ {
+ loadEmployeeService.addEventListener(ResultEvent.RESULT, onEmployeesLoaded);
+ loadEmployeeService.addEventListener(FaultEvent.FAULT, onFault);
+ loadEmployeeService.send();
+ }
+
+ private function onFault(event:FaultEvent):void
+ {
+ throw new Error("Fault: "+ event.fault);
+ }
+
+ private function onEmployeesLoaded(event:ResultEvent):void
+ {
+ loadEmployeeService.removeEventListener(ResultEvent.RESULT, onEmployeesLoaded);
+ var employees:Array = utils.loadFromXML(event.result as XML);
+ saveEmpoyeeList(employees);
+ }
+
+ public function goBack():void
+ {
+ navigation.mainPage = NavigationStore.EMPLOYEE_LIST;
+ }
+
+ 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;
+ }
+
+ public function deleteEmployee (employee:Employee) : void
+ {
+ employees.employeeList.removeItemAt(employees.employeeList.getItemIndex(employee));
+ selectEmployee(null);
+ navigation.mainPage = NavigationStore.EMPLOYEE_LIST;
+ }
+
+ public function newEmployee():void
+ {
+ saveEmployee(new Employee());
+ navigation.mainPage = NavigationStore.EMPLOYEE_DETAIL;
+ }
+
+ 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++ ) {
+ // if the emp_id of the incoming employee matches an employee already in the list
+ if ( employeeList[i].emp_id == employee.emp_id ) {
+ // set our ArrayCollection index to that employee position
+ dpIndex = i;
+ }
+ }
+
+ // 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);
+ }
+ // 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);
+
+ employeeList.addItem(tempEmployee);
+ }
+
+ // clear out the selected employee
+ selectEmployee(null);
+ navigation.mainPage = NavigationStore.EMPLOYEE_LIST;
+
+ }
+ }
+}
@@ -0,0 +1,16 @@
+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;
+ }
+}
@@ -0,0 +1,36 @@
+package cafe.service
+{
+ import cafe.model.Employee;
+
+ public class EmployeeUtils
+ {
+ public function loadFromXML(employees:XML):Array
+ {
+ var employeeList:Array = new Array();
+
+ for each( var thisEmployee:XML in employees..employee )
+ {
+ var employee:Employee = new Employee();
+ employee.email = thisEmployee.email;
+ employee.emp_id = thisEmployee.emp_id;
+ employee.firstname = thisEmployee.firstname;
+ employee.lastname = thisEmployee.lastname;
+ employee.startdate = new Date(Date.parse(thisEmployee.startdate));
+
+ employeeList.push(employee);
+ }
+
+ 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;
+ }
+
+ }
+}
@@ -0,0 +1,6 @@
+<?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>
Oops, something went wrong.

0 comments on commit 91b094a

Please sign in to comment.