Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Updated Swiz_CafeTownsend demo
Browse files Browse the repository at this point in the history
Now uses [BabelFx-for-Swiz](https://github.com/BabelFx/AS3-BabelFx-for-Swiz) library
Updated Constants to use [BabelFx()] tags and injection
Updated LoginView, MainView
- now uses [BabelFx(event="BabelFxEvent.*)] to invoke view handler when locales or parameters change.
  • Loading branch information
ThomasBurleson committed Aug 14, 2012
1 parent b99b1a4 commit 82287d1
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 79 deletions.
3 changes: 2 additions & 1 deletion swiz_cafeTownsend/src/com/cafetownsend/config/SwizSetup.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
]]>
</fx:Script>


<sw:beanProviders>
<config:Beans xmlns:config="com.cafetownsend.config.*" />
</sw:beanProviders>

<sw:config>
<sw:SwizConfig id="appConfig"
strict="true"
eventPackages="com.cafetownsend.event.*"
eventPackages="com.cafetownsend.event.*,ext.babelfx.events.*"
viewPackages="com.cafetownsend.view.*,l10n.views.*"
defaultFaultHandler="{genericFault}"/>
</sw:config>
Expand Down
83 changes: 26 additions & 57 deletions swiz_cafeTownsend/src/com/cafetownsend/model/Constants.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,50 @@ package com.cafetownsend.model
{
import com.cafetownsend.domain.Employee;

import ext.babelfx.events.BabelEvent;
import flash.events.Event;

import mx.resources.IResourceManager;
import mx.resources.ResourceManager;

import spark.effects.easing.IEaser;
import spark.effects.easing.Power;

[l10n(change="onLocaleChanged")]
// ***********************************************************
// MetaData - BabelFx Localization tags
// ***********************************************************

[ l10n ( bundle="login", property="LOGIN_FAILED_MESSAGE", key="login.error.noMatch" )]
[ l10n ( bundle="login", property="LOGIN_FAILED_TITLE", key="login.error.title" )]
[ l10n ( bundle="login", property="LOGIN_INVALID_USERNAME", key="login.error.usernameRequired" )]
[ l10n ( bundle="login", property="LOGIN_INVALID_PASSWORD", key="login.error.passwordRequired" )]

[ l10n ( bundle="employees", property="EMPLOYEE_LOAD_ERROR", key="users.unableToLoad" )]
[ l10n ( bundle="employees", property="EMPLOYEE_INVALID_FIRSTNAME", key="editor.invalid.firstName" )]
[ l10n ( bundle="employees", property="EMPLOYEE_INVALID_LASTNAME", key="editor.invalid.lastName" )]
[ l10n ( bundle="employees", property="EMPLOYEE_CONFIRM_DELETE", key="users.confirmDelete", parameters="employee.firstName, employee.lastName" )]


[Bindable]
public class Constants
{
public var EMPLOYEE_INVALID_FIRSTNAME : String = "Please enter first name.";
public var EMPLOYEE_INVALID_LASTNAME : String = "Please enter last name.";
public var LOGIN_FAILED_TITLE : String = "Login Failed!";
public var LOGIN_FAILED_MESSAGE : String = "Username/Password do not match!";
public var LOGIN_INVALID_USERNAME : String = "Please enter your username!";
public var LOGIN_INVALID_PASSWORD : String = "Please enter your password!";

public var EMPLOYEE_LOAD_ERROR : String = "Unable to get loaded data of employees: {0}";
public var EMPLOYEE_INVALID_FIRSTNAME : String = "Please enter first name.";
public var EMPLOYEE_INVALID_LASTNAME : String = "Please enter last name.";
public var EMPLOYEE_CONFIRM_DELETE : String = 'Are you sure you want to delete "{0} {1}"?';

public var LOGIN_INVALID_USERNAME : String = "Please enter your username!";
public var LOGIN_INVALID_PASSWORD : String = "Please enter your password!";

public var LOGIN_FAILED_TITLE : String = "Login Failed!";
public var LOGIN_FAILED_MESSAGE : String = "Username/Password do not match!";

public var EMPLOYEE_LOAD_ERROR : String = "Unable to get loaded data of employees: {0}";
public var EMPLOYEE_CONFIRM_DELETE : String = 'Are you sure you want to delete "{0} {1}"?';

// effects
public const EFFECT_DURATION : int = 400;
public const EFFECT_EASE : IEaser = new Power( 0.30 );

/**
* To support l10n injection into non-displayObjects (e.g. data models)
* the LocaleMap must have instance references. So we use Swiz to inject
* a reference to each model bean instance that will be used or modified
* when locales change.
*
*/

[Inject("employeeModel.selectedEmployee")]
public function set selectedEmployee(value:Employee):void {
_selectedEmployee = value;
EMPLOYEE_CONFIRM_DELETE = buildConfirmMessage();
}
public var employee : Employee;


/**
* Whenever the locale changes
*/
public function onLocaleChanged(event:BabelEvent):void
{
/**
* l10nInjection supports injection into both GUI and non-GUI instances (data models,
* controllers, etc). But static variables cannot be directly modifed with injection.
* We must hook into the localeChanged event and then manually update the static globals
* with current locale value [shown below]:
*/
LOGIN_FAILED_MESSAGE = rMngr.getString("login","login.error.noMatch");
LOGIN_FAILED_TITLE = rMngr.getString("login","login.error.title");
LOGIN_INVALID_USERNAME = rMngr.getString("login","login.error.usernameRequired");
LOGIN_INVALID_PASSWORD = rMngr.getString("login","login.error.passwordRequired");

EMPLOYEE_LOAD_ERROR = rMngr.getString("employees","users.unableToLoad");
EMPLOYEE_INVALID_FIRSTNAME = rMngr.getString("employees","editor.invalid.firstName");
EMPLOYEE_INVALID_LASTNAME = rMngr.getString("employees","editor.invalid.lastName") ;
EMPLOYEE_CONFIRM_DELETE = buildConfirmMessage();
}

private function buildConfirmMessage():String {
var params : Array = _selectedEmployee ? [_selectedEmployee.firstName, _selectedEmployee.lastName] : ["",""];
return rMngr.getString("employees","users.confirmDelete",params);
}

private function get rMngr() : IResourceManager
{
return ResourceManager.getInstance();
}

private var _selectedEmployee : Employee;
}
}
21 changes: 11 additions & 10 deletions swiz_cafeTownsend/src/com/cafetownsend/view/LoginView.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

<fx:Metadata>

[l10n( bundle="login", change="onLocaleChanged" )]

[l10n( property="fiUserName.label", key="login.form.fiUserName" )]
[l10n( property="fiPassword.label", key="login.form.fiPassword" )]
[l10n( property="loginBtn.label", key="login.submit" )]
[l10n( property="lblHint.text", key="login.tip" )]
[l10n( property="loginBtn.backgroundColor", key="content.frame.color" )]
[ l10n ( "login" )]
[ l10n ( property="fiUserName.label", key="login.form.fiUserName" )]
[ l10n ( property="fiPassword.label", key="login.form.fiPassword" )]
[ l10n ( property="loginBtn.label", key="login.submit" )]
[ l10n ( property="lblHint.text", key="login.tip" )]
[ l10n ( property="loginBtn.backgroundColor", key="content.frame.color" )]

</fx:Metadata>

<fx:Script>
<![CDATA[
import com.cafetownsend.presentation.LoginPresentationModel;
import ext.babelfx.events.BabelEvent;
import ext.babelfx.events.BabelFxEvent;
[Bindable]
[Inject]
Expand All @@ -33,14 +33,15 @@
model.login(username.text, password.text)
}
[BabelFx(event="BabelFxEvent.*")]
/**
* Whenever the locale changes
*/
public function onLocaleChanged(event:BabelEvent):void
public function onLocaleChanged(event:BabelFxEvent):void
{
if ( loginBtn ) loginBtn.skin.invalidateProperties();
if ( event.type == BabelEvent.LOCALE_CHANGED )
if ( event.type == BabelFxEvent.LOCALE_CHANGED )
{
if ( loginErrorTxt ) loginErrorTxt.text = "";
Expand Down
22 changes: 13 additions & 9 deletions swiz_cafeTownsend/src/com/cafetownsend/view/MainView.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

<fx:Metadata>

[l10n ( bundle="login", change="onLocaleChanged")]

[l10n ( property="btnLogout.label", key="login.signOut" )]
[l10n ( property="txtWelcomeUser.text", key="login.welcome", parameters="authenticated.user.username" )]
[l10n ( property="imgHeader.source", key="login.header", content="class" )]
[l10n ( property="contentContainer.backgroundColor", key="content.background.color" )]
[l10n ( property="contentFrame.color", key="content.frame.color" )]
[l10n ( property="btnLogout.backgroundColor", key="content.frame.color" )]
[ l10n ( bundle="login" ) ]
[ l10n ( property="btnLogout.label", key="login.signOut" )]
[ l10n ( property="txtWelcomeUser.text", key="login.welcome", parameters="authenticated.user.username" )]
[ l10n ( property="imgHeader.source", key="login.header", content="class" )]
[ l10n ( property="contentContainer.backgroundColor", key="content.background.color" )]
[ l10n ( property="contentFrame.color", key="content.frame.color" )]
[ l10n ( property="btnLogout.backgroundColor", key="content.frame.color" )]

</fx:Metadata>

Expand All @@ -26,6 +26,8 @@
import com.cafetownsend.model.AppModel;
import com.cafetownsend.model.Constants;
import com.cafetownsend.presentation.MainViewPresentationModel;
import ext.babelfx.events.BabelFxEvent;
protected static const PADDING:int=15;
Expand All @@ -37,10 +39,12 @@
[Bindable] [Inject] public var authenticated: AppModel;
[Bindable] [Inject] public var constants : Constants;
[BabelFx(event="BabelFxEvent.LOCALE_CHANGED")]
/**
* Whenever the locale changes
*/
public function onLocaleChanged(event:Event):void
public function onLocaleChanged(event:BabelFxEvent):void
{
btnLogout.skin.invalidateProperties();
}
Expand Down
4 changes: 2 additions & 2 deletions swiz_cafeTownsend/src/l10n/views/LanguageBar.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<fx:Script>
<![CDATA[
import ext.babelfx.events.BabelEvent;
import ext.babelfx.events.BabelFxEvent;
import l10n.views.assets.LocaleAssets;
Expand Down Expand Up @@ -79,7 +79,7 @@
// Dispatch an l10nInjection event to trigger locale switching
// Then notify any watchers that the locale value has changed...
dispatcher.dispatchEvent(new BabelEvent(BabelEvent.LOAD_LOCALE,_locale));
dispatcher.dispatchEvent(new BabelFxEvent(BabelFxEvent.LOAD_LOCALE,_locale));
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"selectedLocale",null,_locale));
}
Expand Down

0 comments on commit 82287d1

Please sign in to comment.